aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-05-05 12:36:01 +0200
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:06 -0500
commit8b353f1c530ae0f8d112648f34ea612c681ba57c (patch)
tree1910509a3f408e5647ff074c17682b8e885e5bf0
parent0094dfffead41a6c3e84f9aad70911ffcb587fbd (diff)
downloadserd-8b353f1c530ae0f8d112648f34ea612c681ba57c.tar.gz
serd-8b353f1c530ae0f8d112648f34ea612c681ba57c.tar.bz2
serd-8b353f1c530ae0f8d112648f34ea612c681ba57c.zip
Simplify handling of input string arguments
-rw-r--r--doc/serdi.13
-rw-r--r--src/serdi.c21
-rw-r--r--test/meson.build1
3 files changed, 14 insertions, 11 deletions
diff --git a/doc/serdi.1 b/doc/serdi.1
index c5d409bc..c23fa174 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -127,13 +127,14 @@ that enter a parent of
.It Fl s Ar string
Parse
.Ar string
-input instead of a file (terminates options).
+input instead of a file.
.Pp
.It Fl t
Write terser output without newlines.
.Pp
.It Fl v
Display version information and exit.
+.Pp
.It Fl w Ar filename
Write output to the given
.Ar filename
diff --git a/src/serdi.c b/src/serdi.c
index e93d6bcc..30933552 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -69,7 +69,7 @@ print_usage(const char* name, bool error)
fprintf(os, " -p PREFIX Add PREFIX to blank node IDs.\n");
fprintf(os, " -q Suppress all output except data.\n");
fprintf(os, " -r ROOT_URI Keep relative URIs within ROOT_URI.\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;
@@ -102,13 +102,13 @@ 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 = 4194304;
+ const char* input_string = NULL;
const char* add_prefix = NULL;
const char* chop_prefix = NULL;
const char* root_uri = NULL;
@@ -144,9 +144,10 @@ main(int argc, char** argv)
} else if (argv[a][1] == 'v') {
return print_version();
} 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') {
@@ -208,14 +209,14 @@ main(int argc, char** argv)
}
}
- if (a == argc) {
+ if (a == argc && !input_string) {
SERDI_ERROR("missing input\n");
return 1;
}
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;
}
@@ -224,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_MEASURE_STRING(input), SERD_EMPTY_STRING());
}
@@ -267,9 +268,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(SERD_STATIC_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(SERD_STATIC_STRING("stdin"));
st = serd_reader_start_stream(reader,
diff --git a/test/meson.build b/test/meson.build
index 8c09a91a..6f6d7378 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -65,6 +65,7 @@ if get_option('utils')
['-o'],
['-p'],
['-r'],
+ ['-s'],
['-z'],
]