aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-08 14:24:59 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit5aa146e1ce58d295b5f45446bbbbdbb30c8e557d (patch)
treec8b49564b251bf2c3ff63bbfdc932986bea8d0b6 /src/serdi.c
parentbaa2e4e768f542953144cfa6ebe5713ecad389fc (diff)
downloadserd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.tar.gz
serd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.tar.bz2
serd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.zip
Replace serdi -b and -e options with a block size option
This is more powerful, and reduces the number of command line options that almost nobody needs to care about.
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 88ccacd9..73a3f05c 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -15,7 +15,6 @@
*/
#include "console.h"
-#include "system.h"
#include "serd/serd.h"
@@ -49,9 +48,8 @@ print_usage(const char* const name, const bool error)
fprintf(os, " -G PATTERN Only include statements matching PATTERN.\n");
fprintf(os, " -I BASE_URI Input base URI.\n");
fprintf(os, " -a Write ASCII output if possible.\n");
- fprintf(os, " -b Fast bulk output for large serialisations.\n");
+ fprintf(os, " -b BYTES I/O block size.\n");
fprintf(os, " -c PREFIX Chop PREFIX from matching blank node IDs.\n");
- fprintf(os, " -e Eat input one character at a time.\n");
fprintf(os, " -f Fast and loose mode (possibly ugly output).\n");
fprintf(os, " -h Display this help and exit.\n");
fprintf(os, " -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n");
@@ -142,13 +140,12 @@ read_file(SerdWorld* const world,
const size_t stack_size,
const char* const filename,
const char* const add_prefix,
- const bool bulk_read)
+ const size_t block_size)
{
syntax = syntax ? syntax : serd_guess_syntax(filename);
syntax = syntax ? syntax : SERD_TRIG;
- SerdByteSource* byte_source =
- serd_open_input(filename, bulk_read ? SERD_PAGE_SIZE : 1u);
+ SerdByteSource* byte_source = serd_open_input(filename, block_size);
if (!byte_source) {
SERDI_ERRORF(
@@ -185,13 +182,12 @@ main(int argc, char** argv)
SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
SerdReaderFlags reader_flags = 0;
SerdWriterFlags writer_flags = 0;
- bool bulk_read = true;
- bool bulk_write = false;
bool no_inline = false;
bool osyntax_set = false;
bool use_model = false;
bool canonical = false;
bool quiet = false;
+ size_t block_size = 4096u;
size_t stack_size = 4194304;
const char* input_string = NULL;
const char* in_pattern = NULL;
@@ -213,10 +209,6 @@ main(int argc, char** argv)
canonical = true;
} else if (opt == 'a') {
writer_flags |= SERD_WRITE_ASCII;
- } else if (opt == 'b') {
- bulk_write = true;
- } else if (opt == 'e') {
- bulk_read = false;
} else if (opt == 'f') {
no_inline = true;
writer_flags |= (SERD_WRITE_EXPANDED | SERD_WRITE_VERBATIM);
@@ -256,6 +248,19 @@ main(int argc, char** argv)
base = serd_new_uri(SERD_STRING(argv[a]));
break;
+ } else if (opt == 'b') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'b');
+ }
+
+ char* endptr = NULL;
+ const long size = strtol(argv[a], &endptr, 10);
+ if (size < 1 || size == LONG_MAX || *endptr != '\0') {
+ SERDI_ERRORF("invalid block size `%s'\n", argv[a]);
+ return 1;
+ }
+ block_size = (size_t)size;
+ break;
} else if (opt == 'c') {
if (argv[a][o + 1] || ++a == argc) {
return missing_arg(prog, 'c');
@@ -380,8 +385,7 @@ main(int argc, char** argv)
const SerdDescribeFlags describe_flags =
no_inline ? SERD_NO_INLINE_OBJECTS : 0u;
- SerdByteSink* const byte_sink =
- serd_open_output(out_filename, bulk_write ? 4096u : 1u);
+ SerdByteSink* const byte_sink = serd_open_output(out_filename, block_size);
if (!byte_sink) {
perror("serdi: error opening output file");
return 1;
@@ -498,7 +502,7 @@ main(int argc, char** argv)
stack_size,
inputs[i],
n_inputs > 1 ? prefix : add_prefix,
- bulk_read))) {
+ block_size))) {
break;
}
}