aboutsummaryrefslogtreecommitdiffstats
path: root/src/serdi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/serdi.c')
-rw-r--r--src/serdi.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/serdi.c b/src/serdi.c
index 8ed02dfc..aece6d9d 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -24,8 +24,10 @@
# include <io.h>
#endif
+#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#define SERDI_ERROR(msg) fprintf(stderr, "serdi: " msg)
@@ -100,6 +102,7 @@ print_usage(const char* const name, const bool error)
" -f Fast and loose URI pass-through.\n"
" -h Display this help and exit.\n"
" -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n"
+ " -k BYTES Parser stack size.\n"
" -l Lax (non-strict) parsing.\n"
" -o SYNTAX Output syntax: turtle/ntriples/nquads.\n"
" -p PREFIX Add PREFIX to blank node IDs.\n"
@@ -180,6 +183,7 @@ main(int argc, char** argv)
bool full_uris = false;
bool lax = false;
bool quiet = false;
+ size_t stack_size = 1048576U;
const char* add_prefix = NULL;
const char* chop_prefix = NULL;
const char* root_uri = NULL;
@@ -236,6 +240,19 @@ main(int argc, char** argv)
return print_usage(prog, true);
}
break;
+ } else if (opt == 'k') {
+ if (argv[a][o + 1] || ++a == argc) {
+ return missing_arg(prog, 'k');
+ }
+
+ char* endptr = NULL;
+ const long size = strtol(argv[a], &endptr, 10);
+ if (size <= 0 || size == LONG_MAX || *endptr != '\0') {
+ SERDI_ERRORF("invalid stack size '%s'\n", argv[a]);
+ return 1;
+ }
+ stack_size = (size_t)size;
+ break;
} else if (opt == 'o') {
if (argv[a][o + 1] || ++a == argc) {
return missing_arg(prog, 'o');
@@ -307,7 +324,7 @@ main(int argc, char** argv)
output_syntax, writer_flags, env, (SerdWriteFunc)fwrite, out_fd);
SerdReader* const reader =
- serd_reader_new(input_syntax, serd_writer_sink(writer));
+ serd_reader_new(input_syntax, serd_writer_sink(writer), stack_size);
serd_reader_set_strict(reader, !lax);
if (quiet) {