+static int get_integer_opt (const char *str, int *ret_value) /* {{{ */
+{
+ char *endptr;
+ int tmp;
+
+ errno = 0;
+ endptr = NULL;
+ tmp = (int) strtol (str, &endptr, /* base = */ 0);
+ if (errno != 0)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\": %s\n",
+ str, strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+ else if (endptr == str)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+ else if (*endptr != 0)
+ {
+ fprintf (stderr, "Garbage after end of value: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+
+ *ret_value = tmp;
+ return (0);
+} /* }}} int get_integer_opt */
+
+static int get_double_opt (const char *str, double *ret_value) /* {{{ */
+{
+ char *endptr;
+ double tmp;
+
+ errno = 0;
+ endptr = NULL;
+ tmp = strtod (str, &endptr);
+ if (errno != 0)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\": %s\n",
+ str, strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+ else if (endptr == str)
+ {
+ fprintf (stderr, "Unable to parse option as a number: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+ else if (*endptr != 0)
+ {
+ fprintf (stderr, "Garbage after end of value: \"%s\"\n", str);
+ exit (EXIT_FAILURE);
+ }
+
+ *ret_value = tmp;
+ return (0);
+} /* }}} int get_double_opt */
+
+static int read_options (int argc, char **argv) /* {{{ */
+{
+ int opt;
+
+ while ((opt = getopt (argc, argv, "n:H:p:i:d:D:h")) != -1)
+ {
+ switch (opt)
+ {
+ case 'n':
+ get_integer_opt (optarg, &conf_num_values);
+ break;
+
+ case 'H':
+ get_integer_opt (optarg, &conf_num_hosts);
+ break;
+
+ case 'p':
+ get_integer_opt (optarg, &conf_num_plugins);
+ break;
+
+ case 'i':
+ get_double_opt (optarg, &conf_interval);
+ break;
+
+ case 'd':
+ conf_destination = optarg;
+ break;
+
+ case 'D':
+ conf_service = optarg;
+ break;
+
+ case 'h':
+ exit_usage (EXIT_SUCCESS);
+
+ default:
+ exit_usage (EXIT_FAILURE);
+ } /* switch (opt) */
+ } /* while (getopt) */
+
+ return (0);
+} /* }}} int read_options */
+