diff options
author | David Robillard <d@drobilla.net> | 2021-08-08 20:45:55 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:07 -0500 |
commit | ccf868537987ced29aea0d5c6fb6d45c94ee025a (patch) | |
tree | d41146071899d7caab08953a0d17b3752599e902 | |
parent | 9547c806dbf76d6afd1e324fc924abdf944c4bda (diff) | |
download | serd-ccf868537987ced29aea0d5c6fb6d45c94ee025a.tar.gz serd-ccf868537987ced29aea0d5c6fb6d45c94ee025a.tar.bz2 serd-ccf868537987ced29aea0d5c6fb6d45c94ee025a.zip |
Factor out serd_choose_input_syntax()
-rwxr-xr-x | test/test_stdin.py | 2 | ||||
-rw-r--r-- | tools/console.c | 22 | ||||
-rw-r--r-- | tools/console.h | 5 | ||||
-rw-r--r-- | tools/serdi.c | 24 |
4 files changed, 40 insertions, 13 deletions
diff --git a/test/test_stdin.py b/test/test_stdin.py index 461f6d50..11b1ca21 100755 --- a/test/test_stdin.py +++ b/test/test_stdin.py @@ -18,6 +18,8 @@ command = shlex.split(args.wrapper) + [ args.serdi, "-I", "http://example.org", + "-i", + "ntriples", "-", ] diff --git a/tools/console.c b/tools/console.c index 235d15d0..e13bf8a5 100644 --- a/tools/console.c +++ b/tools/console.c @@ -127,6 +127,28 @@ serd_set_output_option(const SerdStringView name, return SERD_FAILURE; } +SerdSyntax +serd_choose_input_syntax(SerdWorld* const world, + 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; + } + + serd_logf(world, + SERD_LOG_LEVEL_WARNING, + "unable to determine syntax of \"%s\", trying TriG", + 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 5d174f1e..16f6fd14 100644 --- a/tools/console.h +++ b/tools/console.h @@ -34,6 +34,11 @@ serd_set_output_option(SerdStringView name, SerdSyntax* syntax, SerdWriterFlags* flags); +SerdSyntax +serd_choose_input_syntax(SerdWorld* world, + SerdSyntax requested, + const char* filename); + SerdByteSource* serd_open_input(const char* filename, size_t block_size); diff --git a/tools/serdi.c b/tools/serdi.c index db4a016f..1e21fe19 100644 --- a/tools/serdi.c +++ b/tools/serdi.c @@ -134,7 +134,7 @@ parse_filter(SerdWorld* const world, static SerdStatus read_file(SerdWorld* const world, - SerdSyntax syntax, + const SerdSyntax syntax, const SerdReaderFlags flags, SerdEnv* const env, const SerdSink* const sink, @@ -143,9 +143,6 @@ read_file(SerdWorld* const world, const char* const add_prefix, const size_t block_size) { - syntax = syntax ? syntax : serd_guess_syntax(filename); - syntax = syntax ? syntax : SERD_TRIG; - SerdByteSource* byte_source = serd_open_input(filename, block_size); if (!byte_source) { @@ -486,15 +483,16 @@ main(int argc, char** argv) snprintf(prefix, prefix_len, "f%d%s", i, add_prefix); } - if ((st = read_file(world, - input_syntax, - reader_flags, - env, - sink, - stack_size, - inputs[i], - n_inputs > 1 ? prefix : add_prefix, - block_size))) { + if ((st = + read_file(world, + serd_choose_input_syntax(world, input_syntax, inputs[i]), + reader_flags, + env, + sink, + stack_size, + inputs[i], + n_inputs > 1 ? prefix : add_prefix, + block_size))) { break; } } |