2 * Copyright IBM Corp 2007
3 * Author: Hans-Joachim Picht <hans@linux.vnet.ibm.com>
5 * Linux for System z Hotplug Daemon
7 * This file is used to parse the command line arguments
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 void print_usage(int is_error
, char program_name
[]);
40 void parse_options(int argc
, char **argv
)
42 int config_file_specified
= -1;
43 const struct option long_options
[] = {
44 { "help", no_argument
, NULL
, 'h'},
45 { "foreground", no_argument
, NULL
, 'f' },
46 { "config", required_argument
, NULL
, 'c' },
47 { "version", no_argument
, NULL
, 'v' },
48 { "verbose", no_argument
, NULL
, 'V' },
52 /* dont run without any argument */
53 if (argc
== 0 || argc
== 1)
54 print_usage(0, argv
[0]);
55 while (optind
< argc
) {
57 struct option
*opt
= 0;
58 int result
= getopt_long(argc
, argv
, "hfc:vVm",
59 long_options
, &index
);
61 break; /* end of list */
64 print_usage(0, argv
[0]);
71 * this prevents -cbla and enforces the
72 * user to specify -c bla
74 if (strcmp(argv
[optind
-1], optarg
) == 0) {
76 config_file_specified
= 1;
78 printf("Unrecognized option: %s\n", optarg
);
89 /* all parameter that do not
90 appear in the optstring */
91 opt
= (struct option
*)&(long_options
[index
]);
92 printf("'%s' was specified.",
94 if (opt
->has_arg
== required_argument
)
95 printf("Arg: <%s>", optarg
);
99 printf("Try '%s' --help' for more information.\n",
104 /* we also run in this case if no argument was s
108 print_usage(0, argv
[0]);
111 if (config_file_specified
== -1) {
112 printf("You have to specify a configuration file!\n");
113 printf("Try '%s' --help' for more information.\n", argv
[0]);