]>
Commit | Line | Data |
---|---|---|
d9a17c07 | 1 | /* Argp example #2 -- a pretty minimal program using argp |
dff8da6b | 2 | Copyright (C) 1991-2024 Free Software Foundation, Inc. |
d9a17c07 RM |
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 | |
5a82c748 | 15 | along with this program; if not, see <https://www.gnu.org/licenses/>. |
d9a17c07 | 16 | */ |
714a562f | 17 | |
052b6a6c UD |
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 | |
9442cd75 | 33 | global variables because they will almost always be constant |
052b6a6c UD |
34 | for a given program, even if it uses different argument |
35 | parsers for various tasks). */ | |
36 | ||
35c47e37 | 37 | #include <stdlib.h> |
714a562f UD |
38 | #include <argp.h> |
39 | ||
40 | const char *argp_program_version = | |
41 | "argp-ex2 1.0"; | |
42 | const char *argp_program_bug_address = | |
052b6a6c | 43 | "<bug-gnu-utils@@gnu.org>"; |
714a562f UD |
44 | |
45 | /* Program documentation. */ | |
46 | static char doc[] = | |
47 | "Argp example #2 -- a pretty minimal program using argp"; | |
48 | ||
49c091e5 | 49 | /* Our argument parser. The @code{options}, @code{parser}, and |
714a562f UD |
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 | ||
09c093b5 RK |
56 | int |
57 | main (int argc, char **argv) | |
714a562f UD |
58 | { |
59 | argp_parse (&argp, argc, argv, 0, 0, 0); | |
60 | exit (0); | |
61 | } |