+ // define command-line options
+ struct option longopts[] = {
+ { "debug", no_argument, 0, 'd' },
+ { "help", no_argument, 0, 'h' },
+ { 0, 0, 0, 0 }
+ };
+
+ // parse command-line options
+ int opt, debug = 0;
+ while ((opt = getopt_long(argc, argv, ":dh", longopts, NULL)) != -1) {
+ switch(opt) {
+ case 'd': debug = 1; break;
+ case 'h': usage(); break;
+ case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
+ case '?':
+ default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
+ }
+ }
+
+ // open file or set input to STDIN
+ char *file;