diff options
-rw-r--r-- | notemap.c | 28 |
1 files 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 <err.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <sysexits.h> +#include <unistd.h> 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); + } } |