diff --git a/c3s/buf_readline.c b/c3s/buf_readline.c
index cb7edcc..3e5799b 100644
--- a/c3s/buf_readline.c
+++ b/c3s/buf_readline.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/ic3/buf_linenoise.c b/ic3/buf_linenoise.c
index 12d959b..c3a4831 100644
--- a/ic3/buf_linenoise.c
+++ b/ic3/buf_linenoise.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -47,7 +45,7 @@ s_buf * buf_linenoise_open_r (s_buf *buf, const s8 *prompt,
assert(buf);
buf_linenoise = malloc(sizeof(s_buf_linenoise));
if (! buf_linenoise) {
- warn("buf_linenoise_open_r: malloc");
+ err_puts("buf_linenoise_open_r: failed to allocate memory");
return NULL;
}
buf_init(&buf_linenoise->buf, false, 1, "");
diff --git a/libc3/array.c b/libc3/array.c
index d1265a4..e89334b 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -29,6 +29,7 @@
#include "fn.h"
#include "ident.h"
#include "integer.h"
+#include "io.h"
#include "list.h"
#include "ptag.h"
#include "quote.h"
@@ -90,8 +91,13 @@ void * array_data (const s_array *a, const uw *address)
assert(a->data);
while (i < a->dimension) {
if (address[i] >= a->dimensions[i].count) {
- warnx("array_data: address overflow: %lu: [%lu >= %lu]",
- i, address[i], a->dimensions[i].count);
+ err_write_1("array_data: address overflow: ");
+ err_inspect_uw(&i);
+ err_write_1(": [");
+ err_inspect_uw(&address[i]);
+ err_write_1(" >= ");
+ err_inspect_uw(&a->dimensions[i].count);
+ err_puts("]");
return NULL;
}
offset += address[i] * a->dimensions[i].item_size;
diff --git a/libc3/assert.h b/libc3/assert.h
new file mode 100644
index 0000000..55c8f93
--- /dev/null
+++ b/libc3/assert.h
@@ -0,0 +1,37 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#ifndef LIBC3_ASSERT_H
+#define LIBC3_ASSERT_H
+
+#include "types.h"
+#include "io.h"
+
+#ifdef DEBUG
+# define assert(test) \
+ do { \
+ if (! (test)) { \
+ err_write_1("assertion failed: "); \
+ err_write_1(__FILE__); \
+ err_write_1(":"); \
+ err_write_1(__LINE__); \
+ err_write_1(": "); \
+ err_write_1(__func__); \
+ err_write_1(": "); \
+ err_puts(# test); \
+ } \
+ } while(0)
+#else
+# define assert(test)
+#endif
+
+#endif /* LIBC3_ASSERT_H */
diff --git a/libc3/bool.c b/libc3/bool.c
index 4f4bf9c..123155f 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -10,9 +10,11 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
+#include "assert.h"
#include "bool.h"
#include "buf.h"
#include "buf_inspect.h"
+#include "io.h"
bool * bool_init_copy (bool *dest, const bool *src)
{
@@ -26,8 +28,9 @@ s_str * bool_inspect (bool *b, s_str *dest)
s_buf tmp;
size = buf_inspect_bool_size(b);
if (size < 0) {
+ err_write_1("bool_inspect: error: ");
+ err_inspect_u8(b);
assert(! "bool_inspect: error");
- errx(1, "bool_inspect: error: %d", *b);
return NULL;
}
buf_init_alloc(&tmp, size);
@@ -35,7 +38,7 @@ s_str * bool_inspect (bool *b, s_str *dest)
assert(tmp.wpos == tmp.size);
if (tmp.wpos != tmp.size) {
buf_clean(&tmp);
- errx(1, "bool_inspect: buf_inspect_bool");
+ err_write_1("bool_inspect: buf_inspect_bool");
return NULL;
}
return buf_to_str(&tmp, dest);
diff --git a/libc3/buf.h b/libc3/buf.h
index 1559765..a284aa3 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -19,8 +19,6 @@
#ifndef LIBC3_BUF_H
#define LIBC3_BUF_H
-#include <assert.h>
-#include <err.h>
#include <stdarg.h>
#include <stdlib.h>
#include "types.h"
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index f7af8bb..353a4aa 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include <string.h>
#include "../libtommath/tommath.h"
@@ -21,6 +21,7 @@
#include "character.h"
#include "ident.h"
#include "integer.h"
+#include "io.h"
#include "list.h"
#include "operator.h"
#include "str.h"
@@ -52,7 +53,7 @@ sw buf_inspect_array (s_buf *buf, const s_array *array)
goto clean;
result += r;
if ((r = buf_inspect_array_data(buf, array)) < 0) {
- warnx("buf_inspect_array: buf_inspect_array_data");
+ err_puts("buf_inspect_array: buf_inspect_array_data");
goto clean;
}
result += r;
@@ -213,7 +214,7 @@ sw buf_inspect_array_size (const s_array *array)
r = strlen(" ");
result += r;
if ((r = buf_inspect_array_data_size(array)) <= 0) {
- warnx("buf_inspect_array_size: buf_inspect_array_data");
+ err_puts("buf_inspect_array_size: buf_inspect_array_data");
goto clean;
}
result += r;
@@ -1701,8 +1702,8 @@ sw buf_inspect_tag (s_buf *buf, const s_tag *tag)
case TAG_VAR: return buf_inspect_var(buf, tag);
case TAG_VOID: return buf_inspect_void(buf, &tag);
}
+ err_puts("buf_inspect_tag: unknown tag_type");
assert(! "buf_inspect_tag: unknown tag type");
- errx(1, "buf_inspect_tag: unknown tag_type");
return -1;
}
@@ -1745,8 +1746,8 @@ sw buf_inspect_tag_size (const s_tag *tag)
case TAG_VAR: return buf_inspect_var_size(tag);
case TAG_VOID: return buf_inspect_void_size(tag);
}
+ err_puts("buf_inspect_tag_size: unknown tag type");
assert(! "buf_inspect_tag_size: unknown tag type");
- errx(1, "buf_inspect_tag_size: unknown tag type");
return -1;
}
@@ -1816,8 +1817,8 @@ sw buf_inspect_tag_type (s_buf *buf, e_tag_type type)
case TAG_VAR:
return buf_write_1(buf, "Var");
}
+ err_puts("buf_inspect_tag_type: unknown tag type");
assert(! "buf_inspect_tag_type: unknown tag type");
- errx(1, "buf_inspect_tag_type: unknown tag type");
return -1;
}
@@ -1887,8 +1888,8 @@ sw buf_inspect_tag_type_size (e_tag_type type)
case TAG_VAR:
return strlen("Var");
}
+ err_puts("buf_inspect_tag_type_size: unknown tag type");
assert(! "buf_inspect_tag_type_size: unknown tag type");
- errx(1, "buf_inspect_tag_type_size: unknown tag type");
return -1;
}
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index bc67562..97cbbbe 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
@@ -90,7 +90,7 @@ sw buf_parse_array_data (s_buf *buf, s_array *dest)
assert(dest);
tmp = *dest;
if (! (address = calloc(tmp.dimension, sizeof(sw)))) {
- warnx("buf_parse_array_data: out of memory: address");
+ err_puts("buf_parse_array_data: out of memory: address");
return -1;
}
tmp.count = 1;
@@ -102,14 +102,15 @@ sw buf_parse_array_data (s_buf *buf, s_array *dest)
assert(tmp.count);
if (! (tmp.tags = calloc(tmp.count, sizeof(s_tag)))) {
free(address);
- warnx("buf_parse_array_data: out of memory: tags");
+ err_puts("buf_parse_array_data: out of memory: tags");
return -1;
}
tag = tmp.tags;
if ((r = buf_parse_array_data_rec(buf, &tmp, address, &tag,
0)) <= 0) {
- warnx("buf_parse_array_data: buf_parse_array_data_rec:"
- " %ld", r);
+ err_write_1("buf_parse_array_data: buf_parse_array_data_rec: ");
+ err_inspect_sw(&r);
+ err_write_1("\n");
goto restore;
}
*dest = tmp;
@@ -134,12 +135,12 @@ sw buf_parse_array_data_rec (s_buf *buf, s_array *dest, uw *address,
tmp = *dest;
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "{")) <= 0) {
- warnx("buf_parse_array_data_rec: {");
+ err_puts("buf_parse_array_data_rec: {");
goto clean;
}
result += r;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_data_rec: 1");
+ err_puts("buf_parse_array_data_rec: 1");
goto restore;
}
result += r;
@@ -147,7 +148,7 @@ sw buf_parse_array_data_rec (s_buf *buf, s_array *dest, uw *address,
while (1) {
if (dimension == tmp.dimension - 1) {
if ((r = buf_parse_tag(buf, *tag)) < 0) {
- warnx("buf_parse_array_data_rec: parse");
+ err_puts("buf_parse_array_data_rec: parse");
goto clean;
}
result += r;
@@ -156,51 +157,52 @@ sw buf_parse_array_data_rec (s_buf *buf, s_array *dest, uw *address,
else {
if ((r = buf_parse_array_data_rec(buf, &tmp, address, tag,
dimension + 1)) <= 0) {
- warnx("buf_parse_array_data_rec: buf_parse_array_data_rec");
+ err_puts("buf_parse_array_data_rec: buf_parse_array_data_rec");
goto restore;
}
result += r;
}
address[dimension]++;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_data_rec: 2");
+ err_puts("buf_parse_array_data_rec: 2");
goto restore;
}
result += r;
if ((r = buf_read_1(buf, ",")) < 0) {
- warnx("buf_parse_array_data_rec: 3");
+ err_puts("buf_parse_array_data_rec: 3");
goto restore;
}
result += r;
if (! r)
break;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_data_rec: 4");
+ err_puts("buf_parse_array_data_rec: 4");
goto restore;
}
result += r;
}
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_data_rec: 4");
+ err_puts("buf_parse_array_data_rec: 4");
goto restore;
}
result += r;
if ((r = buf_read_1(buf, "}")) <= 0) {
- warnx("buf_parse_array_data_rec: }");
+ err_puts("buf_parse_array_data_rec: }");
goto restore;
}
result += r;
if (tmp.dimensions[dimension].count != address[dimension]) {
+ err_write_1("buf_parse_array_dimensions_rec: dimension mismatch: ");
+ err_inspect_uw(&dimension);
+ err_write_1("\n");
assert(! "buf_parse_array_dimensions_rec: dimension mismatch");
- errx(1, "buf_parse_array_dimensions_rec: dimension mismatch"
- ": %lu", dimension);
r = -1;
goto restore;
}
r = result;
goto clean;
restore:
- warnx("buf_parse_array_data_rec: restore");
+ err_puts("buf_parse_array_data_rec: restore");
buf_save_restore_rpos(buf, &save);
clean:
buf_save_clean(buf, &save);
@@ -233,7 +235,7 @@ sw buf_parse_array_dimension_count (s_buf *buf, s_array *dest)
}
if (! (tmp.dimensions = calloc(tmp.dimension,
sizeof(s_array_dimension)))) {
- err(1, "tmp.dimensions");
+ err_puts("tmp.dimensions: failed to allocate memory");
return -1;
}
*dest = tmp;
@@ -260,8 +262,10 @@ sw buf_parse_array_dimensions (s_buf *buf, s_array *dest)
tmp.dimensions[tmp.dimension - 1].item_size = size;
if ((r = buf_parse_array_dimensions_rec(buf, &tmp, address,
0)) <= 0) {
- warnx("buf_parse_array_dimensions: buf_parse_array_dimensions_rec:"
- " %ld", r);
+ err_write_1("buf_parse_array_dimensions:"
+ " buf_parse_array_dimensions_rec: ");
+ err_inspect_sw(&r);
+ err_write_1("\n");
goto clean;
}
*dest = tmp;
@@ -284,12 +288,12 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
tmp = *dest;
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "{")) <= 0) {
- warnx("buf_parse_array_dimensions_rec: {");
+ err_puts("buf_parse_array_dimensions_rec: {");
goto clean;
}
result += r;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_dimensions_rec: 1");
+ err_puts("buf_parse_array_dimensions_rec: 1");
goto restore;
}
result += r;
@@ -297,7 +301,7 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
while (1) {
if (dimension == dest->dimension - 1) {
if ((r = buf_parse_tag(buf, &tag)) <= 0) {
- warnx("buf_parse_array_dimensions_rec: buf_parse_tag");
+ err_puts("buf_parse_array_dimensions_rec: buf_parse_tag");
goto clean;
}
result += r;
@@ -306,33 +310,33 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
else {
if ((r = buf_parse_array_dimensions_rec(buf, &tmp, address,
dimension + 1)) <= 0) {
- warnx("buf_parse_array_dimensions_rec:"
- " buf_parse_array_dimensions_rec");
+ err_puts("buf_parse_array_dimensions_rec:"
+ " buf_parse_array_dimensions_rec");
goto restore;
}
result += r;
}
address[dimension]++;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_dimensions_rec: 2");
+ err_puts("buf_parse_array_dimensions_rec: 2");
goto restore;
}
result += r;
if ((r = buf_read_1(buf, ",")) < 0) {
- warnx("buf_parse_array_dimensions_rec: 3");
+ err_puts("buf_parse_array_dimensions_rec: 3");
goto restore;
}
result += r;
if (! r)
break;
if ((r = buf_ignore_spaces(buf)) < 0) {
- warnx("buf_parse_array_dimensions_rec: 4");
+ err_puts("buf_parse_array_dimensions_rec: 4");
goto restore;
}
result += r;
}
if ((r = buf_read_1(buf, "}")) <= 0) {
- warnx("buf_parse_array_dimensions_rec: }");
+ err_puts("buf_parse_array_dimensions_rec: }");
goto restore;
}
result += r;
@@ -342,16 +346,17 @@ sw buf_parse_array_dimensions_rec (s_buf *buf, s_array *dest,
tmp.dimensions[dimension].item_size = tmp.dimensions[dimension + 1].count * tmp.dimensions[dimension + 1].item_size;
}
else if (tmp.dimensions[dimension].count != address[dimension]) {
+ err_write_1("buf_parse_array_dimensions_rec: dimension mismatch: ");
+ err_inspect_uw(&dimension);
+ err_write_1("\n");
assert(! "buf_parse_array_dimensions_rec: dimension mismatch");
- errx(1, "buf_parse_array_dimensions_rec: dimension mismatch"
- ": %lu", dimension);
r = -1;
goto restore;
}
r = result;
goto clean;
restore:
- warnx("buf_parse_array_dimensions_rec: restore");
+ err_puts("buf_parse_array_dimensions_rec: restore");
buf_save_restore_rpos(buf, &save);
clean:
buf_save_clean(buf, &save);
@@ -444,7 +449,7 @@ sw buf_parse_brackets (s_buf *buf, s_call *dest)
goto restore;
ident_init(&tmp.ident, NULL, sym_1("[]"));
if (! operator_resolve(&tmp.ident, 2, &tmp.ident)) {
- warnx("buf_parse_brackets: could not resolve operator []");
+ err_puts("buf_parse_brackets: could not resolve operator []");
goto restore;
}
*dest = tmp;
@@ -1001,8 +1006,10 @@ sw buf_parse_digit (s_buf *buf, const s_str *base, u8 *dest)
return r;
if ((digit = str_character_position(base, c)) >= 0) {
if (digit > 255) {
+ err_write_1("buf_parse_digit: digit overflow: ");
+ err_inspect_sw(&digit);
+ err_write_1("\n");
assert(! "buf_parse_digit: digit overflow");
- errx(1, "buf_parse_digit: digit overflow: %ld", digit);
return -1;
}
if ((r = buf_read_character_utf8(buf, &c)) <= 0)
@@ -1237,7 +1244,7 @@ sw buf_parse_fn_clause (s_buf *buf, s_fn_clause *dest)
buf_save_init(buf, &save);
fn_clause_init(&tmp, NULL);
if ((r = buf_parse_fn_pattern(buf, &tmp.pattern)) <= 0) {
- warnx("buf_parse_fn: invalid pattern");
+ err_puts("buf_parse_fn: invalid pattern");
goto restore;
}
result += r;
@@ -1248,7 +1255,7 @@ sw buf_parse_fn_clause (s_buf *buf, s_fn_clause *dest)
if ((r = buf_parse_fn_algo(buf, &tmp.algo)) <= 0) {
buf_inspect_fn_clause(&g_c3_env.err, &tmp);
buf_flush(&g_c3_env.err);
- warnx("buf_parse_fn: invalid program");
+ err_puts("buf_parse_fn: invalid program");
goto restore;
}
result += r;
@@ -1693,7 +1700,7 @@ sw buf_parse_list (s_buf *buf, s_list **list)
*i = NULL;
while (1) {
*i = list_new(NULL);
- if ((r = buf_parse_tag(buf, &(*i)->tag)) <= 0)
+ if ((r = buf_parse_list_tag(buf, &(*i)->tag)) <= 0)
goto restore;
result += r;
if ((r = buf_parse_comments(buf)) < 0)
@@ -1849,6 +1856,50 @@ sw buf_parse_list_paren (s_buf *buf, s_list **list)
return r;
}
+sw buf_parse_list_tag (s_buf *buf, s_tag *dest)
+{
+ s_tag key;
+ sw r;
+ sw result = 0;
+ s_buf_save save;
+ s_tag tmp;
+ s_tag value;
+ assert(buf);
+ assert(dest);
+ buf_save_init(buf, &save);
+ if ((r = buf_parse_tag_sym(buf, &key)) < 0)
+ goto clean;
+ result += r;
+ if (r > 0) {
+ if ((r = buf_read_1(buf, ":") <= 0))
+ goto tag;
+ result += r;
+ if ((r = buf_parse_tag(buf, &value)) <= 0)
+ goto tag;
+ result += r;
+ if (! tag_init_tuple(&tmp, 2)) {
+ tag_clean(&value);
+ return -2;
+ }
+ tmp.data.tuple.tag[0] = key;
+ tmp.data.tuple.tag[1] = value;
+ goto ok;
+ }
+ tag:
+ result = 0;
+ buf_save_restore_rpos(buf, &save);
+ if ((r = buf_parse_tag(buf, &tmp)) <= 0)
+ goto clean;
+ result += r;
+ ok:
+ *dest = tmp;
+ r = result;
+ goto clean;
+ clean:
+ buf_save_clean(buf, &save);
+ return r;
+}
+
sw buf_parse_map (s_buf *buf, s_map *dest)
{
s_list *keys;
@@ -1858,6 +1909,8 @@ sw buf_parse_map (s_buf *buf, s_map *dest)
s_buf_save save;
s_list *values;
s_list **values_end;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "%{")) <= 0)
goto clean;
@@ -2134,7 +2187,7 @@ sw buf_parse_ptag (s_buf *buf, p_tag *dest)
(void) buf;
(void) dest;
assert(! "buf_parse_ptag: not implemented");
- errx(1, "buf_parse_ptag: not implemented");
+ err_puts("buf_parse_ptag: not implemented");
return -1;
}
@@ -2143,7 +2196,7 @@ sw buf_parse_ptr (s_buf *buf, s_ptr *dest)
(void) buf;
(void) dest;
assert(! "buf_parse_ptr: not implemented");
- errx(1, "buf_parse_ptr: not implemented");
+ err_puts("buf_parse_ptr: not implemented");
return -1;
}
diff --git a/libc3/buf_parse.h b/libc3/buf_parse.h
index d432c0e..1838e5f 100644
--- a/libc3/buf_parse.h
+++ b/libc3/buf_parse.h
@@ -79,6 +79,7 @@ sw buf_parse_ident_peek (s_buf *buf, s_ident *dest);
sw buf_parse_integer (s_buf *buf, s_integer *dest);
sw buf_parse_list (s_buf *buf, s_list **dest);
sw buf_parse_list_paren (s_buf *buf, s_list **dest);
+sw buf_parse_list_tag (s_buf *buf, s_tag *dest);
sw buf_parse_map (s_buf *buf, s_map *dest);
sw buf_parse_map_key (s_buf *buf, s_tag *dest);
sw buf_parse_map_key_str (s_buf *buf, s_tag *dest);
diff --git a/libc3/buf_parse_s.c.in b/libc3/buf_parse_s.c.in
index 9f5017d..99a590a 100644
--- a/libc3/buf_parse_s.c.in
+++ b/libc3/buf_parse_s.c.in
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=_BITS$ bits=_bits$ */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_s_bits$ (s_buf *buf, s_bits$ *dest)
s_buf_save save;
s_bits$ tmp;
s_bits$ tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_s_bits$ (s_buf *buf, s_bits$ *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_s_bits$_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > S_BITS$_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s_bits$_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_s_bits$_base: invalid radix");
- errx(1, "buf_parse_s_bits$_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s_bits$_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_s_bits$_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_s_bits$_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (u_bits$) ceiling_s_bits$ (S_BITS$_MAX, radix)) {
- warnx("buf_parse_s_bits$_base: *: integer overflow");
+ err_puts("buf_parse_s_bits$_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (u_bits$) S_BITS$_MIN + digit :
u > (u_bits$) (S_BITS$_MAX - digit)) {
- warnx("buf_parse_s_bits$_base: +: integer overflow");
+ err_puts("buf_parse_s_bits$_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_s16.c b/libc3/buf_parse_s16.c
index fcd28a4..3ddaba0 100644
--- a/libc3/buf_parse_s16.c
+++ b/libc3/buf_parse_s16.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=16 bits=16 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_s16 (s_buf *buf, s16 *dest)
s_buf_save save;
s16 tmp;
s16 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_s16 (s_buf *buf, s16 *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_s16_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > S16_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s16_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_s16_base: invalid radix");
- errx(1, "buf_parse_s16_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s16_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_s16_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_s16_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (u16) ceiling_s16 (S16_MAX, radix)) {
- warnx("buf_parse_s16_base: *: integer overflow");
+ err_puts("buf_parse_s16_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (u16) S16_MIN + digit :
u > (u16) (S16_MAX - digit)) {
- warnx("buf_parse_s16_base: +: integer overflow");
+ err_puts("buf_parse_s16_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_s32.c b/libc3/buf_parse_s32.c
index d1e3cad..5b9c50d 100644
--- a/libc3/buf_parse_s32.c
+++ b/libc3/buf_parse_s32.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=32 bits=32 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_s32 (s_buf *buf, s32 *dest)
s_buf_save save;
s32 tmp;
s32 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_s32 (s_buf *buf, s32 *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_s32_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > S32_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s32_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_s32_base: invalid radix");
- errx(1, "buf_parse_s32_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s32_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_s32_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_s32_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (u32) ceiling_s32 (S32_MAX, radix)) {
- warnx("buf_parse_s32_base: *: integer overflow");
+ err_puts("buf_parse_s32_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (u32) S32_MIN + digit :
u > (u32) (S32_MAX - digit)) {
- warnx("buf_parse_s32_base: +: integer overflow");
+ err_puts("buf_parse_s32_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_s64.c b/libc3/buf_parse_s64.c
index d9f0310..eb79780 100644
--- a/libc3/buf_parse_s64.c
+++ b/libc3/buf_parse_s64.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=64 bits=64 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_s64 (s_buf *buf, s64 *dest)
s_buf_save save;
s64 tmp;
s64 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_s64 (s_buf *buf, s64 *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_s64_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > S64_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s64_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_s64_base: invalid radix");
- errx(1, "buf_parse_s64_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s64_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_s64_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_s64_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (u64) ceiling_s64 (S64_MAX, radix)) {
- warnx("buf_parse_s64_base: *: integer overflow");
+ err_puts("buf_parse_s64_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (u64) S64_MIN + digit :
u > (u64) (S64_MAX - digit)) {
- warnx("buf_parse_s64_base: +: integer overflow");
+ err_puts("buf_parse_s64_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_s8.c b/libc3/buf_parse_s8.c
index ed0640e..f77b4d2 100644
--- a/libc3/buf_parse_s8.c
+++ b/libc3/buf_parse_s8.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=8 bits=8 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_s8 (s_buf *buf, s8 *dest)
s_buf_save save;
s8 tmp;
s8 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_s8 (s_buf *buf, s8 *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_s8_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > S8_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s8_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_s8_base: invalid radix");
- errx(1, "buf_parse_s8_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_s8_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_s8_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_s8_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (u8) ceiling_s8 (S8_MAX, radix)) {
- warnx("buf_parse_s8_base: *: integer overflow");
+ err_puts("buf_parse_s8_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (u8) S8_MIN + digit :
u > (u8) (S8_MAX - digit)) {
- warnx("buf_parse_s8_base: +: integer overflow");
+ err_puts("buf_parse_s8_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_sw.c b/libc3/buf_parse_sw.c
index cc9d603..19ae3b4 100644
--- a/libc3/buf_parse_sw.c
+++ b/libc3/buf_parse_sw.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_s.c.in BITS=W bits=w */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
@@ -28,6 +29,8 @@ sw buf_parse_sw (s_buf *buf, sw *dest)
s_buf_save save;
sw tmp;
sw tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "-")) < 0)
goto clean;
@@ -75,9 +78,9 @@ sw buf_parse_sw (s_buf *buf, sw *dest)
}
if (r == 0 && r1 == 0) {
if (negative)
- warnx("invalid number: -0x");
+ err_puts("invalid number: -0x");
else
- warnx("invalid number: 0x");
+ err_puts("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -120,31 +123,33 @@ sw buf_parse_sw_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || radix > SW_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_sw_base: invalid radix: ");
+ err_inspect_sw(&radix);
+ err_write_1("\n");
assert(! "buf_parse_sw_base: invalid radix");
- errx(1, "buf_parse_sw_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_sw_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
+ err_write_1("\n");
assert(! "buf_parse_sw_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_sw_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > (uw) ceiling_sw (SW_MAX, radix)) {
- warnx("buf_parse_sw_base: *: integer overflow");
+ err_puts("buf_parse_sw_base: *: integer overflow");
r = -1;
goto restore;
}
u *= radix;
if (negative ? -u < (uw) SW_MIN + digit :
u > (uw) (SW_MAX - digit)) {
- warnx("buf_parse_sw_base: +: integer overflow");
+ err_puts("buf_parse_sw_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_u.c.in b/libc3/buf_parse_u.c.in
index 31d6b1e..323cdc4 100644
--- a/libc3/buf_parse_u.c.in
+++ b/libc3/buf_parse_u.c.in
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=_BITS$ bits=_bits$ */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_u_bits$ (s_buf *buf, u_bits$ *dest)
@@ -27,6 +29,8 @@ sw buf_parse_u_bits$ (s_buf *buf, u_bits$ *dest)
s_buf_save save;
u_bits$ tmp;
u_bits$ tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_u_bits$ (s_buf *buf, u_bits$ *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_u_bits$_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > U_BITS$_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u_bits$_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_u_bits$_base: invalid radix");
- errx(1, "buf_parse_u_bits$_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u_bits$_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_u_bits$_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_u_bits$_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_u_bits$(U_BITS$_MAX, radix)) {
- warnx("buf_parse_u_bits$_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_u_bits$_base: ");
+ err_inspect_u_bits$(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = U_BITS$_MAX - digit;
if (u > u2) {
- warnx("buf_parse_u_bits$_base: +: integer overflow");
+ err_write_1("buf_parse_u_bits$_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_u16.c b/libc3/buf_parse_u16.c
index cd08c1e..5a4b0b4 100644
--- a/libc3/buf_parse_u16.c
+++ b/libc3/buf_parse_u16.c
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=16 bits=16 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_u16 (s_buf *buf, u16 *dest)
@@ -27,6 +29,8 @@ sw buf_parse_u16 (s_buf *buf, u16 *dest)
s_buf_save save;
u16 tmp;
u16 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_u16 (s_buf *buf, u16 *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_u16_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > U16_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u16_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_u16_base: invalid radix");
- errx(1, "buf_parse_u16_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u16_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_u16_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_u16_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_u16(U16_MAX, radix)) {
- warnx("buf_parse_u16_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_u16_base: ");
+ err_inspect_u16(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = U16_MAX - digit;
if (u > u2) {
- warnx("buf_parse_u16_base: +: integer overflow");
+ err_write_1("buf_parse_u16_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_u32.c b/libc3/buf_parse_u32.c
index 5ef7c01..2abd14b 100644
--- a/libc3/buf_parse_u32.c
+++ b/libc3/buf_parse_u32.c
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=32 bits=32 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_u32 (s_buf *buf, u32 *dest)
@@ -27,6 +29,8 @@ sw buf_parse_u32 (s_buf *buf, u32 *dest)
s_buf_save save;
u32 tmp;
u32 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_u32 (s_buf *buf, u32 *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_u32_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > U32_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u32_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_u32_base: invalid radix");
- errx(1, "buf_parse_u32_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u32_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_u32_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_u32_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_u32(U32_MAX, radix)) {
- warnx("buf_parse_u32_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_u32_base: ");
+ err_inspect_u32(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = U32_MAX - digit;
if (u > u2) {
- warnx("buf_parse_u32_base: +: integer overflow");
+ err_write_1("buf_parse_u32_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_u64.c b/libc3/buf_parse_u64.c
index 1b1eabb..82b03a1 100644
--- a/libc3/buf_parse_u64.c
+++ b/libc3/buf_parse_u64.c
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=64 bits=64 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_u64 (s_buf *buf, u64 *dest)
@@ -27,6 +29,8 @@ sw buf_parse_u64 (s_buf *buf, u64 *dest)
s_buf_save save;
u64 tmp;
u64 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_u64 (s_buf *buf, u64 *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_u64_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > U64_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u64_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_u64_base: invalid radix");
- errx(1, "buf_parse_u64_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u64_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_u64_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_u64_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_u64(U64_MAX, radix)) {
- warnx("buf_parse_u64_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_u64_base: ");
+ err_inspect_u64(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = U64_MAX - digit;
if (u > u2) {
- warnx("buf_parse_u64_base: +: integer overflow");
+ err_write_1("buf_parse_u64_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_u8.c b/libc3/buf_parse_u8.c
index 5374eff..8ddf3fd 100644
--- a/libc3/buf_parse_u8.c
+++ b/libc3/buf_parse_u8.c
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=8 bits=8 */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_u8 (s_buf *buf, u8 *dest)
@@ -27,6 +29,8 @@ sw buf_parse_u8 (s_buf *buf, u8 *dest)
s_buf_save save;
u8 tmp;
u8 tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_u8 (s_buf *buf, u8 *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_u8_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > U8_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u8_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_u8_base: invalid radix");
- errx(1, "buf_parse_u8_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_u8_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_u8_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_u8_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_u8(U8_MAX, radix)) {
- warnx("buf_parse_u8_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_u8_base: ");
+ err_inspect_u8(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = U8_MAX - digit;
if (u > u2) {
- warnx("buf_parse_u8_base: +: integer overflow");
+ err_write_1("buf_parse_u8_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/buf_parse_uw.c b/libc3/buf_parse_uw.c
index 23415da..21171a8 100644
--- a/libc3/buf_parse_uw.c
+++ b/libc3/buf_parse_uw.c
@@ -11,11 +11,13 @@
* THIS SOFTWARE.
*/
/* Gen from buf_parse_u.c.in BITS=W bits=w */
+#include "assert.h"
#include "buf.h"
#include "buf_parse.h"
#include "buf_save.h"
#include "c3_main.h"
#include "ceiling.h"
+#include "io.h"
#include "str.h"
sw buf_parse_uw (s_buf *buf, uw *dest)
@@ -27,6 +29,8 @@ sw buf_parse_uw (s_buf *buf, uw *dest)
s_buf_save save;
uw tmp;
uw tmp1;
+ assert(buf);
+ assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "0b")) < 0)
goto restore;
@@ -64,7 +68,7 @@ sw buf_parse_uw (s_buf *buf, uw *dest)
goto restore;
}
if (r == 0 && r1 == 0) {
- warnx("invalid number: 0x");
+ err_write_1("invalid number: 0x");
goto restore;
}
if (r > r1) {
@@ -107,33 +111,35 @@ sw buf_parse_uw_base (s_buf *buf, const s_str *base,
radix = str_length_utf8(base);
if (radix < 2 || (uw) radix > UW_MAX) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_uw_base: invalid radix: ");
+ err_inspect_sw(&radix);
assert(! "buf_parse_uw_base: invalid radix");
- errx(1, "buf_parse_uw_base: invalid radix: %ld",
- radix);
return -1;
}
while ((r = buf_parse_digit(buf, base, &digit)) > 0) {
result += r;
if (digit >= radix) {
buf_save_clean(buf, &save);
+ err_write_1("buf_parse_uw_base:"
+ " digit greater than or equal to radix: ");
+ err_inspect_u8(&digit);
assert(! "buf_parse_uw_base: digit greater than or equal to"
" radix");
- errx(1, "buf_parse_uw_base: digit greater than or equal to"
- " radix: %u",
- digit);
return -1;
}
if (u > ceiling_uw(UW_MAX, radix)) {
- warnx("buf_parse_uw_base: %llu * %llu: integer overflow",
- (unsigned long long) u,
- (unsigned long long) radix);
+ err_write_1("buf_parse_uw_base: ");
+ err_inspect_uw(&u);
+ err_write_1(" * ");
+ err_inspect_sw(&radix);
+ err_write_1(": integer overflow");
r = -1;
goto restore;
}
u *= radix;
u2 = UW_MAX - digit;
if (u > u2) {
- warnx("buf_parse_uw_base: +: integer overflow");
+ err_write_1("buf_parse_uw_base: +: integer overflow");
r = -1;
goto restore;
}
diff --git a/libc3/c3.h b/libc3/c3.h
index 679f17b..3b32b24 100644
--- a/libc3/c3.h
+++ b/libc3/c3.h
@@ -15,6 +15,7 @@
#include "arg.h"
#include "array.h"
+#include "assert.h"
#include "bool.h"
#include "buf.h"
#include "buf_file.h"
diff --git a/libc3/call.c b/libc3/call.c
index 6d666f6..9c63714 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <string.h>
#include "buf.h"
#include "buf_inspect.h"
@@ -65,29 +65,39 @@ bool call_get (s_call *call, s_facts *facts)
&tag_symbol, &tag_ident) &&
! facts_find_fact_by_tags(facts, &tag_module_name,
&tag_operator, &tag_ident)) {
- warnx("call_get: symbol %s not found in module %s",
- call->ident.sym->str.ptr.ps8,
- call->ident.module->str.ptr.ps8);
+ err_write_1("call_get: symbol ");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_write_1(" not found in module ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1("\n");
return false;
}
facts_with_tags(facts, &cursor, &tag_ident, &tag_fn, &tag_var);
if (facts_cursor_next(&cursor)) {
if (tag_var.type == TAG_FN)
call->fn = fn_new_copy(&tag_var.data.fn);
- else
- warnx("call_get: %s.%s is not a function",
- call->ident.module->str.ptr.ps8,
- call->ident.sym->str.ptr.ps8);
+ else {
+ err_write_1("call_get: ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_puts(" is not a function");
+ return false;
+ }
}
facts_cursor_clean(&cursor);
facts_with_tags(facts, &cursor, &tag_ident, &tag_cfn, &tag_var);
if (facts_cursor_next(&cursor)) {
if (tag_var.type == TAG_CFN)
call->cfn = cfn_new_copy(&tag_var.data.cfn);
- else
- errx(1, "%s.%s is not a C function",
- call->ident.module->str.ptr.ps8,
- call->ident.sym->str.ptr.ps8);
+ else {
+ err_write_1("call_get: ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_puts(" is not a C function");
+ return false;
+ }
}
facts_cursor_clean(&cursor);
if (facts_find_fact_by_tags(facts, &tag_ident, &tag_is_a,
@@ -135,9 +145,11 @@ bool call_op_get (s_call *call, s_facts *facts)
&tag_symbol, &tag_ident, /* module exports symbol */
NULL, NULL });
if (! facts_with_cursor_next(&cursor)) {
- warnx("symbol %s not found in module %s",
- call->ident.sym->str.ptr.ps8,
- call->ident.module->str.ptr.ps8);
+ err_write_1("call_get: symbol ");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_write_1(" not found in module ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1("\n");
facts_with_cursor_clean(&cursor);
return false;
}
@@ -146,10 +158,15 @@ bool call_op_get (s_call *call, s_facts *facts)
&tag_ident, &tag_fn, &tag_var,
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
- if (tag_var.type != TAG_FN)
- errx(1, "%s.%s is not a function",
- call->ident.module->str.ptr.ps8,
- call->ident.sym->str.ptr.ps8);
+ if (tag_var.type != TAG_FN) {
+ err_write_1("call_get: ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_puts(" is not a function");
+ facts_with_cursor_clean(&cursor);
+ return false;
+ }
call->fn = fn_new_copy(&tag_var.data.fn);
}
facts_with_cursor_clean(&cursor);
@@ -157,10 +174,15 @@ bool call_op_get (s_call *call, s_facts *facts)
&tag_ident, &tag_cfn, &tag_var,
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
- if (tag_var.type != TAG_CFN)
- errx(1, "%s.%s is not a C function",
- call->ident.module->str.ptr.ps8,
- call->ident.sym->str.ptr.ps8);
+ if (tag_var.type != TAG_CFN) {
+ err_write_1("call_get: ");
+ err_write_1(call->ident.module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(call->ident.sym->str.ptr.ps8);
+ err_puts(" is not a C function");
+ facts_with_cursor_clean(&cursor);
+ return false;
+ }
call->cfn = cfn_new_copy(&tag_var.data.cfn);
}
facts_with_cursor_clean(&cursor);
@@ -195,9 +217,21 @@ s_call * call_init (s_call *call)
s_call * call_init_1 (s_call *call, const s8 *p)
{
s_buf buf;
- buf_init_1(&buf, false, (s8 *) p);
- if (buf_parse_call(&buf, call) != (sw) strlen(p))
- errx(1, "invalid call: %s", p);
+ uw len;
+ sw r;
+ len = strlen(p);
+ buf_init(&buf, false, len, (s8 *) p);
+ r = buf_parse_call(&buf, call);
+ if (r < 0 || (uw) r != len) {
+ err_write_1("call_init_1: invalid call: ");
+ err_write_1(p);
+ err_write_1(": ");
+ err_inspect_sw(&r);
+ err_write_1(" != ");
+ err_inspect_uw(&len);
+ err_write_1("\n");
+ return NULL;
+ }
return call;
}
diff --git a/libc3/env.c b/libc3/env.c
index 54d9e2e..10747a8 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -794,7 +794,8 @@ const s_list * env_get_struct_type_spec (s_env *env,
module->str.ptr.ps8);
return NULL;
}
- if (tag_var.type != TAG_LIST) {
+ if (tag_var.type != TAG_LIST ||
+ ! list_is_plist(tag_var.data.list)) {
warnx("env_get_struct_type_spec: module %s"
" has a defstruct that is not a property list",
module->str.ptr.ps8);
diff --git a/libc3/eval.c b/libc3/eval.c
index 8903491..93a1c26 100644
--- a/libc3/eval.c
+++ b/libc3/eval.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <stdlib.h>
#include "c3.h"
diff --git a/libc3/facts_with_cursor.c b/libc3/facts_with_cursor.c
index 38c9b4c..44a482e 100644
--- a/libc3/facts_with_cursor.c
+++ b/libc3/facts_with_cursor.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include "buf.h"
#include "buf_inspect.h"
@@ -33,8 +33,11 @@ void facts_with_cursor_clean (s_facts_with_cursor *cursor)
}
free(cursor->levels);
free(cursor->spec);
- if (pthread_mutex_destroy(&cursor->mutex))
- errx(1, "facts_with_cursor_clean: pthread_mutex_destroy");
+ if (pthread_mutex_destroy(&cursor->mutex)) {
+ err_puts("facts_with_cursor_clean: pthread_mutex_destroy");
+ assert(! "facts_with_cursor_clean: pthread_mutex_destroy");
+ exit(1);
+ }
}
s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
@@ -43,30 +46,36 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
s_facts_with_cursor_level *level;
p_facts_spec parent_spec;
assert(cursor);
- if (pthread_mutex_lock(&cursor->mutex))
- errx(1, "facts_with_cursor_next: pthread_mutex_lock");
+ if (pthread_mutex_lock(&cursor->mutex)) {
+ err_puts("facts_with_cursor_next: pthread_mutex_lock");
+ assert(! "facts_with_cursor_next: pthread_mutex_lock");
+ exit(1);
+ }
if (! cursor->facts_count)
goto ko;
if (cursor->level == cursor->facts_count) {
level = &cursor->levels[cursor->facts_count - 1];
#ifdef DEBUG_FACTS
- buf_write_1(&g_c3_env.err, "[debug] cursor->level=");
- buf_inspect_uw(&g_c3_env.err, &cursor->level);
- buf_write_1(&g_c3_env.err, " level->spec=");
- buf_inspect_facts_spec(&g_c3_env.err, level->spec);
- buf_write_1(&g_c3_env.err, " ");
- buf_inspect_fact(&g_c3_env.err, level->fact);
+ err_write_1("[debug] cursor->level=");
+ err_inspect_uw(&cursor->level);
+ err_write_1(" level->spec=");
+ err_inspect_facts_spec(level->spec);
+ err_write_1(" ");
+ err_inspect_fact(level->fact);
#endif
level->fact = facts_cursor_next(&level->cursor);
#ifdef DEBUG_FACTS
- buf_write_1(&g_c3_env.err, " -> ");
- buf_inspect_fact(&g_c3_env.err, level->fact);
- buf_write_1(&g_c3_env.err, "\n");
- buf_flush(&g_c3_env.err);
+ err_write_1(" -> ");
+ err_inspect_fact(level->fact);
+ err_write_1("\n");
+ err_flush(err);
#endif
if (level->fact) {
- if (pthread_mutex_unlock(&cursor->mutex))
- errx(1, "facts_with_cursor_next: pthread_mutex_unlock");
+ if (pthread_mutex_unlock(&cursor->mutex)) {
+ err_puts("facts_with_cursor_next: pthread_mutex_unlock");
+ assert(! "facts_with_cursor_next: pthread_mutex_unlock");
+ exit(1);
+ }
return level->fact;
}
free(level->spec);
@@ -118,11 +127,17 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
}
cursor->level--;
}
- if (pthread_mutex_unlock(&cursor->mutex))
- errx(1, "facts_with_cursor_next: pthread_mutex_unlock");
+ if (pthread_mutex_unlock(&cursor->mutex)) {
+ err_puts("facts_with_cursor_next: pthread_mutex_unlock");
+ assert(! "facts_with_cursor_next: pthread_mutex_unlock");
+ exit(1);
+ }
return fact;
ko:
- if (pthread_mutex_unlock(&cursor->mutex))
- errx(1, "facts_with_cursor_next: pthread_mutex_unlock");
+ if (pthread_mutex_unlock(&cursor->mutex)) {
+ err_puts("facts_with_cursor_next: pthread_mutex_unlock");
+ assert(! "facts_with_cursor_next: pthread_mutex_unlock");
+ exit(1);
+ }
return NULL;
}
diff --git a/libc3/ident.c b/libc3/ident.c
index eb98e86..12967f3 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include "buf.h"
#include "buf_inspect.h"
#include "character.h"
@@ -87,11 +87,6 @@ s_tag * ident_get (const s_ident *ident, s_facts *facts, s_tag *dest)
&tag_symbol, &tag_ident, /* module exports symbol */
NULL, NULL });
if (! facts_with_cursor_next(&cursor)) {
- /*
- warnx("symbol %s not found in module %s",
- ident->sym->str.ptr.ps8,
- module->str.ptr.ps8);
- */
facts_with_cursor_clean(&cursor);
return NULL;
}
@@ -101,9 +96,11 @@ s_tag * ident_get (const s_ident *ident, s_facts *facts, s_tag *dest)
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
if (tag_var.type != TAG_CFN) {
- warnx("%s.%s :cfn is not a C function",
- module->str.ptr.ps8,
- ident->sym->str.ptr.ps8);
+ err_write_1("call_get: ");
+ err_write_1(module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(ident->sym->str.ptr.ps8);
+ err_puts(" is not a C function");
facts_with_cursor_clean(&cursor);
return NULL;
}
@@ -115,9 +112,11 @@ s_tag * ident_get (const s_ident *ident, s_facts *facts, s_tag *dest)
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
if (tag_var.type != TAG_FN) {
- warnx("%s.%s :fn is not a function",
- module->str.ptr.ps8,
- ident->sym->str.ptr.ps8);
+ err_write_1("call_get: ");
+ err_write_1(module->str.ptr.ps8);
+ err_write_1(".");
+ err_write_1(ident->sym->str.ptr.ps8);
+ err_puts(" is not a function");
facts_with_cursor_clean(&cursor);
return NULL;
}
diff --git a/libc3/io.c b/libc3/io.c
index ae83a48..2139674 100644
--- a/libc3/io.c
+++ b/libc3/io.c
@@ -16,7 +16,7 @@
#include "io.h"
#define DEF_ERR_INSPECT(name, type) \
- sw err_inspect_ ## name (const type *x) \
+ sw err_inspect_ ## name (type x) \
{ \
sw r; \
sw result = 0; \
@@ -31,7 +31,7 @@
}
#define DEF_IO_INSPECT(name, type) \
- sw io_inspect_ ## name (const type *x) \
+ sw io_inspect_ ## name (type x) \
{ \
sw r; \
sw result = 0; \
@@ -64,10 +64,18 @@ sw err_puts (const s8 *x)
if ((r = buf_write_u8(&g_c3_env.err, '\n')) < 0)
return r;
result += r;
- buf_flush(&g_c3_env.out);
+ buf_flush(&g_c3_env.err);
return result;
}
+sw err_write_1 (const s8 *x)
+{
+ sw r;
+ if ((r = buf_write_1(&g_c3_env.err, x)) > 0)
+ buf_flush(&g_c3_env.err);
+ return r;
+}
+
sw io_inspect (const s_tag *x)
{
sw r;
@@ -96,8 +104,28 @@ sw io_puts (const s8 *x)
return result;
}
-DEF_ERR_IO_INSPECT(fact, s_fact)
-DEF_ERR_IO_INSPECT(fn_pattern, s_list)
-DEF_ERR_IO_INSPECT(list, s_list *)
-DEF_ERR_IO_INSPECT(str, s_str)
-DEF_ERR_IO_INSPECT(tag, s_tag)
+sw io_write_1 (const s8 *x)
+{
+ sw r;
+ if ((r = buf_write_1(&g_c3_env.out, x)) > 0)
+ buf_flush(&g_c3_env.out);
+ return r;
+}
+
+DEF_ERR_IO_INSPECT(array, const s_array *)
+DEF_ERR_IO_INSPECT(fact, const s_fact *)
+DEF_ERR_IO_INSPECT(fn_pattern, const s_list *)
+DEF_ERR_IO_INSPECT(list, const s_list **)
+DEF_ERR_IO_INSPECT(map, const s_map *)
+DEF_ERR_IO_INSPECT(str, const s_str *)
+DEF_ERR_IO_INSPECT(tag, const s_tag *)
+DEF_ERR_IO_INSPECT(s8, const s8 *)
+DEF_ERR_IO_INSPECT(s16, const s16 *)
+DEF_ERR_IO_INSPECT(s32, const s32 *)
+DEF_ERR_IO_INSPECT(s64, const s64 *)
+DEF_ERR_IO_INSPECT(sw, const sw *)
+DEF_ERR_IO_INSPECT(u8, const u8 *)
+DEF_ERR_IO_INSPECT(u16, const u16 *)
+DEF_ERR_IO_INSPECT(u32, const u32 *)
+DEF_ERR_IO_INSPECT(u64, const u64 *)
+DEF_ERR_IO_INSPECT(uw, const uw *)
diff --git a/libc3/io.h b/libc3/io.h
index 5e7db1b..620ee0f 100644
--- a/libc3/io.h
+++ b/libc3/io.h
@@ -16,10 +16,10 @@
#include "types.h"
#define PROTOTYPE_ERR_INSPECT(name, type) \
- sw err_inspect_ ## name (const type *x) \
+ sw err_inspect_ ## name (type x) \
#define PROTOTYPE_IO_INSPECT(name, type) \
- sw io_inspect_ ## name (const type *x) \
+ sw io_inspect_ ## name (type x) \
#define PROTOTYPES_ERR_IO_INSPECT(name, type) \
PROTOTYPE_ERR_INSPECT(name, type); \
@@ -28,17 +28,30 @@
/* error output */
sw err_inspect (const s_tag *x);
sw err_puts (const s8 *x);
+sw err_write_1 (const s8 *x);
/* standard output */
sw io_inspect (const s_tag *x);
sw io_puts (const s8 *x);
-
-PROTOTYPES_ERR_IO_INSPECT(array, s_array);
-PROTOTYPES_ERR_IO_INSPECT(fact, s_fact);
-PROTOTYPES_ERR_IO_INSPECT(fn_pattern, s_list);
-PROTOTYPES_ERR_IO_INSPECT(list, s_list *);
-PROTOTYPES_ERR_IO_INSPECT(map, s_map);
-PROTOTYPES_ERR_IO_INSPECT(str, s_str);
-PROTOTYPES_ERR_IO_INSPECT(tag, s_tag);
+sw io_write_1 (const s8 *x);
+
+PROTOTYPES_ERR_IO_INSPECT(array, const s_array *);
+PROTOTYPES_ERR_IO_INSPECT(fact, const s_fact *);
+PROTOTYPES_ERR_IO_INSPECT(facts_spec, const p_facts_spec);
+PROTOTYPES_ERR_IO_INSPECT(fn_pattern, const s_list *);
+PROTOTYPES_ERR_IO_INSPECT(list, const s_list **);
+PROTOTYPES_ERR_IO_INSPECT(map, const s_map *);
+PROTOTYPES_ERR_IO_INSPECT(str, const s_str *);
+PROTOTYPES_ERR_IO_INSPECT(tag, const s_tag *);
+PROTOTYPES_ERR_IO_INSPECT(s8, const s8 *);
+PROTOTYPES_ERR_IO_INSPECT(s16, const s16 *);
+PROTOTYPES_ERR_IO_INSPECT(s32, const s32 *);
+PROTOTYPES_ERR_IO_INSPECT(s64, const s64 *);
+PROTOTYPES_ERR_IO_INSPECT(sw, const sw *);
+PROTOTYPES_ERR_IO_INSPECT(u8, const u8 *);
+PROTOTYPES_ERR_IO_INSPECT(u16, const u16 *);
+PROTOTYPES_ERR_IO_INSPECT(u32, const u32 *);
+PROTOTYPES_ERR_IO_INSPECT(u64, const u64 *);
+PROTOTYPES_ERR_IO_INSPECT(uw, const uw *);
#endif /* LIBC3_IO_H */
diff --git a/libc3/list.c b/libc3/list.c
index 8e7c46f..e7fb81f 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include <string.h>
#include "array.h"
@@ -138,6 +138,22 @@ s_str * list_inspect (const s_list *x, s_str *dest)
return NULL;
}
+bool list_is_plist (const s_list *list)
+{
+ const s_list *l;
+ if (! list)
+ return false;
+ l = list;
+ while (l) {
+ if (l->tag.type != TAG_TUPLE ||
+ l->tag.data.tuple.count != 2 ||
+ l->tag.data.tuple.tag[0].type != TAG_SYM)
+ return false;
+ l = list_next(l);
+ }
+ return true;
+}
+
sw list_length (const s_list *list)
{
sw length = 0;
@@ -161,7 +177,7 @@ s_list * list_new (s_list *next)
{
s_list *dest;
if (! (dest = calloc(1, sizeof(s_list)))) {
- warnx("list_new: out of memory");
+ err_puts("list_new: failed to allocate memory");
return NULL;
}
return list_init(dest, next);
@@ -258,14 +274,20 @@ s_array * list_to_array (s_list *list, const s_sym *type,
size = sym_type_size(type);
dest->dimension = 1;
dest->type = type;
- if (! (dest->dimensions = calloc(1, sizeof(s_array_dimension))))
- errx(1, "list_to_array: out of memory: 1");
+ if (! (dest->dimensions = calloc(1, sizeof(s_array_dimension)))) {
+ err_puts("list_to_array: out of memory: 1");
+ assert(! "list_to_array: out of memory: 1");
+ return NULL;
+ }
dest->count = len;
dest->dimensions[0].count = len;
dest->dimensions[0].item_size = size;
dest->size = len * size;
- if (! (data = dest->data = calloc(len, size)))
- errx(1, "list_to_array: out of memory: 2");
+ if (! (data = dest->data = calloc(len, size))) {
+ err_puts("list_to_array: out of memory: 2");
+ assert(! "list_to_array: out of memory: 2");
+ return NULL;
+ }
init_copy = sym_to_init_copy(type);
l = list;
while (l) {
diff --git a/libc3/list.h b/libc3/list.h
index bb3ec64..6a6ab09 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -46,12 +46,12 @@ s_list * list_new_str_1 (s8 *free, const s8 *p, s_list *next);
/* Observers */
s_list ** list_cast (const s_tag *tag, s_list **list);
+bool list_is_plist (const s_list *list);
sw list_length (const s_list *list);
s_list * list_next (const s_list *list);
s_array * list_to_array (s_list *list, const s_sym *type,
s_array *dest);
s_tuple * list_to_tuple_reverse (const s_list *list, s_tuple *dest);
-/* Call str_delete after use. */
s_str * list_inspect (const s_list *list, s_str *dest);
/* Operators */
diff --git a/libc3/log.c b/libc3/log.c
index 2e95e5a..ff0ab04 100644
--- a/libc3/log.c
+++ b/libc3/log.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include "buf.h"
#include "buf_file.h"
#include "hash.h"
@@ -35,21 +35,27 @@ void log_delete (s_log *log)
free(log);
}
-void log_init (s_log *log)
+s_log * log_init (s_log *log)
{
- buf_init_alloc(&log->buf, BUF_SIZE);
+ if (! buf_init_alloc(&log->buf, BUF_SIZE))
+ return NULL;
log->count = 0;
hash_init(&log->hash);
+ return log;
}
s_log * log_new (void)
{
s_log *log;
- if (! (log = malloc(sizeof(s_log)))) {
- warnx("log_new: failed to allocate memory");
+ log = malloc(sizeof(s_log));
+ if (! log) {
+ err_puts("log_new: failed to allocate memory");
+ return NULL;
+ }
+ if (! log_init(log)) {
+ free(log);
return NULL;
}
- log_init(log);
return log;
}
diff --git a/libc3/log.h b/libc3/log.h
index 30138da..1ea3662 100644
--- a/libc3/log.h
+++ b/libc3/log.h
@@ -15,18 +15,16 @@
#include "types.h"
-/* stack-allocation compatible functions */
-void log_init (s_log *log);
-void log_clean (s_log *log);
+/* Stack-allocation compatible functions, call log_clean after use. */
+void log_clean (s_log *log);
+s_log * log_init (s_log *log);
-/* constructor */
+/* Heap-allocation functions, call log_delete after use. */
+void log_delete (s_log *log);
s_log * log_new (void);
-/* destructor */
-void log_delete (s_log *log);
-
-/* modifiers */
+/* Operators. */
void log_close (s_log *log);
-sw log_open (s_log *log, FILE *fp);
+sw log_open (s_log *log, FILE *fp);
#endif /* LIBC3_LOG_H */
diff --git a/libc3/operator.c b/libc3/operator.c
index ca44a7a..6dd2233 100644
--- a/libc3/operator.c
+++ b/libc3/operator.c
@@ -10,8 +10,8 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include "c3.h"
+#include "env.h"
+#include "operator.h"
s8 operator_arity (const s_ident *op)
{
diff --git a/libc3/sym.c b/libc3/sym.c
index 8216495..874b7e0 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <stdlib.h>
#include <string.h>
#include "c3.h"
@@ -138,8 +136,11 @@ s_sym_list * sym_list_new (s_sym *sym, s_sym_list *next)
{
s_sym_list *sym_list;
sym_list = malloc(sizeof(s_sym_list));
- if (! sym_list)
- err(1, "out of memory");
+ if (! sym_list) {
+ err_puts("sym_list_new: failed to allocate memory");
+ assert(! "sym_list_new: failed to allocate memory");
+ return NULL;
+ }
sym_list->sym = sym;
sym_list->next = next;
return sym_list;
@@ -148,11 +149,24 @@ s_sym_list * sym_list_new (s_sym *sym, s_sym_list *next)
const s_sym * sym_new (const s_str *src)
{
s_sym *sym;
+ s_sym_list *tmp;
sym = malloc(sizeof(s_sym));
- if (! sym)
- err(1, "out of memory");
- str_init_copy(&sym->str, src);
- g_sym_list = sym_list_new(sym, g_sym_list);
+ if (! sym) {
+ err_puts("sym_new: failed to allocate memory");
+ assert(! "sym_new: failed to allocate memory");
+ return NULL;
+ }
+ if (! str_init_copy(&sym->str, src)) {
+ free(sym);
+ return NULL;
+ }
+ tmp = sym_list_new(sym, g_sym_list);
+ if (! tmp) {
+ str_clean(&sym->str);
+ free(sym);
+ return NULL;
+ }
+ g_sym_list = tmp;
return sym;
}
@@ -212,8 +226,10 @@ f_buf_inspect sym_to_buf_inspect (const s_sym *type)
return (f_buf_inspect) buf_inspect_tuple;
if (type == sym_1("Var"))
return (f_buf_inspect) buf_inspect_var;
+ err_write_1("sym_to_buf_inspect: unknown type: ");
+ err_write_1(type->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_to_buf_inspect: unknown type");
- errx(1, "sym_to_buf_inspect: unknown type");
return NULL;
}
@@ -273,8 +289,10 @@ f_buf_inspect_size sym_to_buf_inspect_size (const s_sym *type)
return (f_buf_inspect_size) buf_inspect_tuple_size;
if (type == sym_1("Var"))
return (f_buf_inspect_size) buf_inspect_var_size;
- assert(! "sym_to_buf_inspect: unknown type");
- errx(1, "sym_to_buf_inspect: unknown type");
+ err_write_1("sym_to_buf_inspect_size: unknown type: ");
+ err_write_1(type->str.ptr.ps8);
+ err_write_1("\n");
+ assert(! "sym_to_buf_inspect_size: unknown type");
return NULL;
}
@@ -334,8 +352,10 @@ f_clean sym_to_clean (const s_sym *type)
return (f_clean) tuple_clean;
if (type == sym_1("Var"))
return NULL;
+ err_write_1("sym_to_clean: unknown type: ");
+ err_write_1(type->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_to_clean: unknown type");
- errx(1, "sym_to_clean: unknown type");
return NULL;
}
@@ -344,8 +364,10 @@ ffi_type * sym_to_ffi_type (const s_sym *sym, ffi_type *result_type)
assert(sym);
if (sym == sym_1("Result") ||
sym == sym_1("&result")) {
- if (! result_type)
- warnx("invalid result type: &result");
+ if (! result_type) {
+ err_puts("sym_to_ffi_type: invalid result type: Result");
+ return NULL;
+ }
return result_type;
}
if (sym->str.ptr.ps8[sym->str.size - 2] == '*')
@@ -405,8 +427,10 @@ ffi_type * sym_to_ffi_type (const s_sym *sym, ffi_type *result_type)
if (sym == sym_1("Void") ||
sym == sym_1("void"))
return &ffi_type_void;
+ err_write_1("sym_to_ffi_type: unknown type: ");
+ err_write_1(sym->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_to_ffi_type: unknown type");
- errx(1, "sym_to_ffi_type: unknown type: %s", sym->str.ptr.ps8);
return NULL;
}
@@ -466,8 +490,10 @@ f_init_copy sym_to_init_copy (const s_sym *type)
return (f_init_copy) tuple_init_copy;
if (type == sym_1("Var"))
return (f_init_copy) var_init_copy;
+ err_write_1("sym_to_init_copy: unknown type: ");
+ err_write_1(type->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_to_init_copy: unknown type");
- errx(1, "sym_to_init_copy: unknown type");
return NULL;
}
@@ -612,7 +638,9 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
*dest = TAG_TUPLE;
return true;
}
- warnx("sym_to_tag_type: unknown type: %s", sym->str.ptr.ps8);
+ err_write_1("sym_to_tag_type: unknown type: ");
+ err_write_1(sym->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_to_tag_type: unknown type");
return false;
}
@@ -673,7 +701,9 @@ uw sym_type_size (const s_sym *type)
return sizeof(s_tuple);
if (type == sym_1("Var"))
return sizeof(s_tag);
+ err_write_1("sym_type_size: unknown type: ");
+ err_write_1(type->str.ptr.ps8);
+ err_write_1("\n");
assert(! "sym_type_size: unknown type");
- errx(1, "sym_type_size: unknown type: %s", type->str.ptr.ps8);
return 0;
}
diff --git a/libc3/tuple.c b/libc3/tuple.c
index 0aea6ee..ab5c959 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -10,12 +10,13 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include <string.h>
#include "buf.h"
#include "buf_inspect.h"
#include "buf_parse.h"
+#include "io.h"
#include "tuple.h"
#include "tag.h"
@@ -38,15 +39,20 @@ void tuple_delete (s_tuple *tuple)
s_tuple * tuple_init (s_tuple *tuple, uw count)
{
uw i;
+ s_tuple tmp;
assert(tuple);
assert(2 <= count);
- tuple->count = count;
- tuple->tag = calloc(count, sizeof(s_tag));
- if (! tuple->tag)
- err(1, "tuple_init: out of memory");
+ tmp.count = count;
+ tmp.tag = calloc(count, sizeof(s_tag));
+ if (! tmp.tag) {
+ err_puts("tuple_init: failed to allocate memory");
+ assert(! "tuple_init: failed to allocate memory");
+ return NULL;
+ }
i = count;
while (i--)
- tag_init_void(tuple->tag + i);
+ tag_init_void(tmp.tag + i);
+ *tuple = tmp;
return tuple;
}
@@ -62,8 +68,13 @@ s_tuple * tuple_init_1 (s_tuple *tuple, const s8 *p)
buf.wpos = len;
r = buf_parse_tuple(&buf, tuple);
if (r < 0 || (uw) r != len) {
- warnx("tuple_init_1: invalid tuple: \"%s\", %lu != %ld",
- p, len, r);
+ err_write_1("tuple_init_1: invalid tuple: \"");
+ err_write_1(p);
+ err_write_1("\", ");
+ err_inspect_uw(&len);
+ err_write_1(" != ");
+ err_inspect_sw(&r);
+ err_write_1("\n");
assert(! "tuple_init_1: invalid tuple");
return NULL;
}
@@ -111,18 +122,32 @@ s_str * tuple_inspect (const s_tuple *x, s_str *dest)
s_tuple * tuple_new (uw count)
{
- s_tuple *t;
- t = malloc(sizeof(s_tuple));
- if (! t)
- errx(1, "tuple_new: out of memory");
- return tuple_init(t, count);
+ s_tuple *tuple;
+ tuple = malloc(sizeof(s_tuple));
+ if (! tuple) {
+ err_puts("tuple_new: failed to allocate memory");
+ assert(! "tuple_new: failed to allocate memory");
+ return NULL;
+ }
+ if (! tuple_init(tuple, count)) {
+ free(tuple);
+ return NULL;
+ }
+ return tuple;
}
s_tuple * tuple_new_1 (const s8 *p)
{
- s_tuple *t;
- t = malloc(sizeof(s_tuple));
- if (! t)
- errx(1, "tuple_new_1: out of memory");
- return tuple_init_1(t, p);
+ s_tuple *tuple;
+ tuple = malloc(sizeof(s_tuple));
+ if (! tuple) {
+ err_puts("tuple_new_1: failed to allocate memory");
+ assert(! "tuple_new_1: failed to allocate memory");
+ return NULL;
+ }
+ if (! tuple_init_1(tuple, p)) {
+ free(tuple);
+ return NULL;
+ }
+ return tuple;
}
diff --git a/libc3/window/cairo/cairo_font.c b/libc3/window/cairo/cairo_font.c
index 994c548..2569b51 100644
--- a/libc3/window/cairo/cairo_font.c
+++ b/libc3/window/cairo/cairo_font.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <libc3/c3.h>
#include "cairo_font.h"
@@ -31,12 +29,13 @@ void cairo_font_clean (s_cairo_font *font)
static FT_Library * cairo_font_ft (void)
{
if (! g_cairo_font_ft) {
- if (! (g_cairo_font_ft = malloc(sizeof(FT_Library)))) {
- warn("cairo_font_ft");
+ g_cairo_font_ft = malloc(sizeof(FT_Library));
+ if (! g_cairo_font_ft) {
+ err_puts("cairo_font_ft: failed to allocate memory");
return NULL;
}
if (FT_Init_FreeType(g_cairo_font_ft)) {
- warnx("cairo_font_ft: error initializing FreeType");
+ err_puts("cairo_font_ft: error initializing FreeType");
free(g_cairo_font_ft);
g_cairo_font_ft = NULL;
return NULL;
@@ -54,13 +53,14 @@ s_cairo_font * cairo_font_init (s_cairo_font *font, const s_str *path)
return NULL;
str_init_copy(&font->path, path);
if (! file_search(path, sym_1("r"), &font->real_path)) {
- warnx("cairo_font_init(%s): file not found", path->ptr.ps8);
+ err_write_1("cairo_font_init: file not found: ");
+ err_puts(path->ptr.ps8);
str_clean(&font->path);
return NULL;
}
if (FT_New_Face(*ft, font->real_path.ptr.ps8, 0, &font->ft_face)) {
- warnx("cairo_font_init(%s): Error loading font",
- font->real_path.ptr.ps8);
+ err_write_1("cairo_font_init: error loading font: ");
+ err_puts(font->real_path.ptr.ps8);
str_clean(&font->path);
str_clean(&font->real_path);
return NULL;
diff --git a/libc3/window/cairo/cairo_sprite.c b/libc3/window/cairo/cairo_sprite.c
index 0284863..505b1fa 100644
--- a/libc3/window/cairo/cairo_sprite.c
+++ b/libc3/window/cairo/cairo_sprite.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <libc3/c3.h>
#include "cairo_sprite.h"
@@ -63,14 +61,15 @@ s_cairo_sprite * cairo_sprite_init (s_cairo_sprite *sprite,
assert(dim_y);
str_init_copy_1(&sprite->path, path);
if (! file_search(&sprite->path, sym_1("r"), &sprite->real_path)) {
- warnx("cairo_sprite_init: file not found: %s", path);
+ err_write_1("cairo_sprite_init: file not found: ");
+ err_puts(path);
str_clean(&sprite->path);
return NULL;
}
src = cairo_image_surface_create_from_png(sprite->real_path.ptr.ps8);
if (! src) {
- warnx("cairo_sprite_init: error loading image: %s",
- sprite->real_path.ptr.ps8);
+ err_write_1("cairo_sprite_init: error loading image: ");
+ err_puts(sprite->real_path.ptr.ps8);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
return NULL;
@@ -84,7 +83,8 @@ s_cairo_sprite * cairo_sprite_init (s_cairo_sprite *sprite,
sprite->frame_count = frame_count ? frame_count : (dim_x * dim_y);
sprite->surface = calloc(frame_count, sizeof(cairo_surface_t *));
if (! sprite->surface) {
- warn("cairo_sprite_init: sprite->surface");
+ err_puts("cairo_sprite_init: sprite->surface:"
+ " failed to allocate memory");
cairo_surface_destroy(src);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
diff --git a/libc3/window/cairo/demo/bg_rect.c b/libc3/window/cairo/demo/bg_rect.c
index d53f0f8..645d4e1 100644
--- a/libc3/window/cairo/demo/bg_rect.c
+++ b/libc3/window/cairo/demo/bg_rect.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
#include <libc3/c3.h>
#include "../types.h"
diff --git a/libc3/window/cairo/demo/window_cairo_demo.c b/libc3/window/cairo/demo/window_cairo_demo.c
index c687106..3a409ca 100644
--- a/libc3/window/cairo/demo/window_cairo_demo.c
+++ b/libc3/window/cairo/demo/window_cairo_demo.c
@@ -10,9 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
-#include <stdio.h>
#include <stdlib.h>
#include <libc3/c3.h>
#include <xkbcommon/xkbcommon.h>
@@ -30,7 +28,13 @@ bool window_cairo_demo_button (s_window_cairo *window, u8 button,
{
assert(window);
(void) window;
- printf("c3_window_cairo_demo_button: %lu (%ld, %ld)\n", (uw) button, x, y);
+ io_write_1("c3_window_cairo_demo_button: ");
+ io_inspect_u8(&button);
+ io_write_1(" (");
+ io_inspect_sw(&x);
+ io_write_1(", ");
+ io_inspect_sw(&y);
+ io_puts(")");
return true;
}
@@ -59,7 +63,10 @@ bool window_cairo_demo_key (s_window_cairo *window, uw keysym)
break;
default:
xkb_keysym_get_name(keysym, keysym_name, sizeof(keysym_name));
- printf("c3_window_cairo_demo_key: %lu %s\n", keysym, keysym_name);
+ io_write_1("c3_window_cairo_demo_key: ");
+ io_inspect_uw(&keysym);
+ io_write_1(" ");
+ io_puts(keysym_name);
}
return true;
}
@@ -68,8 +75,9 @@ bool window_cairo_demo_load (s_window_cairo *window)
{
assert(window);
if (window->sequence_count != WINDOW_CAIRO_DEMO_SEQUENCE_COUNT) {
- fprintf(stderr, "window_cairo_demo_load: "
- "window->sequence_count = %lu\n", window->sequence_count);
+ err_write_1("window_cairo_demo_load: window->sequence_count = ");
+ err_inspect_uw(&window->sequence_count);
+ err_write_1("\n");
assert(window->sequence_count == WINDOW_CAIRO_DEMO_SEQUENCE_COUNT);
return false;
}
diff --git a/libc3/window/sdl2/demo/bg_rect.c b/libc3/window/sdl2/demo/bg_rect.c
index 6802a2d..a269c6c 100644
--- a/libc3/window/sdl2/demo/bg_rect.c
+++ b/libc3/window/sdl2/demo/bg_rect.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
#include <libc3/c3.h>
#include "../types.h"
diff --git a/libc3/window/sdl2/gl_camera.c b/libc3/window/sdl2/gl_camera.c
index fd57698..3f4c946 100644
--- a/libc3/window/sdl2/gl_camera.c
+++ b/libc3/window/sdl2/gl_camera.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
#include <libc3/c3.h>
#include "gl_camera.h"
@@ -41,7 +40,7 @@ s_gl_camera * gl_camera_new (uw w, uw h)
s_gl_camera *camera;
camera = calloc(1, sizeof(s_gl_camera));
if (! camera) {
- warn("gl_camera_new: camera");
+ err_puts("gl_camera_new: failed to allocate memory");
return NULL;
}
if (! gl_camera_init(camera, w, h)) {
diff --git a/libc3/window/sdl2/gl_cylinder.c b/libc3/window/sdl2/gl_cylinder.c
index 44e5dbe..cc65fd0 100644
--- a/libc3/window/sdl2/gl_cylinder.c
+++ b/libc3/window/sdl2/gl_cylinder.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
#include <libc3/c3.h>
#include "gl.h"
@@ -31,8 +30,11 @@ s_gl_cylinder * gl_cylinder_init (s_gl_cylinder *cylinder,
p = calloc(segments_u * segments_v + 2,
sizeof(s_gl_3d));
if (! p) {
- warn("gl_cylinder_init(%lu, %lu): point array", segments_u,
- segments_v);
+ err_write_1("gl_cylinder_init(");
+ err_inspect_uw(&segments_u);
+ err_write_1(", ");
+ err_inspect_uw(&segments_v);
+ err_puts("): failed to allocate memory");
return NULL;
}
cylinder->vertex = p;
diff --git a/libc3/window/sdl2/gl_sphere.c b/libc3/window/sdl2/gl_sphere.c
index 8b07c3d..57c07e9 100644
--- a/libc3/window/sdl2/gl_sphere.c
+++ b/libc3/window/sdl2/gl_sphere.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <math.h>
#include <libc3/c3.h>
#include "gl.h"
@@ -48,8 +47,11 @@ s_gl_sphere * gl_sphere_init (s_gl_sphere *sphere, uw segments_u,
sphere->segments_v = segments_v;
p = calloc(segments_u * segments_v + 2, sizeof(s_gl_3d));
if (! p) {
- warn("gl_sphere_init(%lu, %lu): point array", segments_u,
- segments_v);
+ err_write_1("gl_sphere_init(");
+ err_inspect_uw(&segments_u);
+ err_write_1(", ");
+ err_inspect_uw(&segments_v);
+ err_write_1("): failed to allocate memory");
return NULL;
}
sphere->vertex = p;
@@ -84,7 +86,7 @@ s_gl_sphere * gl_sphere_new (uw segments_u, uw segments_w)
s_gl_sphere *sphere;
sphere = calloc(1, sizeof(s_gl_sphere));
if (! sphere) {
- warn("gl_sphere_new: sphere");
+ err_puts("gl_sphere_new: failed to allocate memory");
return NULL;
}
if (! gl_sphere_init(sphere, segments_u, segments_w)) {
diff --git a/libc3/window/sdl2/sdl2_font.c b/libc3/window/sdl2/sdl2_font.c
index e500c25..e4bdff9 100644
--- a/libc3/window/sdl2/sdl2_font.c
+++ b/libc3/window/sdl2/sdl2_font.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <libc3/c3.h>
#include "sdl2_font.h"
@@ -29,14 +27,15 @@ s_sdl2_font * sdl2_font_init (s_sdl2_font *font, const s8 *path)
assert(path);
str_init_copy_1(&font->path, path);
if (! file_search(&font->path, sym_1("r"), &font->real_path)) {
- warnx("sdl2_font_init(%s): file not found", path);
+ err_write_1("sdl2_font_init: file not found: ");
+ err_puts(path);
str_clean(&font->path);
return NULL;
}
font->ftgl_font = ftglCreateTextureFont(font->real_path.ptr.ps8);
if (! font->ftgl_font) {
- warnx("sdl2_font_init(%s): Error loading font",
- font->real_path.ptr.ps8);
+ err_write_1("sdl2_font_init: error loading font: ");
+ err_puts(font->real_path.ptr.ps8);
str_clean(&font->path);
str_clean(&font->real_path);
return NULL;
diff --git a/libc3/window/sdl2/sdl2_sprite.c b/libc3/window/sdl2/sdl2_sprite.c
index 1728c28..cb86351 100644
--- a/libc3/window/sdl2/sdl2_sprite.c
+++ b/libc3/window/sdl2/sdl2_sprite.c
@@ -10,9 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
-#include <unistd.h>
#include <libc3/c3.h>
#include "sdl2_sprite.h"
@@ -125,27 +122,31 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
sprite->frame_count = (frame_count > 0) ? frame_count : (dim_x * dim_y);
str_init_copy_1(&sprite->path, path);
if (! file_search(&sprite->path, sym_1("r"), &sprite->real_path)) {
- warnx("sdl2_sprite_init: file not found: %s", path);
+ err_write_1("sdl2_sprite_init: file not found: ");
+ err_puts(path);
str_clean(&sprite->path);
return NULL;
}
fp = fopen(sprite->real_path.ptr.ps8, "rb");
if (! fp) {
- warn("sdl2_sprite_init: %s", sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: fopen: ");
+ err_puts(sprite->real_path.ptr.ps8);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
return NULL;
}
if (fread(png_header, 1, sizeof(png_header), fp) !=
sizeof(png_header)) {
- warn("sdl2_sprite_init: %s", sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: fread: ");
+ err_puts(sprite->real_path.ptr.ps8);
fclose(fp);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
return NULL;
}
if (png_sig_cmp(png_header, 0, sizeof(png_header))) {
- warn("sdl2_sprite_init: %s: not a png", sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: not a png: ");
+ err_puts(sprite->real_path.ptr.ps8);
fclose(fp);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
@@ -154,8 +155,8 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
png_read = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);
if (! png_read) {
- warn("sdl2_sprite_init: %s: png_create_read_struct",
- sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: png_create_read_struct: ");
+ err_puts(sprite->real_path.ptr.ps8);
fclose(fp);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
@@ -163,8 +164,8 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
}
png_info = png_create_info_struct(png_read);
if (! png_info) {
- warn("sdl2_sprite_init: %s: png_create_info_struct",
- sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: png_create_info_struct: ");
+ err_puts(sprite->real_path.ptr.ps8);
png_destroy_read_struct(&png_read, NULL, NULL);
fclose(fp);
str_clean(&sprite->path);
@@ -190,15 +191,20 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
if (! png_info_to_gl_info(png_color_type, png_bit_depth, &gl_format,
&gl_internal_format, &gl_type,
&png_components)) {
- if (! gl_format || ! png_components)
- warnx("sdl2_sprite_init: %s: unknown PNG color type: %d",
- sprite->real_path.ptr.ps8, png_color_type);
- if (! gl_internal_format)
- warnx("sdl2_sprite_init: %s: unknown OpenGL internal format",
- sprite->real_path.ptr.ps8);
- if (! gl_type)
- warnx("sdl2_sprite_init: %s: unknown OpenGL type",
- sprite->real_path.ptr.ps8);
+ if (! gl_format || ! png_components) {
+ err_write_1("sdl2_sprite_init: unknown PNG color type ");
+ err_inspect_s32(&png_color_type);
+ err_write_1(": ");
+ err_puts(sprite->real_path.ptr.ps8);
+ }
+ if (! gl_internal_format) {
+ err_write_1("sdl2_sprite_init: unknown OpenGL internal format: ");
+ err_puts(sprite->real_path.ptr.ps8);
+ }
+ if (! gl_type) {
+ err_write_1("sdl2_sprite_init: unknown OpenGL type: ");
+ err_puts(sprite->real_path.ptr.ps8);
+ }
png_destroy_read_struct(&png_read, &png_info, NULL);
fclose(fp);
str_clean(&sprite->path);
@@ -230,7 +236,8 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
sprite->h = sprite->total_h / dim_y;
sprite->texture = malloc(sprite->frame_count * sizeof(GLuint));
if (! sprite->texture) {
- warn("sdl2_sprite_init: sprite->texture");
+ err_puts("sdl2_sprite_init: sprite->texture:"
+ " failed to allocate memory");
str_clean(&sprite->path);
str_clean(&sprite->real_path);
return NULL;
@@ -238,8 +245,10 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
glGenTextures(sprite->frame_count, sprite->texture);
GLenum gl_error = glGetError();
if (gl_error != GL_NO_ERROR) {
- warnx("sdl2_sprite_init: %s: glGenTextures: %s\n",
- sprite->real_path.ptr.ps8, gluErrorString(gl_error));
+ err_write_1("sdl2_sprite_init: glGenTextures: ");
+ err_write_1((const s8 *) gluErrorString(gl_error));
+ err_write_1(": ");
+ err_puts(sprite->real_path.ptr.ps8);
free(sprite->texture);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
@@ -248,7 +257,8 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
sprite_stride = sprite->w * png_pixel_size;
data = malloc(sprite->h * sprite_stride);
if (! data) {
- warn("sdl2_sprite_init: %s", sprite->real_path.ptr.ps8);
+ err_write_1("sdl2_sprite_init: failed to allocate memory: ");
+ err_puts(sprite->real_path.ptr.ps8);
free(sprite->texture);
str_clean(&sprite->path);
str_clean(&sprite->real_path);
@@ -280,8 +290,10 @@ s_sdl2_sprite * sdl2_sprite_init (s_sdl2_sprite *sprite,
sprite->h, gl_format, gl_type, data);
gl_error = glGetError();
if (gl_error != GL_NO_ERROR) {
- warnx("sdl2_sprite_init: %s: glTexImage2D: %s\n",
- sprite->real_path.ptr.ps8, gluErrorString(gl_error));
+ err_write_1("sdl2_sprite_init: glTexImage2D: ");
+ err_write_1((const s8 *) gluErrorString(gl_error));
+ err_write_1(": ");
+ err_puts(sprite->real_path.ptr.ps8);
return NULL;
}
i++;
diff --git a/libc3/window/window.c b/libc3/window/window.c
index 331e6d3..e95fd38 100644
--- a/libc3/window/window.c
+++ b/libc3/window/window.c
@@ -10,8 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
#include <libc3/c3.h>
#include "window.h"
@@ -22,12 +20,12 @@ bool window_animate (s_window *window)
s_sequence *seq;
f64 t;
if (clock_gettime(CLOCK_MONOTONIC, &clock_monotonic)) {
- warn("window_animate");
+ err_puts("window_animate: clock_gettime");
return false;
}
if (window->sequence_pos >= window->sequence_count) {
- warnx("window_animate: window->sequence_pos >="
- " window->sequence_count");
+ err_puts("window_animate: window->sequence_pos >="
+ " window->sequence_count");
return false;
}
seq = window->sequence + window->sequence_pos;
@@ -56,11 +54,11 @@ bool window_set_sequence_pos (s_window *window, uw sequence_pos)
seq->frame = 0;
seq->t = 0.0;
if (clock_gettime(CLOCK_MONOTONIC, &seq->t0)) {
- warn("window_set_sequence_pos");
+ err_puts("window_set_sequence_pos: clock_gettime");
return false;
}
window->sequence_pos = sequence_pos;
- printf("%s\n", seq->title);
+ io_puts(seq->title);
if (! seq->load(seq, window))
return false;
return true;
diff --git a/test/buf_file_test.c b/test/buf_file_test.c
index e5a6692..82a2d40 100644
--- a/test/buf_file_test.c
+++ b/test/buf_file_test.c
@@ -10,6 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
+#include <assert.h>
#include "../libc3/buf.h"
#include "../libc3/buf_file.h"
#include "test.h"
diff --git a/test/facts_test.c b/test/facts_test.c
index 1e588b0..fb324c4 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -448,8 +448,11 @@ TEST_CASE(facts_open_file)
s_facts facts;
s_str path;
if (file_copy_1("facts_test_open_file.1.in.facts",
- "facts_test_open_file.1.facts"))
- err(1, "%s:%i: file_copy_1", __FILE__, __LINE__);
+ "facts_test_open_file.1.facts")) {
+ fprintf(stderr, "%s:%i: %s: file_copy_1", __FILE__, __LINE__,
+ __func__);
+ exit(1);
+ }
facts_init(&facts);
str_init_1(&path, NULL, "facts_test_open_file.1.facts");
TEST_EQ(facts_open_file(&facts, &path), 760);
@@ -478,8 +481,11 @@ TEST_CASE(facts_open_file)
unlink("facts_test_open_file.1.facts");
facts_init(&facts);
if (file_copy_1("facts_test_open_file.2.in.facts",
- "facts_test_open_file.2.facts"))
- err(1, "%s:%i: file_copy_1", __FILE__, __LINE__);
+ "facts_test_open_file.2.facts")) {
+ fprintf(stderr, "%s:%i: %s: file_copy_1", __FILE__, __LINE__,
+ __func__);
+ exit(1);
+ }
str_init_1(&path, NULL, "facts_test_open_file.2.facts");
TEST_EQ(facts_open_file(&facts, &path), 1523);
TEST_EQ(facts_count(&facts), 46);
@@ -505,8 +511,11 @@ TEST_CASE(facts_open_file)
unlink("facts_test_open_file.2.facts");
facts_init(&facts);
if (file_copy_1("facts_test_open_file.3.in.facts",
- "facts_test_open_file.3.facts"))
- err(1, "%s:%i: file_copy_1", __FILE__, __LINE__);
+ "facts_test_open_file.3.facts")) {
+ fprintf(stderr, "%s:%i: %s: file_copy_1", __FILE__, __LINE__,
+ __func__);
+ exit(1);
+ }
str_init_1(&path, NULL, "facts_test_open_file.3.facts");
TEST_EQ(facts_open_file(&facts, &path), 1550);
TEST_EQ(facts_count(&facts), 0);
diff --git a/test/ic3/plist.err.expected b/test/ic3/plist.err.expected
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/ic3/plist.err.expected
diff --git a/test/ic3/plist.in b/test/ic3/plist.in
new file mode 100644
index 0000000..3ef99f2
--- /dev/null
+++ b/test/ic3/plist.in
@@ -0,0 +1,6 @@
+quote [a: 1]
+[a: 1]
+quote [a: 1, b: 2]
+[a: 1, b: 2]
+quote [a: 1, b: 2, c: 3]
+[a: 1, b: 2, c: 3]
diff --git a/test/ic3/plist.out.expected b/test/ic3/plist.out.expected
new file mode 100644
index 0000000..5b5b6f2
--- /dev/null
+++ b/test/ic3/plist.out.expected
@@ -0,0 +1,6 @@
+[a: 1]
+[a: 1]
+[a: 1, b: 2]
+[a: 1, b: 2]
+[a: 1, b: 2, c: 3]
+[a: 1, b: 2, c: 3]
diff --git a/test/ic3/plist.ret.expected b/test/ic3/plist.ret.expected
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/ic3/plist.ret.expected
@@ -0,0 +1 @@
+0
diff --git a/test/set__fact_test.c b/test/set__fact_test.c
index dc4142a..813746f 100644
--- a/test/set__fact_test.c
+++ b/test/set__fact_test.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "../libc3/fact.h"
diff --git a/test/skiplist__fact_test.c b/test/skiplist__fact_test.c
index 37a2484..ba5cb9a 100644
--- a/test/skiplist__fact_test.c
+++ b/test/skiplist__fact_test.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "../libc3/fact.h"