diff --git a/lib/c3/0.1/c3.facts b/lib/c3/0.1/c3.facts
index 1496a9f..07e27f8 100644
--- a/lib/c3/0.1/c3.facts
+++ b/lib/c3/0.1/c3.facts
@@ -1,6 +1,6 @@
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x000000000000001B}
+ version: 1,
+ count: 27}
{C3, :is_a, :module}
{C3, :name, "C3"}
{C3, :path, "c3.facts"}
diff --git a/libc3/bool.c b/libc3/bool.c
index 3e0a27d..9ad5136 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -14,18 +14,18 @@
#include "buf.h"
#include "buf_inspect.h"
-s_str * bool_inspect (bool *x, s_str *dest)
+s_str * bool_inspect (bool *b, s_str *dest)
{
sw size;
s_buf tmp;
- size = buf_inspect_bool_size(x);
+ size = buf_inspect_bool_size(b);
if (size < 0) {
assert(! "bool_inspect: error");
- errx(1, "bool_inspect: error: %d", *x);
+ errx(1, "bool_inspect: error: %d", *b);
return NULL;
}
buf_init_alloc(&tmp, size);
- buf_inspect_bool(&tmp, x);
+ buf_inspect_bool(&tmp, b);
assert(tmp.wpos == tmp.size);
if (tmp.wpos != tmp.size) {
buf_clean(&tmp);
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 7282cd8..d5ca671 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -1005,13 +1005,13 @@ sw buf_inspect_str (s_buf *buf, const s_str *str)
if (str_has_reserved_characters(str))
return buf_inspect_str_reserved(buf, str);
buf_save_init(buf, &save);
- if ((r = buf_write_u8(buf, '"')) < 0)
- return r;
+ if ((r = buf_write_u8(buf, '"')) <= 0)
+ goto clean;
result += r;
if ((r = buf_write_str(buf, str)) < 0)
goto restore;
result += r;
- if ((r = buf_write_u8(buf, '"')) < 0)
+ if ((r = buf_write_u8(buf, '"')) <= 0)
goto restore;
result += r;
r = result;
@@ -1054,39 +1054,46 @@ sw buf_inspect_str_character (s_buf *buf, const character *c)
int j;
sw r;
sw result = 0;
+ sw result1 = 0;
s_buf_save save;
if (! str_character_is_reserved(*c))
return buf_write_character_utf8(buf, *c);
buf_save_init(buf, &save);
- if ((r = buf_write_u8(buf, '\\')) < 0)
+ if ((r = buf_write_u8(buf, '\\')) <= 0)
goto restore;
+ result += r;
switch (*c) {
- case '\0': if ((r = buf_write_u8(buf, '0')) < 0) goto restore; break;
- case '\n': if ((r = buf_write_u8(buf, 'n')) < 0) goto restore; break;
- case '\r': if ((r = buf_write_u8(buf, 'r')) < 0) goto restore; break;
- case '\t': if ((r = buf_write_u8(buf, 't')) < 0) goto restore; break;
- case '\v': if ((r = buf_write_u8(buf, 'v')) < 0) goto restore; break;
- case '\"': if ((r = buf_write_u8(buf, '"')) < 0) goto restore; break;
- case '\'': if ((r = buf_write_u8(buf, '\'')) < 0) goto restore; break;
- case '\\': if ((r = buf_write_u8(buf, '\\')) < 0) goto restore; break;
+ case '\0': if ((r = buf_write_u8(buf, '0')) <= 0) goto restore; break;
+ case '\n': if ((r = buf_write_u8(buf, 'n')) <= 0) goto restore; break;
+ case '\r': if ((r = buf_write_u8(buf, 'r')) <= 0) goto restore; break;
+ case '\t': if ((r = buf_write_u8(buf, 't')) <= 0) goto restore; break;
+ case '\v': if ((r = buf_write_u8(buf, 'v')) <= 0) goto restore; break;
+ case '\"': if ((r = buf_write_u8(buf, '"')) <= 0) goto restore; break;
+ case '\'': if ((r = buf_write_u8(buf, '\'')) <= 0) goto restore; break;
+ case '\\': if ((r = buf_write_u8(buf, '\\')) <= 0) goto restore; break;
default:
buf_init(&char_buf, false, sizeof(b), b);
- if ((r = buf_write_character_utf8(&char_buf, *c)) < 0)
+ if ((r = buf_write_character_utf8(&char_buf, *c)) <= 0)
goto restore;
- i = r;
+ i = r - 1;
j = 0;
- if (i-- > 0) {
- if ((r = buf_write_u8(buf, 'x')) < 0)
+ if ((r = buf_write_u8(buf, 'x')) <= 0)
+ goto restore;
+ result1 += r;
+ if ((r = buf_u8_to_hex(buf, char_buf.ptr.pu8[j++])) <= 0)
+ goto restore;
+ result1 += r;
+ while (i--) {
+ if ((r = buf_write_1(buf, "\\x")) <= 0)
goto restore;
- if ((r = buf_u8_to_hex(buf, char_buf.ptr.pu8[j++])) < 0)
+ result1 += r;
+ if ((r = buf_u8_to_hex(buf, char_buf.ptr.pu8[j++])) <= 0)
goto restore;
- while (i--) {
- if ((r = buf_write_1(buf, "\\x")) < 0 ||
- (r = buf_u8_to_hex(buf, char_buf.ptr.pu8[j++])) < 0)
- goto restore;
- }
+ result1 += r;
}
+ r = result1;
}
+ result += r;
r = result;
goto clean;
restore:
@@ -1123,7 +1130,7 @@ sw buf_inspect_str_character_size (const character *c)
return size;
}
-/* XXX keep in sync with buf_inspect_str_reserved_size */
+/* keep in sync with buf_inspect_str_reserved_size */
sw buf_inspect_str_reserved (s_buf *buf, const s_str *str)
{
u8 byte;
@@ -1155,6 +1162,7 @@ sw buf_inspect_str_reserved (s_buf *buf, const s_str *str)
}
if ((r = buf_write_u8(buf, '"')) < 0)
goto restore;
+ result += r;
r = result;
goto clean;
restore:
@@ -1421,3 +1429,9 @@ sw buf_inspect_void (s_buf *buf, const void *_)
result += r;
return result;
}
+
+sw buf_inspect_void_size (const void *_)
+{
+ (void) _;
+ return strlen("void");
+}
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 0668c11..5538981 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -17,6 +17,288 @@
#include "../libtommath/tommath.h"
#include "c3.h"
+#define DEF_BUF_PARSE_S(BITS, bits) \
+ sw buf_parse_s ## bits (s_buf *buf, s ## bits *dest) \
+ { \
+ s_buf_save digits; \
+ e_bool negative = false; \
+ sw r; \
+ sw r1; \
+ sw result = 0; \
+ s_buf_save save; \
+ s ## bits tmp; \
+ s ## bits tmp1; \
+ buf_save_init(buf, &save); \
+ if ((r = buf_read_1(buf, "-")) < 0) \
+ goto clean; \
+ if (r > 0) { \
+ result += r; \
+ negative = true; \
+ } \
+ if ((r = buf_read_1(buf, "0b")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_binary, \
+ negative, dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ goto ok; \
+ } \
+ if ((r = buf_read_1(buf, "0o")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_octal, \
+ negative, dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ goto ok; \
+ } \
+ if ((r = buf_read_1(buf, "0x")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ buf_save_init(buf, &digits); \
+ if ((r = buf_parse_s ## bits ## _base(buf, \
+ g_c3_bases_hexadecimal, \
+ negative, &tmp)) < 0) { \
+ buf_save_clean(buf, &digits); \
+ goto restore; \
+ } \
+ buf_save_restore_rpos(buf, &digits); \
+ buf_save_clean(buf, &digits); \
+ if ((r1 = buf_parse_s ## bits ## _base(buf, \
+ g_c3_bases_hexadecimal + \
+ 1, \
+ negative, &tmp1)) < 0) { \
+ r = r1; \
+ goto restore; \
+ } \
+ if (r == 0 && r1 == 0) { \
+ if (negative) \
+ warnx("invalid number: -0x"); \
+ else \
+ warnx("invalid number: 0x"); \
+ goto restore; \
+ } \
+ if (r > r1) { \
+ result += r; \
+ *dest = tmp; \
+ } \
+ else { \
+ result += r1; \
+ *dest = tmp1; \
+ } \
+ goto ok; \
+ } \
+ if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_decimal, \
+ negative, dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ ok: \
+ r = result; \
+ goto clean; \
+ restore: \
+ buf_save_restore_rpos(buf, &save); \
+ clean: \
+ buf_save_clean(buf, &save); \
+ return r; \
+ } \
+ \
+ sw buf_parse_s ## bits ## _base (s_buf *buf, const s_str *base, \
+ bool negative, s ## bits *dest) \
+ { \
+ u8 digit; \
+ sw r; \
+ sw radix; \
+ sw result = 0; \
+ s_buf_save save; \
+ u ## bits u = 0; \
+ assert(buf); \
+ assert(base); \
+ assert(dest); \
+ buf_save_init(buf, &save); \
+ radix = str_length_utf8(base); \
+ if (radix < 2 || radix > S ## BITS ## _MAX) { \
+ buf_save_clean(buf, &save); \
+ 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); \
+ 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"); \
+ 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"); \
+ r = -1; \
+ goto restore; \
+ } \
+ u += digit; \
+ } \
+ *dest = negative ? -u : u; \
+ r = result; \
+ goto clean; \
+ restore: \
+ buf_save_restore_rpos(buf, &save); \
+ clean: \
+ buf_save_clean(buf, &save); \
+ return r; \
+ }
+
+#define DEF_BUF_PARSE_U(BITS, bits) \
+ sw buf_parse_u ## bits (s_buf *buf, u ## bits *dest) \
+ { \
+ s_buf_save digits; \
+ sw r; \
+ sw r1; \
+ sw result = 0; \
+ s_buf_save save; \
+ u ## bits tmp; \
+ u ## bits tmp1; \
+ buf_save_init(buf, &save); \
+ if ((r = buf_read_1(buf, "0b")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_binary, \
+ dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ goto ok; \
+ } \
+ if ((r = buf_read_1(buf, "0o")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_octal, \
+ dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ goto ok; \
+ } \
+ if ((r = buf_read_1(buf, "0x")) < 0) \
+ goto restore; \
+ if (r > 0) { \
+ result += r; \
+ buf_save_init(buf, &digits); \
+ if ((r = buf_parse_u ## bits ## _base(buf, \
+ g_c3_bases_hexadecimal, \
+ &tmp)) < 0) { \
+ buf_save_clean(buf, &digits); \
+ goto restore; \
+ } \
+ buf_save_restore_rpos(buf, &digits); \
+ buf_save_clean(buf, &digits); \
+ if ((r1 = buf_parse_u ## bits ## _base(buf, \
+ g_c3_bases_hexadecimal + \
+ 1, &tmp1)) < 0) { \
+ r = r1; \
+ goto restore; \
+ } \
+ if (r == 0 && r1 == 0) { \
+ warnx("invalid number: 0x"); \
+ goto restore; \
+ } \
+ if (r > r1) { \
+ result += r; \
+ *dest = tmp; \
+ } \
+ else { \
+ result += r1; \
+ *dest = tmp1; \
+ } \
+ goto ok; \
+ } \
+ if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_decimal, \
+ dest)) <= 0) \
+ goto restore; \
+ result += r; \
+ ok: \
+ r = result; \
+ goto clean; \
+ restore: \
+ buf_save_restore_rpos(buf, &save); \
+ clean: \
+ buf_save_clean(buf, &save); \
+ return r; \
+ } \
+ \
+ sw buf_parse_u ## bits ## _base (s_buf *buf, const s_str *base, \
+ u ## bits *dest) \
+ { \
+ u8 digit; \
+ sw r; \
+ sw radix; \
+ sw result = 0; \
+ s_buf_save save; \
+ u ## bits u = 0; \
+ assert(buf); \
+ assert(base); \
+ assert(dest); \
+ buf_save_init(buf, &save); \
+ radix = str_length_utf8(base); \
+ if (radix < 2 || (uw) radix > U ## BITS ## _MAX) { \
+ buf_save_clean(buf, &save); \
+ 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); \
+ 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); \
+ r = -1; \
+ goto restore; \
+ } \
+ u *= radix; \
+ if (u > (u ## bits) (U ## BITS ## _MAX - digit)) { \
+ warnx("buf_parse_u" # bits "_base: +: integer overflow"); \
+ r = -1; \
+ goto restore; \
+ } \
+ u += digit; \
+ } \
+ *dest = u; \
+ r = result; \
+ goto clean; \
+ restore: \
+ buf_save_restore_rpos(buf, &save); \
+ clean: \
+ buf_save_clean(buf, &save); \
+ return r; \
+ }
+
sw buf_parse_cfn_arg_types (s_buf *buf, s_list **dest);
sw buf_parse_array (s_buf *buf, s_array *dest)
@@ -1290,365 +1572,222 @@ sw buf_parse_integer_unsigned_hex (s_buf *buf, s_integer *dest)
r = result;
goto clean;
error:
- r = -1;
- integer_clean(dest);
- buf_save_restore_rpos(buf, &save);
- clean:
- buf_save_clean(buf, &save);
- return r;
-}
-
-sw buf_parse_integer_unsigned_oct (s_buf *buf, s_integer *dest)
-{
- const mp_digit radix = 8;
- sw r;
- u8 digit;
- int result = 0;
- s_buf_save save;
- buf_save_init(buf, &save);
- if ((r = buf_parse_digit_oct(buf, &digit)) <= 0)
- goto clean;
- result += r;
- integer_init_zero(dest);
- if (mp_add_d(&dest->mp_int, digit, &dest->mp_int) != MP_OKAY)
- goto error;
- while ((r = buf_read_1(buf, "_")) >= 0 &&
- (r = buf_parse_digit_oct(buf, &digit)) > 0) {
- result += r;
- if (mp_mul_d(&dest->mp_int, radix, &dest->mp_int) != MP_OKAY ||
- mp_add_d(&dest->mp_int, digit, &dest->mp_int) != MP_OKAY)
- goto error;
- }
- if (result > 0)
- r = result;
- goto clean;
- error:
- r = -1;
- integer_clean(dest);
- buf_save_restore_rpos(buf, &save);
- clean:
- buf_save_clean(buf, &save);
- return r;
-}
-
-sw buf_parse_list (s_buf *buf, s_list **list)
-{
- s_list **i;
- sw r;
- sw result = 0;
- s_buf_save save;
- buf_save_init(buf, &save);
- i = list;
- if ((r = buf_read_1(buf, "(")) <= 0)
- goto clean;
- result += r;
- if ((r = buf_parse_comments(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_read_1(buf, ")")) < 0)
- goto restore;
- if (r > 0) {
- result += r;
- *list = NULL;
- r = result;
- goto clean;
- }
- *i = NULL;
- while (1) {
- *i = list_new(NULL, NULL);
- if ((r = buf_parse_tag(buf, &(*i)->tag)) <= 0)
- goto restore;
- result += r;
- if ((r = buf_parse_comments(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_read_1(buf, ")")) < 0)
- goto restore;
- if (r > 0) {
- result += r;
- r = result;
- goto clean;
- }
- if ((r = buf_read_1(buf, ",")) < 0)
- goto restore;
- if (r > 0) {
- result += r;
- i = &(*i)->next.data.list;
- if ((r = buf_parse_comments(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto restore;
- result += r;
- continue;
- }
- if ((r = buf_read_1(buf, "|")) < 0)
- goto restore;
- if (r > 0) {
- result += r;
- if ((r = buf_parse_comments(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_parse_tag(buf, &(*i)->next)) <= 0)
- goto restore;
- result += r;
- if ((r = buf_parse_comments(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto restore;
- result += r;
- if ((r = buf_read_1(buf, ")")) <= 0)
- goto restore;
- result += r;
- r = result;
- goto clean;
- }
- goto restore;
- }
- restore:
+ r = -1;
+ integer_clean(dest);
buf_save_restore_rpos(buf, &save);
clean:
buf_save_clean(buf, &save);
return r;
}
-sw buf_parse_module_name (s_buf *buf, const s_sym **dest)
+sw buf_parse_integer_unsigned_oct (s_buf *buf, s_integer *dest)
{
+ const mp_digit radix = 8;
sw r;
- sw result = 0;
+ u8 digit;
+ int result = 0;
s_buf_save save;
- s_str str;
- const s_sym *sym;
- s_buf tmp;
buf_save_init(buf, &save);
- buf_init_alloc(&tmp, SYM_MAX);
- if ((r = buf_parse_sym(buf, &sym)) <= 0)
+ if ((r = buf_parse_digit_oct(buf, &digit)) <= 0)
goto clean;
result += r;
- if ((r = buf_inspect_sym(&tmp, sym)) < 0)
- goto clean;
- save.rpos = buf->rpos;
- while ((r = buf_read_1(buf, ".")) > 0 &&
- (r = buf_parse_sym(buf, &sym)) > 0) {
- result += r + 1;
- save.rpos = buf->rpos;
- if ((r = buf_write_1(&tmp, ".")) < 0 ||
- (r = buf_inspect_sym(&tmp, sym)) < 0)
- goto clean;
+ integer_init_zero(dest);
+ if (mp_add_d(&dest->mp_int, digit, &dest->mp_int) != MP_OKAY)
+ goto error;
+ while ((r = buf_read_1(buf, "_")) >= 0 &&
+ (r = buf_parse_digit_oct(buf, &digit)) > 0) {
+ result += r;
+ if (mp_mul_d(&dest->mp_int, radix, &dest->mp_int) != MP_OKAY ||
+ mp_add_d(&dest->mp_int, digit, &dest->mp_int) != MP_OKAY)
+ goto error;
}
- if ((r = buf_peek_1(buf, ".")) <= 0)
- buf_save_restore_rpos(buf, &save);
- buf_read_to_str(&tmp, &str);
- *dest = str_to_sym(&str);
- str_clean(&str);
- r = result;
+ if (result > 0)
+ r = result;
+ goto clean;
+ error:
+ r = -1;
+ integer_clean(dest);
+ buf_save_restore_rpos(buf, &save);
clean:
buf_save_clean(buf, &save);
- buf_clean(&tmp);
- return r;
-}
-
-sw buf_parse_new_tag (s_buf *buf, s_tag **dest)
-{
- sw r;
- s_tag *tag = tag_new();
- if ((r = buf_parse_tag(buf, tag)) < 0) {
- tag_delete(tag);
- *dest = NULL;
- return r;
- }
- *dest = tag;
return r;
}
-sw buf_parse_ptag (s_buf *buf, p_tag *ptag)
-{
- (void) buf;
- (void) ptag;
- assert(! "buf_parse_ptag: not implemented");
- errx(1, "buf_parse_ptag: not implemented");
- return -1;
-}
-
-sw buf_parse_quote (s_buf *buf, s_quote *dest)
+sw buf_parse_list (s_buf *buf, s_list **list)
{
- s_quote quote;
+ s_list **i;
sw r;
sw result = 0;
s_buf_save save;
buf_save_init(buf, &save);
- if ((r = buf_read_1(buf, "quote")) <= 0)
+ i = list;
+ if ((r = buf_read_1(buf, "(")) <= 0)
goto clean;
result += r;
- if ((r = buf_ignore_spaces(buf)) <= 0)
+ if ((r = buf_parse_comments(buf)) < 0)
goto restore;
result += r;
- quote.tag = tag_new();
- if ((r = buf_parse_tag(buf, quote.tag)) <= 0)
+ if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
- *dest = quote;
- r = result;
- goto clean;
- restore:
- buf_save_restore_rpos(buf, &save);
- clean:
- buf_save_clean(buf, &save);
- return r;
-}
-
-#define DEF_BUF_PARSE_S(BITS, bits) \
- sw buf_parse_s ## bits (s_buf *buf, s ## bits *dest) \
- { \
- s_buf_save digits; \
- e_bool negative = false; \
- sw r; \
- sw r1; \
- sw result = 0; \
- s_buf_save save; \
- s ## bits tmp; \
- s ## bits tmp1; \
- buf_save_init(buf, &save); \
- if ((r = buf_read_1(buf, "-")) < 0) \
- goto clean; \
- if (r > 0) { \
- result += r; \
- negative = true; \
- } \
- if ((r = buf_read_1(buf, "0b")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_bin, \
- negative, dest)) <= 0) \
- goto restore; \
- result += r; \
- goto ok; \
- } \
- if ((r = buf_read_1(buf, "0o")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_oct, \
- negative, dest)) <= 0) \
- goto restore; \
- result += r; \
- goto ok; \
- } \
- if ((r = buf_read_1(buf, "0x")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- buf_save_init(buf, &digits); \
- if ((r = buf_parse_s ## bits ## _base(buf, g_c3_bases_hex, \
- negative, &tmp)) < 0) { \
- buf_save_clean(buf, &digits); \
- goto restore; \
- } \
- buf_save_restore_rpos(buf, &digits); \
- buf_save_clean(buf, &digits); \
- if ((r1 = buf_parse_s ## bits ## _base(buf, g_c3_bases_hex + 1, \
- negative, &tmp1)) < 0) { \
- r = r1; \
- goto restore; \
- } \
- if (r == 0 && r1 == 0) { \
- if (negative) \
- warnx("invalid number: -0x"); \
- else \
- warnx("invalid number: 0x"); \
- goto restore; \
- } \
- if (r > r1) { \
- result += r; \
- *dest = tmp; \
- } \
- else { \
- result += r1; \
- *dest = tmp1; \
- } \
- goto ok; \
- } \
- if ((r = buf_parse_s ## bits ## _base(buf, &g_c3_base_dec, \
- negative, dest)) <= 0) \
- goto restore; \
- result += r; \
- ok: \
- r = result; \
- goto clean; \
- restore: \
- buf_save_restore_rpos(buf, &save); \
- clean: \
- buf_save_clean(buf, &save); \
- return r; \
- } \
- \
- sw buf_parse_s ## bits ## _base (s_buf *buf, const s_str *base, \
- bool negative, s ## bits *dest) \
- { \
- u8 digit; \
- sw r; \
- sw radix; \
- sw result = 0; \
- s_buf_save save; \
- u ## bits u = 0; \
- assert(buf); \
- assert(base); \
- assert(dest); \
- buf_save_init(buf, &save); \
- radix = str_length_utf8(base); \
- if (radix < 2 || radix > S ## BITS ## _MAX) { \
- buf_save_clean(buf, &save); \
- 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); \
- 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"); \
- 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"); \
- r = -1; \
- goto restore; \
- } \
- u += digit; \
- } \
- *dest = negative ? -u : u; \
- r = result; \
- goto clean; \
- restore: \
- buf_save_restore_rpos(buf, &save); \
- clean: \
- buf_save_clean(buf, &save); \
- return r; \
+ if ((r = buf_read_1(buf, ")")) < 0)
+ goto restore;
+ if (r > 0) {
+ result += r;
+ *list = NULL;
+ r = result;
+ goto clean;
+ }
+ *i = NULL;
+ while (1) {
+ *i = list_new(NULL, NULL);
+ if ((r = buf_parse_tag(buf, &(*i)->tag)) <= 0)
+ goto restore;
+ result += r;
+ if ((r = buf_parse_comments(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_read_1(buf, ")")) < 0)
+ goto restore;
+ if (r > 0) {
+ result += r;
+ r = result;
+ goto clean;
+ }
+ if ((r = buf_read_1(buf, ",")) < 0)
+ goto restore;
+ if (r > 0) {
+ result += r;
+ i = &(*i)->next.data.list;
+ if ((r = buf_parse_comments(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto restore;
+ result += r;
+ continue;
+ }
+ if ((r = buf_read_1(buf, "|")) < 0)
+ goto restore;
+ if (r > 0) {
+ result += r;
+ if ((r = buf_parse_comments(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_parse_tag(buf, &(*i)->next)) <= 0)
+ goto restore;
+ result += r;
+ if ((r = buf_parse_comments(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_read_1(buf, ")")) <= 0)
+ goto restore;
+ result += r;
+ r = result;
+ goto clean;
+ }
+ goto restore;
+ }
+ restore:
+ buf_save_restore_rpos(buf, &save);
+ clean:
+ buf_save_clean(buf, &save);
+ return r;
+}
+
+sw buf_parse_module_name (s_buf *buf, const s_sym **dest)
+{
+ sw r;
+ sw result = 0;
+ s_buf_save save;
+ s_str str;
+ const s_sym *sym;
+ s_buf tmp;
+ buf_save_init(buf, &save);
+ buf_init_alloc(&tmp, SYM_MAX);
+ if ((r = buf_parse_sym(buf, &sym)) <= 0)
+ goto clean;
+ result += r;
+ if ((r = buf_inspect_sym(&tmp, sym)) < 0)
+ goto clean;
+ save.rpos = buf->rpos;
+ while ((r = buf_read_1(buf, ".")) > 0 &&
+ (r = buf_parse_sym(buf, &sym)) > 0) {
+ result += r + 1;
+ save.rpos = buf->rpos;
+ if ((r = buf_write_1(&tmp, ".")) < 0 ||
+ (r = buf_inspect_sym(&tmp, sym)) < 0)
+ goto clean;
+ }
+ if ((r = buf_peek_1(buf, ".")) <= 0)
+ buf_save_restore_rpos(buf, &save);
+ buf_read_to_str(&tmp, &str);
+ *dest = str_to_sym(&str);
+ str_clean(&str);
+ r = result;
+ clean:
+ buf_save_clean(buf, &save);
+ buf_clean(&tmp);
+ return r;
+}
+
+sw buf_parse_new_tag (s_buf *buf, s_tag **dest)
+{
+ sw r;
+ s_tag *tag = tag_new();
+ if ((r = buf_parse_tag(buf, tag)) < 0) {
+ tag_delete(tag);
+ *dest = NULL;
+ return r;
}
+ *dest = tag;
+ return r;
+}
+
+sw buf_parse_ptag (s_buf *buf, p_tag *ptag)
+{
+ (void) buf;
+ (void) ptag;
+ assert(! "buf_parse_ptag: not implemented");
+ errx(1, "buf_parse_ptag: not implemented");
+ return -1;
+}
+
+sw buf_parse_quote (s_buf *buf, s_quote *dest)
+{
+ s_quote quote;
+ sw r;
+ sw result = 0;
+ s_buf_save save;
+ buf_save_init(buf, &save);
+ if ((r = buf_read_1(buf, "quote")) <= 0)
+ goto clean;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) <= 0)
+ goto restore;
+ result += r;
+ quote.tag = tag_new();
+ if ((r = buf_parse_tag(buf, quote.tag)) <= 0)
+ goto restore;
+ result += r;
+ *dest = quote;
+ r = result;
+ goto clean;
+ restore:
+ buf_save_restore_rpos(buf, &save);
+ clean:
+ buf_save_clean(buf, &save);
+ return r;
+}
DEF_BUF_PARSE_S(8, 8)
DEF_BUF_PARSE_S(16, 16)
@@ -2225,140 +2364,6 @@ sw buf_parse_tuple (s_buf *buf, s_tuple *tuple)
return r;
}
-#define DEF_BUF_PARSE_U(BITS, bits) \
- sw buf_parse_u ## bits (s_buf *buf, u ## bits *dest) \
- { \
- s_buf_save digits; \
- sw r; \
- sw r1; \
- sw result = 0; \
- s_buf_save save; \
- u ## bits tmp; \
- u ## bits tmp1; \
- buf_save_init(buf, &save); \
- if ((r = buf_read_1(buf, "0b")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_bin, \
- dest)) <= 0) \
- goto restore; \
- result += r; \
- goto ok; \
- } \
- if ((r = buf_read_1(buf, "0o")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_oct, \
- dest)) <= 0) \
- goto restore; \
- result += r; \
- goto ok; \
- } \
- if ((r = buf_read_1(buf, "0x")) < 0) \
- goto restore; \
- if (r > 0) { \
- result += r; \
- buf_save_init(buf, &digits); \
- if ((r = buf_parse_u ## bits ## _base(buf, g_c3_bases_hex, \
- &tmp)) < 0) { \
- buf_save_clean(buf, &digits); \
- goto restore; \
- } \
- buf_save_restore_rpos(buf, &digits); \
- buf_save_clean(buf, &digits); \
- if ((r1 = buf_parse_u ## bits ## _base(buf, g_c3_bases_hex + 1, \
- &tmp1)) < 0) { \
- r = r1; \
- goto restore; \
- } \
- if (r == 0 && r1 == 0) { \
- warnx("invalid number: 0x"); \
- goto restore; \
- } \
- if (r > r1) { \
- result += r; \
- *dest = tmp; \
- } \
- else { \
- result += r1; \
- *dest = tmp1; \
- } \
- goto ok; \
- } \
- if ((r = buf_parse_u ## bits ## _base(buf, &g_c3_base_dec, \
- dest)) <= 0) \
- goto restore; \
- result += r; \
- ok: \
- r = result; \
- goto clean; \
- restore: \
- buf_save_restore_rpos(buf, &save); \
- clean: \
- buf_save_clean(buf, &save); \
- return r; \
- } \
- \
- sw buf_parse_u ## bits ## _base (s_buf *buf, const s_str *base, \
- u ## bits *dest) \
- { \
- u8 digit; \
- sw r; \
- sw radix; \
- sw result = 0; \
- s_buf_save save; \
- u ## bits u = 0; \
- assert(buf); \
- assert(base); \
- assert(dest); \
- buf_save_init(buf, &save); \
- radix = str_length_utf8(base); \
- if (radix < 2 || (uw) radix > U ## BITS ## _MAX) { \
- buf_save_clean(buf, &save); \
- 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); \
- 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); \
- r = -1; \
- goto restore; \
- } \
- u *= radix; \
- if (u > (u ## bits) (U ## BITS ## _MAX - digit)) { \
- warnx("buf_parse_u" # bits "_base: +: integer overflow"); \
- r = -1; \
- goto restore; \
- } \
- u += digit; \
- } \
- *dest = u; \
- r = result; \
- goto clean; \
- restore: \
- buf_save_restore_rpos(buf, &save); \
- clean: \
- buf_save_clean(buf, &save); \
- return r; \
- }
-
DEF_BUF_PARSE_U(8, 8)
DEF_BUF_PARSE_U(16, 16)
DEF_BUF_PARSE_U(32, 32)
diff --git a/libc3/facts.c b/libc3/facts.c
index ea88ecf..8a48970 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -111,6 +111,7 @@ sw facts_dump (s_facts *facts, s_buf *buf)
sw r;
sw result = 0;
s_tag subject;
+ u64 u;
assert(facts);
assert(buf);
tag_init_var(&subject);
@@ -118,12 +119,13 @@ sw facts_dump (s_facts *facts, s_buf *buf)
tag_init_var(&object);
if ((r = buf_write_1(buf,
"%{module: C3.Facts.Dump,\n"
- " version: 0x0000000000000001,\n"
- " count: 0x")) < 0)
+ " version: 1,\n"
+ " count: ")) < 0)
return r;
result += r;
facts_lock_r(facts);
- if ((r = buf_inspect_u64_hex(buf, facts_count(facts))) < 0)
+ u = facts_count(facts);
+ if ((r = buf_inspect_u64(buf, &u)) < 0)
goto ko;
result += r;
if ((r = buf_write_1(buf, "}\n")) < 0)
@@ -144,7 +146,8 @@ sw facts_dump (s_facts *facts, s_buf *buf)
if ((r = buf_write_1(buf, "%{hash: 0x")) < 0)
return r;
result += r;
- if ((r = buf_inspect_u64_hex(buf, hash_to_u64(&hash))) < 0)
+ u = hash_to_u64(&hash);
+ if ((r = buf_inspect_u64_hexadecimal(buf, &u)) < 0)
return r;
result += r;
if ((r = buf_write_1(buf, "}\n")) < 0)
@@ -242,11 +245,11 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
assert(buf);
if ((r = buf_read_1(buf,
"%{module: C3.Facts.Dump,\n"
- " version: 0x0000000000000001,\n"
- " count: 0x")) <= 0)
+ " version: 1,\n"
+ " count: ")) <= 0)
goto ko_header;
result += r;
- if ((r = buf_parse_u64_hex(buf, &count)) <= 0)
+ if ((r = buf_parse_u64(buf, &count)) <= 0)
goto ko_header;
result += r;
if ((r = buf_read_1(buf, "}\n")) <= 0)
@@ -283,7 +286,7 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
if (hash_u64_buf != hash_u64) {
s_buf tmp;
buf_init_alloc(&tmp, 16);
- buf_inspect_u64_hex(&tmp, hash_u64);
+ buf_inspect_u64_hexadecimal(&tmp, &hash_u64);
buf_write_s8(&tmp, 0);
warnx("facts_load: %s: invalid hash line %lu: 0x%s",
path->ptr.ps8,
@@ -440,7 +443,7 @@ sw facts_open_buf (s_facts *facts, s_buf *buf, const s_str *path)
sw result = 0;
if ((r = buf_read_1(buf,
"%{module: C3.Facts.Save,\n"
- " version: 0x0000000000000001}\n")) <= 0) {
+ " version: 1}\n")) <= 0) {
warnx("facts_open_buf: %s: invalid or missing header",
path->ptr.ps8);
return -1;
@@ -630,7 +633,7 @@ sw facts_save_header (s_buf *buf)
sw result = 0;
if ((r = buf_write_1(buf,
"%{module: C3.Facts.Save,\n"
- " version: 0x0000000000000001}\n")) < 0)
+ " version: 1}\n")) < 0)
return r;
result += r;
return result;
diff --git a/libc3/str.c b/libc3/str.c
index 26b7da6..e3061ff 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -27,9 +27,10 @@ sw str_character (const s_str *str, uw position, character *dest)
{
character c;
uw i = 0;
+ sw r;
s_str s;
s = *str;
- while (s->size && i <= position) {
+ while (s.size > 0 && i <= position) {
if ((r = str_read_character_utf8(&s, &c)) <= 0)
return -1;
i++;
diff --git a/test/bool_test.c b/test/bool_test.c
index 2ff1aa2..31e7447 100644
--- a/test/bool_test.c
+++ b/test/bool_test.c
@@ -18,11 +18,12 @@
#define BOOL_TEST_INSPECT(test, expected) \
do { \
s_str str; \
+ bool tmp; \
test_context("bool_inspect(" # test ") -> " # expected); \
- TEST_EQ(bool_inspect(test, &str), &str); \
+ tmp = (test); \
+ TEST_EQ(bool_inspect(&tmp, &str), &str); \
TEST_EQ(str.size, strlen(expected)); \
- if (g_test_last_ok) \
- TEST_STRNCMP(str.ptr.p, (expected), str.size); \
+ TEST_STRNCMP(str.ptr.p, (expected), str.size); \
str_clean(&str); \
} while (0)
diff --git a/test/buf_inspect_test.c b/test/buf_inspect_test.c
index 1e1057e..5cbdb5d 100644
--- a/test/buf_inspect_test.c
+++ b/test/buf_inspect_test.c
@@ -19,9 +19,12 @@
do { \
s8 b[16]; \
s_buf buf; \
+ bool tmp; \
test_context("buf_inspect_bool(" # test ") -> " # expected); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_bool(&buf, (test)), strlen(expected)); \
+ tmp = (test); \
+ TEST_EQ(buf_inspect_bool_size(&tmp), strlen(expected)); \
+ TEST_EQ(buf_inspect_bool(&buf, &tmp), strlen(expected)); \
TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
@@ -30,9 +33,12 @@
do { \
s8 b[32]; \
s_buf buf; \
+ character tmp; \
test_context("buf_inspect_character(" # test ") -> " # expected); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_character(&buf, test), strlen(expected)); \
+ tmp = (test); \
+ TEST_EQ(buf_inspect_character_size(&tmp), strlen(expected)); \
+ TEST_EQ(buf_inspect_character(&buf, &tmp), strlen(expected)); \
TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
@@ -41,10 +47,12 @@
do { \
s8 b[32]; \
s_buf buf; \
+ f32 tmp; \
test_context("buf_inspect_f32(" # test ") -> " # expected); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_f32_size(test), strlen(expected)); \
- TEST_EQ(buf_inspect_f32(&buf, test), strlen(expected)); \
+ tmp = (test); \
+ TEST_EQ(buf_inspect_f32_size(&tmp), strlen(expected)); \
+ TEST_EQ(buf_inspect_f32(&buf, &tmp), strlen(expected)); \
TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
@@ -53,10 +61,12 @@
do { \
s8 b[64]; \
s_buf buf; \
+ f64 tmp; \
test_context("buf_inspect_f64(" # test ") -> " # expected); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_f64_size(test), strlen(expected)); \
- TEST_EQ(buf_inspect_f64(&buf, test), strlen(expected)); \
+ tmp = (test); \
+ TEST_EQ(buf_inspect_f64_size(&tmp), strlen(expected)); \
+ TEST_EQ(buf_inspect_f64(&buf, &tmp), strlen(expected)); \
TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
@@ -72,6 +82,7 @@
buf_parse_integer(&buf_test, &i); \
buf_clean(&buf_test); \
buf_init(&buf_result, false, sizeof(b), b); \
+ TEST_EQ(buf_inspect_integer_size(&i), strlen(test)); \
TEST_EQ(buf_inspect_integer(&buf_result, &i), strlen(test)); \
if (g_test_last_ok) \
integer_clean(&i); \
@@ -93,6 +104,7 @@
errx(1, "BUF_INSPECT_TEST_LIST: buf_parse_list"); \
} \
buf_init_alloc(&buf, 1024 * 1024); \
+ TEST_EQ(buf_inspect_list_size(list_test), strlen(expected)); \
TEST_EQ(buf_inspect_list(&buf, list_test), strlen(expected)); \
TEST_EQ(buf.wpos, strlen(expected)); \
if (g_test_last_ok) \
@@ -102,39 +114,32 @@
test_context(NULL); \
} while (0)
-#define BUF_INSPECT_TEST_STR_CHARACTER(test, expected) \
+#define BUF_INSPECT_TEST_STR(test, expected) \
do { \
- s8 b[32]; \
+ s8 b[1024]; \
s_buf buf; \
- test_context("buf_inspect_str_character(" # test ") -> " \
- # expected); \
+ s_str str; \
+ test_context("buf_inspect_str(" # test ") -> " # expected); \
+ str_init_1(&str, NULL, (test)); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_str_character(&buf, test), strlen(expected)); \
- TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
+ TEST_EQ(buf_inspect_str_size(&str), strlen(expected)); \
+ TEST_EQ(buf_inspect_str(&buf, &str), strlen(expected)); \
+ TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
-#define BUF_INSPECT_TEST_STR_CHARACTER_SIZE(test, expected) \
+#define BUF_INSPECT_TEST_STR_CHARACTER(test, expected) \
do { \
s8 b[32]; \
s_buf buf; \
- test_context("buf_inspect_str_character_size(" \
- # test ") -> " # expected); \
- buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_str_character_size(test), expected); \
- test_context(NULL); \
- } while (0)
-
-#define BUF_INSPECT_TEST_STR(test, expected) \
- do { \
- s8 b[1024]; \
- s_buf buf; \
- s_str str; \
- test_context("buf_inspect_str(" # test ") -> " # expected); \
- str_init_1(&str, NULL, (test)); \
+ character tmp; \
+ test_context("buf_inspect_str_character(" # test ") -> " \
+ # expected); \
buf_init(&buf, false, sizeof(b), b); \
- TEST_EQ(buf_inspect_str(&buf, &str), strlen(expected)); \
- TEST_STRNCMP(buf.ptr.p, (expected), buf.wpos); \
+ tmp = (test); \
+ TEST_EQ(buf_inspect_str_character_size(&tmp), strlen(expected)); \
+ TEST_EQ(buf_inspect_str_character(&buf, &tmp), strlen(expected)); \
+ TEST_STRNCMP(buf.ptr.ps8, (expected), buf.wpos); \
test_context(NULL); \
} while (0)
@@ -162,13 +167,11 @@ TEST_CASE_PROTOTYPE(buf_inspect_integer);
TEST_CASE_PROTOTYPE(buf_inspect_list);
TEST_CASE_PROTOTYPE(buf_inspect_str);
TEST_CASE_PROTOTYPE(buf_inspect_str_character);
-TEST_CASE_PROTOTYPE(buf_inspect_str_character_size);
TEST_CASE_PROTOTYPE(buf_inspect_tag);
void buf_inspect_test ()
{
TEST_CASE_RUN(buf_inspect_bool);
- TEST_CASE_RUN(buf_inspect_str_character_size);
TEST_CASE_RUN(buf_inspect_str_character);
TEST_CASE_RUN(buf_inspect_character);
TEST_CASE_RUN(buf_inspect_f32);
@@ -323,24 +326,6 @@ TEST_CASE(buf_inspect_str_character)
}
TEST_CASE_END(buf_inspect_str_character)
-TEST_CASE(buf_inspect_str_character_size)
-{
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(0, 2);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(1, 4);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(2, 4);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('0', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('9', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('A', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('Z', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('a', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE('z', 1);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(928, 2);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(0xFF, 2);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(42164, 3);
- BUF_INSPECT_TEST_STR_CHARACTER_SIZE(65856, 4);
-}
-TEST_CASE_END(buf_inspect_str_character_size)
-
TEST_CASE(buf_inspect_tag)
{
s_tag tag;
@@ -373,7 +358,7 @@ TEST_CASE(buf_inspect_tag)
BUF_INSPECT_TEST_TAG(tag_u8(&tag, 0), "0");
BUF_INSPECT_TEST_TAG(tag_u8(&tag, 1), "1");
BUF_INSPECT_TEST_TAG(tag_u8(&tag, 10), "10");
- BUF_INSPECT_TEST_TAG(tag_void(&tag), "");
+ BUF_INSPECT_TEST_TAG(tag_void(&tag), "void");
tag_clean(&tag);
}
TEST_CASE_END(buf_inspect_tag)
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index dd0e5a2..b065dc7 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -506,10 +506,8 @@
test_context("buf_parse_str(" # test ") -> " # expected); \
buf_init_1(&buf, (test)); \
TEST_EQ(buf_parse_str(&buf, &dest), strlen(test)); \
- if (g_test_last_ok) \
- TEST_EQ(dest.size, strlen(expected)); \
- if (g_test_last_ok) \
- TEST_STRNCMP(dest.ptr.p, (expected), dest.size); \
+ TEST_EQ(dest.size, strlen(expected)); \
+ TEST_STRNCMP(dest.ptr.p, (expected), dest.size); \
buf_clean(&buf); \
str_clean(&dest); \
test_context(NULL); \
@@ -1213,6 +1211,7 @@ TEST_CASE(buf_parse_str)
BUF_PARSE_TEST_STR("\"\\s\"", " ");
BUF_PARSE_TEST_STR("\"\\x01\"", "\x01");
BUF_PARSE_TEST_STR("\"\\x02\"", "\x02");
+ BUF_PARSE_TEST_STR("\"\\xff\"", "\xFF");
BUF_PARSE_TEST_STR("\"\\xFF\"", "\xFF");
BUF_PARSE_TEST_STR("\"0\"", "0");
BUF_PARSE_TEST_STR("\"9\"", "9");
diff --git a/test/facts_test.c b/test/facts_test.c
index 6047ba5..9cc32e6 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -258,7 +258,7 @@ TEST_CASE(facts_load)
s_str path;
facts_init(&facts);
str_init_1(&path, NULL, "facts_test_load_file.facts");
- TEST_EQ(facts_load_file(&facts, &path), 742);
+ TEST_EQ(facts_load_file(&facts, &path), 708);
TEST_EQ(facts_count(&facts), 23);
while (p[i]) {
fact_test_init_1(&fact, p[i]);
@@ -467,7 +467,7 @@ TEST_CASE(facts_open_file)
errx(1, "%s:%i: cp", __FILE__, __LINE__);
facts_init(&facts);
str_init_1(&path, NULL, "facts_test_open_file.1.facts");
- TEST_EQ(facts_open_file(&facts, &path), 798);
+ TEST_EQ(facts_open_file(&facts, &path), 747);
TEST_EQ(facts_count(&facts), 23);
i = 0;
while (p[i]) {
@@ -497,7 +497,7 @@ TEST_CASE(facts_open_file)
if (r > 0)
errx(1, "%s:%i: cp", __FILE__, __LINE__);
str_init_1(&path, NULL, "facts_test_open_file.2.facts");
- TEST_EQ(facts_open_file(&facts, &path), 1531);
+ TEST_EQ(facts_open_file(&facts, &path), 1480);
TEST_EQ(facts_count(&facts), 46);
i = 0;
while (p[i]) {
@@ -525,7 +525,7 @@ TEST_CASE(facts_open_file)
if (r > 0)
errx(1, "%s:%i: cp", __FILE__, __LINE__);
str_init_1(&path, NULL, "facts_test_open_file.3.facts");
- TEST_EQ(facts_open_file(&facts, &path), 1588);
+ TEST_EQ(facts_open_file(&facts, &path), 1537);
TEST_EQ(facts_count(&facts), 0);
i = 0;
while (p[i]) {
diff --git a/test/facts_test_dump_file.expected.facts b/test/facts_test_dump_file.expected.facts
index 236f018..ecdb52e 100644
--- a/test/facts_test_dump_file.expected.facts
+++ b/test/facts_test_dump_file.expected.facts
@@ -1,6 +1,6 @@
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -24,4 +24,4 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_load_file.facts b/test/facts_test_load_file.facts
index 236f018..ecdb52e 100644
--- a/test/facts_test_load_file.facts
+++ b/test/facts_test_load_file.facts
@@ -1,6 +1,6 @@
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -24,4 +24,4 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_open_file.1.expected.facts b/test/facts_test_open_file.1.expected.facts
index 4488c58..cb71f14 100644
--- a/test/facts_test_open_file.1.expected.facts
+++ b/test/facts_test_open_file.1.expected.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,7 +26,7 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
remove {"a", "a", "a"}
remove {:a, :a, :a}
remove {A, A, A}
diff --git a/test/facts_test_open_file.1.in.facts b/test/facts_test_open_file.1.in.facts
index cf3a10a..b258c9a 100644
--- a/test/facts_test_open_file.1.in.facts
+++ b/test/facts_test_open_file.1.in.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,4 +26,4 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_open_file.2.expected.facts b/test/facts_test_open_file.2.expected.facts
index b53142e..64e3432 100644
--- a/test/facts_test_open_file.2.expected.facts
+++ b/test/facts_test_open_file.2.expected.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,7 +26,7 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
add {b, b, b}
add {-18446744073709551617, -18446744073709551617, -18446744073709551617}
add {18446744073709551617, 18446744073709551617, 18446744073709551617}
diff --git a/test/facts_test_open_file.2.in.facts b/test/facts_test_open_file.2.in.facts
index b53142e..64e3432 100644
--- a/test/facts_test_open_file.2.in.facts
+++ b/test/facts_test_open_file.2.in.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,7 +26,7 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
add {b, b, b}
add {-18446744073709551617, -18446744073709551617, -18446744073709551617}
add {18446744073709551617, 18446744073709551617, 18446744073709551617}
diff --git a/test/facts_test_open_file.3.expected.facts b/test/facts_test_open_file.3.expected.facts
index da01a1e..288e66b 100644
--- a/test/facts_test_open_file.3.expected.facts
+++ b/test/facts_test_open_file.3.expected.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,7 +26,7 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
remove {a, a, a}
remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
diff --git a/test/facts_test_open_file.3.in.facts b/test/facts_test_open_file.3.in.facts
index 595b4d5..cbe7f0c 100644
--- a/test/facts_test_open_file.3.in.facts
+++ b/test/facts_test_open_file.3.in.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,7 +26,7 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
remove {a, a, a}
remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
diff --git a/test/facts_test_save.expected.facts b/test/facts_test_save.expected.facts
index cf3a10a..b258c9a 100644
--- a/test/facts_test_save.expected.facts
+++ b/test/facts_test_save.expected.facts
@@ -1,8 +1,8 @@
%{module: C3.Facts.Save,
- version: 0x0000000000000001}
+ version: 1}
%{module: C3.Facts.Dump,
- version: 0x0000000000000001,
- count: 0x0000000000000017}
+ version: 1,
+ count: 23}
{a, a, a}
{-18446744073709551616, -18446744073709551616, -18446744073709551616}
{18446744073709551616, 18446744073709551616, 18446744073709551616}
@@ -26,4 +26,4 @@
{{:a, :b}, {:a, :b}, {:a, :b}}
{{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
{{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x08DD94636F1EB189}
+%{hash: 0x8dd94636f1eb189}
diff --git a/test/str_test.c b/test/str_test.c
index 3208523..418bbc9 100644
--- a/test/str_test.c
+++ b/test/str_test.c
@@ -19,21 +19,20 @@
#define STR_TEST_INSPECT(test, expected) \
do { \
- s_str *str_test; \
s_str result; \
- str_test = (test); \
- assert(str_test); \
+ assert(test); \
test_context("str_inspect(" # test ") -> " # expected); \
- TEST_EQ(str_inspect(str_test, &result), &result); \
+ TEST_EQ(str_inspect((test), &result), &result); \
TEST_STRNCMP(result.ptr.p, (expected), result.size); \
str_clean(&result); \
- str_delete(str_test); \
test_context(NULL); \
} while (0)
#define STR_TEST_INSPECT_1(test, result) \
do { \
- STR_TEST_INSPECT(str_new_1(NULL, (test)), (result)); \
+ s_str str; \
+ str_init_1(&str, NULL, (test)); \
+ STR_TEST_INSPECT(&str, (result)); \
} while (0)
#define STR_TEST_TO_HEX(test, result) \
@@ -203,6 +202,7 @@ TEST_CASE_END(str_init_dup_1)
TEST_CASE(str_inspect)
{
+ s_str str;
s8 zero[16];
bzero(zero, sizeof(zero));
STR_TEST_INSPECT_1("", "\"\"");
@@ -254,31 +254,31 @@ TEST_CASE(str_inspect)
"\"\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\"");
STR_TEST_INSPECT_1("\xff\xff\xff\xff\xff\xff\xff\xff",
"\"\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\"");
- STR_TEST_INSPECT(str_new(NULL, 1, zero), "\"\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 2, zero), "\"\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 3, zero), "\"\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 4, zero), "\"\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 5, zero), "\"\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 6, zero), "\"\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 7, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 1, zero), "\"\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 2, zero), "\"\\0\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 3, zero), "\"\\0\\0\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 4, zero), "\"\\0\\0\\0\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 5, zero), "\"\\0\\0\\0\\0\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 6, zero), "\"\\0\\0\\0\\0\\0\\0\"");
+ STR_TEST_INSPECT(str_init(&str, NULL, 7, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 8, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 8, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 9, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 9, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 10, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 10, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 11, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 11, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 12, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 12, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 13, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 13, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 14, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 14, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 15, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 15, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
- STR_TEST_INSPECT(str_new(NULL, 16, zero),
+ STR_TEST_INSPECT(str_init(&str, NULL, 16, zero),
"\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0"
"\\0\"");
}