aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-09-24 16:36:56 +0200
committerDavid Robillard <d@drobilla.net>2017-09-24 19:02:59 +0200
commitf34171637b94c204971a2256849491f025862373 (patch)
treeb6d2a1a89b013534ea5b44cdbb5a983fe98f3a01 /src/serdi.c
parentf1d036ccba93c9e9d89dcbdae720887a630a35e5 (diff)
downloadserd-f34171637b94c204971a2256849491f025862373.tar.gz
serd-f34171637b94c204971a2256849491f025862373.tar.bz2
serd-f34171637b94c204971a2256849491f025862373.zip
Make serdi guess input syntax from extension if unspecified
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/serdi.c b/src/serdi.c
index d2af3e05..59dbaf35 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -50,6 +50,20 @@ get_syntax(const char* name)
return (SerdSyntax)0;
}
+static SerdSyntax
+guess_syntax(const char* filename)
+{
+ const char* ext = strrchr(filename, '.');
+ if (ext) {
+ for (const Syntax* s = syntaxes; s->name; ++s) {
+ if (!serd_strncasecmp(s->extension, ext, strlen(ext))) {
+ return s->syntax;
+ }
+ }
+ }
+ return (SerdSyntax)0;
+}
+
static int
print_version(void)
{
@@ -106,8 +120,8 @@ main(int argc, char** argv)
}
FILE* in_fd = NULL;
- SerdSyntax input_syntax = SERD_TURTLE;
- SerdSyntax output_syntax = SERD_NTRIPLES;
+ SerdSyntax input_syntax = (SerdSyntax)0;
+ SerdSyntax output_syntax = (SerdSyntax)0;
bool from_file = true;
bool bulk_read = true;
bool bulk_write = false;
@@ -192,6 +206,17 @@ main(int argc, char** argv)
}
}
+ if (!input_syntax && !(input_syntax = guess_syntax((const char*)in_name))) {
+ input_syntax = SERD_TRIG;
+ }
+
+ if (!output_syntax) {
+ output_syntax = (
+ (input_syntax == SERD_TURTLE || input_syntax == SERD_NTRIPLES)
+ ? SERD_NTRIPLES
+ : SERD_NQUADS);
+ }
+
SerdURI base_uri = SERD_URI_NULL;
SerdNode base = SERD_NODE_NULL;
if (a < argc) { // Base URI given on command line