aboutsummaryrefslogtreecommitdiffstats
path: root/tools/serd-pipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/serd-pipe.c')
-rw-r--r--tools/serd-pipe.c13
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;
}