diff options
author | David Robillard <d@drobilla.net> | 2021-08-01 20:09:38 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | fac7901dca0b4821582c6062600d37ac987082d9 (patch) | |
tree | 177f20f43d11e65857be9a6d71a5e27c370212c5 /tools/serd-pipe.c | |
parent | aa96c067439252b1955cfa11e75948d15f1b1656 (diff) | |
download | serd-fac7901dca0b4821582c6062600d37ac987082d9.tar.gz serd-fac7901dca0b4821582c6062600d37ac987082d9.tar.bz2 serd-fac7901dca0b4821582c6062600d37ac987082d9.zip |
Collapse input and output options into single flags
Diffstat (limited to 'tools/serd-pipe.c')
-rw-r--r-- | tools/serd-pipe.c | 70 |
1 files changed, 29 insertions, 41 deletions
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index bdb871fa..16abbd2c 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -39,23 +39,20 @@ print_usage(const char* const name, const bool error) "Use - for INPUT to read from standard input.\n\n" " -B BASE_URI Base URI.\n" " -C Convert literals to canonical form.\n" - " -a Write ASCII output.\n" + " -I SYNTAX Input syntax (turtle/ntriples/trig/nquads),\n" + " or flag (lax/variables/verbatim).\n" + " -O SYNTAX Output syntax (empty/turtle/ntriples/nquads),\n" + " or flag (ascii/expanded/verbatim/terse/lax).\n" " -b BYTES I/O block size.\n" " -c PREFIX Chop PREFIX from matching blank node IDs.\n" - " -f Fast and loose URI pass-through.\n" " -h Display this help and exit.\n" - " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n" " -k BYTES Parser stack size.\n" - " -l Lax (non-strict) parsing.\n" - " -o SYNTAX Output syntax: empty/turtle/ntriples/nquads.\n" " -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 STRING Parse STRING as input.\n" - " -t Write terser output without newlines.\n" " -v Display version information and exit.\n" - " -w FILENAME Write output to FILENAME instead of stdout.\n" - " -x Support parsing variable nodes like \"?x\".\n"; + " -w FILENAME Write output to FILENAME instead of stdout.\n"; FILE* const os = error ? stderr : stdout; fprintf(os, "%s", error ? "\n" : ""); @@ -145,24 +142,12 @@ main(int argc, char** argv) if (opt == 'C') { canonical = true; - } else if (opt == 'a') { - writer_flags |= SERD_WRITE_ASCII; - } else if (opt == 'f') { - writer_flags |= (SERD_WRITE_EXPANDED | SERD_WRITE_VERBATIM); } else if (opt == 'h') { return print_usage(prog, false); - } else if (opt == 'l') { - reader_flags |= SERD_READ_LAX; - writer_flags |= SERD_WRITE_LAX; } else if (opt == 'q') { quiet = true; - } else if (opt == 't') { - writer_flags |= SERD_WRITE_TERSE; } else if (opt == 'v') { return serd_print_version(argv[0]); - } else if (opt == 'x') { - reader_flags |= SERD_READ_VARIABLES; - break; } else if (argv[a][1] == 'B') { if (++a == argc) { return missing_arg(prog, 'B'); @@ -170,6 +155,30 @@ main(int argc, char** argv) base = serd_node_new(NULL, serd_a_uri_string(argv[a])); break; + } else if (opt == 'I') { + if (argv[a][o + 1] || ++a == argc) { + return missing_arg(prog, 'I'); + } + + if (serd_set_input_option( + serd_string(argv[a]), &input_syntax, &reader_flags)) { + return print_usage(argv[0], true); + } + break; + } else if (opt == 'O') { + if (argv[a][o + 1] || ++a == argc) { + return missing_arg(prog, 'O'); + } + + if (serd_set_output_option( + serd_string(argv[a]), &output_syntax, &writer_flags)) { + return print_usage(argv[0], true); + } + + osyntax_set = + output_syntax != SERD_SYNTAX_EMPTY || !strcmp(argv[a], "empty"); + + break; } else if (opt == 'b') { if (argv[a][o + 1] || ++a == argc) { return missing_arg(prog, 'b'); @@ -190,15 +199,6 @@ main(int argc, char** argv) chop_prefix = argv[a]; break; - } else if (opt == 'i') { - if (argv[a][o + 1] || ++a == argc) { - return missing_arg(prog, 'i'); - } - - if (!(input_syntax = serd_syntax_by_name(argv[a]))) { - return print_usage(prog, true); - } - break; } else if (opt == 'k') { if (argv[a][o + 1] || ++a == argc) { return missing_arg(prog, 'k'); @@ -212,18 +212,6 @@ main(int argc, char** argv) } stack_size = (size_t)size; break; - } else if (opt == 'o') { - osyntax_set = true; - if (argv[a][o + 1] || ++a == argc) { - return missing_arg(prog, 'o'); - } - - if (!strcmp(argv[a], "empty")) { - output_syntax = SERD_SYNTAX_EMPTY; - } else if (!(output_syntax = serd_syntax_by_name(argv[a]))) { - return print_usage(argv[0], true); - } - break; } else if (opt == 'p') { if (argv[a][o + 1] || ++a == argc) { return missing_arg(prog, 'p'); |