diff options
Diffstat (limited to 'sm.c')
-rw-r--r-- | sm.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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); |