Section 26.6. Parsing Argument Strings

   


26.6. Parsing Argument Strings

Although popt is usually used for parsing arguments already divided into an argv-style array, some programs need to parse strings that are formatted identically to command lines. To facilitate this, popt provides a function that parses a string into an array of string, using rules similar to normal shell parsing.

 #include <popt.h> int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); 


The string s is parsed into an argv-style array. The integer pointed to by the second parameter, argcPtr, contains the number of elements parsed, and the pointer pointed to by the final parameter is set to point to the newly created array. The array is dynamically allocated and should be free() ed when the application is finished with it.

The argvPtr created by poptParseArgvString() is suitable to pass directly to poptGetContext().[9]

[9] This is often a good time to use POPT_CONTEXT_KEEP_FIRST.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net