diff options
author | David Robillard <d@drobilla.net> | 2019-05-05 12:36:01 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 5796f49ec8ff1933f4a3c258c16f140b39cc1c03 (patch) | |
tree | cf51d132804857652ff44b500fca73618ddbf22c /tools | |
parent | 959a0db69fa0a61b8a131ee49f9a553f0e01f3e1 (diff) | |
download | serd-5796f49ec8ff1933f4a3c258c16f140b39cc1c03.tar.gz serd-5796f49ec8ff1933f4a3c258c16f140b39cc1c03.tar.bz2 serd-5796f49ec8ff1933f4a3c258c16f140b39cc1c03.zip |
Simplify handling of input string arguments
Diffstat (limited to 'tools')
-rw-r--r-- | tools/serd-pipe.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index a5f2a1b2..7cc63a30 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -47,7 +47,7 @@ print_usage(const char* const name, const bool error) " -p PREFIX Add PREFIX to blank node IDs.\n" " -q Suppress all output except data.\n" " -r ROOT_URI Keep relative URIs within ROOT_URI.\n" - " -s INPUT Parse INPUT as string (terminates options).\n" + " -s STRING Parse STRING as input.\n" " -t Write terser output without newlines.\n" " -v Display version information and exit.\n"; @@ -83,18 +83,18 @@ main(int argc, char** argv) SerdSyntax output_syntax = SERD_SYNTAX_EMPTY; SerdReaderFlags reader_flags = 0; SerdWriterFlags writer_flags = 0; - bool from_string = false; bool from_stdin = false; bool bulk_read = true; bool bulk_write = false; bool osyntax_set = false; bool quiet = false; size_t stack_size = 1048576U; + const char* input_string = NULL; const char* add_prefix = NULL; const char* chop_prefix = NULL; const char* root_uri = NULL; int a = 1; - for (; a < argc && !from_string && argv[a][0] == '-'; ++a) { + for (; a < argc && argv[a][0] == '-'; ++a) { if (argv[a][1] == '\0') { from_stdin = true; break; @@ -130,9 +130,6 @@ main(int argc, char** argv) writer_flags |= SERD_WRITE_TERSE; } else if (opt == 'v') { return serd_print_version(argv[0]); - } else if (opt == 's') { - from_string = true; - break; } else if (argv[a][1] == 'B') { if (++a == argc) { return missing_arg(prog, 'B'); @@ -195,6 +192,13 @@ main(int argc, char** argv) root_uri = argv[a]; break; + } else if (opt == 's') { + if (argv[a][o + 1] || ++a == argc) { + return missing_arg(prog, 's'); + } + + input_string = argv[a]; + break; } else { SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1); return print_usage(prog, true); @@ -202,7 +206,7 @@ main(int argc, char** argv) } } - if (a == argc) { + if (a == argc && !input_string) { SERDI_ERROR("missing input\n"); return print_usage(prog, true); } @@ -212,7 +216,7 @@ 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; } @@ -221,7 +225,7 @@ main(int argc, char** argv) output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES; } - if (!base && !from_string && !from_stdin) { // Use input file URI + if (!base && input) { // Use input file URI base = serd_new_file_uri(serd_string(input), serd_empty_string()); } @@ -260,8 +264,8 @@ main(int argc, char** argv) const char* position = NULL; SerdInputStream in = {NULL, NULL, NULL, NULL}; size_t block_size = 1U; - if (from_string) { - position = input; + if (input_string) { + position = input_string; in = serd_open_input_string(&position); input_name = serd_new_string(serd_string("string")); } else if (from_stdin) { |