From 9643e3cb444ee26088be4636ba2b753ac0166156 Mon Sep 17 00:00:00 2001 From: Erik K Date: Tue, 24 May 2022 09:36:31 +0000 Subject: added touch command --- sm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sm.c b/sm.c index 3ab7726..59e286e 100644 --- a/sm.c +++ b/sm.c @@ -379,6 +379,19 @@ list(const char *filename) } } +static int +touch(const char *filename) +{ + Document *d; + + if ((d = dbfind(filename)) == NULL) { + fprintf(stderr, "%s: no such file\n", filename); + return 0; + } + d->creat = d->mod = time(NULL); + return 1; +} + static int unset(const char *filename, const char *plname) { @@ -469,6 +482,9 @@ editcmd: } else if (!strcmp(cmd.argv[0], "rm")) { if (dbdel(cmd.argv[1])) dbwrite(kdbloc); + } else if (!strcmp(cmd.argv[0], "touch")) { + if (touch(cmd.argv[1])) + dbwrite(kdbloc); } else if (cmd.argc < 3) { fprintf(stderr, "invalid command/needs more parameters\n"); } else if (!strcmp(cmd.argv[0], "set")) { -- cgit v1.2.3