diff options
author | David Robillard <d@drobilla.net> | 2021-08-08 20:45:55 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | ed12fd8066ed47c1ee675a69dfed21751313f197 (patch) | |
tree | 4ef4ae0b70f2b281f8d8c3aefd35cb224e105ac3 | |
parent | 816a9532765b2184c5f127494b95bdb9103bc960 (diff) | |
download | serd-ed12fd8066ed47c1ee675a69dfed21751313f197.tar.gz serd-ed12fd8066ed47c1ee675a69dfed21751313f197.tar.bz2 serd-ed12fd8066ed47c1ee675a69dfed21751313f197.zip |
Factor out serd_choose_syntax()
-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, |