aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-10 13:21:51 +0100
committerDavid Robillard <d@drobilla.net>2019-04-13 19:48:23 +0200
commit9a3c3f9cd9c664cbe9a9b397761192b9a744975e (patch)
treea73b663889dd50e5d275f475713c10d99da49bf8 /src
parentc8e1af98cab4726124a0c9ee7afbbe63fc8fc6f9 (diff)
downloadserd-9a3c3f9cd9c664cbe9a9b397761192b9a744975e.tar.gz
serd-9a3c3f9cd9c664cbe9a9b397761192b9a744975e.tar.bz2
serd-9a3c3f9cd9c664cbe9a9b397761192b9a744975e.zip
Add option for writing terse output without newlines
Diffstat (limited to 'src')
-rw-r--r--src/n3.c2
-rw-r--r--src/serdi.c39
-rw-r--r--src/writer.c12
3 files changed, 29 insertions, 24 deletions
diff --git a/src/n3.c b/src/n3.c
index 356e139b..68ca8b62 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1046,7 +1046,7 @@ read_object(SerdReader* reader, ReadContext* ctx, bool emit, bool* ate_dot)
if (!emit) {
ctx->object = o;
- } else if (!ret && emit && simple && o) {
+ } else if (!ret && simple && o) {
ret = emit_statement(reader, *ctx, o);
serd_stack_pop_to(&reader->stack, orig_stack_size);
}
diff --git a/src/serdi.c b/src/serdi.c
index a9e25c14..5c543f9d 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -66,6 +66,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;
}
@@ -92,28 +93,28 @@ 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 no_inline = false;
- bool lax = false;
- bool use_model = 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 = 0;
+ bool from_string = false;
+ bool from_stdin = false;
+ bool bulk_read = true;
+ bool bulk_write = false;
+ bool no_inline = false;
+ bool lax = false;
+ bool use_model = 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;
break;
} else 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') {
@@ -134,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');
@@ -210,8 +213,6 @@ main(int argc, char** argv)
SerdWorld* world = serd_world_new();
SerdEnv* env = serd_env_new(base);
- const SerdWriterFlags writer_flags = (ascii ? SERD_WRITE_ASCII : 0U);
-
const SerdSerialisationFlags serialisation_flags =
no_inline ? SERD_NO_INLINE_OBJECTS : 0U;
diff --git a/src/writer.c b/src/writer.c
index 46d485c3..e2abf5a8 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -382,16 +382,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);
}
}