argp-ex2.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Argp example #2 -- a pretty minimal program using argp
  2. Copyright (C) 1991-2019 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /* This program doesn't use any options or arguments, but uses
  15. argp to be compliant with the GNU standard command line
  16. format.
  17. In addition to making sure no arguments are given, and
  18. implementing a --help option, this example will have a
  19. --version option, and will put the given documentation string
  20. and bug address in the --help output, as per GNU standards.
  21. The variable ARGP contains the argument parser specification;
  22. adding fields to this structure is the way most parameters are
  23. passed to argp_parse (the first three fields are usually used,
  24. but not in this small program). There are also two global
  25. variables that argp knows about defined here,
  26. ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
  27. global variables because they will almost always be constant
  28. for a given program, even if it uses different argument
  29. parsers for various tasks). */
  30. #include <stdlib.h>
  31. #include <argp.h>
  32. const char *argp_program_version =
  33. "argp-ex2 1.0";
  34. const char *argp_program_bug_address =
  35. "<bug-gnu-utils@@gnu.org>";
  36. /* Program documentation. */
  37. static char doc[] =
  38. "Argp example #2 -- a pretty minimal program using argp";
  39. /* Our argument parser. The @code{options}, @code{parser}, and
  40. @code{args_doc} fields are zero because we have neither options or
  41. arguments; @code{doc} and @code{argp_program_bug_address} will be
  42. used in the output for @samp{--help}, and the @samp{--version}
  43. option will print out @code{argp_program_version}. */
  44. static struct argp argp = { 0, 0, 0, doc };
  45. int
  46. main (int argc, char **argv)
  47. {
  48. argp_parse (&argp, argc, argv, 0, 0, 0);
  49. exit (0);
  50. }