added instert line command

master
bx 2022-04-02 15:05:07 +00:00
parent 64be24496e
commit 9b230368c2
4 changed files with 25 additions and 0 deletions

22
c_insertline.c 100644
View File

@ -0,0 +1,22 @@
void
c_insertline(char *c) {
c += 2;
int line = atoi(c);
for(; *c != 0 && *c != ' '; c++);
c += 1; // start of text
Row *r = b_getline(buffer, line);
if (r == NULL) {
printf("%i, invalid line.\n", line);
return;
}
// ^ same as write line
r = b_insert(r);
// v same as write line
int i = 0;
for (;i < ROW_SIZE && c[i] != 0; i++) {
r->text[i] = c[i];
}
for(;i < ROW_SIZE; i++) {
r->text[i] = 0;
}
}

View File

@ -7,3 +7,4 @@ NULL,
['q'] = NULL,
['Q'] = c_quit,
['S'] = c_save,
['i'] = c_insertline,

1
efn.c
View File

@ -21,3 +21,4 @@
#include "b_getline.c"
#include "c_save.c"
#include "c_insertline.c"

1
efn.h
View File

@ -13,3 +13,4 @@ Row *b_insert(Row *);
Row *b_getline(Row *, int);
void c_writeline(char *);
void c_save(char*);
void c_insertline(char *);