diff --git a/Makefile b/Makefile
index 962d3a2..92f2d6f 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ all:
${MAKE} -C libkc3 all
${MAKE} -C ikc3 all
${MAKE} -C kc3s all
+ ${MAKE} -C ekc3 all
${MAKE} -C test all
${MAKE} -C libkc3_window all
@@ -26,6 +27,7 @@ asan:
${MAKE} -C libkc3 asan
${MAKE} -C ikc3 asan
${MAKE} -C kc3s asan
+ ${MAKE} -C ekc3 asan
${MAKE} -C test asan
${MAKE} -C libkc3_window asan
@@ -36,6 +38,7 @@ build:
${MAKE} -C libkc3 build
${MAKE} -C ikc3 build
${MAKE} -C kc3s build
+ ${MAKE} -C ekc3 build
${MAKE} -C test build
${MAKE} -C libkc3_window build
@@ -45,6 +48,7 @@ clean:
${MAKE} -C libkc3 clean
${MAKE} -C ikc3 clean
${MAKE} -C kc3s clean
+ ${MAKE} -C ekc3 clean
${MAKE} -C test clean
${MAKE} -C libkc3_window clean
@@ -53,6 +57,7 @@ clean_cov:
${MAKE} -C libkc3 clean_cov
${MAKE} -C ikc3 clean_cov
${MAKE} -C kc3s clean_cov
+ ${MAKE} -C ekc3 clean_cov
${MAKE} -C test clean_cov
${MAKE} -C libkc3_window clean_cov
@@ -62,6 +67,7 @@ cov:
${MAKE} -C libkc3 cov
${MAKE} -C ikc3 cov
${MAKE} -C kc3s cov
+ ${MAKE} -C ekc3 cov
${MAKE} -C test cov
${MAKE} -C libkc3_window cov
@@ -71,6 +77,7 @@ debug:
${MAKE} -C libkc3 debug
${MAKE} -C ikc3 debug
${MAKE} -C kc3s debug
+ ${MAKE} -C ekc3 debug
${MAKE} -C test debug
${MAKE} -C libkc3_window debug
@@ -116,6 +123,7 @@ distclean:
${MAKE} -C libkc3 distclean
${MAKE} -C ikc3 distclean
${MAKE} -C kc3s distclean
+ ${MAKE} -C ekc3 distclean
${MAKE} -C test distclean
${MAKE} -C libkc3_window distclean
@@ -123,6 +131,7 @@ gcovr:
${MAKE} -C libkc3 gcovr
${MAKE} -C ikc3 gcovr
${MAKE} -C kc3s gcovr
+ ${MAKE} -C ekc3 gcovr
${MAKE} -C test gcovr
${MAKE} -C libkc3_window gcovr
if [ -d "$$HOME/Downloads/kc3_gcovr" ]; then bin/gcovr-to-downloads; fi
@@ -166,6 +175,7 @@ install:
${MAKE} -C libkc3 install
${MAKE} -C ikc3 install
${MAKE} -C kc3s install
+ ${MAKE} -C ekc3 install
${MAKE} -C libkc3_window install
libkc3_gcovr:
@@ -198,6 +208,8 @@ test:
${MAKE} -C libtommath build
${MAKE} -C libkc3 build
${MAKE} -C ikc3 build
+ ${MAKE} -C kc3s build
+ ${MAKE} -C ekc3 build
${MAKE} -C test test
if ${HAVE_ASAN}; then ${MAKE} test_asan; fi
@@ -205,18 +217,24 @@ test_asan:
${MAKE} -C libtommath asan
${MAKE} -C libkc3 asan
${MAKE} -C ikc3 asan
+ ${MAKE} -C kc3s asan
+ ${MAKE} -C ekc3 asan
${MAKE} -C test test_asan
test_cov: cov clean_cov
${MAKE} -C libtommath cov clean_cov
${MAKE} -C libkc3 cov clean_cov
${MAKE} -C ikc3 cov clean_cov
+ ${MAKE} -C kc3s cov clean_cov
+ ${MAKE} -C ekc3 cov clean_cov
${MAKE} -C test test_cov
test_debug:
${MAKE} -C libtommath debug
${MAKE} -C libkc3 debug
${MAKE} -C ikc3 debug
+ ${MAKE} -C kc3s debug
+ ${MAKE} -C ekc3 debug
${MAKE} -C test test_debug
test_ekc3: build
diff --git a/ekc3/configure b/ekc3/configure
index 1403402..f74c320 100755
--- a/ekc3/configure
+++ b/ekc3/configure
@@ -18,10 +18,10 @@ CONFIG_H_PREFIX=LIBKC3_WEB_
. ../config.subr
-LIB=libkc3_web.la
-LIB_ASAN=libkc3_web_asan.la
-LIB_COV=libkc3_web_cov.la
-LIB_DEBUG=libkc3_web_debug.la
+LIB=libekc3.la
+LIB_ASAN=libekc3_asan.la
+LIB_COV=libekc3_cov.la
+LIB_DEBUG=libekc3_debug.la
echo "LIB = $LIB" >> ${CONFIG_MK}
echo "LIB_ASAN = $LIB_ASAN" >> ${CONFIG_MK}
diff --git a/ekc3/ekc3.c b/ekc3/ekc3.c
index 09ef6e9..64bc8ea 100644
--- a/ekc3/ekc3.c
+++ b/ekc3/ekc3.c
@@ -13,9 +13,9 @@
#include <libkc3/kc3.h>
#include "ekc3.h"
-#define EC3_BUF_PARSE_STR_BUF_SIZE (1024 * 1024)
+#define EKC3_BUF_PARSE_STR_BUF_SIZE (1024 * 1024)
-s_list ** ec3_append_and_empty_buf (s_list **tail, s_buf *buf)
+s_list ** ekc3_append_and_empty_buf (s_list **tail, s_buf *buf)
{
sw r;
s_str str;
@@ -40,7 +40,7 @@ s_list ** ec3_append_and_empty_buf (s_list **tail, s_buf *buf)
return tail;
}
-s_list ** ec3_append_block (s_list **tail, s_block *block)
+s_list ** ekc3_append_block (s_list **tail, s_block *block)
{
assert(tail);
assert(! *tail);
@@ -53,19 +53,19 @@ s_list ** ec3_append_block (s_list **tail, s_block *block)
return tail;
}
-s_list ** ec3_append_silent_block (s_list **tail, s_block *block)
+s_list ** ekc3_append_silent_block (s_list **tail, s_block *block)
{
assert(tail);
assert(! *tail);
assert(block);
- if (! ec3_append_sym(tail, sym_1("silent")))
+ if (! ekc3_append_sym(tail, sym_1("silent")))
return NULL;
- if (! ec3_append_block(tail, block))
+ if (! ekc3_append_block(tail, block))
return NULL;
return tail;
}
-s_list ** ec3_append_str (s_list **tail, s_str *str)
+s_list ** ekc3_append_str (s_list **tail, s_str *str)
{
assert(tail);
assert(! *tail);
@@ -78,7 +78,7 @@ s_list ** ec3_append_str (s_list **tail, s_str *str)
return tail;
}
-s_list ** ec3_append_sym (s_list **tail, const s_sym *sym)
+s_list ** ekc3_append_sym (s_list **tail, const s_sym *sym)
{
assert(tail);
assert(! *tail);
@@ -91,7 +91,7 @@ s_list ** ec3_append_sym (s_list **tail, const s_sym *sym)
return tail;
}
-sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
+sw ekc3_buf_parse (s_buf *buf, p_ekc3 *dest)
{
s_block block;
character c;
@@ -100,12 +100,12 @@ sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
s_buf_save save;
s_buf str_buf;
s_list **tail;
- p_ec3 tmp;
+ p_ekc3 tmp;
assert(dest);
assert(buf);
- if (! buf_init_alloc(&str_buf, EC3_BUF_PARSE_STR_BUF_SIZE))
+ if (! buf_init_alloc(&str_buf, EKC3_BUF_PARSE_STR_BUF_SIZE))
return -1;
- ec3_init(&tmp);
+ ekc3_init(&tmp);
tail = &tmp;
buf_save_init(buf, &save);
while (1) {
@@ -114,12 +114,12 @@ sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
goto restore;
if (r > 0) {
result += r;
- if (! ec3_append_and_empty_buf(tail, &str_buf))
+ if (! ekc3_append_and_empty_buf(tail, &str_buf))
goto ko;
- r = ec3_buf_parse_c3_block(buf, &block);
+ r = ekc3_buf_parse_kc3_block(buf, &block);
if (r <= 0)
goto restore;
- if (! ec3_append_block(tail, &block))
+ if (! ekc3_append_block(tail, &block))
goto ko;
continue;
}
@@ -128,12 +128,12 @@ sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
goto restore;
if (r > 0) {
result += r;
- if (! ec3_append_and_empty_buf(tail, &str_buf))
+ if (! ekc3_append_and_empty_buf(tail, &str_buf))
goto ko;
- r = ec3_buf_parse_c3_block(buf, &block);
+ r = ekc3_buf_parse_kc3_block(buf, &block);
if (r <= 0)
goto restore;
- if (! ec3_append_block(tail, &block))
+ if (! ekc3_append_block(tail, &block))
goto ko;
continue;
}
@@ -148,8 +148,8 @@ sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
result += r;
r = buf_write_character_utf8(&str_buf, c);
if (r <= 0) {
- err_puts("ec3_buf_parse: buf_write_character_utf8 str_buf");
- assert(! "ec3_buf_parse: buf_write_character_utf8 str_buf");
+ err_puts("ekc3_buf_parse: buf_write_character_utf8 str_buf");
+ assert(! "ekc3_buf_parse: buf_write_character_utf8 str_buf");
goto restore;
}
}
@@ -157,63 +157,139 @@ sw ec3_buf_parse (s_buf *buf, p_ec3 *dest)
r = -1;
restore:
buf_save_restore_rpos(buf, &save);
- ec3_clean(&tmp);
+ ekc3_clean(&tmp);
clean:
buf_clean(&str_buf);
buf_save_clean(buf, &save);
return r;
}
-sw ec3_buf_parse_c3_block (s_buf *buf, s_block *dest)
+sw ekc3_buf_parse_kc3_block (s_buf *buf, s_block *dest)
{
sw r;
sw result = 0;
s_buf_save save;
+ s_list *list;
+ s_list **tail;
+ s_block tmp;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
- r = buf_ignore_spaces(buf);
- if (r < 0)
- goto clean;
- if (! r) {
- r = -1;
- goto clean;
+ list = NULL;
+ tail = &list;
+ while (1) {
+ r = buf_ignore_spaces(buf);
+ if (r < 0)
+ goto clean;
+ if (! r) {
+ r = -1;
+ goto clean;
+ }
+ r = buf_read_1(buf, "%>");
+ if (r > 0) {
+ result += r;
+ if (! block_init_from_list(&tmp, (const s_list * const*) &list)) {
+ list_delete_all(list);
+ r = -1;
+ goto clean;
+ }
+ *dest = tmp;
+ r = result;
+ goto clean;
+ }
+ *tail = list_new(NULL);
+ r = buf_parse_tag(buf, &(*tail)->tag);
+ if (r <= 0) {
+ list_delete_all(list);
+ goto clean;
+ }
+ result += r;
+ tail = &(*tail)->next.data.list;
}
- result += r;
-
clean:
buf_save_clean(buf, &save);
return r;
}
-void ec3_clean (p_ec3 *ec3)
+void ekc3_clean (p_ekc3 *ekc3)
{
- list_delete_all(*ec3);
+ list_delete_all(*ekc3);
}
-p_ec3 * ec3_init (p_ec3 *ec3)
+p_ekc3 * ekc3_init (p_ekc3 *ekc3)
{
- p_ec3 tmp = {0};
- *ec3 = tmp;
- return ec3;
+ p_ekc3 tmp = {0};
+ *ekc3 = tmp;
+ return ekc3;
}
-sw ec3_render (const p_ec3 *ec3, s_buf *buf, s_map *map)
+sw ekc3_render (const p_ekc3 *ekc3)
{
- assert(ec3);
- assert(buf);
- assert(map);
- (void) ec3;
- (void) buf;
- (void) map;
- return -42;
+ const s_list *l;
+ sw r;
+ sw result = 0;
+ assert(ekc3);
+ l = *ekc3;
+ while (l) {
+ if (! (r = ekc3_render_tag(&l->tag)))
+ return r;
+ result += r;
+ l = list_next(l);
+ }
+ return result;
+}
+
+sw ekc3_render_buf (s_buf *in)
+{
+ p_ekc3 ekc3;
+ sw r;
+ assert(in);
+ ekc3_init(&ekc3);
+ r = ekc3_buf_parse(in, &ekc3);
+ if (r < 0)
+ return r;
+ r = ekc3_render(&ekc3);
+ ekc3_clean(&ekc3);
+ return r;
+}
+
+sw ekc3_render_file (const s_str *path)
+{
+ s_tag *file_dir;
+ s_tag file_dir_save;
+ s_tag *file_path;
+ s_tag file_path_save;
+ FILE *fp;
+ s_buf in;
+ char in_data[BUF_SIZE];
+ sw r;
+ buf_init(&in, false, BUF_SIZE, in_data);
+ fp = file_open(path->ptr.pchar, "rb");
+ if (! fp)
+ return -1;
+ if (! buf_file_open_r(&in, fp)) {
+ fclose(fp);
+ return -1;
+ }
+ file_dir = frame_get_w(&g_kc3_env.global_frame, &g_sym___DIR__);
+ file_dir_save = *file_dir;
+ file_dirname(path, &file_dir->data.str);
+ file_path = frame_get_w(&g_kc3_env.global_frame, &g_sym___FILE__);
+ file_path_save = *file_path;
+ file_path->data.str = *path;
+ r = ekc3_render_buf(&in);
+ *file_dir = file_dir_save;
+ *file_path = file_path_save;
+ buf_file_close(&in);
+ fclose(fp);
+ return r;
}
-s_fn * ec3_to_render_fn (const p_ec3 *ec3, s_fn *dest)
+s_fn * ekc3_to_render_fn (const p_ekc3 *ekc3, s_fn *dest)
{
- assert(ec3);
+ assert(ekc3);
assert(dest);
- (void) ec3;
+ (void) ekc3;
(void) dest;
return NULL;
}
diff --git a/ekc3/ekc3.h b/ekc3/ekc3.h
index 740d8bd..9a90fdf 100644
--- a/ekc3/ekc3.h
+++ b/ekc3/ekc3.h
@@ -26,10 +26,12 @@ s_list ** ekc3_append_silent_block (s_list **tail, s_block *block);
s_list ** ekc3_append_str (s_list **tail, s_str *str);
s_list ** ekc3_append_sym (s_list **tail, const s_sym *sym);
sw ekc3_buf_parse (s_buf *buf, p_ekc3 *dest);
-sw ekc3_buf_parse_c3_block (s_buf *buf, s_block *dest);
+sw ekc3_buf_parse_kc3_block (s_buf *buf, s_block *dest);
/* Observers. */
-sw ekc3_render (const p_ekc3 *ekc3, s_buf *buf, s_map *map);
-s_fn * ekc3_to_render_fn (const p_ekc3 *ekc3, s_fn *dest);
+sw ekc3_render (const p_ekc3 *ekc3);
+sw ekc3_render_buf (s_buf *in);
+sw ekc3_render_file (const s_str *path);
+sw ekc3_render_tag (const s_tag *tag);
#endif /* EKC3_H */
diff --git a/env b/env
index 9a086eb..de90e5d 100644
--- a/env
+++ b/env
@@ -1 +1 @@
-export LD_LIBRARY_PATH="$PWD/libkc3/.libs:$LD_LIBRARY_PATH"
+export LD_LIBRARY_PATH="$PWD/libkc3/.libs:$PWD/ekc3/.libs:$PWD/lib/kc3/0.1:$LD_LIBRARY_PATH"
diff --git a/ikc3/ikc3.c b/ikc3/ikc3.c
index 6e9be7b..aae0ddb 100644
--- a/ikc3/ikc3.c
+++ b/ikc3/ikc3.c
@@ -113,7 +113,7 @@ int main (int argc, char **argv)
r = 1;
goto clean;
}
- fp = fopen(argv[1], "rb");
+ fp = file_open(argv[1], "rb");
if (! fp) {
e = errno;
err_write_1("ikc3: ");
diff --git a/kc3s/kc3s.c b/kc3s/kc3s.c
index aea9fbd..92f59ec 100644
--- a/kc3s/kc3s.c
+++ b/kc3s/kc3s.c
@@ -69,16 +69,20 @@ sw kc3s_run (void)
tag_clean(&input);
continue;
}
+ /*
if (buf_inspect_tag(&g_kc3_env.out, &result) < 0) {
tag_clean(&input);
tag_clean(&result);
break;
}
+ */
tag_clean(&input);
tag_clean(&result);
+ /*
buf_write_u8(&g_kc3_env.out, '\n');
if ((r = buf_flush(&g_kc3_env.out)) < 0)
break;
+ */
}
if (r < 0 ||
(r == 0 &&
diff --git a/lib/kc3/0.1/ekc3.kc3 b/lib/kc3/0.1/ekc3.kc3
index 59342b6..b9d79b9 100644
--- a/lib/kc3/0.1/ekc3.kc3
+++ b/lib/kc3/0.1/ekc3.kc3
@@ -1,6 +1,6 @@
defmodule EKC3 do
- dlopen(__DIR__ + "/libekc3.so")
+ dlopen(__DIR__ + "/ekc3/libekc3.so")
def render_file = cfn Str "ekc3_render_file" (Str)
diff --git a/libkc3/block.c b/libkc3/block.c
index 64459de..c9307c0 100644
--- a/libkc3/block.c
+++ b/libkc3/block.c
@@ -18,6 +18,7 @@
#include "buf_inspect.h"
#include "buf_parse.h"
#include "io.h"
+#include "list.h"
#include "tag.h"
void block_clean (s_block *block)
@@ -104,6 +105,29 @@ s_block * block_init_copy (s_block *block, const s_block *src)
return block;
}
+s_block * block_init_from_list (s_block *block,
+ const s_list * const *list)
+{
+ uw i;
+ const s_list *l;
+ uw len;
+ s_block tmp;
+ assert(block);
+ assert(list);
+ l = *list;
+ len = list_length(l);
+ block_init(&tmp, len);
+ i = 0;
+ while (l) {
+ if (! tag_init_copy(tmp.tag + i, &l->tag))
+ return NULL;
+ i++;
+ l = list_next(l);
+ }
+ *block = tmp;
+ return block;
+}
+
s_str * block_inspect (const s_block *x, s_str *dest)
{
s_buf buf;
diff --git a/libkc3/block.h b/libkc3/block.h
index 093623d..55a9457 100644
--- a/libkc3/block.h
+++ b/libkc3/block.h
@@ -27,6 +27,8 @@ s_block * block_init (s_block *block, uw count);
s_block * block_init_1 (s_block *block, const char *p);
s_block * block_init_cast (s_block *block, const s_tag *tag);
s_block * block_init_copy (s_block *block, const s_block *src);
+s_block * block_init_from_list (s_block *block,
+ const s_list * const *list);
void block_clean (s_block *block);
/* Constructors, call block_delete after use */
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 019a96c..f8e6d8c 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -108,9 +108,11 @@ void ** kc3_dlopen (const s_str *path, void **dest)
{
assert(path);
assert(dest);
+#if DEBUG_KC3_DLOPEN
err_write_1("kc3_dlopen: ");
err_inspect_str(path);
err_write_1("\n");
+#endif
*dest = dlopen(path->ptr.pchar, RTLD_GLOBAL);
if (! *dest) {
err_write_1("kc3_dlopen: ");
diff --git a/libkc3/kc3.h b/libkc3/kc3.h
index 0d6242e..07cc81e 100644
--- a/libkc3/kc3.h
+++ b/libkc3/kc3.h
@@ -16,6 +16,7 @@
#include "arg.h"
#include "array.h"
#include "assert.h"
+#include "block.h"
#include "bool.h"
#include "buf.h"
#include "buf_file.h"