commit 2e5d0e9de9f3861d2bb094d20e94e5a66b70ba7f
parent 4c0c0eef7ba78a6877908cb7b2f5634eeedc30ef
Author: phoebos <ben@bvnf.space>
Date: Fri, 24 Sep 2021 01:54:52 +0100
ed: check if buffer was changed; add 'Q'
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/PROGRESS b/PROGRESS
@@ -14,7 +14,7 @@
[ ] dirname
[ ] du
[x] echo
-[ ] ed [-ps] p i a
+[ ] ed [-ps] p i a q Q
[x] false
[ ] find
[ ] grep
diff --git a/ed.c b/ed.c
@@ -199,6 +199,7 @@ delete_line(int lineno) {
int
ed(char *startfile) {
+ int changed = 0;
if (startfile)
if (read_buf(startfile) != 0)
return 1;
@@ -250,12 +251,14 @@ ed(char *startfile) {
printf("?\n");
continue;
}
+ changed = 1;
break;
case 'a':
if (input(cur_line+1) != 0) {
printf("?\n");
continue;
}
+ changed = 1;
break;
case 'p':
printf("%s", find_line(cur_line)->s);
@@ -265,6 +268,7 @@ ed(char *startfile) {
printf("?\n");
continue;
}
+ changed = 1;
break;
case 'c':
/* delete then insert */
@@ -272,6 +276,7 @@ ed(char *startfile) {
printf("?\n");
continue;
}
+ changed = 1;
if (input(cur_line) != 0) {
printf("?\n");
continue;
@@ -285,6 +290,11 @@ ed(char *startfile) {
printf("? writing to a new filename not yet implemented\n");
break;
case 'q':
+ if (changed == 0)
+ return 0;
+ printf("?\n");
+ break;
+ case 'Q':
return 0;
case '\n':
break;