From 85ab7c292a99856e21f9cad1b8e36b220db17ca6 Mon Sep 17 00:00:00 2001 From: starnakin Date: Mon, 24 Jul 2023 04:05:26 +0200 Subject: [PATCH] add: base with add function --- lib/IronGolem | 2 +- run.sh | 2 +- src/commands/add.🗿 | 26 ++++++++++++++++++++++++++ src/main.🗿 | 24 ++++++++++++++++++++++++ src/utils.🗿 | 13 +++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/commands/add.🗿 create mode 100644 src/utils.🗿 diff --git a/lib/IronGolem b/lib/IronGolem index 357da75..a39e4a7 160000 --- a/lib/IronGolem +++ b/lib/IronGolem @@ -1 +1 @@ -Subproject commit 357da752fc9495912749f0bff148791cd162e66c +Subproject commit a39e4a780d4e8e0344a05577d27a5a1af9956514 diff --git a/run.sh b/run.sh index d8bdcb9..c42b4e4 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ cd lib/IronGolem/ ./run.sh cd $OLDPWD -cat lib/IronGolem/tmp.🗿 src/*.🗿 > tmp.🗿 +cat lib/IronGolem/IronGolem.🗿 src/*/*.🗿 src/*.🗿 > tmp.🗿 golemc tmp.🗿 >tmp.asm orgaasm tmp.asm tmp.rom orgaemu tmp.rom diff --git a/src/commands/add.🗿 b/src/commands/add.🗿 new file mode 100644 index 0000000..803ef5d --- /dev/null +++ b/src/commands/add.🗿 @@ -0,0 +1,26 @@ +cmd_add(text_ptr, line_pos) +{ + local line; + local tmp; + local out; + local len; + local cursor_pos; + + tmp = NULL; + loop + { + line = geadline("(add)"); + if (line == NULL | strcmp(line, ".\n") == 0) + break; + tmp = realloc(tmp, strlen(line) + strlen(tmp) + 1); + if (tmp == NULL) + return 1; + strcat(tmp, line); + } + cursor_pos = line_pos_to_cursor_pos([text_ptr], line_pos); + dbg cursor_pos; + out = replace([text_ptr], tmp, cursor_pos, cursor_pos); + free([text_ptr]); + [text_ptr] = out; + return 0; +} diff --git a/src/main.🗿 b/src/main.🗿 index e69de29..b43451a 100644 --- a/src/main.🗿 +++ b/src/main.🗿 @@ -0,0 +1,24 @@ +define BUFFER_SIZE=1000; + +main() +{ + local text; + local line_pos; + local line; + local cmd; + + line_pos = 0; + text = strdup(""); + if (text == NULL) + return 1; + cmd = 0; + loop + { + line = geadline("(default)"); + if (line == NULL) + return; + if (strcmp(line, "a\n") == 0) + cmd_add(&text, line_pos); + putstr(text); + } +} diff --git a/src/utils.🗿 b/src/utils.🗿 new file mode 100644 index 0000000..fa617e8 --- /dev/null +++ b/src/utils.🗿 @@ -0,0 +1,13 @@ +line_pos_to_cursor_pos(text, line_pos) +{ + local ptr = text; + loop + { + if (line_pos == 0) + return ptr - text; + ptr = strchr(ptr, '\n'); + if (ptr == NULL) + return 0; + line_pos--; + } +}