diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/serdi.c | 40 | ||||
-rw-r--r-- | src/writer.c | 12 |
2 files changed, 27 insertions, 25 deletions
diff --git a/src/serdi.c b/src/serdi.c index b066b265..986971e8 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -68,6 +68,7 @@ print_usage(const char* name, bool error) fprintf(os, " -q Suppress all output except data.\n"); fprintf(os, " -r ROOT_URI Keep relative URIs within ROOT_URI.\n"); fprintf(os, " -s INPUT Parse INPUT as string (terminates options).\n"); + fprintf(os, " -t Write terser output without newlines.\n"); fprintf(os, " -v Display version information and exit.\n"); return error ? 1 : 0; } @@ -94,21 +95,20 @@ main(int argc, char** argv) return print_usage(argv[0], true); } - SerdSyntax input_syntax = (SerdSyntax)0; - SerdSyntax output_syntax = (SerdSyntax)0; - bool from_string = false; - bool from_stdin = false; - bool ascii = false; - bool bulk_read = true; - bool bulk_write = false; - bool full_uris = false; - bool lax = false; - bool quiet = false; - size_t stack_size = 4194304; - const char* add_prefix = NULL; - const char* chop_prefix = NULL; - const char* root_uri = NULL; - int a = 1; + SerdSyntax input_syntax = (SerdSyntax)0; + SerdSyntax output_syntax = (SerdSyntax)0; + SerdWriterFlags writer_flags = 0u; + bool from_string = false; + bool from_stdin = false; + bool bulk_read = true; + bool bulk_write = false; + bool lax = false; + bool quiet = false; + size_t stack_size = 4194304; + const char* add_prefix = NULL; + const char* chop_prefix = NULL; + const char* root_uri = NULL; + int a = 1; for (; a < argc && argv[a][0] == '-'; ++a) { if (argv[a][1] == '\0') { from_stdin = true; @@ -116,13 +116,13 @@ main(int argc, char** argv) } if (argv[a][1] == 'a') { - ascii = true; + writer_flags |= SERD_WRITE_ASCII; } else if (argv[a][1] == 'b') { bulk_write = true; } else if (argv[a][1] == 'e') { bulk_read = false; } else if (argv[a][1] == 'f') { - full_uris = true; + writer_flags |= (SERD_WRITE_UNQUALIFIED | SERD_WRITE_UNRESOLVED); } else if (argv[a][1] == 'h') { return print_usage(argv[0], false); } else if (argv[a][1] == 'l') { @@ -135,6 +135,8 @@ main(int argc, char** argv) from_string = true; ++a; break; + } else if (argv[a][1] == 't') { + writer_flags |= SERD_WRITE_TERSE; } else if (argv[a][1] == 'i') { if (++a == argc) { return missing_arg(argv[0], 'i'); @@ -207,10 +209,6 @@ main(int argc, char** argv) output_syntax = input_has_graphs ? SERD_NQUADS : SERD_NTRIPLES; } - const SerdWriterFlags writer_flags = - ((ascii ? SERD_WRITE_ASCII : 0) | // - (full_uris ? (SERD_WRITE_UNQUALIFIED | SERD_WRITE_UNRESOLVED) : 0)); - SerdNode* base = NULL; if (a < argc) { // Base URI given on command line base = serd_new_uri(SERD_MEASURE_STRING(argv[a])); diff --git a/src/writer.c b/src/writer.c index 2e4bcb6c..867b5020 100644 --- a/src/writer.c +++ b/src/writer.c @@ -482,16 +482,20 @@ uri_sink(const void* buf, size_t size, size_t nmemb, void* stream) static void write_newline(SerdWriter* writer) { - sink("\n", 1, writer); - for (int i = 0; i < writer->indent; ++i) { - sink("\t", 1, writer); + if (writer->flags & SERD_WRITE_TERSE) { + sink(" ", 1, writer); + } else { + sink("\n", 1, writer); + for (int i = 0; i < writer->indent; ++i) { + sink("\t", 1, writer); + } } } static void write_top_level_sep(SerdWriter* writer) { - if (!writer->empty) { + if (!writer->empty && !(writer->flags & SERD_WRITE_TERSE)) { write_newline(writer); } } |