+
+/* Command-line parser */
+
+static void
+load_default(void)
+{
+ if (cf_def_file)
+ if (cf_load(cf_def_file))
+ die("Cannot load default config %s", optarg);
+}
+
+int
+cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index)
+{
+ static int other_options = 0;
+ while (1) {
+ int res = getopt_long (argc, argv, short_opts, long_opts, long_index);
+ if (res == 'S' || res == 'C')
+ {
+ if (other_options)
+ die("The -S and -C options must precede all other arguments");
+ if (res == 'S') {
+ load_default();
+ if (cf_set(optarg))
+ die("Cannot set %s", optarg);
+ } else {
+ if (cf_load(optarg))
+ die("Cannot load %s", optarg);
+ }
+ } else {
+ /* unhandled option or end of options */
+ load_default();
+ other_options++;
+ return res;
+ }
+ }
+}