add: work

This commit is contained in:
2023-07-24 10:15:29 +02:00
parent 85ab7c292a
commit 731da51b61
5 changed files with 101 additions and 31 deletions

View File

@ -1,24 +1,77 @@
define BUFFER_SIZE=1000;
define LOCATION_LENGTH = 0;
define LOCATION_CURRENT_LINE = 1;
define LOCATION_ARRAY = 2;
parsing(text, cmd_ptr)
{
local input;
local tmp;
local line_application;
input = geadline("(default)");
if (input == NULL)
return 1;
[input + strlen(input) - 1] = 0;
if (isdigit([input]) == 1)
{
line_application = aton(input);
if (line_application >= [text + LOCATION_LENGTH])
{
[cmd_ptr] = NULL;
putstr("invalid line\n");
free(input);
return 0;
}
[text + LOCATION_CURRENT_LINE] = line_application;
}
tmp = input;
loop
{
if (isdigit([tmp]) == 0)
break;
tmp++;
}
if (strcmp(tmp, "") == 0)
[cmd_ptr] = strdup("p");
else
[cmd_ptr] = strdup(input);
free(input);
if ([cmd_ptr] == NULL)
return 1;
}
main()
{
local text;
local line_pos;
local line;
local array;
local cmd;
line_pos = 0;
text = strdup("");
text = galloc(3);
if (text == NULL)
return 1;
cmd = 0;
[text + LOCATION_CURRENT_LINE] = 0;
[text + LOCATION_LENGTH] = 0;
array = [text + LOCATION_ARRAY];
[array] = galloc(1);
if ([array] == NULL)
{
free(text);
return 1;
}
[[array]] = NULL;
loop
{
line = geadline("(default)");
if (line == NULL)
return;
if (strcmp(line, "a\n") == 0)
cmd_add(&text, line_pos);
putstr(text);
if (parsing(text, &cmd))
return 1;
if (cmd != NULL)
{
dbg [text + LOCATION_CURRENT_LINE];
if (strcmp(cmd, "a") == 0)
cmd_add(text);
else if (strcmp(cmd, "p") == 0)
cmd_print(text);
free(cmd);
}
}
}