core: add an id to list
This commit is contained in:
53
src/main.🗿
53
src/main.🗿
@ -1,6 +1,8 @@
|
||||
enum LOCATION_LENGTH, LOCATION_CURRENT_LINE, LOCATION_ARRAY;
|
||||
enum LOCATION_LENGTH, LOCATION_CURRENT_LINE, LOCATION_ARRAY, LOCATION_MODE;
|
||||
enum MODE_PRINT, MODE_NO_PRINT;
|
||||
define DATA_SIZE=4;
|
||||
|
||||
parsing(text, cmd_ptr)
|
||||
parsing(data, cmd_ptr)
|
||||
{
|
||||
local input;
|
||||
local tmp;
|
||||
@ -18,14 +20,14 @@ parsing(text, cmd_ptr)
|
||||
if (isdigit([input]) == 1)
|
||||
{
|
||||
line_application = aton(input);
|
||||
if (line_application == 0 | line_application >= [text + LOCATION_LENGTH] + 1)
|
||||
if (line_application == 0 | line_application >= [data + LOCATION_LENGTH] + 1)
|
||||
{
|
||||
[cmd_ptr] = NULL;
|
||||
putstr("invalid line\n");
|
||||
free(input);
|
||||
return 0;
|
||||
}
|
||||
[text + LOCATION_CURRENT_LINE] = line_application - 1;
|
||||
[data + LOCATION_CURRENT_LINE] = line_application - 1;
|
||||
}
|
||||
tmp = input;
|
||||
loop
|
||||
@ -43,43 +45,50 @@ parsing(text, cmd_ptr)
|
||||
return 1;
|
||||
}
|
||||
|
||||
global id=0;
|
||||
|
||||
main()
|
||||
{
|
||||
local text;
|
||||
local data;
|
||||
local cmd;
|
||||
|
||||
text = galloc(3);
|
||||
if (text == NULL)
|
||||
data = galloc(DATA_SIZE);
|
||||
if (data == NULL)
|
||||
return 1;
|
||||
[text + LOCATION_CURRENT_LINE] = 0 - 1;
|
||||
[text + LOCATION_LENGTH] = 0;
|
||||
[text + LOCATION_ARRAY];
|
||||
[text + LOCATION_ARRAY] = galloc(0);
|
||||
if ([text + LOCATION_ARRAY] == NULL)
|
||||
[data + LOCATION_MODE] = 0;
|
||||
[data + LOCATION_CURRENT_LINE] = 0 - 1;
|
||||
[data + LOCATION_LENGTH] = 0;
|
||||
[data + LOCATION_ARRAY];
|
||||
[data + LOCATION_ARRAY] = galloc(2);
|
||||
if ([data + LOCATION_ARRAY] == NULL)
|
||||
{
|
||||
free(text);
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
[[data + LOCATION_ARRAY] + MAP_KEY] = id++;
|
||||
[[data + LOCATION_ARRAY] + MAP_VALUE] = galloc(0);
|
||||
if ([[data + LOCATION_ARRAY] + MAP_VALUE] == NULL)
|
||||
{
|
||||
free([data + LOCATION_ARRAY]);
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
loop
|
||||
{
|
||||
if (parsing(text, &cmd))
|
||||
if (parsing(data, &cmd))
|
||||
return 1;
|
||||
if (cmd != NULL)
|
||||
{
|
||||
if (strcmp(cmd, "a") == 0)
|
||||
cmd_add(text, NULL);
|
||||
cmd_add(data, NULL);
|
||||
else if (strcmp(cmd, "p") == 0)
|
||||
cmd_print(text, NULL);
|
||||
cmd_print(data, NULL);
|
||||
else if (strcmp(cmd, "n") == 0)
|
||||
cmd_numbered(text, NULL);
|
||||
cmd_numbered(data, NULL);
|
||||
else if (strcmp(cmd, "d") == 0)
|
||||
cmd_delete(text, NULL);
|
||||
cmd_delete(data, NULL);
|
||||
else
|
||||
{
|
||||
putstr("cmd not foud");
|
||||
putchar('\n');
|
||||
}
|
||||
error(data, "cmd not foud");
|
||||
free(cmd);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user