l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Mar 30 01:42

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] writing free getopt, ran into a dilemma...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] writing free getopt, ran into a dilemma...

On 28 Mar 2002, Micah Cowan wrote:

> Permuting is probably the easiest way to go; but another alternative
> would be to create another function, increment_optind(), instead of
> doing ++optind.  This function could then automatically skip options.

increment_optind() sounds excellent!  Thanks!

> Oh, but you mentioned it doesn't currently even handle the middle
> options (which is what I thought the point was for your getopt()?).

I'm not sure what you mean by "middle options"...  It currently behaves
exactly like GNU getopt as far as required arguments (as in "o:") and
non-option arguments (as in "-") except it doesn't permute[1] argv and
optind doesn't work like GNU getopt.  I don't use optional arguments
(which I believe is a GNU extension) but I'll implement it if I knew how
to use it :)  And... I don't think there's anything else, is there???

Oh, my code does handle "--" :)

> You'd still need
> increment_optind()---or you could break getopt()'s parameter list by
> passing back the allocated string (make sure it gets freed
> somewhere...).

My original version of getopt allocated an array that is the same size as
argc+1, but I realized freeing it becomes a problem (don't wanna use
atexit(), and wanna keep compatibility so don't wanna use a cleanup
function call).  I modified the program to not use allocation at all.

> If you email me the code, I'd be happy to comment on it (comp.lang.c is
> a hobby of mine, though one I haven't gotten around to lately).  I won't
> get to it this weekend, though, since I'll be out of town (and away from
> email).

I'm gonna work on the code some more and send you a copy for a review.
Maybe I'll just put up a copy on my website.  Thanks, Micah!


[1] - Thank you for bringing up the proper vocabulary :)

Mark K. Kim
PGP key available upon request.

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.