aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-09-24 16:35:44 +0200
committerDavid Robillard <d@drobilla.net>2017-09-24 19:02:59 +0200
commitf1d036ccba93c9e9d89dcbdae720887a630a35e5 (patch)
treecc19501cdb1aaa59c17bc2ccef4495c528c2cfc6 /src/serdi.c
parent8d954ab071e286f0b2bdfc542bb3725eb5a2ab0e (diff)
downloadserd-f1d036ccba93c9e9d89dcbdae720887a630a35e5.tar.gz
serd-f1d036ccba93c9e9d89dcbdae720887a630a35e5.tar.bz2
serd-f1d036ccba93c9e9d89dcbdae720887a630a35e5.zip
Make serdi syntax options case-insensitive
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 75a978b9..d2af3e05 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -24,6 +24,32 @@
#define SERDI_ERROR(msg) fprintf(stderr, "serdi: " msg);
#define SERDI_ERRORF(fmt, ...) fprintf(stderr, "serdi: " fmt, __VA_ARGS__);
+typedef struct {
+ SerdSyntax syntax;
+ const char* name;
+ const char* extension;
+} Syntax;
+
+static const Syntax syntaxes[] = {
+ {SERD_TURTLE, "turtle", ".ttl"},
+ {SERD_NTRIPLES, "ntriples", ".nt"},
+ {SERD_NQUADS, "nquads", ".nq"},
+ {SERD_TRIG, "trig", ".trig"},
+ {(SerdSyntax)0, NULL, NULL}
+};
+
+static SerdSyntax
+get_syntax(const char* name)
+{
+ for (const Syntax* s = syntaxes; s->name; ++s) {
+ if (!serd_strncasecmp(s->name, name, strlen(name))) {
+ return s->syntax;
+ }
+ }
+ SERDI_ERRORF("unknown syntax `%s'\n", name);
+ return (SerdSyntax)0;
+}
+
static int
print_version(void)
{
@@ -59,24 +85,6 @@ print_usage(const char* name, bool error)
return error ? 1 : 0;
}
-static bool
-set_syntax(SerdSyntax* syntax, const char* name)
-{
- if (!strcmp(name, "turtle")) {
- *syntax = SERD_TURTLE;
- } else if (!strcmp(name, "ntriples")) {
- *syntax = SERD_NTRIPLES;
- } else if (!strcmp(name, "nquads")) {
- *syntax = SERD_NQUADS;
- } else if (!strcmp(name, "trig")) {
- *syntax = SERD_TRIG;
- } else {
- SERDI_ERRORF("unknown syntax `%s'\n", name);
- return false;
- }
- return true;
-}
-
static int
missing_arg(const char* name, char opt)
{
@@ -138,13 +146,13 @@ main(int argc, char** argv)
} else if (argv[a][1] == 'i') {
if (++a == argc) {
return missing_arg(argv[0], 'i');
- } else if (!set_syntax(&input_syntax, argv[a])) {
+ } else if (!(input_syntax = get_syntax(argv[a]))) {
return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'o') {
if (++a == argc) {
return missing_arg(argv[0], 'o');
- } else if (!set_syntax(&output_syntax, argv[a])) {
+ } else if (!(output_syntax = get_syntax(argv[a]))) {
return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'p') {