commit 8375d76ba651551481a377643db178c5da61b136
parent 693d6207f0e9d6629848a6a954ab11e89f524e0a
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Thu, 5 Aug 2021 17:45:48 +0000
implement remove command
Diffstat:
3 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/fs.c b/fs.c
@@ -17,25 +17,28 @@ ctlcmd(char *buf)
char *args[256];
n = tokenize(buf, args, 256);
if (n <= 0) return "expected a command";
- if (strcmp(args[0], "test") == 0) return "test!";
- if (strcmp(args[0], "clear") == 0) {
- int i;
- Object *obj;
- for (i = 0; i < rich.count; i++) {
- obj = rich.obj + i;
- removefile(obj->ftext);
- removefile(obj->ffont);
- removefile(obj->flink);
- removefile(obj->fimage);
- removefile(obj->dir);
+ if (strcmp(args[0], "remove") == 0) {
+ int i, j;
+ for (i = 0; i < n; i++) {
+ for (j = 0; j < rich.count; j++) {
+ if (strcmp(rich.obj[j].id, args[i]) == 0) {
+ Object *sp, *tp;
+ rmobjectftree(&rich.obj[j]);
+ sp = &rich.obj[j];
+ tp = &rich.obj[j+1];
+ memcpy(sp, tp, (rich.count - j - 1) * sizeof(Object));
+ rich.count--;
+ break;
+ }
+ }
}
-
+ } else if (strcmp(args[0], "clear") == 0) {
+ for (rich.count--; rich.count >= 0; rich.count--)
+ rmobjectftree(rich.obj + rich.count);
rich.count = 0;
rich.obj = realloc(rich.obj, 0);
-
- return nil;
- }
- return "not implemented";
+ } else return "unknown command";
+ return nil;
}
void
diff --git a/richterm.c b/richterm.c
@@ -436,6 +436,16 @@ mkobjectftree(Object *obj, File *root, char *text)
}
void
+rmobjectftree(Object *obj)
+{
+ removefile(obj->ftext);
+ removefile(obj->ffont);
+ removefile(obj->flink);
+ removefile(obj->fimage);
+ removefile(obj->dir);
+}
+
+void
redraw(int regen)
{
if (regen != 0) generatepage(&rich);
diff --git a/richterm.h b/richterm.h
@@ -20,6 +20,7 @@ struct Object {
};
Object * mkobjectftree(Object *, File *, char *);
+void rmobjectftree(Object *);
typedef struct Fonts Fonts;