From db17119022081cd0b64a5721a7ca269d02d0eef4 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 26 Jan 2020 11:30:53 -0500 Subject: Implement -a --- notemap.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/notemap.c b/notemap.c index 7d06205..fbb6e8d 100644 --- a/notemap.c +++ b/notemap.c @@ -15,9 +15,11 @@ */ #include +#include #include #include #include +#include typedef unsigned char byte; @@ -41,6 +43,28 @@ static const char *uuidGen(void) { return str; } -int main(void) { - printf("%s\n", uuidGen()); +int main(int argc, char *argv[]) { + const char *path = ".notemap"; + bool add = false; + + int opt; + while (0 < (opt = getopt(argc, argv, "am:"))) { + switch (opt) { + break; case 'a': add = true; + break; case 'm': path = optarg; + break; default: return EX_USAGE; + } + } + + if (add) { + FILE *map = fopen(path, "a"); + if (!map) err(EX_CANTCREAT, "%s", path); + for (int i = optind; i < argc; ++i) { + if (access(argv[i], R_OK)) err(EX_NOINPUT, "%s", argv[i]); + fprintf(map, "%s %s\n", uuidGen(), argv[i]); + if (ferror(map)) err(EX_IOERR, "%s", path); + } + int error = fclose(map); + if (error) err(EX_IOERR, "%s", path); + } } -- cgit 1.4.1