argp-ex2.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Argp example #2 -- a pretty minimal program using argp */
  2. /* This program doesn't use any options or arguments, but uses
  3. argp to be compliant with the GNU standard command line
  4. format.
  5. In addition to making sure no arguments are given, and
  6. implementing a --help option, this example will have a
  7. --version option, and will put the given documentation string
  8. and bug address in the --help output, as per GNU standards.
  9. The variable ARGP contains the argument parser specification;
  10. adding fields to this structure is the way most parameters are
  11. passed to argp_parse (the first three fields are usually used,
  12. but not in this small program). There are also two global
  13. variables that argp knows about defined here,
  14. ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
  15. global variables because they will almost always be constant
  16. for a given program, even if it uses different argument
  17. parsers for various tasks). */
  18. #include <stdlib.h>
  19. #include <argp.h>
  20. const char *argp_program_version =
  21. "argp-ex2 1.0";
  22. const char *argp_program_bug_address =
  23. "<bug-gnu-utils@@gnu.org>";
  24. /* Program documentation. */
  25. static char doc[] =
  26. "Argp example #2 -- a pretty minimal program using argp";
  27. /* Our argument parser. The @code{options}, @code{parser}, and
  28. @code{args_doc} fields are zero because we have neither options or
  29. arguments; @code{doc} and @code{argp_program_bug_address} will be
  30. used in the output for @samp{--help}, and the @samp{--version}
  31. option will print out @code{argp_program_version}. */
  32. static struct argp argp = { 0, 0, 0, doc };
  33. int main (int argc, char **argv)
  34. {
  35. argp_parse (&argp, argc, argv, 0, 0, 0);
  36. exit (0);
  37. }