summaryrefslogtreecommitdiff
path: root/src/weerklank.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/weerklank.c')
-rw-r--r--src/weerklank.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/src/weerklank.c b/src/weerklank.c
index ad03389..18b8b59 100644
--- a/src/weerklank.c
+++ b/src/weerklank.c
@@ -1,22 +1,17 @@
#include <stdio.h>
-#include <stdlib.h>
#include <stdbool.h>
-#include <string.h>
#include <ctype.h>
-#include <unistd.h>
-#include "util/versie.h"
-
-static void usage(FILE *f) {
- fprintf(f,
- "Gebruik: weerklank [-nehV] [touwtje]...\n"
- "\n"
- "Exporteer de touwtjes.\n"
- "\n"
- " -n Voeg geen nieuwe regel toe\n"
- " -e Ontleed terugslagontsnappingen\n"
- " -h Toon deze hulptekst\n"
- " -V Toon versienummer\n");
-}
+#include "util/option.h"
+
+static const char *usage_string =
+ "Gebruik: %s [-nehV] [touwtje]...\n"
+ "\n"
+ "Exporteer de touwtjes.\n"
+ "\n"
+ " -n Voeg geen nieuwe regel toe\n"
+ " -e Ontleed terugslagontsnappingen\n"
+ " -h Toon deze hulptekst\n"
+ " -V Toon versienummer\n";
struct options {
bool nonewline;
@@ -25,33 +20,15 @@ struct options {
// Returns pointer to argument array containing the file names
static char** parse_options(int argc, char **argv, struct options *opts) {
- int opt;
- while ((opt = getopt(argc, argv, "nehV")) != -1) {
- switch (opt) {
- case 'n':
- opts->nonewline = true;
- break;
-
- case 'e':
- opts->unescape = true;
- break;
-
- case 'h':
- usage(stdout);
- exit(0);
-
- case 'V':
- drukkedoos_print_versie(stdout, "weerklank");
- exit(0);
-
- case '?':
- fprintf(stderr, "weerklank: Ongeldige optie: -%c\n", optopt);
- usage(stderr);
- exit(1);
- }
- }
-
- return argv + optind;
+ const struct option_spec spec[] = {
+ {'n', OPTION_SETBOOL(&opts->nonewline)},
+ {'e', OPTION_SETBOOL(&opts->unescape)},
+ {'h', OPTION_HELPUSAGE(usage_string)},
+ {'V', OPTION_VERSION()},
+ OPTION_SPEC_END
+ };
+
+ return option_parse(argc, argv, spec);
}
static const char lowercase_escapes[] = "\a\b\0\0\e\f\0\0\0\0\0\0\0\n\0\0\0\r\0\t\0\v\0\0\0\0";