+
+static void print_version(void)
+{
+ printf("pb-discover (" PACKAGE_NAME ") " PACKAGE_VERSION "\n");
+}
+
+static void print_usage(void)
+{
+ print_version();
+ printf(
+"Usage: pb-discover [-h, --help] [-l, --log log-file] [-V, --version]\n");
+}
+
+/**
+ * enum opt_value - Tri-state options variables.
+ */
+
+enum opt_value {opt_undef = 0, opt_yes, opt_no};
+
+/**
+ * struct opts - Values from command line options.
+ */
+
+struct opts {
+ enum opt_value show_help;
+ const char *log_file;
+ enum opt_value show_version;
+};
+
+/**
+ * opts_parse - Parse the command line options.
+ */
+
+static int opts_parse(struct opts *opts, int argc, char *argv[])
+{
+ static const struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"log", required_argument, NULL, 'l'},
+ {"version", no_argument, NULL, 'V'},
+ { NULL, 0, NULL, 0},
+ };
+ static const char short_options[] = "hl:V";
+ static const struct opts default_values = {
+ .log_file = "pb-discover.log",
+ };
+
+ *opts = default_values;
+
+ while (1) {
+ int c = getopt_long(argc, argv, short_options, long_options,
+ NULL);
+
+ if (c == EOF)
+ break;
+
+ switch (c) {
+ case 'h':
+ opts->show_help = opt_yes;
+ break;
+ case 'l':
+ opts->log_file = optarg;
+ break;
+ case 'V':
+ opts->show_version = opt_yes;
+ break;
+ default:
+ opts->show_help = opt_yes;
+ return -1;
+ }
+ }
+
+ return optind != argc;
+}