add: base with add function

This commit is contained in:
starnakin 2023-07-24 04:05:26 +02:00
parent 7c160040b3
commit 85ab7c292a
5 changed files with 65 additions and 2 deletions

@ -1 +1 @@
Subproject commit 357da752fc9495912749f0bff148791cd162e66c
Subproject commit a39e4a780d4e8e0344a05577d27a5a1af9956514

2
run.sh
View File

@ -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

26
src/commands/add.🗿 Normal file
View File

@ -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;
}

View File

@ -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);
}
}

13
src/utils.🗿 Normal file
View File

@ -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--;
}
}