can now writelines

master
bx 2022-04-02 13:51:43 +00:00
parent a9118be5b1
commit c839aa9e61
5 changed files with 33 additions and 0 deletions

8
b_getline.c 100644
View File

@ -0,0 +1,8 @@
Row *
b_getline(Row *r, int l) {
if (l == 1) return r;
if (r->n == NULL) return NULL;
return b_getline(r->n, l - 1);
}

19
c_writeline.c 100644
View File

@ -0,0 +1,19 @@
void
c_writeline(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;
}
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

@ -3,3 +3,4 @@ NULL,
['q'] = c_quit,
['O'] = c_open,
['P'] = c_print,
['w'] = c_writeline,

3
efn.c
View File

@ -17,3 +17,6 @@
#include "b_truncate.c"
#include "c_print.c"
#include "b_insert.c"
#include "c_writeline.c"
#include "b_getline.c"

2
efn.h
View File

@ -10,3 +10,5 @@ void c_open(char *);
void b_truncate(Row *);
void c_print(char *);
Row *b_insert(Row *);
Row *b_getline(Row *, int);
void c_writeline(char *);