An unnamed Administration source, Ben Duncan, wrote:
> Ok, now for my question of the day.
> After 18 years in UNIX and 8 in linux, started getting serious on
> developing my C skills. Most of revolves around Appgen stuff.
> 
> Anyway, I wrote a C program to tell me what kind of application an
> Appgen program is.  Program is called typeprog. To wit:
> 
> typeprog PDEF.OE07000
> 
> returns:
> 
> "Program PDEF.OE070000 is a Maint and uses OE-INVCE file."
> 
> Now, I would like to xpand that to use something like
> 
> "typeprog `ls PDEF.IV*`  "  or      " ls PDEF.IV | typeprog"
> 
> as well.
> 
> Now, I know argv[1] gives me the program name, but how do I go about
> xpanding that to use the latter style as well as the first and determine 
> which
>  I have incoming and to walk the list given by the latter?

Method 1: Parse the input yourself, reading stdin until you get to 
a newline character ('\n'). Meanwhile, store the input in a buffer. 
After you get the newline, go back and parse the buffer, looking for 
the tokens you want. This is the hard way.

Method 2: Keep reading argv[n] until it returns NULL, at which point,
there's nothing else on the command line. Meanwhile, when argv[n]
has somethiny you are looking for, branch, do what needs to be done,
then go back to processing argv. Easier than Method 1.

Method 3: Use the getopt() library call. In this case, getopt_long()
might be more useful for parsing multi-character command line arguments.
See "man 3 getopt" and/or "man 3 getopt_long".

Method 4: Use popt(). It is getopt on steroids, and has the additional
ability to store filters for command line options in an external file,
thus allowing you to extend your command line option processing without
having to modify/rebuild your program. popt() and friends should be
available on any system that is RPM-based.

Kurt
-- 
But soft you, the fair Ophelia:
Ope not thy ponderous and marble jaws,
But get thee to a nunnery -- go!
                -- Mark "The Bard" Twain
_______________________________________________
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc -> http://www.linux-sxs.org/mailman/listinfo/linux-users

Reply via email to