+/*** Options ***/
+
+static int num_lines = 4;
+static char *font_name = "-bitstream-bitstream vera sans-bold-r-normal-*-*-320-*-*-p-*-*";
+static char *default_color = "green";
+static char *default_outline_color = "black";
+static int default_duration = 1000;
+static int default_min_duration = 250;
+static int debug_mode;
+
+static const char short_opts[] = "c:d:Df:l:m:o:";
+
+static const struct option long_opts[] = {
+ { "color", required_argument, NULL, 'c' },
+ { "debug", no_argument, NULL, 'D' },
+ { "duration", required_argument, NULL, 'd' },
+ { "font", required_argument, NULL, 'f' },
+ { "lines", required_argument, NULL, 'l' },
+ { "min-duration", required_argument, NULL, 'm' },
+ { "outline-color", required_argument, NULL, 'o' },
+ { NULL, 0, NULL, 0 },
+};
+
+static void NONRET
+usage(void)
+{
+ fprintf(stderr, "Usage: osdd <options>\n\n\
+Options:\n\
+-c, --color=<c>\t\tDefault color (#rgb, #rrggbb or a name from rgb.txt)\n\
+-D, --debug\t\tDebugging mode (do not detach from the terminal)\n\
+-d, --duration=<ms>\tDefault message duration in milliseconds\n\
+-f, --font=<f>\t\tFont to use for the OSD\n\
+-l, --lines=<n>\t\tNumber of lines of the OSD\n\
+-m, --min-duration=<ms>\tDefault minimum message duration in milliseconds\n\
+-o, --outline-color=<c>\tDefault outline color\n\
+");
+ exit(1);
+}
+
+static void
+parse_opts(int argc, char **argv)
+{
+ int opt;
+ while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) >= 0)
+ switch (opt)
+ {
+ case 'c':
+ default_color = optarg;
+ break;
+ case 'd':
+ default_duration = atoi(optarg);
+ break;
+ case 'D':
+ debug_mode = 1;
+ break;
+ case 'f':
+ font_name = optarg;
+ break;
+ case 'l':
+ num_lines = atoi(optarg);
+ if (num_lines < 1)
+ usage();
+ break;
+ case 'm':
+ default_min_duration = atoi(optarg);
+ break;
+ case 'o':
+ default_outline_color = optarg;
+ break;
+ default:
+ usage();
+ }
+
+ if (optind < argc)
+ usage();
+}
+