aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-12-02 11:19:56 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit1d8cc6eebcb61f261f6d92318ffda32d8a4de080 (patch)
tree78b07be5de29d2d36f64d3cc28e0b01f39d7f30c
parentaa6b5ec5b9344bce0ea38d294aef0782c3745548 (diff)
downloadserd-1d8cc6eebcb61f261f6d92318ffda32d8a4de080.tar.gz
serd-1d8cc6eebcb61f261f6d92318ffda32d8a4de080.tar.bz2
serd-1d8cc6eebcb61f261f6d92318ffda32d8a4de080.zip
Make r_err take a single line without trailing newline
Towards having an actual logging (rather than printing) mechanism.
-rw-r--r--src/n3.c107
-rw-r--r--src/reader.c4
-rw-r--r--src/reader.h2
-rw-r--r--src/world.c1
4 files changed, 57 insertions, 57 deletions
diff --git a/src/n3.c b/src/n3.c
index 006d28ba..7512cf7e 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -52,7 +52,7 @@ read_HEX(SerdReader* const reader)
return (uint8_t)eat_byte_safe(reader, c);
}
- r_err(reader, SERD_BAD_SYNTAX, "invalid hexadecimal digit '%c'\n", c);
+ r_err(reader, SERD_BAD_SYNTAX, "invalid hexadecimal digit '%c'", c);
return 0;
}
@@ -99,8 +99,8 @@ read_UCHAR(SerdReader* const reader,
} else if (code < 0x00110000) {
size = 4;
} else {
- r_err(
- reader, SERD_BAD_SYNTAX, "unicode character 0x%X out of range\n", code);
+ r_err(reader, SERD_BAD_SYNTAX, "unicode character 0x%X out of range", code);
+
*char_code = 0xFFFD;
const SerdStatus st = push_bytes(reader, dest, replacement_char, 3);
return st ? st : SERD_SUCCESS;
@@ -185,14 +185,14 @@ read_utf8_bytes(SerdReader* const reader,
{
*size = utf8_num_bytes(c);
if (*size <= 1 || *size > 4) {
- return bad_char(reader, "invalid UTF-8 start 0x%X\n", c);
+ return bad_char(reader, "invalid UTF-8 start 0x%X", c);
}
bytes[0] = c;
for (unsigned i = 1; i < *size; ++i) {
const int b = peek_byte(reader);
if (b == EOF || ((uint8_t)b & 0x80) == 0) {
- return bad_char(reader, "invalid UTF-8 continuation 0x%X\n", (uint8_t)b);
+ return bad_char(reader, "invalid UTF-8 continuation 0x%X", (uint8_t)b);
}
bytes[i] = (uint8_t)eat_byte_safe(reader, b);
@@ -332,7 +332,7 @@ read_string_escape(SerdReader* const reader, SerdNode* const ref)
SerdStatus st = SERD_SUCCESS;
uint32_t code = 0;
if ((st = read_ECHAR(reader, ref)) && (st = read_UCHAR(reader, ref, &code))) {
- return r_err(reader, st, "invalid escape '\\%c'\n", peek_byte(reader));
+ return r_err(reader, st, "invalid escape '\\%c'", peek_byte(reader));
}
return st;
@@ -352,7 +352,7 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
skip_byte(reader, c);
st = read_string_escape(reader, ref);
} else if (c == EOF) {
- st = r_err(reader, SERD_NO_DATA, "unexpected end of file\n");
+ st = r_err(reader, SERD_NO_DATA, "unexpected end of file");
} else if (c == q) {
skip_byte(reader, q);
const int q2 = eat_byte_safe(reader, peek_byte(reader));
@@ -392,10 +392,10 @@ read_STRING_LITERAL(SerdReader* const reader,
const int c = peek_byte(reader);
switch (c) {
case EOF:
- return r_err(reader, SERD_BAD_SYNTAX, "end of file in short string\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "end of file in short string");
case '\n':
case '\r':
- return r_err(reader, SERD_BAD_SYNTAX, "line end in short string\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "line end in short string");
case '\\':
skip_byte(reader, c);
TRY(st, read_string_escape(reader, ref));
@@ -418,7 +418,7 @@ read_String(SerdReader* const reader, SerdNode* const node)
const int q1 = eat_byte_safe(reader, peek_byte(reader));
const int q2 = peek_byte(reader);
if (q2 == EOF) {
- return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file");
}
if (q2 != q1) { // Short string (not triple quoted)
@@ -428,7 +428,7 @@ read_String(SerdReader* const reader, SerdNode* const node)
skip_byte(reader, q2);
const int q3 = peek_byte(reader);
if (q3 == EOF) {
- return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file");
}
if (q3 != q1) { // Empty short string ("" or '')
@@ -437,7 +437,7 @@ read_String(SerdReader* const reader, SerdNode* const node)
if (!fancy_syntax(reader)) {
return r_err(
- reader, SERD_BAD_SYNTAX, "syntax does not support long literals\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support long literals");
}
skip_byte(reader, q3);
@@ -474,7 +474,7 @@ read_PN_CHARS_BASE(SerdReader* const reader, SerdNode* const dest)
TRY(st, read_utf8_code(reader, dest, &code, (uint8_t)c));
if (!is_PN_CHARS_BASE(code)) {
- r_err(reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
+ r_err(reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name", code);
if (reader->strict) {
return SERD_BAD_SYNTAX;
}
@@ -510,7 +510,7 @@ read_PN_CHARS(SerdReader* const reader, SerdNode* const dest)
if (!is_PN_CHARS(code)) {
return r_err(
- reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name\n", code);
+ reader, SERD_BAD_SYNTAX, "invalid character U+%04X in name", code);
}
return st;
@@ -569,7 +569,7 @@ read_PN_LOCAL_ESC(SerdReader* const reader, SerdNode* const dest)
break;
}
- return r_err(reader, SERD_BAD_SYNTAX, "invalid escape\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid escape");
}
static SerdStatus
@@ -611,7 +611,7 @@ read_PN_LOCAL(SerdReader* const reader,
break;
default:
if ((st = read_PLX(reader, dest)) > SERD_FAILURE) {
- return r_err(reader, st, "bad escape\n");
+ return r_err(reader, st, "bad escape");
}
if (st != SERD_SUCCESS && (st = read_PN_CHARS_BASE(reader, dest))) {
@@ -623,7 +623,7 @@ read_PN_LOCAL(SerdReader* const reader,
if (c == '.' || c == ':') {
st = push_byte(reader, dest, eat_byte_safe(reader, c));
} else if ((st = read_PLX(reader, dest)) > SERD_FAILURE) {
- return r_err(reader, st, "bad escape\n");
+ return r_err(reader, st, "bad escape");
} else if (st != SERD_SUCCESS && (st = read_PN_CHARS(reader, dest))) {
break;
}
@@ -659,7 +659,7 @@ read_PN_PREFIX_tail(SerdReader* const reader, SerdNode* const dest)
if ((st = read_PN_CHARS(reader, dest))) {
return r_err(reader,
st > SERD_FAILURE ? st : SERD_BAD_SYNTAX,
- "prefix ends with '.'\n");
+ "prefix ends with '.'");
}
}
@@ -679,7 +679,7 @@ read_LANGTAG(SerdReader* const reader)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
- return r_err(reader, SERD_BAD_SYNTAX, "unexpected '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected '%c'", c);
}
SerdNode* node = push_node(reader, SERD_LITERAL, "", 0);
@@ -706,19 +706,19 @@ read_IRIREF_scheme(SerdReader* const reader, SerdNode* const dest)
{
int c = peek_byte(reader);
if (!is_alpha(c)) {
- return r_err(reader, SERD_BAD_SYNTAX, "bad IRI scheme start '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "bad IRI scheme start '%c'", c);
}
SerdStatus st = SERD_SUCCESS;
while ((c = peek_byte(reader)) != EOF) {
if (c == '>') {
- return r_err(reader, SERD_BAD_SYNTAX, "missing IRI scheme\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "missing IRI scheme");
}
if (!is_uri_scheme_char(c)) {
return r_err(reader,
SERD_BAD_SYNTAX,
- "bad IRI scheme char U+%04X (%c)\n",
+ "bad IRI scheme char U+%04X (%c)",
(unsigned)c,
(char)c);
}
@@ -746,7 +746,7 @@ read_IRIREF(SerdReader* const reader, SerdNode** const dest)
}
if (!fancy_syntax(reader) && (st = read_IRIREF_scheme(reader, *dest))) {
- return r_err(reader, st, "expected IRI scheme\n");
+ return r_err(reader, st, "expected IRI scheme");
}
uint32_t code = 0;
@@ -755,12 +755,12 @@ read_IRIREF(SerdReader* const reader, SerdNode** const dest)
switch (c) {
case '"':
case '<':
- return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'", c);
case '>':
return SERD_SUCCESS;
case '\\':
if (read_UCHAR(reader, *dest, &code)) {
- return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI escape\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI escape");
}
switch (code) {
case 0:
@@ -769,7 +769,7 @@ read_IRIREF(SerdReader* const reader, SerdNode** const dest)
case '>':
return r_err(reader,
SERD_BAD_SYNTAX,
- "invalid escaped IRI character U+%04X\n",
+ "invalid escaped IRI character U+%04X",
code);
default:
break;
@@ -780,12 +780,12 @@ read_IRIREF(SerdReader* const reader, SerdNode** const dest)
case '{':
case '|':
case '}':
- return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'\n", c);
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid IRI character '%c'", c);
default:
if (c <= 0x20) {
st = r_err(reader,
SERD_BAD_SYNTAX,
- "invalid IRI character (escape %%%02X)\n",
+ "invalid IRI character (escape %%%02X)",
(unsigned)c);
if (reader->strict) {
break;
@@ -835,7 +835,7 @@ read_0_9(SerdReader* const reader, SerdNode* const str, const bool at_least_one)
}
if (at_least_one && count == 0) {
- return r_err(reader, SERD_BAD_SYNTAX, "expected digit\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected digit");
}
return st;
@@ -993,7 +993,7 @@ read_verb(SerdReader* const reader, SerdNode** const dest)
if ((st = read_PrefixedName(reader, *dest, false, &ate_dot)) || ate_dot) {
*dest = NULL;
return r_err(
- reader, st > SERD_FAILURE ? st : SERD_BAD_SYNTAX, "expected verb\n");
+ reader, st > SERD_FAILURE ? st : SERD_BAD_SYNTAX, "expected verb");
}
return SERD_SUCCESS;
@@ -1010,7 +1010,7 @@ adjust_blank_id(SerdReader* const reader, char* const buf)
} else if (tag == 'B' && reader->seen_genid) {
return r_err(reader,
SERD_BAD_LABEL,
- "found both 'b' and 'B' blank IDs, prefix required\n");
+ "found both 'b' and 'B' blank IDs, prefix required");
}
}
@@ -1041,7 +1041,7 @@ read_BLANK_NODE_LABEL(SerdReader* const reader,
TRY(st, push_byte(reader, n, eat_byte_safe(reader, c)));
} else if ((st = read_PN_CHARS(reader, n))) {
st = st > SERD_FAILURE ? st : SERD_BAD_SYNTAX;
- return r_err(reader, st, "invalid name start\n");
+ return r_err(reader, st, "invalid name start");
}
// Read middle: (PN_CHARS | '.')*
@@ -1107,7 +1107,7 @@ read_anon(SerdReader* const reader,
TRY(st, read_predicateObjectList(reader, ctx, &ate_dot_in_list));
if (ate_dot_in_list) {
- return r_err(reader, SERD_BAD_SYNTAX, "'.' inside blank\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "'.' inside blank");
}
read_ws_star(reader);
@@ -1145,14 +1145,14 @@ read_object(SerdReader* const reader,
case '_':
break;
default:
- return r_err(reader, SERD_BAD_SYNTAX, "expected: ':', '<', or '_'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected: ':', '<', or '_'");
}
}
switch (c) {
case EOF:
case ')':
- return r_err(reader, SERD_BAD_SYNTAX, "expected object\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected object");
case '[':
simple = false;
st = read_anon(reader, *ctx, false, &o);
@@ -1216,7 +1216,7 @@ read_object(SerdReader* const reader,
} else if ((st = read_PN_PREFIX_tail(reader, o)) > SERD_FAILURE ||
(st = read_PrefixedName(reader, o, false, ate_dot))) {
st = (st > SERD_FAILURE) ? st : SERD_BAD_SYNTAX;
- return r_err(reader, st, "expected prefixed name\n");
+ return r_err(reader, st, "expected prefixed name");
}
}
@@ -1241,7 +1241,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_BAD_SYNTAX, "syntax does not support abbreviation\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support abbreviation");
}
while (st <= SERD_FAILURE && !*ate_dot && eat_delim(reader, ',')) {
@@ -1273,7 +1273,7 @@ read_predicateObjectList(SerdReader* const reader,
switch (c = peek_byte(reader)) {
case EOF:
serd_stack_pop_to(&reader->stack, orig_stack_size);
- return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of file");
case '.':
case ']':
case '}':
@@ -1287,7 +1287,7 @@ read_predicateObjectList(SerdReader* const reader,
if (!ate_semi) {
serd_stack_pop_to(&reader->stack, orig_stack_size);
- return r_err(reader, SERD_BAD_SYNTAX, "missing ';' or '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "missing ';' or '.'");
}
}
@@ -1395,7 +1395,7 @@ read_subject(SerdReader* const reader,
}
if (ate_dot) {
- return r_err(reader, SERD_BAD_SYNTAX, "subject ends with '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "subject ends with '.'");
}
return st;
@@ -1420,7 +1420,7 @@ read_labelOrSubject(SerdReader* const reader, SerdNode** const dest)
if (!read_iri(reader, dest, &ate_dot)) {
return SERD_SUCCESS;
} else {
- return r_err(reader, SERD_BAD_SYNTAX, "expected label or subject\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected label or subject");
}
}
}
@@ -1471,7 +1471,7 @@ read_base(SerdReader* const reader, const bool sparql, const bool token)
}
if (peek_byte(reader) == '.') {
- return r_err(reader, SERD_BAD_SYNTAX, "full stop after SPARQL BASE\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "full stop after SPARQL BASE");
}
return SERD_SUCCESS;
@@ -1523,7 +1523,7 @@ read_directive(SerdReader* const reader)
switch (peek_byte(reader)) {
case 'B':
case 'P':
- return r_err(reader, SERD_BAD_SYNTAX, "uppercase directive\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "uppercase directive");
}
}
@@ -1538,7 +1538,7 @@ read_directive(SerdReader* const reader)
break;
}
- return r_err(reader, SERD_BAD_SYNTAX, "invalid directive\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid directive");
}
static SerdStatus
@@ -1555,11 +1555,11 @@ read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
ctx->subject = 0;
if ((st = read_subject(reader, *ctx, &ctx->subject, &s_type))) {
- return r_err(reader, st, "expected subject\n");
+ return r_err(reader, st, "expected subject");
}
if ((st = read_triples(reader, *ctx, &ate_dot)) && s_type != '[') {
- return r_err(reader, st, "bad predicate object list\n");
+ return r_err(reader, st, "bad predicate object list");
}
serd_stack_pop_to(&reader->stack, orig_stack_size);
@@ -1573,7 +1573,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_BAD_SYNTAX, "graph followed by '.'\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "graph followed by '.'");
}
return SERD_SUCCESS;
@@ -1605,7 +1605,7 @@ read_n3_statement(SerdReader* const reader)
case '@':
if (!fancy_syntax(reader)) {
return r_err(
- reader, SERD_BAD_SYNTAX, "syntax does not support directives\n");
+ reader, SERD_BAD_SYNTAX, "syntax does not support directives");
}
TRY(st, read_directive(reader));
read_ws_star(reader);
@@ -1615,7 +1615,7 @@ read_n3_statement(SerdReader* const reader)
TRY(st, read_wrappedGraph(reader, &ctx));
read_ws_star(reader);
} else {
- return r_err(reader, SERD_BAD_SYNTAX, "syntax does not support graphs\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "syntax does not support graphs");
}
break;
default:
@@ -1635,10 +1635,10 @@ read_n3_statement(SerdReader* const reader)
read_ws_star(reader);
} else if (!tokcmp(ctx.subject, "true", 4) ||
!tokcmp(ctx.subject, "false", 5)) {
- return r_err(reader, SERD_BAD_SYNTAX, "expected subject\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "expected subject");
} else if (read_ws_star(reader) && peek_byte(reader) == '{') {
if (s_type == '(' || (s_type == '[' && !*ctx.flags)) {
- return r_err(reader, SERD_BAD_SYNTAX, "invalid graph name\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "invalid graph name");
}
ctx.graph = ctx.subject;
ctx.subject = NULL;
@@ -1650,7 +1650,7 @@ read_n3_statement(SerdReader* const reader)
}
if (ate_dot && (reader->strict || (s_type != '('))) {
- return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of statement\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "unexpected end of statement");
}
return st > SERD_FAILURE ? st : SERD_BAD_SYNTAX;
@@ -1713,8 +1713,7 @@ read_nquads_statement(SerdReader* const reader)
}
if (peek_byte(reader) == '@') {
- return r_err(
- reader, SERD_BAD_SYNTAX, "syntax does not support directives\n");
+ return r_err(reader, SERD_BAD_SYNTAX, "syntax does not support directives");
}
// subject predicate object
diff --git a/src/reader.c b/src/reader.c
index 73ddc95f..7eb2323e 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -241,7 +241,7 @@ 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_BAD_SYNTAX, "corrupt byte order mark\n");
+ r_err(me, SERD_BAD_SYNTAX, "corrupt byte order mark");
return SERD_BAD_SYNTAX;
}
}
@@ -307,7 +307,7 @@ serd_reader_prepare(SerdReader* const reader)
} else if (st == SERD_FAILURE) {
reader->source.eof = true;
} else {
- r_err(reader, st, "error preparing read: %s\n", strerror(errno));
+ r_err(reader, st, "error preparing read: %s", strerror(errno));
}
return st;
}
diff --git a/src/reader.h b/src/reader.h
index 5441d8b6..1c308824 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -129,7 +129,7 @@ eat_byte_check(SerdReader* reader, const int byte)
{
const int c = peek_byte(reader);
if (c != byte) {
- return r_err(reader, SERD_BAD_SYNTAX, "expected '%c', not '%c'\n", byte, c);
+ return r_err(reader, SERD_BAD_SYNTAX, "expected '%c', not '%c'", byte, c);
}
skip_byte(reader, c);
diff --git a/src/world.c b/src/world.c
index 386d7a55..837298f4 100644
--- a/src/world.c
+++ b/src/world.c
@@ -58,6 +58,7 @@ serd_world_error(const SerdWorld* const world, const SerdError* const e)
e->caret->col);
}
vfprintf(stderr, e->fmt, *e->args);
+ fprintf(stderr, "\n");
}
return e->status;
}