- if (ac != 2 && ac != 5)
- usage(1, av[0]);
- if (!strcmp(av[1], "-h") || !strcmp(av[1], "--help"))
- usage(0, av[0]);
+ int rc;
+ char *a0;
+ sd_event *loop;
+
+ /* get the program name */
+ a0 = av[0];
+
+ /* check options */
+ while (ac > 1 && av[1][0] == '-') {
+ if (av[1][1] == '-') {
+ /* long option */
+
+ if (!strcmp(av[1], "--human")) /* request for human output */
+ human = 1;
+
+ else if (!strcmp(av[1], "--raw")) /* request for raw output */
+ raw = 1;
+
+ /* emit usage and exit */
+ else
+ usage(!!strcmp(av[1], "--help"), a0);
+ } else {
+ /* short option(s) */
+ for (rc = 1 ; av[1][rc] ; rc++)
+ switch (av[1][rc]) {
+ case 'H': human = 1; break;
+ case 'r': raw = 1; break;
+ default: usage(av[1][rc] != 'h', a0);
+ }
+ }
+ av++;
+ ac--;
+ }
+
+ /* check the argument count */
+ if (ac != 2 && ac != 4 && ac != 5)
+ usage(1, a0);
+
+ /* set raw by default */
+ if (!human)
+ raw = 1;