diff options
author | David Robillard <d@drobilla.net> | 2018-07-08 18:46:38 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 66c589578eb9b9dc89da6a34d274627f7f2435d7 (patch) | |
tree | 79605f183d4b5b7687c43197ab58f0e067dc8927 /tools | |
parent | 155f5e2f24c24f5b5ffbf13fcea5cf1a355ec372 (diff) | |
download | serd-66c589578eb9b9dc89da6a34d274627f7f2435d7.tar.gz serd-66c589578eb9b9dc89da6a34d274627f7f2435d7.tar.bz2 serd-66c589578eb9b9dc89da6a34d274627f7f2435d7.zip |
Add command-line option to write output to a file
Diffstat (limited to 'tools')
-rw-r--r-- | tools/serd-pipe.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index 080fc9a1..84893506 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -52,6 +52,7 @@ print_usage(const char* const name, const bool error) " -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"; FILE* const os = error ? stderr : stdout; @@ -121,6 +122,7 @@ main(int argc, char** argv) const char* add_prefix = ""; const char* chop_prefix = NULL; const char* root_uri = NULL; + const char* out_filename = NULL; int a = 1; for (; a < argc && argv[a][0] == '-'; ++a) { if (argv[a][1] == '\0') { @@ -238,6 +240,13 @@ main(int argc, char** argv) input_string = argv[a]; break; + } else if (opt == 'w') { + if (argv[a][o + 1] || ++a == argc) { + return missing_arg(argv[0], 'w'); + } + + out_filename = argv[a]; + break; } else { SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1); return print_usage(prog, true); @@ -285,7 +294,7 @@ main(int argc, char** argv) SerdEnv* const env = serd_env_new(base ? serd_node_string_view(base) : serd_empty_string()); - SerdOutputStream out = serd_open_tool_output("-"); + SerdOutputStream out = serd_open_tool_output(out_filename); if (!out.stream) { perror("serdi: error opening output file"); return 1; @@ -366,7 +375,7 @@ main(int argc, char** argv) serd_node_free(base); serd_world_free(world); - if (fclose(stdout)) { + if (serd_close_output(&out)) { perror("serd-pipe: write error"); st = SERD_BAD_STREAM; } |