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