diff --git a/libc3/facts.c b/libc3/facts.c
index 1c8293d..fcc5d5f 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -25,6 +25,7 @@
#include "facts_cursor.h"
#include "facts_with.h"
#include "hash.h"
+#include "log.h"
#include "set__fact.h"
#include "set__tag.h"
#include "skiplist__fact.h"
@@ -67,7 +68,7 @@ s_fact * facts_add_tags (s_facts *facts, const s_tag *subject,
void facts_clean (s_facts *facts)
{
if (facts->log)
- buf_file_close(facts->log);
+ facts_close(facts);
skiplist_delete__fact(facts->index_osp);
skiplist_delete__fact(facts->index_pos);
skiplist_delete__fact(facts->index_spo);
@@ -75,6 +76,14 @@ void facts_clean (s_facts *facts)
set_clean__tag(&facts->tags);
}
+void facts_close (s_facts *facts)
+{
+ assert(facts->log);
+ log_close(facts->log);
+ log_delete(facts->log);
+ facts->log = NULL;
+}
+
void facts_delete (s_facts *facts)
{
assert(facts);
@@ -276,33 +285,39 @@ sw facts_load_file (s_facts *facts, const s8 *path)
return result;
}
-sw facts_log_add (s_buf *log, const s_fact *fact)
+sw facts_log_add (s_log *log, const s_fact *fact)
{
sw r;
sw result = 0;
- if ((r = buf_write_1(log, "add ")) < 0)
+ assert(log);
+ assert(fact);
+ if ((r = buf_write_1(&log->buf, "add ")) < 0)
return r;
result += r;
- if ((r = buf_inspect_fact(log, fact)) < 0)
+ hash_update_1(&log->hash, "add");
+ if ((r = buf_inspect_fact(&log->buf, fact)) < 0)
return r;
result += r;
- if ((r = buf_write_1(log, "\n")) < 0)
+ hash_update_fact(&log->hash, fact);
+ if ((r = buf_write_1(&log->buf, "\n")) < 0)
return r;
result += r;
return result;
}
-sw facts_log_remove (s_buf *log, const s_fact *fact)
+sw facts_log_remove (s_log *log, const s_fact *fact)
{
sw r;
sw result = 0;
- if ((r = buf_write_1(log, "remove ")) < 0)
+ if ((r = buf_write_1(&log->buf, "remove ")) < 0)
return r;
result += r;
- if ((r = buf_inspect_fact(log, fact)) < 0)
+ hash_update_1(&log->hash, "remove");
+ if ((r = buf_inspect_fact(&log->buf, fact)) < 0)
return r;
result += r;
- if ((r = buf_write_1(log, "\n")) < 0)
+ hash_update_fact(&log->hash, fact);
+ if ((r = buf_write_1(&log->buf, "\n")) < 0)
return r;
result += r;
return result;
@@ -334,7 +349,6 @@ sw facts_open_file (s_facts *facts, const s8 *path)
{
FILE *fp;
s_buf in;
- s_buf *out;
sw r;
sw result = 0;
BUF_INIT_ALLOCA(&in, BUF_SIZE);
@@ -348,13 +362,13 @@ sw facts_open_file (s_facts *facts, const s8 *path)
return r;
result += r;
fclose(fp);
- if (! (fp = fopen(path, "wb"))) {
+ if (! (fp = fopen(path, "ab"))) {
warn("fopen: %s", path);
return -1;
}
- out = buf_new_alloc(BUF_SIZE);
- buf_file_open_w(out, fp);
- facts->log = out;
+ if (! (facts->log = log_new(BUF_SIZE)))
+ return -1;
+ log_open(facts->log, fp);
return result;
}
@@ -385,7 +399,9 @@ sw facts_open_file_create (s_facts *facts, const s8 *path)
return r;
result += r;
buf_flush(out);
- facts->log = out;
+ if (! (facts->log = log_new()))
+ return -1;
+ buf_file_open_w(&facts->log->buf, fp);
return result;
}
@@ -455,27 +471,30 @@ e_bool facts_remove_fact (s_facts *facts, const s_fact *fact)
sw facts_save_file (s_facts *facts, const s8 *path)
{
- s_buf *buf;
+ s_buf buf;
FILE *fp;
sw r;
sw result = 0;
assert(facts);
assert(path);
assert(! facts->log);
- buf = buf_new_alloc(1024);
+ BUF_INIT_ALLOCA(&buf, BUF_SIZE);
if (! (fp = fopen(path, "wb"))) {
warn("fopen: %s", path);
return -1;
}
- buf_file_open_w(buf, fp);
- if ((r = facts_save_header(buf)) < 0)
+ buf_file_open_w(&buf, fp);
+ if ((r = facts_save_header(&buf)) < 0)
goto ko;
result += r;
- if ((r = facts_dump(facts, buf)) < 0)
+ if ((r = facts_dump(facts, &buf)) < 0)
goto ko;
result += r;
- buf_flush(buf);
- facts->log = buf;
+ buf_flush(&buf);
+ if (! (facts->log = log_new()))
+ goto ko;
+ if (log_open(facts->log, fp) < 0)
+ goto ko;
return result;
ko:
fclose(fp);
diff --git a/libc3/facts.h b/libc3/facts.h
index 636bd1e..6451a7d 100644
--- a/libc3/facts.h
+++ b/libc3/facts.h
@@ -47,8 +47,8 @@ sw facts_dump (const s_facts *facts, s_buf *buf);
sw facts_dump_file (const s_facts *facts, const s8 *path);
s_fact * facts_find_fact (const s_facts *facts, const s_fact *fact);
s_tag * facts_find_tag (const s_facts *facts, const s_tag *tag);
-sw facts_log_add (s_buf *log, const s_fact *fact);
-sw facts_log_remove (s_buf *log, const s_fact *fact);
+sw facts_log_add (s_log *log, const s_fact *fact);
+sw facts_log_remove (s_log *log, const s_fact *fact);
sw facts_save_header (s_buf *buf);
#endif /* FACTS_H */
diff --git a/libc3/hash.c b/libc3/hash.c
index a8f9b11..4006587 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -25,6 +25,11 @@
hash_update(hash, &x, sizeof(x)); \
} \
+void hash_clean (t_hash *hash)
+{
+ bzero(hash, sizeof(t_hash));
+}
+
void hash_init (t_hash *hash)
{
assert(hash);
@@ -52,6 +57,13 @@ void hash_update (t_hash *hash, const void *data, uw size)
SHA1Update(hash, data, size);
}
+void hash_update_1 (t_hash *hash, const s8 *p)
+{
+ assert(hash);
+ assert(p);
+ hash_update(hash, p, strlen(p));
+}
+
void hash_update_bool (t_hash *hash, e_bool x)
{
bool b = x ? 1 : 0;
diff --git a/libc3/hash.h b/libc3/hash.h
index 78c4e08..8d3dce8 100644
--- a/libc3/hash.h
+++ b/libc3/hash.h
@@ -19,10 +19,12 @@
#define HASH_UPDATE_PROTOTYPE(type) \
void hash_update_##type (t_hash *hash, type x)
+void hash_clean (t_hash *hash);
void hash_init (t_hash *hash);
uw hash_to_uw (t_hash *hash);
u64 hash_to_u64 (t_hash *hash);
void hash_update (t_hash *hash, const void *data, uw size);
+void hash_update_1 (t_hash *hash, const s8 *p);
void hash_update_bool (t_hash *hash, e_bool b);
void hash_update_call (t_hash *hash, const s_call *call);
void hash_update_fact (t_hash *hash, const s_fact *fact);
diff --git a/libc3/log.c b/libc3/log.c
new file mode 100644
index 0000000..e6517ed
--- /dev/null
+++ b/libc3/log.c
@@ -0,0 +1,63 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers 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.
+ */
+#include <assert.h>
+#include "buf.h"
+#include "buf_file.h"
+#include "hash.h"
+#include "log.h"
+
+void log_clean (s_log *log)
+{
+ assert(log);
+ buf_clean(&log->buf);
+ hash_clean(&log->hash);
+}
+
+void log_close (s_log *log)
+{
+ buf_file_close(&log->buf);
+}
+
+void log_delete (s_log *log)
+{
+ assert(log);
+ log_clean(log);
+ free(log);
+}
+
+void log_init (s_log *log)
+{
+ buf_init_alloc(&log->buf, BUF_SIZE);
+ log->count = 0;
+ hash_init(&log->hash);
+}
+
+s_log * log_new ()
+{
+ s_log *log;
+ if (! (log = malloc(sizeof(s_log)))) {
+ warnx("log_new: failed to allocate memory");
+ return NULL;
+ }
+ log_init(log);
+ return log;
+}
+
+sw log_open (s_log *log, FILE *fp)
+{
+ assert(log);
+ assert(fp);
+ buf_file_open_w(&log->buf, fp);
+ return 0;
+}
diff --git a/libc3/log.h b/libc3/log.h
new file mode 100644
index 0000000..905044d
--- /dev/null
+++ b/libc3/log.h
@@ -0,0 +1,33 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers 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 LOG_H
+#define LOG_H
+
+#include "types.h"
+
+/* stack-allocation compatible functions */
+void log_init (s_log *log);
+void log_clean (s_log *log);
+
+/* constructor */
+s_log * log_new ();
+
+/* destructor */
+void log_delete (s_log *log);
+
+/* modifiers */
+void log_close (s_log *log);
+sw log_open (s_log *log, FILE *fp);
+
+#endif /* C3_H */
diff --git a/libc3/sources.mk b/libc3/sources.mk
index 05b21cd..356db4b 100644
--- a/libc3/sources.mk
+++ b/libc3/sources.mk
@@ -1,3 +1,3 @@
# sources.mk generated by update_sources
-SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c
-LO_SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c
+SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c log.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c
+LO_SOURCES = arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c log.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c
diff --git a/libc3/sources.sh b/libc3/sources.sh
index d8e0645..8c2cb53 100644
--- a/libc3/sources.sh
+++ b/libc3/sources.sh
@@ -1,3 +1,3 @@
# sources.sh generated by update_sources
-SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c '
-LO_SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c '
+SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c log.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c '
+LO_SOURCES='arg.c binding.c bool.c buf.c buf_file.c buf_inspect.c buf_parse.c buf_parse_c.c buf_save.c c3.c call.c character.c compare.c debug.c env.c error.c error_handler.c eval.c fact.c facts.c facts_cursor.c facts_spec.c facts_spec_cursor.c facts_with.c facts_with_cursor.c fn.c frame.c hash.c ident.c integer.c list.c log.c quote.c set__fact.c set__tag.c set_cursor__fact.c set_cursor__tag.c set_item__fact.c set_item__tag.c skiplist__fact.c skiplist_node__fact.c str.c sym.c tag.c tuple.c ucd.c ../libtommath/bn_cutoffs.c ../libtommath/bn_deprecated.c ../libtommath/bn_mp_2expt.c ../libtommath/bn_mp_abs.c ../libtommath/bn_mp_add.c ../libtommath/bn_mp_add_d.c ../libtommath/bn_mp_addmod.c ../libtommath/bn_mp_and.c ../libtommath/bn_mp_clamp.c ../libtommath/bn_mp_clear.c ../libtommath/bn_mp_clear_multi.c ../libtommath/bn_mp_cmp.c ../libtommath/bn_mp_cmp_d.c ../libtommath/bn_mp_cmp_mag.c ../libtommath/bn_mp_cnt_lsb.c ../libtommath/bn_mp_complement.c ../libtommath/bn_mp_copy.c ../libtommath/bn_mp_count_bits.c ../libtommath/bn_mp_decr.c ../libtommath/bn_mp_div.c ../libtommath/bn_mp_div_2.c ../libtommath/bn_mp_div_2d.c ../libtommath/bn_mp_div_3.c ../libtommath/bn_mp_div_d.c ../libtommath/bn_mp_dr_is_modulus.c ../libtommath/bn_mp_dr_reduce.c ../libtommath/bn_mp_dr_setup.c ../libtommath/bn_mp_error_to_string.c ../libtommath/bn_mp_exch.c ../libtommath/bn_mp_expt_u32.c ../libtommath/bn_mp_exptmod.c ../libtommath/bn_mp_exteuclid.c ../libtommath/bn_mp_fread.c ../libtommath/bn_mp_from_sbin.c ../libtommath/bn_mp_from_ubin.c ../libtommath/bn_mp_fwrite.c ../libtommath/bn_mp_gcd.c ../libtommath/bn_mp_get_double.c ../libtommath/bn_mp_get_i32.c ../libtommath/bn_mp_get_i64.c ../libtommath/bn_mp_get_l.c ../libtommath/bn_mp_get_ll.c ../libtommath/bn_mp_get_mag_u32.c ../libtommath/bn_mp_get_mag_u64.c ../libtommath/bn_mp_get_mag_ul.c ../libtommath/bn_mp_get_mag_ull.c ../libtommath/bn_mp_grow.c ../libtommath/bn_mp_incr.c ../libtommath/bn_mp_init.c ../libtommath/bn_mp_init_copy.c ../libtommath/bn_mp_init_i32.c ../libtommath/bn_mp_init_i64.c ../libtommath/bn_mp_init_l.c ../libtommath/bn_mp_init_ll.c ../libtommath/bn_mp_init_multi.c ../libtommath/bn_mp_init_set.c ../libtommath/bn_mp_init_size.c ../libtommath/bn_mp_init_u32.c ../libtommath/bn_mp_init_u64.c ../libtommath/bn_mp_init_ul.c ../libtommath/bn_mp_init_ull.c ../libtommath/bn_mp_invmod.c ../libtommath/bn_mp_is_square.c ../libtommath/bn_mp_iseven.c ../libtommath/bn_mp_isodd.c ../libtommath/bn_mp_kronecker.c ../libtommath/bn_mp_lcm.c ../libtommath/bn_mp_log_u32.c ../libtommath/bn_mp_lshd.c ../libtommath/bn_mp_mod.c ../libtommath/bn_mp_mod_2d.c ../libtommath/bn_mp_mod_d.c ../libtommath/bn_mp_montgomery_calc_normalization.c ../libtommath/bn_mp_montgomery_reduce.c ../libtommath/bn_mp_montgomery_setup.c ../libtommath/bn_mp_mul.c ../libtommath/bn_mp_mul_2.c ../libtommath/bn_mp_mul_2d.c ../libtommath/bn_mp_mul_d.c ../libtommath/bn_mp_mulmod.c ../libtommath/bn_mp_neg.c ../libtommath/bn_mp_or.c ../libtommath/bn_mp_pack.c ../libtommath/bn_mp_pack_count.c ../libtommath/bn_mp_prime_fermat.c ../libtommath/bn_mp_prime_frobenius_underwood.c ../libtommath/bn_mp_prime_is_prime.c ../libtommath/bn_mp_prime_miller_rabin.c ../libtommath/bn_mp_prime_next_prime.c ../libtommath/bn_mp_prime_rabin_miller_trials.c ../libtommath/bn_mp_prime_rand.c ../libtommath/bn_mp_prime_strong_lucas_selfridge.c ../libtommath/bn_mp_radix_size.c ../libtommath/bn_mp_radix_smap.c ../libtommath/bn_mp_rand.c ../libtommath/bn_mp_read_radix.c ../libtommath/bn_mp_reduce.c ../libtommath/bn_mp_reduce_2k.c ../libtommath/bn_mp_reduce_2k_l.c ../libtommath/bn_mp_reduce_2k_setup.c ../libtommath/bn_mp_reduce_2k_setup_l.c ../libtommath/bn_mp_reduce_is_2k.c ../libtommath/bn_mp_reduce_is_2k_l.c ../libtommath/bn_mp_reduce_setup.c ../libtommath/bn_mp_root_u32.c ../libtommath/bn_mp_rshd.c ../libtommath/bn_mp_sbin_size.c ../libtommath/bn_mp_set.c ../libtommath/bn_mp_set_i32.c ../libtommath/bn_mp_set_i64.c ../libtommath/bn_mp_set_l.c ../libtommath/bn_mp_set_ll.c ../libtommath/bn_mp_set_u32.c ../libtommath/bn_mp_set_u64.c ../libtommath/bn_mp_set_ul.c ../libtommath/bn_mp_set_ull.c ../libtommath/bn_mp_shrink.c ../libtommath/bn_mp_signed_rsh.c ../libtommath/bn_mp_sqr.c ../libtommath/bn_mp_sqrmod.c ../libtommath/bn_mp_sqrt.c ../libtommath/bn_mp_sqrtmod_prime.c ../libtommath/bn_mp_sub.c ../libtommath/bn_mp_sub_d.c ../libtommath/bn_mp_submod.c ../libtommath/bn_mp_to_radix.c ../libtommath/bn_mp_to_sbin.c ../libtommath/bn_mp_to_ubin.c ../libtommath/bn_mp_ubin_size.c ../libtommath/bn_mp_unpack.c ../libtommath/bn_mp_xor.c ../libtommath/bn_mp_zero.c ../libtommath/bn_prime_tab.c ../libtommath/bn_s_mp_add.c ../libtommath/bn_s_mp_balance_mul.c ../libtommath/bn_s_mp_exptmod.c ../libtommath/bn_s_mp_exptmod_fast.c ../libtommath/bn_s_mp_get_bit.c ../libtommath/bn_s_mp_invmod_fast.c ../libtommath/bn_s_mp_invmod_slow.c ../libtommath/bn_s_mp_karatsuba_mul.c ../libtommath/bn_s_mp_karatsuba_sqr.c ../libtommath/bn_s_mp_montgomery_reduce_fast.c ../libtommath/bn_s_mp_mul_digs.c ../libtommath/bn_s_mp_mul_digs_fast.c ../libtommath/bn_s_mp_mul_high_digs.c ../libtommath/bn_s_mp_mul_high_digs_fast.c ../libtommath/bn_s_mp_prime_is_divisible.c ../libtommath/bn_s_mp_rand_jenkins.c ../libtommath/bn_s_mp_reverse.c ../libtommath/bn_s_mp_sqr.c ../libtommath/bn_s_mp_sqr_fast.c ../libtommath/bn_s_mp_sub.c ../libtommath/bn_s_mp_toom_mul.c ../libtommath/bn_s_mp_toom_sqr.c '
diff --git a/libc3/types.h b/libc3/types.h
index ddb10e7..5ce58b7 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -99,6 +99,7 @@ typedef struct ident s_ident;
typedef struct integer s_integer;
typedef struct list s_list;
typedef struct list s_list_map;
+typedef struct log s_log;
typedef struct module s_module;
typedef struct str s_str;
typedef struct sym s_sym;
@@ -257,6 +258,12 @@ struct env {
s_unwind_protect *unwind_protect;
};
+struct log {
+ s_buf buf;
+ u64 count;
+ t_hash hash;
+};
+
struct sym {
s_str str;
};
@@ -359,7 +366,7 @@ TYPEDEF_SKIPLIST_NODE(fact, s_fact *);
} s_skiplist__##name
TYPEDEF_SKIPLIST(fact, s_fact *);
-
+
/* 5 */
struct facts {
s_set__tag tags;
@@ -367,9 +374,7 @@ struct facts {
s_skiplist__fact *index_spo;
s_skiplist__fact *index_pos;
s_skiplist__fact *index_osp;
- s_buf *log;
- u64 log_count;
- t_hash log_hash;
+ s_log *log;
};
struct facts_cursor {
diff --git a/test/facts_test.c b/test/facts_test.c
index 74793f3..bd0b3e5 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -16,6 +16,7 @@
#include "../libc3/buf.h"
#include "../libc3/compare.h"
#include "../libc3/facts.h"
+#include "../libc3/log.h"
#include "fact_test.h"
#include "test.h"
@@ -295,12 +296,10 @@ void facts_test_log_add ()
s_fact fact[24];
s_facts facts;
FILE *fp;
- s_buf log;
- BUF_INIT_ALLOCA(&log, 1024);
fp = fopen("facts_test_log_add.facts", "w");
- buf_file_open_w(&log, fp);
facts_init(&facts);
- facts.log = &log;
+ facts.log = log_new();
+ log_open(facts.log, fp);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -347,12 +346,10 @@ void facts_test_log_remove ()
s_fact fact[24];
s_facts facts;
FILE *fp;
- s_buf log;
- BUF_INIT_ALLOCA(&log, 1024);
fp = fopen("facts_test_log_remove.facts", "w");
- buf_file_open_w(&log, fp);
facts_init(&facts);
- facts.log = &log;
+ facts.log = log_new();
+ log_open(facts.log, fp);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -367,7 +364,6 @@ void facts_test_log_remove ()
i++;
}
facts_clean(&facts);
- buf_file_close(&log);
fclose(fp);
test_file_compare("facts_test_log_remove.facts",
"facts_test_log_remove.facts.expected");