added delete command

master
bx 2022-04-02 16:28:26 +00:00
parent 054e0b02e8
commit 0ebcdc3ad5
4 changed files with 20 additions and 6 deletions

12
c_delete.c 100644
View File

@ -0,0 +1,12 @@
void
c_delete(char *c) {
Row *line = b_getline(buffer, atoi(c + 2));
Row *prev_line = b_getline(buffer, atoi(c + 2) - 1);
if (line == NULL || prev_line == NULL) {puts ("invalid line"); return; }
prev_line->n = line->n;
line->n->p = prev_line;
free(line);
}

View File

@ -1,17 +1,15 @@
void (*commands[256])(char *) = { void (*commands[256])(char *) = {
NULL, NULL,
['q'] = c_quit,
['O'] = c_open, ['O'] = c_open,
['P'] = c_print,
['w'] = c_writeline, ['w'] = c_writeline,
['q'] = NULL,
['Q'] = c_quit, ['Q'] = c_quit,
['S'] = c_save, ['S'] = c_save,
['i'] = c_insertline, ['i'] = c_insertline,
['p'] = NULL,
['p'] = c_print, ['p'] = c_print,
['P'] = NULL,
[']'] = c_indent,
['['] = c_unindent, ['['] = c_unindent,
[']'] = c_indent,
['d'] = c_delete,

2
efn.c
View File

@ -23,4 +23,6 @@
#include "c_save.c" #include "c_save.c"
#include "c_insertline.c" #include "c_insertline.c"
#include "c_indent.c" #include "c_indent.c"
#include "c_delete.c"

2
efn.h
View File

@ -16,5 +16,7 @@ void c_save(char*);
void c_insertline(char *); void c_insertline(char *);
void c_indent(char *); void c_indent(char *);
void c_unindent(char *); void c_unindent(char *);
void c_delete(char *);