aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/byte_sink.h2
-rw-r--r--src/byte_source.c2
-rw-r--r--src/byte_source.h2
-rw-r--r--src/env.c10
-rw-r--r--src/n3.c154
-rw-r--r--src/reader.c8
-rw-r--r--src/reader.h4
-rw-r--r--src/serdi.c2
-rw-r--r--src/string.c46
-rw-r--r--src/writer.c20
10 files changed, 129 insertions, 121 deletions
diff --git a/src/byte_sink.h b/src/byte_sink.h
index 0b4a83b1..0f3d35f5 100644
--- a/src/byte_sink.h
+++ b/src/byte_sink.h
@@ -41,7 +41,7 @@ serd_byte_sink_flush(SerdByteSink* bsink)
const size_t n_out = bsink->sink(bsink->buf, size, bsink->stream);
bsink->size = 0;
- return (n_out != size) ? SERD_ERR_BAD_WRITE : SERD_SUCCESS;
+ return (n_out != size) ? SERD_BAD_WRITE : SERD_SUCCESS;
}
return SERD_SUCCESS;
diff --git a/src/byte_source.c b/src/byte_source.c
index b56e0102..54b0ad7e 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -19,7 +19,7 @@ serd_byte_source_page(SerdByteSource* const source)
if (n_read == 0) {
source->file_buf[0] = '\0';
source->eof = true;
- return (source->error_func(source->stream) ? SERD_ERR_UNKNOWN
+ return (source->error_func(source->stream) ? SERD_BAD_STREAM
: SERD_FAILURE);
}
diff --git a/src/byte_source.h b/src/byte_source.h
index b6cba5d4..46e1f874 100644
--- a/src/byte_source.h
+++ b/src/byte_source.h
@@ -93,7 +93,7 @@ serd_byte_source_advance(SerdByteSource* source)
if (!source->read_func(&source->read_byte, 1, 1, source->stream)) {
source->eof = true;
st =
- source->error_func(source->stream) ? SERD_ERR_UNKNOWN : SERD_FAILURE;
+ source->error_func(source->stream) ? SERD_BAD_STREAM : SERD_FAILURE;
}
}
} else if (!source->eof) {
diff --git a/src/env.c b/src/env.c
index de7ff889..1faeecf1 100644
--- a/src/env.c
+++ b/src/env.c
@@ -65,7 +65,7 @@ SerdStatus
serd_env_set_base_uri(SerdEnv* const env, const SerdNode* const uri)
{
if (uri && uri->type != SERD_URI) {
- return SERD_ERR_BAD_ARG;
+ return SERD_BAD_ARG;
}
if (!uri || !uri->buf) {
@@ -134,7 +134,7 @@ serd_env_set_prefix(SerdEnv* const env,
const SerdNode* const uri)
{
if (!name->buf || uri->type != SERD_URI) {
- return SERD_ERR_BAD_ARG;
+ return SERD_BAD_ARG;
}
if (serd_uri_string_has_scheme(uri->buf)) {
@@ -196,13 +196,13 @@ serd_env_expand(const SerdEnv* const env,
SerdStringView* const uri_suffix)
{
if (!env) {
- return SERD_ERR_BAD_CURIE;
+ return SERD_BAD_CURIE;
}
const char* const colon =
(const char*)memchr(curie->buf, ':', curie->n_bytes + 1);
if (curie->type != SERD_CURIE || !colon) {
- return SERD_ERR_BAD_ARG;
+ return SERD_BAD_ARG;
}
const size_t name_len = (size_t)(colon - curie->buf);
@@ -214,7 +214,7 @@ serd_env_expand(const SerdEnv* const env,
uri_suffix->len = curie->n_bytes - name_len - 1;
return SERD_SUCCESS;
}
- return SERD_ERR_BAD_CURIE;
+ return SERD_BAD_CURIE;
}
SerdNode
diff --git a/src/n3.c b/src/n3.c
index f808e74a..b7b89342 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -50,7 +50,7 @@ read_HEX(SerdReader* const reader)
return (uint8_t)eat_byte_safe(reader, c);
}
- r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid hexadecimal digit '%c'\n", c);
+ r_err(reader, SERD_BAD_SYNTAX, "invalid hexadecimal digit '%c'\n", c);
return 0;
}
@@ -68,7 +68,7 @@ read_UCHAR(SerdReader* const reader, const Ref dest, uint32_t* const char_code)
length = 4;
break;
default:
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
skip_byte(reader, b);
@@ -78,7 +78,7 @@ read_UCHAR(SerdReader* const reader, const Ref dest, uint32_t* const char_code)
uint32_t code = 0U;
for (unsigned i = 0U; i < length; ++i) {
if (!(buf[i] = read_HEX(reader))) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
code = (code << (i ? 4U : 0U)) | hex_digit_value(buf[i]);
@@ -95,10 +95,8 @@ read_UCHAR(SerdReader* const reader, const Ref dest, uint32_t* const char_code)
} else if (code < 0x00110000) {
size = 4;
} else {
- r_err(reader,
- SERD_ERR_BAD_SYNTAX,
- "unicode character 0x%X out of range\n",
- code);
+ r_err(
+ reader, SERD_BAD_SYNTAX, "unicode character 0x%X out of range\n", code);
push_bytes(reader, dest, replacement_char, 3);
*char_code = 0xFFFD;
return SERD_SUCCESS;
@@ -159,7 +157,7 @@ read_ECHAR(SerdReader* const reader, const Ref dest, SerdNodeFlags* const flags)
case '\'':
return push_byte(reader, dest, eat_byte_safe(reader, c));
default:
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
}
@@ -172,8 +170,8 @@ bad_char(SerdReader* const reader, const char* const fmt, const uint8_t c)
b = peek_byte(reader);
}
- r_err(reader, SERD_ERR_BAD_SYNTAX, fmt, c);
- return reader->strict ? SERD_ERR_BAD_SYNTAX : SERD_FAILURE;
+ r_err(reader, SERD_BAD_SYNTAX, fmt, c);
+ return reader->strict ? SERD_BAD_SYNTAX : SERD_FAILURE;
}
static SerdStatus
@@ -368,7 +366,7 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
st = read_character(reader, ref, flags, (uint8_t)q2);
}
} else if (c == EOF) {
- st = r_err(reader, SERD_ERR_BAD_SYNTAX, "end of file in long string\n");
+ st = r_err(reader, SERD_BAD_SYNTAX, "end of file in long string\n");
} else {
st =
read_character(reader, ref, flags, (uint8_t)eat_byte_safe(reader, c));
@@ -392,11 +390,10 @@ read_STRING_LITERAL(SerdReader* const reader,
const int c = peek_byte(reader);
switch (c) {
case EOF:
- return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "end of file in short string\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "end of file in short string\n");
case '\n':
case '\r':
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "line end in short string\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "line end in short string\n");
case '\\':
skip_byte(reader, c);
TRY(st, read_string_escape(reader, ref, flags));
@@ -411,7 +408,7 @@ read_STRING_LITERAL(SerdReader* const reader,
}
}
- return eat_byte_check(reader, q) ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX;
+ return eat_byte_check(reader, q) ? SERD_SUCCESS : SERD_BAD_SYNTAX;
}
static SerdStatus
@@ -422,7 +419,7 @@ read_String(SerdReader* const reader,
const int q1 = eat_byte_safe(reader, peek_byte(reader));
const int q2 = peek_byte(reader);
if (q2 == EOF) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
}
if (q2 != q1) { // Short string (not triple quoted)
@@ -432,7 +429,7 @@ read_String(SerdReader* const reader,
skip_byte(reader, q2);
const int q3 = peek_byte(reader);
if (q3 == EOF) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
}
if (q3 != q1) { // Empty short string ("" or '')
@@ -441,7 +438,7 @@ read_String(SerdReader* const reader,
if (!fancy_syntax(reader)) {
return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "syntax does not support long literals\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support long literals\n");
}
skip_byte(reader, q3);
@@ -478,10 +475,9 @@ read_PN_CHARS_BASE(SerdReader* const reader, const Ref dest)
read_utf8_code(reader, dest, &code, (uint8_t)c);
if (!is_PN_CHARS_BASE(code)) {
- r_err(
- reader, SERD_ERR_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
+ r_err(reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
if (reader->strict) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
}
@@ -515,7 +511,7 @@ read_PN_CHARS(SerdReader* const reader, const Ref dest)
if (!is_PN_CHARS(code)) {
return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
+ reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
}
return st;
@@ -532,7 +528,7 @@ read_PERCENT(SerdReader* const reader, const Ref dest)
return push_byte(reader, dest, h2);
}
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
static SerdStatus
@@ -565,7 +561,7 @@ read_PN_LOCAL_ESC(SerdReader* const reader, const Ref dest)
push_byte(reader, dest, eat_byte_safe(reader, c));
break;
default:
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid escape\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid escape\n");
}
return SERD_SUCCESS;
@@ -620,7 +616,7 @@ read_PN_LOCAL(SerdReader* const reader, const Ref dest, bool* const ate_dot)
if (c == '.' || c == ':') {
push_byte(reader, dest, eat_byte_safe(reader, c));
} else if ((st = read_PLX(reader, dest)) > SERD_FAILURE) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad escape\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "bad escape\n");
} else if (st != SERD_SUCCESS && (st = read_PN_CHARS(reader, dest))) {
break;
}
@@ -653,7 +649,7 @@ read_PN_PREFIX_tail(SerdReader* const reader, const Ref dest)
const SerdNode* const n = deref(reader, dest);
if (n->buf[n->n_bytes - 1] == '.' && read_PN_CHARS(reader, dest)) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "prefix ends with '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "prefix ends with '.'\n");
}
return SERD_SUCCESS;
@@ -672,7 +668,7 @@ read_LANGTAG(SerdReader* const reader, Ref* const dest)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected '%c'\n", c);
}
*dest = push_node(reader, SERD_LITERAL, "", 0);
@@ -698,17 +694,17 @@ read_IRIREF_scheme(SerdReader* const reader, const Ref dest)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad IRI scheme start '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "bad IRI scheme start '%c'\n", c);
}
while ((c = peek_byte(reader)) != EOF) {
if (c == '>') {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "missing IRI scheme\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "missing IRI scheme\n");
}
if (!is_uri_scheme_char(c)) {
return r_err(reader,
- SERD_ERR_BAD_SYNTAX,
+ SERD_BAD_SYNTAX,
"bad IRI scheme char U+%04X (%c)\n",
(unsigned)c,
(char)c);
@@ -720,21 +716,21 @@ read_IRIREF_scheme(SerdReader* const reader, const Ref dest)
}
}
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
}
static SerdStatus
read_IRIREF(SerdReader* const reader, Ref* const dest)
{
if (!eat_byte_check(reader, '<')) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
*dest = push_node(reader, SERD_URI, "", 0);
if (!fancy_syntax(reader) && read_IRIREF_scheme(reader, *dest)) {
*dest = pop_node(reader, *dest);
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected IRI scheme\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected IRI scheme\n");
}
SerdStatus st = SERD_SUCCESS;
@@ -745,8 +741,7 @@ read_IRIREF(SerdReader* const reader, Ref* const dest)
case '"':
case '<':
*dest = pop_node(reader, *dest);
- return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
case '>':
return SERD_SUCCESS;
@@ -754,7 +749,7 @@ read_IRIREF(SerdReader* const reader, Ref* const dest)
case '\\':
if (read_UCHAR(reader, *dest, &code)) {
*dest = pop_node(reader, *dest);
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid IRI escape\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI escape\n");
}
switch (code) {
@@ -764,7 +759,7 @@ read_IRIREF(SerdReader* const reader, Ref* const dest)
case '>':
*dest = pop_node(reader, *dest);
return r_err(reader,
- SERD_ERR_BAD_SYNTAX,
+ SERD_BAD_SYNTAX,
"invalid escaped IRI character U+%04X\n",
code);
default:
@@ -778,13 +773,12 @@ read_IRIREF(SerdReader* const reader, Ref* const dest)
case '|':
case '}':
*dest = pop_node(reader, *dest);
- return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
default:
if (c <= 0x20) {
st = r_err(reader,
- SERD_ERR_BAD_SYNTAX,
+ SERD_BAD_SYNTAX,
"invalid IRI character (escape %%%02X)\n",
(unsigned)c);
if (reader->strict) {
@@ -798,7 +792,7 @@ read_IRIREF(SerdReader* const reader, Ref* const dest)
} else if (read_utf8_character(reader, *dest, (uint8_t)c)) {
if (reader->strict) {
*dest = pop_node(reader, *dest);
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
}
}
@@ -839,7 +833,7 @@ read_0_9(SerdReader* const reader, const Ref str, const bool at_least_one)
}
if (at_least_one && count == 0) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected digit\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected digit\n");
}
return SERD_SUCCESS;
@@ -952,7 +946,7 @@ read_literal(SerdReader* const reader,
case '^':
skip_byte(reader, '^');
if (!eat_byte_check(reader, '^')) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected '^'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected '^'\n");
}
if ((st = read_iri(reader, datatype, ate_dot))) {
@@ -993,7 +987,7 @@ read_verb(SerdReader* const reader, Ref* const dest)
if (st > SERD_FAILURE ||
(st = read_PrefixedName(reader, *dest, false, &ate_dot)) || ate_dot) {
*dest = pop_node(reader, *dest);
- st = st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX;
+ st = st > SERD_FAILURE ? st : SERD_BAD_SYNTAX;
return r_err(reader, st, "bad verb\n");
}
@@ -1007,7 +1001,7 @@ read_BLANK_NODE_LABEL(SerdReader* const reader,
{
skip_byte(reader, '_');
if (!eat_byte_check(reader, ':')) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
const Ref ref = *dest = push_node(reader,
@@ -1020,7 +1014,7 @@ read_BLANK_NODE_LABEL(SerdReader* const reader,
push_byte(reader, ref, eat_byte_safe(reader, c));
} else if (read_PN_CHARS(reader, ref)) {
*dest = pop_node(reader, *dest);
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid name start\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid name start\n");
}
while ((c = peek_byte(reader))) { // Middle: (PN_CHARS | '.')*
@@ -1047,7 +1041,7 @@ read_BLANK_NODE_LABEL(SerdReader* const reader,
} else if (reader->seen_genid && n->buf[reader->bprefix_len] == 'B') {
*dest = pop_node(reader, *dest);
return r_err(reader,
- SERD_ERR_ID_CLASH,
+ SERD_BAD_LABEL,
"found both 'b' and 'B' blank IDs, prefix required\n");
}
}
@@ -1094,7 +1088,7 @@ read_anon(SerdReader* const reader,
TRY_FAILING(st, read_predicateObjectList(reader, ctx, &ate_dot_in_list));
if (ate_dot_in_list) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "'.' inside blank\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "'.' inside blank\n");
}
read_ws_star(reader);
@@ -1107,7 +1101,7 @@ read_anon(SerdReader* const reader,
return st > SERD_FAILURE ? st
: (eat_byte_check(reader, ']') == ']') ? SERD_SUCCESS
- : SERD_ERR_BAD_SYNTAX;
+ : SERD_BAD_SYNTAX;
}
/* If emit is true: recurses, calling statement_sink for every statement
@@ -1143,13 +1137,13 @@ read_object(SerdReader* const reader,
case '_':
break;
default:
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected: ':', '<', or '_'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected: ':', '<', or '_'\n");
}
}
switch (c) {
case EOF:
case ')':
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected object\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected object\n");
case '[':
simple = false;
st = read_anon(reader, *ctx, false, &o);
@@ -1198,10 +1192,10 @@ read_object(SerdReader* const reader,
datatype = push_node(reader, SERD_URI, XSD_BOOLEAN, XSD_BOOLEAN_LEN);
st = SERD_SUCCESS;
} else if (read_PN_PREFIX_tail(reader, o) > SERD_FAILURE) {
- st = SERD_ERR_BAD_SYNTAX;
+ st = SERD_BAD_SYNTAX;
} else {
if ((st = read_PrefixedName(reader, o, false, ate_dot))) {
- st = st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX;
+ st = st > SERD_FAILURE ? st : SERD_BAD_SYNTAX;
pop_node(reader, o);
return r_err(reader, st, "expected prefixed name\n");
}
@@ -1237,7 +1231,7 @@ read_objectList(SerdReader* const reader, ReadContext ctx, bool* const ate_dot)
TRY(st, read_object(reader, &ctx, true, ate_dot));
if (!fancy_syntax(reader) && peek_delim(reader, ',')) {
return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "syntax does not support abbreviation\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support abbreviation\n");
}
while (!*ate_dot && eat_delim(reader, ',')) {
@@ -1266,7 +1260,7 @@ read_predicateObjectList(SerdReader* const reader,
read_ws_star(reader);
switch (c = peek_byte(reader)) {
case EOF:
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
case '.':
case ']':
case '}':
@@ -1278,7 +1272,7 @@ read_predicateObjectList(SerdReader* const reader,
} while (c == ';');
if (!ate_semi) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "missing ';' or '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "missing ';' or '.'\n");
}
}
@@ -1298,7 +1292,7 @@ end_collection(SerdReader* const reader,
*ctx.flags &= ~(unsigned)SERD_LIST_CONT;
if (!st) {
return (eat_byte_check(reader, ')') == ')') ? SERD_SUCCESS
- : SERD_ERR_BAD_SYNTAX;
+ : SERD_BAD_SYNTAX;
}
return st;
@@ -1389,7 +1383,7 @@ read_subject(SerdReader* const reader,
if (ate_dot) {
pop_node(reader, *dest);
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "subject ends with '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "subject ends with '.'\n");
}
return st;
@@ -1404,7 +1398,7 @@ read_labelOrSubject(SerdReader* const reader, Ref* const dest)
skip_byte(reader, '[');
read_ws_star(reader);
if (!eat_byte_check(reader, ']')) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
*dest = blank_id(reader);
return SERD_SUCCESS;
@@ -1414,7 +1408,7 @@ read_labelOrSubject(SerdReader* const reader, Ref* const dest)
if (!read_iri(reader, dest, &ate_dot)) {
return SERD_SUCCESS;
} else {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected label or subject\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected label or subject\n");
}
}
}
@@ -1458,11 +1452,11 @@ read_base(SerdReader* const reader, const bool sparql, const bool token)
read_ws_star(reader);
if (!sparql) {
- return eat_byte_check(reader, '.') ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX;
+ return eat_byte_check(reader, '.') ? SERD_SUCCESS : SERD_BAD_SYNTAX;
}
if (peek_byte(reader) == '.') {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "full stop after SPARQL BASE\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "full stop after SPARQL BASE\n");
}
return SERD_SUCCESS;
@@ -1482,7 +1476,7 @@ read_prefixID(SerdReader* const reader, const bool sparql, const bool token)
if (eat_byte_check(reader, ':') != ':') {
pop_node(reader, name);
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
read_ws_star(reader);
@@ -1498,7 +1492,7 @@ read_prefixID(SerdReader* const reader, const bool sparql, const bool token)
pop_node(reader, name);
if (!sparql) {
read_ws_star(reader);
- st = eat_byte_check(reader, '.') ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX;
+ st = eat_byte_check(reader, '.') ? SERD_SUCCESS : SERD_BAD_SYNTAX;
}
return st;
@@ -1513,7 +1507,7 @@ read_directive(SerdReader* const reader)
switch (peek_byte(reader)) {
case 'B':
case 'P':
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "uppercase directive\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "uppercase directive\n");
}
}
@@ -1528,14 +1522,14 @@ read_directive(SerdReader* const reader)
break;
}
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid directive\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid directive\n");
}
static SerdStatus
read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
{
if (!eat_byte_check(reader, '{')) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
read_ws_star(reader);
@@ -1545,7 +1539,7 @@ read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
ctx->subject = 0;
SerdStatus st = read_subject(reader, *ctx, &ctx->subject, &s_type);
if (st) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad subject\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "bad subject\n");
}
if ((st = read_triples(reader, *ctx, &ate_dot)) && s_type != '[') {
@@ -1563,7 +1557,7 @@ read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
skip_byte(reader, '}');
read_ws_star(reader);
if (peek_byte(reader) == '.') {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "graph followed by '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "graph followed by '.'\n");
}
return SERD_SUCCESS;
@@ -1605,7 +1599,7 @@ read_n3_statement(SerdReader* const reader)
case '@':
if (!fancy_syntax(reader)) {
return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "syntax does not support directives\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support directives\n");
}
TRY(st, read_directive(reader));
read_ws_star(reader);
@@ -1615,8 +1609,7 @@ read_n3_statement(SerdReader* const reader)
TRY(st, read_wrappedGraph(reader, &ctx));
read_ws_star(reader);
} else {
- return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "syntax does not support graphs\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "syntax does not support graphs\n");
}
break;
default:
@@ -1637,10 +1630,10 @@ read_n3_statement(SerdReader* const reader)
read_ws_star(reader);
} else if (!tokcmp(reader, ctx.subject, "true", 4) ||
!tokcmp(reader, ctx.subject, "false", 5)) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected subject\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected subject\n");
} else if (read_ws_star(reader) && peek_byte(reader) == '{') {
if (s_type == '(' || (s_type == '[' && !*ctx.flags)) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid graph name\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid graph name\n");
}
ctx.graph = ctx.subject;
ctx.subject = 0;
@@ -1653,15 +1646,14 @@ read_n3_statement(SerdReader* const reader)
}
if (ate_dot) {
- return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "unexpected end of statement\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of statement\n");
}
- return st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX;
+ return st > SERD_FAILURE ? st : SERD_BAD_SYNTAX;
} else if (!ate_dot) {
read_ws_star(reader);
- st = (eat_byte_check(reader, '.') == '.') ? SERD_SUCCESS
- : SERD_ERR_BAD_SYNTAX;
+ st =
+ (eat_byte_check(reader, '.') == '.') ? SERD_SUCCESS : SERD_BAD_SYNTAX;
}
ctx.subject = pop_node(reader, ctx.subject);
@@ -1720,7 +1712,7 @@ read_nquads_statement(SerdReader* const reader)
if (peek_byte(reader) == '@') {
return r_err(
- reader, SERD_ERR_BAD_SYNTAX, "syntax does not support directives\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support directives\n");
}
// subject predicate object
@@ -1746,7 +1738,7 @@ read_nquads_statement(SerdReader* const reader)
// Terminating '.'
read_ws_star(reader);
if (!eat_byte_check(reader, '.')) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
}
diff --git a/src/reader.c b/src/reader.c
index 00f5e73f..6e520208 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -272,13 +272,13 @@ serd_reader_read_file(SerdReader* const reader, const char* const uri)
{
char* const path = serd_file_uri_parse(uri, NULL);
if (!path) {
- return SERD_ERR_BAD_ARG;
+ return SERD_BAD_ARG;
}
FILE* fd = serd_fopen(path, "rb");
if (!fd) {
serd_free(path);
- return SERD_ERR_UNKNOWN;
+ return SERD_BAD_STREAM;
}
SerdStatus ret = serd_reader_read_file_handle(reader, fd, path);
@@ -296,8 +296,8 @@ skip_bom(SerdReader* const me)
serd_byte_source_advance(&me->source) ||
serd_byte_source_peek(&me->source) != 0xBF ||
serd_byte_source_advance(&me->source)) {
- r_err(me, SERD_ERR_BAD_SYNTAX, "corrupt byte order mark\n");
- return SERD_ERR_BAD_SYNTAX;
+ r_err(me, SERD_BAD_SYNTAX, "corrupt byte order mark\n");
+ return SERD_BAD_SYNTAX;
}
}
diff --git a/src/reader.h b/src/reader.h
index e24bb31a..1dcf926f 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -152,7 +152,7 @@ eat_byte_check(SerdReader* reader, const int byte)
{
const int c = peek_byte(reader);
if (c != byte) {
- r_err(reader, SERD_ERR_BAD_SYNTAX, "expected '%c', not '%c'\n", byte, c);
+ r_err(reader, SERD_BAD_SYNTAX, "expected '%c', not '%c'\n", byte, c);
return 0;
}
return eat_byte_safe(reader, byte);
@@ -163,7 +163,7 @@ eat_string(SerdReader* reader, const char* str, unsigned n)
{
for (unsigned i = 0; i < n; ++i) {
if (!eat_byte_check(reader, str[i])) {
- return SERD_ERR_BAD_SYNTAX;
+ return SERD_BAD_SYNTAX;
}
}
return SERD_SUCCESS;
diff --git a/src/serdi.c b/src/serdi.c
index d3ff0813..baa19a36 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -391,7 +391,7 @@ main(int argc, char** argv)
if (fclose(out_fd)) {
perror("serdi: write error");
- st = SERD_ERR_UNKNOWN;
+ st = SERD_BAD_STREAM;
}
return (st > SERD_FAILURE) ? 1 : 0;
diff --git a/src/string.c b/src/string.c
index 4d8f4f09..5281d500 100644
--- a/src/string.c
+++ b/src/string.c
@@ -27,24 +27,42 @@ serd_strerror(const SerdStatus status)
return "Success";
case SERD_FAILURE:
return "Non-fatal failure";
- case SERD_ERR_UNKNOWN:
+ case SERD_NO_DATA:
+ return "Unexpected end of input";
+ case SERD_OVERFLOW:
+ return "Insufficient space";
+
+ case SERD_UNKNOWN_ERROR:
break;
- case SERD_ERR_BAD_SYNTAX:
+
+ case SERD_BAD_SYNTAX:
return "Invalid syntax";
- case SERD_ERR_BAD_ARG:
+ case SERD_BAD_ARG:
return "Invalid argument";
- case SERD_ERR_NOT_FOUND:
- return "Not found";
- case SERD_ERR_ID_CLASH:
- return "Blank node ID clash";
- case SERD_ERR_BAD_CURIE:
- return "Invalid CURIE";
- case SERD_ERR_INTERNAL:
- return "Internal error";
- case SERD_ERR_BAD_WRITE:
- return "Error writing to file/stream";
- case SERD_ERR_BAD_TEXT:
+ case SERD_BAD_LABEL:
+ return "Clashing blank node label";
+ case SERD_BAD_CURIE:
+ return "Invalid CURIE or unknown namespace prefix";
+ case SERD_BAD_ALLOC:
+ return "Memory allocation failed";
+ case SERD_BAD_READ:
+ return "Error reading from file";
+ case SERD_BAD_WRITE:
+ return "Error writing to file";
+ case SERD_BAD_STREAM:
+ return "File or stream error";
+ case SERD_BAD_STACK:
+ return "Stack overflow";
+ case SERD_BAD_TEXT:
return "Invalid text encoding";
+ case SERD_BAD_CALL:
+ return "Invalid call";
+ case SERD_BAD_URI:
+ return "Invalid or unresolved URI";
+ case SERD_BAD_DATA:
+ return "Invalid data";
+ case SERD_BAD_LITERAL:
+ return "Invalid literal";
}
return "Unknown error";
diff --git a/src/writer.c b/src/writer.c
index 612c2620..43f2ebe5 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -244,9 +244,9 @@ sink(const void* buf, size_t len, SerdWriter* writer)
if (written != len) {
if (errno) {
const char* const message = strerror(errno);
- w_err(writer, SERD_ERR_BAD_WRITE, "write error (%s)\n", message);
+ w_err(writer, SERD_BAD_WRITE, "write error (%s)\n", message);
} else {
- w_err(writer, SERD_ERR_BAD_WRITE, "write error\n");
+ w_err(writer, SERD_BAD_WRITE, "write error\n");
}
}
@@ -256,7 +256,7 @@ sink(const void* buf, size_t len, SerdWriter* writer)
SERD_NODISCARD static inline SerdStatus
esink(const void* buf, size_t len, SerdWriter* writer)
{
- return sink(buf, len, writer) == len ? SERD_SUCCESS : SERD_ERR_BAD_WRITE;
+ return sink(buf, len, writer) == len ? SERD_SUCCESS : SERD_BAD_WRITE;
}
// Write a single character, as an escape for single byte characters
@@ -271,8 +271,7 @@ write_character(SerdWriter* writer,
const uint32_t c = parse_utf8_char(utf8, size);
switch (*size) {
case 0:
- *st =
- w_err(writer, SERD_ERR_BAD_TEXT, "invalid UTF-8 start: %X\n", utf8[0]);
+ *st = w_err(writer, SERD_BAD_TEXT, "invalid UTF-8 start: %X\n", utf8[0]);
return 0;
case 1:
snprintf(escape, sizeof(escape), "\\u%04X", utf8[0]);
@@ -331,7 +330,7 @@ write_uri(SerdWriter* writer, const char* utf8, size_t n_bytes, SerdStatus* st)
const size_t n_bulk = sink(&utf8[i], j - i, writer);
len += n_bulk;
if (n_bulk != j - i) {
- *st = SERD_ERR_BAD_WRITE;
+ *st = SERD_BAD_WRITE;
return len;
}
@@ -366,7 +365,7 @@ ewrite_uri(SerdWriter* writer, const char* utf8, size_t n_bytes)
SerdStatus st = SERD_SUCCESS;
write_uri(writer, utf8, n_bytes, &st);
- return (st == SERD_ERR_BAD_WRITE || (writer->flags & SERD_WRITE_STRICT))
+ return (st == SERD_BAD_WRITE || (writer->flags & SERD_WRITE_STRICT))
? st
: SERD_SUCCESS;
}
@@ -754,7 +753,7 @@ write_uri_node(SerdWriter* const writer,
if (!has_scheme && !supports_uriref(writer) &&
!serd_env_base_uri(writer->env, NULL)->buf) {
return w_err(writer,
- SERD_ERR_BAD_ARG,
+ SERD_BAD_ARG,
"syntax does not support URI reference <%s>\n",
node->buf);
}
@@ -961,7 +960,7 @@ serd_writer_write_statement(SerdWriter* writer,
if (!is_resource(subject) || !is_resource(predicate) || !object ||
!object->buf) {
- return SERD_ERR_BAD_ARG;
+ return SERD_BAD_ARG;
}
// Simple case: write a line of NTriples or NQuads
@@ -1101,8 +1100,7 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node)
}
if (serd_stack_is_empty(&writer->anon_stack)) {
- return w_err(
- writer, SERD_ERR_UNKNOWN, "unexpected end of anonymous node\n");
+ return w_err(writer, SERD_BAD_CALL, "unexpected end of anonymous node\n");
}
// Write the end separator ']' and pop the context