arg-parser-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Arg-parser-bug] Option to return non option char pointer in arg_par


From: Antonio Diaz Diaz
Subject: Re: [Arg-parser-bug] Option to return non option char pointer in arg_parser?
Date: Tue, 15 Dec 2015 13:56:08 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.8.1.4) Gecko/20070601 SeaMonkey/1.1.2

Hello Javier,

Javier López wrote:
So for example if the utility receives

    $ app --option "option_string" extra_arg

And --option is defined as an 'ap_yes' option, then this new
hypothetical new function would return a pointer to a "extra_arg"
string.

You can already obtain a pointer to "extra_arg" with "ap_argument( parser, 1 )":

------------------------------------------------------------------------
http://www.nongnu.org/arg-parser/manual/arg_parser_manual.html#C-version
-- Function: const char * ap_argument ( const struct Arg_parser * const ap, const int i )

This function returns the argument at position i. It may be the argument of an option or a non-option argument, depending on the value returned by ap_code(i). Valid values for i range from 0 to ap_arguments() - 1.
------------------------------------------------------------------------


Right now I'm going through argv and comparing arguments to see if
it's a defined option, however that doesn't feel right.

See the file 'cmain.c' in the Arg_parser distribution for an example of use:

  for( argind = 0; argind < ap_arguments( &parser ); ++argind )
    {
    const int code = ap_code( &parser, argind );
    const char * const arg = ap_argument( &parser, argind );
    if( code )  /* option */
    [...]
    else        /* non-option */
      printf( "non-option argument '%s'", arg );
    printf( "\n" );
    }


Best regards,
Antonio.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]