aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-04-11 21:18:49 -0400
committerDavid Robillard <d@drobilla.net>2021-04-11 21:19:04 -0400
commita2ed0f1da672bbdeb85944b15df3bf2558f29ac7 (patch)
tree3e7487db19d16f79ba3b1d74d2767911242864a4
parent3566788d55df78788fff5ccbea14eb8337df98db (diff)
downloadserd-a2ed0f1da672bbdeb85944b15df3bf2558f29ac7.tar.gz
serd-a2ed0f1da672bbdeb85944b15df3bf2558f29ac7.tar.bz2
serd-a2ed0f1da672bbdeb85944b15df3bf2558f29ac7.zip
Support combining several BSD-style command line flags in serdi
-rw-r--r--NEWS3
-rw-r--r--src/serdi.c127
-rw-r--r--wscript3
3 files changed, 73 insertions, 60 deletions
diff --git a/NEWS b/NEWS
index ef15d1fb..1bd53c47 100644
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,10 @@
serd (0.30.11) unstable;
* Fix writing long literals with triple quotes
+ * Support combining several BSD-style command line flags in serdi
* Write statements with invalid URI characters in lax mode
- -- David Robillard <d@drobilla.net> Fri, 09 Apr 2021 19:40:44 +0000
+ -- David Robillard <d@drobilla.net> Mon, 12 Apr 2021 01:15:27 +0000
serd (0.30.10) stable;
diff --git a/src/serdi.c b/src/serdi.c
index a5c3c0da..a464c8ec 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -183,8 +183,9 @@ choose_style(const SerdSyntax input_syntax,
int
main(int argc, char** argv)
{
+ const char* const prog = argv[0];
if (argc < 2) {
- return print_usage(argv[0], true);
+ return print_usage(prog, true);
}
FILE* in_fd = NULL;
@@ -202,71 +203,79 @@ main(int argc, char** argv)
const uint8_t* chop_prefix = NULL;
const uint8_t* root_uri = NULL;
int a = 1;
- for (; a < argc && argv[a][0] == '-'; ++a) {
+ for (; a < argc && from_file && argv[a][0] == '-'; ++a) {
if (argv[a][1] == '\0') {
in_name = (const uint8_t*)"(stdin)";
in_fd = stdin;
break;
}
- if (argv[a][1] == 'a') {
- ascii = true;
- } else if (argv[a][1] == 'b') {
- bulk_write = true;
- } else if (argv[a][1] == 'e') {
- bulk_read = false;
- } else if (argv[a][1] == 'f') {
- full_uris = true;
- } else if (argv[a][1] == 'h') {
- return print_usage(argv[0], false);
- } else if (argv[a][1] == 'l') {
- lax = true;
- } else if (argv[a][1] == 'q') {
- quiet = true;
- } else if (argv[a][1] == 'v') {
- return print_version();
- } else if (argv[a][1] == 's') {
- in_name = (const uint8_t*)"(string)";
- from_file = false;
- ++a;
- break;
- } else if (argv[a][1] == 'i') {
- if (++a == argc) {
- return missing_arg(argv[0], 'i');
- }
-
- if (!(input_syntax = get_syntax(argv[a]))) {
- return print_usage(argv[0], true);
- }
- } else if (argv[a][1] == 'o') {
- if (++a == argc) {
- return missing_arg(argv[0], 'o');
- }
-
- if (!(output_syntax = get_syntax(argv[a]))) {
- return print_usage(argv[0], true);
+ for (int o = 1; argv[a][o]; ++o) {
+ const char opt = argv[a][o];
+
+ if (opt == 'a') {
+ ascii = true;
+ } else if (opt == 'b') {
+ bulk_write = true;
+ } else if (opt == 'e') {
+ bulk_read = false;
+ } else if (opt == 'f') {
+ full_uris = true;
+ } else if (opt == 'h') {
+ return print_usage(prog, false);
+ } else if (opt == 'l') {
+ lax = true;
+ } else if (opt == 'q') {
+ quiet = true;
+ } else if (opt == 'v') {
+ return print_version();
+ } else if (opt == 's') {
+ in_name = (const uint8_t*)"(string)";
+ from_file = false;
+ break;
+ } else if (opt == 'i') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'i');
+ }
+
+ if (!(input_syntax = get_syntax(argv[a]))) {
+ return print_usage(prog, true);
+ }
+ break;
+ } else if (opt == 'o') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'o');
+ }
+
+ if (!(output_syntax = get_syntax(argv[a]))) {
+ return print_usage(prog, true);
+ }
+ break;
+ } else if (opt == 'p') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'p');
+ }
+
+ add_prefix = (const uint8_t*)argv[a];
+ break;
+ } else if (opt == 'c') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'c');
+ }
+
+ chop_prefix = (const uint8_t*)argv[a];
+ break;
+ } else if (opt == 'r') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'r');
+ }
+
+ root_uri = (const uint8_t*)argv[a];
+ break;
+ } else {
+ SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
+ return print_usage(prog, true);
}
- } else if (argv[a][1] == 'p') {
- if (++a == argc) {
- return missing_arg(argv[0], 'p');
- }
-
- add_prefix = (const uint8_t*)argv[a];
- } else if (argv[a][1] == 'c') {
- if (++a == argc) {
- return missing_arg(argv[0], 'c');
- }
-
- chop_prefix = (const uint8_t*)argv[a];
- } else if (argv[a][1] == 'r') {
- if (++a == argc) {
- return missing_arg(argv[0], 'r');
- }
-
- root_uri = (const uint8_t*)argv[a];
- } else {
- SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
- return print_usage(argv[0], true);
}
}
diff --git a/wscript b/wscript
index 2a4085b4..7c76aae4 100644
--- a/wscript
+++ b/wscript
@@ -581,6 +581,8 @@ def test(tst):
with tst.group('GoodCommands') as check:
check([serdi, '%s/serd.ttl' % srcdir], stdout=os.devnull)
+ check([serdi, '-li', 'turtle', '%s/test/lax/test-bad-string.ttl' % srcdir],
+ stdout=os.devnull)
check([serdi, '-v'])
check([serdi, '-h'])
check([serdi, '-s', '<urn:eg:s> a <urn:eg:T> .'])
@@ -598,6 +600,7 @@ def test(tst):
check([serdi, '-i', 'illegal'])
check([serdi, '-i', 'turtle'])
check([serdi, '-i'])
+ check([serdi, '-fi'])
check([serdi, '-o', 'illegal'])
check([serdi, '-o'])
check([serdi, '-p'])