diff options
-rw-r--r-- | tools/console.c | 14 | ||||
-rw-r--r-- | tools/console.h | 4 | ||||
-rw-r--r-- | tools/serd-pipe.c | 12 |
3 files changed, 23 insertions, 7 deletions
diff --git a/tools/console.c b/tools/console.c index c187f500..f07573fa 100644 --- a/tools/console.c +++ b/tools/console.c @@ -93,3 +93,17 @@ serd_open_tool_input(const char* const filename) return serd_open_input_file(filename); } + +SerdOutputStream +serd_open_tool_output(const char* const filename) +{ + if (!filename || !strcmp(filename, "-")) { + serd_set_stream_utf8_mode(stdout); + return serd_open_output_stream((SerdWriteFunc)fwrite, + (SerdErrorFunc)ferror, + (SerdCloseFunc)fclose, + stdout); + } + + return serd_open_output_file(filename); +} diff --git a/tools/console.h b/tools/console.h index 763ff215..9aeb87b4 100644 --- a/tools/console.h +++ b/tools/console.h @@ -6,6 +6,7 @@ #include "serd/env.h" #include "serd/input_stream.h" +#include "serd/output_stream.h" #include "serd/status.h" #include <stdio.h> @@ -22,4 +23,7 @@ serd_set_base_uri_from_path(SerdEnv* env, const char* path); SerdInputStream serd_open_tool_input(const char* filename); +SerdOutputStream +serd_open_tool_output(const char* filename); + #endif // SERD_TOOLS_CONSOLE_H diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index 1ad07719..7216445a 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -11,7 +11,6 @@ #include "serd/reader.h" #include "serd/sink.h" #include "serd/status.h" -#include "serd/stream.h" #include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" @@ -255,7 +254,6 @@ main(int argc, char** argv) } serd_set_stream_utf8_mode(stdin); - serd_set_stream_utf8_mode(stdout); char* const* const inputs = argv + a; const int n_inputs = argc - a; @@ -283,7 +281,6 @@ main(int argc, char** argv) zix_free(NULL, input_path); } - FILE* const out_fd = stdout; SerdWorld* const world = serd_world_new(); const SerdLimits limits = {stack_size, MAX_DEPTH}; serd_world_set_limits(world, limits); @@ -291,10 +288,11 @@ main(int argc, char** argv) SerdEnv* const env = serd_env_new(base ? serd_node_string_view(base) : serd_empty_string()); - SerdOutputStream out = serd_open_output_stream((SerdWriteFunc)fwrite, - (SerdErrorFunc)ferror, - (SerdCloseFunc)fclose, - out_fd); + SerdOutputStream out = serd_open_tool_output("-"); + if (!out.stream) { + perror("serdi: error opening output file"); + return 1; + } SerdWriter* const writer = serd_writer_new( world, output_syntax, writer_flags, env, &out, bulk_write ? 4096U : 1U); |