commit 7d182ecb46ac967d16633dfaafb1909e30dcb91c parent 353e8f211d5e6cc1afab847120b2b20ca626197b Author: phoebos <ben@bvnf.space> Date: Fri, 24 Sep 2021 00:16:11 +0100 ed: add 'd' Diffstat:
M | ed.c | | | 25 | +++++++++++++++++++++++-- |
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/ed.c b/ed.c @@ -187,6 +187,17 @@ input_fail: } int +delete_line(int lineno) { + struct line *l = find_line(lineno); + if (l == NULL) + return 1; + l->prev->next = l->next; + l->next->prev = l->prev; + free(l); + return 0; +} + +int ed(char *startfile) { if (startfile) if (read_buf(startfile) != 0) @@ -235,16 +246,26 @@ ed(char *startfile) { cur_line = num_lines; break; case 'i': - if (input(cur_line) != 0) + if (input(cur_line) != 0) { + printf("?\n"); continue; + } break; case 'a': - if (input(cur_line+1) != 0) + if (input(cur_line+1) != 0) { + printf("?\n"); continue; + } break; case 'p': printf("%s", find_line(cur_line)->s); break; + case 'd': + if (delete_line(cur_line) != 0) { + printf("?\n"); + continue; + } + break; case 'w': if (startfile) { if (write_buf(startfile) != 0)