diff options
author | David Robillard <d@drobilla.net> | 2019-05-05 12:36:01 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 21b6a8c6e6854e84821b59255b11f256f0e11630 (patch) | |
tree | d54d568847843f89f635bbcf3d5fa02aea9e9ad7 | |
parent | 9e4025839c192b78da9887401ee38145cca98c62 (diff) | |
download | serd-21b6a8c6e6854e84821b59255b11f256f0e11630.tar.gz serd-21b6a8c6e6854e84821b59255b11f256f0e11630.tar.bz2 serd-21b6a8c6e6854e84821b59255b11f256f0e11630.zip |
Simplify handling of input string arguments
-rw-r--r-- | doc/serdi.1 | 2 | ||||
-rw-r--r-- | src/serdi.c | 22 | ||||
-rw-r--r-- | wscript | 1 |
3 files changed, 14 insertions, 11 deletions
diff --git a/doc/serdi.1 b/doc/serdi.1 index 2d88586c..77f1bb1a 100644 --- a/doc/serdi.1 +++ b/doc/serdi.1 @@ -82,7 +82,7 @@ Statements will be written in simple sorted order, which is faster, but may resu .TP .BR \-s " " \fIINPUT\fR -Parse \fIINPUT\fR as a string (terminates options). +Parse \fIINPUT\fR as a string. .TP .BR \-t diff --git a/src/serdi.c b/src/serdi.c index 8e786f45..9eaf5eb4 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -66,7 +66,7 @@ print_usage(const char* name, bool error) fprintf(os, " -q Suppress all output except data.\n"); fprintf(os, " -r ROOT_URI Keep relative URIs within ROOT_URI.\n"); fprintf(os, " -S Stream model quickly without inlining.\n"); - fprintf(os, " -s INPUT Parse INPUT as string (terminates options).\n"); + fprintf(os, " -s INPUT Parse INPUT as string.\n"); fprintf(os, " -t Write terser output without newlines.\n"); fprintf(os, " -v Display version information and exit.\n"); return error ? 1 : 0; @@ -91,7 +91,6 @@ main(int argc, char** argv) SerdSyntax output_syntax = (SerdSyntax)0; SerdReaderFlags reader_flags = 0; SerdWriterFlags writer_flags = 0; - bool from_string = false; bool from_stdin = false; bool bulk_read = true; bool bulk_write = false; @@ -99,6 +98,7 @@ main(int argc, char** argv) bool use_model = false; bool quiet = false; size_t stack_size = 4194304; + const char* input_string = NULL; const char* add_prefix = NULL; const char* chop_prefix = NULL; const char* root_uri = NULL; @@ -134,9 +134,10 @@ main(int argc, char** argv) } else if (argv[a][1] == 'S') { no_inline = true; } else if (argv[a][1] == 's') { - from_string = true; - ++a; - break; + if (++a == argc) { + return missing_arg(argv[0], 's'); + } + input_string = argv[a]; } else if (argv[a][1] == 't') { writer_flags |= SERD_WRITE_TERSE; } else if (argv[a][1] == 'i') { @@ -183,7 +184,7 @@ main(int argc, char** argv) } } - if (a == argc) { + if (a == argc && !input_string) { SERDI_ERROR("missing input\n"); return 1; } @@ -195,7 +196,8 @@ main(int argc, char** argv) const char* input = argv[a++]; - if (!input_syntax && !(input_syntax = serd_guess_syntax(input))) { + if ((!input_syntax && !input) || + !(input_syntax = serd_guess_syntax(input))) { input_syntax = SERD_TRIG; } @@ -204,7 +206,7 @@ main(int argc, char** argv) output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES; } - if (!base) { + if (!base && input) { base = serd_new_file_uri(input, NULL); } @@ -255,9 +257,9 @@ main(int argc, char** argv) SerdStatus st = SERD_SUCCESS; SerdNode* input_name = NULL; - if (from_string) { + if (input_string) { input_name = serd_new_string("string"); - st = serd_reader_start_string(reader, input, input_name); + st = serd_reader_start_string(reader, input_string, input_name); } else if (from_stdin) { input_name = serd_new_string("stdin"); st = serd_reader_start_stream(reader, @@ -695,6 +695,7 @@ def test(tst): check([serdi, '-p']) check([serdi, '-q', '%s/tests/bad/bad-base.ttl' % srcdir], stderr=None) check([serdi, '-r']) + check([serdi, '-s']) check([serdi, '-z']) check([serdi] + ['%s/tests/bad/bad-base.ttl' % srcdir] * 2) |