diff options
author | David Robillard <d@drobilla.net> | 2023-12-02 15:53:25 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 339f9d90d1fe001978d15e1c007a3861a7145453 (patch) | |
tree | d29ec45610ad04a79dd353fbb2609bbb2931148f /tools | |
parent | 4711fdf527f416faee8ff19e15f050d4b48dcfb2 (diff) | |
download | serd-339f9d90d1fe001978d15e1c007a3861a7145453.tar.gz serd-339f9d90d1fe001978d15e1c007a3861a7145453.tar.bz2 serd-339f9d90d1fe001978d15e1c007a3861a7145453.zip |
[WIP] Add support for converting literals to canonical form
Diffstat (limited to 'tools')
-rw-r--r-- | tools/serd-pipe.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/tools/serd-pipe.c b/tools/serd-pipe.c index 3f1c3f53..bdb871fa 100644 --- a/tools/serd-pipe.c +++ b/tools/serd-pipe.c @@ -3,6 +3,7 @@ #include "console.h" +#include "serd/canon.h" #include "serd/env.h" #include "serd/input_stream.h" #include "serd/log.h" @@ -37,6 +38,7 @@ print_usage(const char* const name, const bool error) "Read and write RDF syntax.\n" "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" " -b BYTES I/O block size.\n" " -c PREFIX Chop PREFIX from matching blank node IDs.\n" @@ -115,6 +117,7 @@ main(int argc, char** argv) SerdReaderFlags reader_flags = 0; SerdWriterFlags writer_flags = 0; bool osyntax_set = false; + bool canonical = false; bool quiet = false; size_t block_size = 4096U; size_t stack_size = 1048576U; @@ -140,7 +143,9 @@ main(int argc, char** argv) for (int o = 1; argv[a][o]; ++o) { const char opt = argv[a][o]; - if (opt == 'a') { + 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); @@ -305,6 +310,13 @@ main(int argc, char** argv) SerdWriter* const writer = serd_writer_new(world, output_syntax, writer_flags, env, &out, block_size); + const SerdSink* sink = serd_writer_sink(writer); + + SerdSink* canon = NULL; + if (canonical) { + sink = canon = serd_canon_new(world, sink, reader_flags); + } + if (quiet) { serd_set_log_func(world, serd_quiet_log_func, NULL); } @@ -321,12 +333,8 @@ main(int argc, char** argv) const char* position = input_string; SerdInputStream string_in = serd_open_input_string(&position); - SerdReader* const reader = - serd_reader_new(world, - input_syntax ? input_syntax : SERD_TRIG, - reader_flags, - env, - serd_writer_sink(writer)); + SerdReader* const reader = serd_reader_new( + world, input_syntax ? input_syntax : SERD_TRIG, reader_flags, env, sink); serd_reader_add_blank_prefix(reader, add_prefix); @@ -361,7 +369,7 @@ main(int argc, char** argv) serd_choose_syntax(world, input_syntax, inputs[i]), reader_flags, env, - serd_writer_sink(writer), + sink, stack_size, inputs[i], n_inputs > 1 ? prefix : add_prefix, @@ -371,6 +379,7 @@ main(int argc, char** argv) } free(prefix); + serd_sink_free(canon); serd_writer_free(writer); serd_node_free(NULL, input_name); serd_env_free(env); |