diff options
-rw-r--r-- | tools/console.c | 19 | ||||
-rw-r--r-- | tools/console.h | 4 | ||||
-rw-r--r-- | tools/serd-pipe.c | 7 |
3 files changed, 25 insertions, 5 deletions
diff --git a/tools/console.c b/tools/console.c index f07573fa..d0e6aaef 100644 --- a/tools/console.c +++ b/tools/console.c @@ -63,6 +63,25 @@ serd_set_base_uri_from_path(SerdEnv* const env, const char* const path) return SERD_SUCCESS; } +SerdSyntax +serd_choose_syntax(const SerdSyntax requested, const char* const filename) +{ + if (requested) { + return requested; + } + + const SerdSyntax guessed = serd_guess_syntax(filename); + if (guessed != SERD_SYNTAX_EMPTY) { + return guessed; + } + + fprintf(stderr, + "warning: unable to determine syntax of \"%s\", trying TriG\n", + filename); + + return SERD_TRIG; +} + /// Wrapper for getc that is compatible with SerdReadFunc but faster than fread static size_t serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream) diff --git a/tools/console.h b/tools/console.h index 9aeb87b4..273b40c9 100644 --- a/tools/console.h +++ b/tools/console.h @@ -8,6 +8,7 @@ #include "serd/input_stream.h" #include "serd/output_stream.h" #include "serd/status.h" +#include "serd/syntax.h" #include <stdio.h> @@ -20,6 +21,9 @@ serd_print_version(const char* program); SerdStatus serd_set_base_uri_from_path(SerdEnv* env, const char* path); +SerdSyntax +serd_choose_syntax(SerdSyntax requested, const char* filename); + SerdInputStream serd_open_tool_input(const char* filename); diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index 7216445a..3d095e2e 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -79,7 +79,7 @@ quiet_error_func(void* const handle, const SerdError* const e) static SerdStatus read_file(SerdWorld* const world, - SerdSyntax syntax, + const SerdSyntax syntax, const SerdReaderFlags flags, const SerdSink* const sink, const size_t stack_size, @@ -87,9 +87,6 @@ read_file(SerdWorld* const world, const char* const add_prefix, const bool bulk_read) { - syntax = syntax ? syntax : serd_guess_syntax(filename); - syntax = syntax ? syntax : SERD_TRIG; - SerdInputStream in = serd_open_tool_input(filename); if (!in.stream) { SERDI_ERRORF( @@ -349,7 +346,7 @@ main(int argc, char** argv) } if ((st = read_file(world, - input_syntax, + serd_choose_syntax(input_syntax, inputs[i]), reader_flags, serd_writer_sink(writer), stack_size, |