add: help

This commit is contained in:
starnakin 2023-07-26 18:49:48 +02:00
parent 31f89f44ec
commit 6c9f86a88c
6 changed files with 34 additions and 20 deletions

View File

@ -1,4 +1,4 @@
cmd_add(text, args) cmd_add(data, args)
{ {
local line; local line;
local i, j; local i, j;
@ -6,19 +6,19 @@ cmd_add(text, args)
loop loop
{ {
line = geadline("(add)"); line = get_input(data, "(add)", NULL);
if (line == NULL) if (line == NULL)
return 1; return 1;
if (strcmp(line, ".") == 0) if (strcmp(line, ".") == 0)
return 0; return 0;
tmp = galloc([text + LOCATION_LENGTH] + 1); tmp = galloc([data + LOCATION_LENGTH] + 1);
if (tmp == NULL) if (tmp == NULL)
return 1; return 1;
i = 0; i = 0;
j = 0; j = 0;
loop loop
{ {
if (i == [text + LOCATION_CURRENT_LINE] + 1 | i == [text + LOCATION_LENGTH]) if (i == [data + LOCATION_CURRENT_LINE] + 1 | i == [data + LOCATION_LENGTH])
{ {
[tmp + i] = galloc(MAP_SIZE); [tmp + i] = galloc(MAP_SIZE);
if ([tmp + i] == NULL) if ([tmp + i] == NULL)
@ -27,14 +27,14 @@ cmd_add(text, args)
[[tmp + i] + MAP_VALUE] = line; [[tmp + i] + MAP_VALUE] = line;
j++; j++;
} }
[tmp + i + j] = [[text + LOCATION_ARRAY] + i]; [tmp + i + j] = [[data + LOCATION_ARRAY] + i];
if (i + j == [text + LOCATION_LENGTH] | i == [text + LOCATION_LENGTH]) if (i + j == [data + LOCATION_LENGTH] | i == [data + LOCATION_LENGTH])
break; break;
i++; i++;
} }
free([text + LOCATION_ARRAY]); free([data + LOCATION_ARRAY]);
[text + LOCATION_ARRAY] = tmp; [data + LOCATION_ARRAY] = tmp;
[text + LOCATION_LENGTH] = [text + LOCATION_LENGTH] + 1; [data + LOCATION_LENGTH] = [data + LOCATION_LENGTH] + 1;
[text + LOCATION_CURRENT_LINE] = [text + LOCATION_CURRENT_LINE] + 1; [data + LOCATION_CURRENT_LINE] = [data + LOCATION_CURRENT_LINE] + 1;
} }
} }

4
src/commands/help.🗿 Normal file
View File

@ -0,0 +1,4 @@
cmd_help(data, args)
{
[data + LOCATION_MODE] = [data + LOCATION_MODE] == 0;
}

View File

@ -1,12 +1,12 @@
cmd_numbered(text, args) cmd_numbered(data, args)
{ {
if ([text + LOCATION_LENGTH] == 0) if ([data + LOCATION_LENGTH] == 0)
{ {
putstr("Empty buffer\n"); error(data ,"Empty buffer\n");
return 1; return 1;
} }
putnum([text + LOCATION_CURRENT_LINE] + 1); putnum([data + LOCATION_CURRENT_LINE] + 1);
putchar('\t'); putchar('\t');
putstr([[[text + LOCATION_ARRAY] + [text + LOCATION_CURRENT_LINE]] + MAP_VALUE]); putstr([[[data + LOCATION_ARRAY] + [data + LOCATION_CURRENT_LINE]] + MAP_VALUE]);
putchar('\n'); putchar('\n');
} }

View File

@ -1,10 +1,10 @@
cmd_print(text, args) cmd_print(data, args)
{ {
if ([text + LOCATION_LENGTH] == 0) if ([data + LOCATION_LENGTH] == 0)
{ {
putstr("Empty buffer\n"); error(data, "Empty buffer\n");
return 1; return 1;
} }
putstr([[[text + LOCATION_ARRAY] + [text + LOCATION_CURRENT_LINE]] + MAP_VALUE]); putstr([[[data + LOCATION_ARRAY] + [data + LOCATION_CURRENT_LINE]] + MAP_VALUE]);
putchar('\n'); putchar('\n');
} }

View File

@ -8,7 +8,7 @@ parsing(data, cmd_ptr)
local tmp; local tmp;
local line_application; local line_application;
input = geadline("(default)"); input = get_input(data, "(default)", NULL);
if (input == NULL) if (input == NULL)
return 1; return 1;
if (strcmp(input, ".") == 0) if (strcmp(input, ".") == 0)
@ -87,6 +87,8 @@ main()
cmd_numbered(data, NULL); cmd_numbered(data, NULL);
else if (strcmp(cmd, "d") == 0) else if (strcmp(cmd, "d") == 0)
cmd_delete(data, NULL); cmd_delete(data, NULL);
else if (strcmp(cmd, "h") == 0)
cmd_help(data, NULL);
else else
error(data, "cmd not foud"); error(data, "cmd not foud");
free(cmd); free(cmd);

View File

@ -22,3 +22,11 @@ error(data, description)
else else
putstr("?\n"); putstr("?\n");
} }
get_input(data, description, buffer)
{
if ([data + LOCATION_MODE] == MODE_PRINT)
return geadline2(description, buffer);
else
return geadline2("", buffer);
}