1 /*
2 File autogenerated by gengetopt version 2.3
3 generated with the following command:
4 gengetopt --file-name=demo_info_options --unamed-opts --input=demo_info_options.ggo
5
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
9 */
10
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 /* If we use autoconf. */
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 /* Check for configure's getopt check result. */
20 #ifndef HAVE_GETOPT_LONG
21 #include "getopt.h"
22 #else
23 #include <getopt.h>
24 #endif
25
26 #include "demo_info_options.h"
27
28
29 void
cmdline_parser_print_version(void)30 cmdline_parser_print_version (void)
31 {
32 printf ("%s %s\n", PACKAGE, VERSION);
33 }
34
35 void
cmdline_parser_print_help(void)36 cmdline_parser_print_help (void)
37 {
38 cmdline_parser_print_version ();
39 printf("\n"
40 "Usage: %s [OPTIONS]... [FILES]...\n\
41 -h --help Print help and exit\n\
42 -V --version Print version and exit\n\
43 -a --assign Test the assignment operator (default=off)\n\
44 -w --warning Turn on warnings (for debugging) (default=off)\n\
45 -n --notice Turn on notices (for debugging) (default=off)\n\
46 ", PACKAGE);
47 }
48
49
50 static char *
gengetopt_strdup(char * s)51 gengetopt_strdup (char * s)
52 {
53 char * n, * pn, * ps = s;
54 while (*ps) ps++;
55 n = (char *) malloc (1 + ps - s);
56 if (n != NULL)
57 {
58 for (ps=s,pn=n; *ps; ps++,pn++)
59 *pn = *ps;
60 *pn = 0;
61 }
62 return n;
63 }
64
65
66 int
cmdline_parser(int argc,char * const * argv,struct gengetopt_args_info * args_info)67 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
68 {
69 int c; /* Character of the parsed option. */
70 int missing_required_options = 0;
71
72 args_info->help_given = 0 ;
73 args_info->version_given = 0 ;
74 args_info->assign_given = 0 ;
75 args_info->warning_given = 0 ;
76 args_info->notice_given = 0 ;
77 #define clear_args() { \
78 args_info->assign_flag = 0;\
79 args_info->warning_flag = 0;\
80 args_info->notice_flag = 0;\
81 }
82
83 clear_args();
84
85 args_info->inputs = NULL;
86 args_info->inputs_num = 0;
87
88 while (1)
89 {
90 int option_index = 0;
91 static struct option long_options[] = {
92 { "help", 0, NULL, 'h' },
93 { "version", 0, NULL, 'V' },
94 { "assign", 0, NULL, 'a' },
95 { "warning", 0, NULL, 'w' },
96 { "notice", 0, NULL, 'n' },
97 { NULL, 0, NULL, 0 }
98 };
99
100 c = getopt_long (argc, argv, "hVawn", long_options, &option_index);
101
102 if (c == -1) break; /* Exit from `while (1)' loop. */
103
104 switch (c)
105 {
106 case 'h': /* Print help and exit. */
107 clear_args ();
108 cmdline_parser_print_help ();
109 exit (0);
110
111 case 'V': /* Print version and exit. */
112 clear_args ();
113 cmdline_parser_print_version ();
114 exit (0);
115
116 case 'a': /* Test the assignment operator. */
117 args_info->assign_flag = !(args_info->assign_flag);
118 break;
119
120 case 'w': /* Turn on warnings (for debugging). */
121 args_info->warning_flag = !(args_info->warning_flag);
122 break;
123
124 case 'n': /* Turn on notices (for debugging). */
125 args_info->notice_flag = !(args_info->notice_flag);
126 break;
127
128 case 0: /* Long option with no short option */
129
130 case '?': /* Invalid option. */
131 /* `getopt_long' already printed an error message. */
132 exit (1);
133
134 default: /* bug: option not considered. */
135 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
136 abort ();
137 } /* switch */
138 } /* while */
139
140 if ( missing_required_options )
141 exit (1);
142
143 if (optind < argc)
144 {
145 int i = 0 ;
146
147 args_info->inputs_num = argc - optind ;
148 args_info->inputs =
149 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
150 while (optind < argc)
151 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
152 }
153
154 return 0;
155 }
156