argp-ex2.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #if (defined(__GLIBC__) && !defined(__UCLIBC__)) || defined(__UCLIBC_HAS_ARGP__)
  20. #include <argp.h>
  21. const char *argp_program_version =
  22. "argp-ex2 1.0";
  23. const char *argp_program_bug_address =
  24. "<bug-gnu-utils@@gnu.org>";
  25. /* Program documentation. */
  26. static char doc[] =
  27. "Argp example #2 -- a pretty minimal program using argp";
  28. /* Our argument parser. The @code{options}, @code{parser}, and
  29. @code{args_doc} fields are zero because we have neither options or
  30. arguments; @code{doc} and @code{argp_program_bug_address} will be
  31. used in the output for @samp{--help}, and the @samp{--version}
  32. option will print out @code{argp_program_version}. */
  33. static struct argp argp = { 0, 0, 0, doc };
  34. #endif
  35. int main (int argc, char **argv)
  36. {
  37. #if (defined(__GLIBC__) && !defined(__UCLIBC__)) || defined(__UCLIBC_HAS_ARGP__)
  38. argp_parse (&argp, argc, argv, 0, 0, 0);
  39. exit (0);
  40. #else
  41. return 23;
  42. #endif
  43. }