summaryrefslogtreecommitdiffstats
path: root/sm.c
diff options
context:
space:
mode:
authorErik K <erikk@previousplan.org>2022-05-14 20:49:17 +0000
committerErik K <erikk@previousplan.org>2022-05-14 20:49:17 +0000
commitcf2ff5f763dd9ebdf38f76761bcc41a4990fc156 (patch)
treebe54bdf53d4b7744c3df5ab38013d6763e21d6d4 /sm.c
parentb2fada1dd19211d71e04557653d08e697134a6ce (diff)
added unset command
Diffstat (limited to 'sm.c')
-rw-r--r--sm.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/sm.c b/sm.c
index d4064c7..6358086 100644
--- a/sm.c
+++ b/sm.c
@@ -37,6 +37,7 @@ static int pladddoc(const char *, Document *);
static int add(const char *);
static int edit(const char *);
static void list(const char *);
+static int unset(const char *, const char *);
static Document **docdb;
static int ndocdb;
@@ -93,6 +94,7 @@ dbdel(const char *filename)
plugins[i]->usedby = xrealloc(plugins[i]->usedby,
--plugins[i]->nusedby *
sizeof(*plugins[i]->usedby));
+ break;
}
}
@@ -365,6 +367,35 @@ list(const char *filename)
}
}
+static int
+unset(const char *filename, const char *plname)
+{
+ Document *d;
+ int i, j;
+
+ if ((d = dbfind(filename)) == NULL) {
+ fprintf(stderr, "%s: no such file\n", filename);
+ return 0;
+ }
+ for (i = 0; i < NPLUGINS; i++) {
+ if (strcmp(plugins[i]->name, plname) != 0)
+ continue;
+ for (j = 0; j < plugins[i]->nusedby; j++) {
+ if (plugins[i]->usedby[j] != d)
+ continue;
+ if (j + 1 < plugins[i]->nusedby) {
+ memmove(&plugins[i]->usedby[j], &plugins[i]->usedby[j +
+ 1], (plugins[i]->nusedby - j - 1) *
+ sizeof(*plugins[i]->usedby));
+ }
+ plugins[i]->usedby = xrealloc(plugins[i]->usedby,
+ --plugins[i]->nusedby *
+ sizeof(*plugins[i]->usedby));
+ return 1;
+ }
+ }
+ return 0;
+}
int
@@ -435,6 +466,9 @@ editcmd:
}
if (pladddoc(cmd.argv[2], d))
dbwrite(kdbloc);
+ } else if (!strcmp(cmd.argv[0], "unset")) {
+ if (unset(cmd.argv[1], cmd.argv[2]))
+ dbwrite(kdbloc);
}
}
fputc('\n', stdout);