From fac7901dca0b4821582c6062600d37ac987082d9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 1 Aug 2021 20:09:38 -0400 Subject: Collapse input and output options into single flags --- tools/serd-pipe.c | 70 +++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) (limited to 'tools/serd-pipe.c') 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,30 +142,42 @@ 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'); } 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) { @@ -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'); -- cgit v1.2.1