diff options
Diffstat (limited to 'src/serdi.c')
-rw-r--r-- | src/serdi.c | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/src/serdi.c b/src/serdi.c index b0f96f6c..6e3be8b0 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -64,7 +64,8 @@ print_usage(const char* name, bool error) fprintf(os, "Use - for INPUT to read from standard input.\n\n"); fprintf(os, " -C Convert literals to canonical form.\n"); fprintf(os, " -I BASE_URI Input base URI.\n"); - fprintf(os, " -V Validate inputs.\n"); + fprintf(os, " -V CHECKS Validate with checks matching CHECKS.\n"); + fprintf(os, " -X CHECKS Exclude validation checks matching CHECKS.\n"); fprintf(os, " -a Write ASCII output if possible.\n"); fprintf(os, " -b Fast bulk output for large serialisations.\n"); fprintf(os, " -c PREFIX Chop PREFIX from matching blank node IDs.\n"); @@ -75,15 +76,17 @@ print_usage(const char* name, bool error) fprintf(os, " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n"); fprintf(os, " -k BYTES Parser stack size.\n"); fprintf(os, " -l Lax (non-strict) parsing.\n"); - fprintf(os, " -m Build and serialise a model (no streaming).\n"); - fprintf(os, " -o SYNTAX Output syntax: turtle/ntriples/nquads.\n"); + fprintf(os, " -m Build a model in memory before writing.\n"); + fprintf(os, " -o SYNTAX Output syntax: empty/turtle/ntriples/nquads.\n"); fprintf(os, " -p PREFIX Add PREFIX to blank node IDs.\n"); 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.\n"); + fprintf(os, " -s STRING Parse STRING as input.\n"); fprintf(os, " -t Write terser output without newlines.\n"); fprintf(os, " -v Display version information and exit.\n"); + fprintf(os, " -w FILENAME Write output to FILENAME instead of stdout.\n"); fprintf(os, " -x Support parsing variable nodes like `?x'.\n"); + fprintf(os, "\nSee serdi(1) for more detailed information: man serdi\n"); return error ? 1 : 0; } @@ -235,7 +238,18 @@ main(int argc, char** argv) base = serd_new_uri(SERD_MEASURE_STRING(argv[a])); } else if (argv[a][1] == 'V') { + if (++a == argc) { + return missing_arg(argv[0], 'V'); + } + + // Just enable validation and skip the pattern, checks are parsed below validate = use_model = true; + } else if (argv[a][1] == 'X') { + if (++a == argc) { + return missing_arg(argv[0], 'X'); + } + + // Checks are parsed below } else if (argv[a][1] == 'a') { writer_flags |= SERD_WRITE_ASCII; } else if (argv[a][1] == 'b') { @@ -390,7 +404,8 @@ main(int argc, char** argv) if (use_model) { const SerdModelFlags flags = SERD_INDEX_SPO | (input_has_graphs ? SERD_INDEX_GRAPHS : 0u) | - (no_inline ? 0u : SERD_INDEX_OPS) | (validate ? SERD_STORE_CURSORS : 0u); + (no_inline ? 0u : SERD_INDEX_OPS) | + (validate ? (SERD_STORE_CURSORS | SERD_INDEX_POS) : 0u); model = serd_model_new(world, flags); inserter = serd_inserter_new(model, env, NULL); @@ -453,8 +468,10 @@ main(int argc, char** argv) for (int i = 0; i < n_inputs; ++i) { if (!base) { - SerdNode* file_uri = - serd_new_file_uri(SERD_MEASURE_STRING(inputs[i]), SERD_EMPTY_STRING()); + SerdNode* file_uri = serd_new_real_file_uri(inputs[i], NULL); + /* SERD_MEASURE_STRING(inputs[i]), SERD_EMPTY_STRING()); */ + + /* fprintf(stderr, "SET BASE URI <%s>\n", serd_node_string(file_uri)); */ serd_env_set_base_uri(env, serd_node_string_view(file_uri)); serd_node_free(file_uri); @@ -473,18 +490,21 @@ main(int argc, char** argv) inputs[i], n_inputs > 1 ? prefix : add_prefix, bulk_read))) { + /* serd_world_logf(world, */ + /* "serd", */ + /* SERD_LOG_LEVEL_ERR, */ + /* 0, */ + /* NULL, */ + /* "error parsing %s\n", */ + /* inputs[i]); */ break; } } free(prefix); - if (!st && validate) { - st = serd_validate(model); - } - - if (st <= SERD_FAILURE && use_model) { + if (!st && output_syntax != SERD_SYNTAX_EMPTY && use_model) { const SerdSink* writer_sink = serd_writer_sink(writer); - SerdRange* range = serd_model_all(model); + SerdRange* range = serd_model_all(model, SERD_ORDER_GSPO); serd_env_write_prefixes(env, writer_sink); @@ -492,6 +512,22 @@ main(int argc, char** argv) serd_range_free(range); } + if (!st && validate) { + SerdValidator* const validator = serd_validator_new(world); + + for (int i = 1; i < argc && argv[i][0] == '-'; ++i) { + if (argv[i][1] == 'V') { + serd_validator_enable_checks(validator, argv[++i]); + } else if (argv[i][1] == 'X') { + serd_validator_disable_checks(validator, argv[++i]); + } + } + + st = serd_validate_model(validator, model, NULL); + + serd_validator_free(validator); + } + serd_sink_free(canon); serd_sink_free(filter); serd_sink_free(inserter); @@ -508,5 +544,5 @@ main(int argc, char** argv) serd_byte_sink_free(byte_sink); - return (st > SERD_FAILURE) ? 1 : 0; + return st <= SERD_FAILURE ? 0 : (int)st; } |