Back to index

glibc  2.9
argp-ex2.c
Go to the documentation of this file.
00001 /* Argp example #2 -- a pretty minimal program using argp */
00002 
00003 /* This program doesn't use any options or arguments, but uses
00004    argp to be compliant with the GNU standard command line
00005    format.
00006 
00007    In addition to making sure no arguments are given, and
00008    implementing a --help option, this example will have a
00009    --version option, and will put the given documentation string
00010    and bug address in the --help output, as per GNU standards.
00011 
00012    The variable ARGP contains the argument parser specification;
00013    adding fields to this structure is the way most parameters are
00014    passed to argp_parse (the first three fields are usually used,
00015    but not in this small program).  There are also two global
00016    variables that argp knows about defined here,
00017    ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
00018    global variables because they will almost always be constant
00019    for a given program, even if it uses different argument
00020    parsers for various tasks).  */
00021 
00022 #include <argp.h>
00023 
00024 const char *argp_program_version =
00025   "argp-ex2 1.0";
00026 const char *argp_program_bug_address =
00027   "<bug-gnu-utils@@gnu.org>";
00028 
00029 /* Program documentation.  */
00030 static char doc[] =
00031   "Argp example #2 -- a pretty minimal program using argp";
00032 
00033 /* Our argument parser.  The @code{options}, @code{parser}, and
00034    @code{args_doc} fields are zero because we have neither options or
00035    arguments; @code{doc} and @code{argp_program_bug_address} will be
00036    used in the output for @samp{--help}, and the @samp{--version}
00037    option will print out @code{argp_program_version}.  */
00038 static struct argp argp = { 0, 0, 0, doc };
00039 
00040 int main (int argc, char **argv)
00041 {
00042   argp_parse (&argp, argc, argv, 0, 0, 0);
00043   exit (0);
00044 }