diff options
-rw-r--r-- | include/msg.h | 2 | ||||
-rw-r--r-- | src/main.c | 36 | ||||
-rw-r--r-- | src/msg.c | 12 |
3 files changed, 38 insertions, 12 deletions
diff --git a/include/msg.h b/include/msg.h index 418d9f3..300b3fb 100644 --- a/include/msg.h +++ b/include/msg.h @@ -29,6 +29,6 @@ typedef struct { char *base_directory; } msg_t; -int run(int argc, char **argv); +int run(void); #endif @@ -19,9 +19,43 @@ #define _GNU_SOURCE #include <msg.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +msg_t *msg; + +void +usage(char *program) +{ + printf("Usage: %s [-o <output>] [-h] <directory>\n", program); + printf("\t-o <output>: Output directory\n"); + printf("\t-h : Help\n"); + printf("\t<directory>: Working directory\n"); +} int main(int argc, char **argv) { - return run(argc, argv); + int opt; + msg = malloc(sizeof(msg_t)); + + while ((opt = getopt(argc, argv, "o:h")) != -1) { + switch (opt) { + case 'o': + /* msg.output_directory = optarg; */ + break; + case 'h': + default: + usage(argv[0]); + return EXIT_SUCCESS; + } + } + + msg->base_directory = "compromyse.xyz"; + + int r = run(); + + free(msg); + return r; } @@ -36,8 +36,8 @@ #include <template.h> #include <util.h> +extern msg_t *msg; template_t *base_template; -msg_t *msg; void handle_file(const char *path) @@ -108,15 +108,8 @@ handle_file(const char *path) } int -run(int argc, char **argv) +run(void) { - if (argc < 2) { - printf("Usage: %s [directory]\n", argv[0]); - return EXIT_FAILURE; - } - msg = malloc(sizeof(msg_t)); - msg->base_directory = argv[1]; - struct stat sb; if (stat(msg->base_directory, &sb) != 0 || !S_ISDIR(sb.st_mode)) { printf("%s does not exist.\n", msg->base_directory); @@ -156,6 +149,5 @@ run(int argc, char **argv) template_delete(base_template); config_delete(config); - free(msg); return EXIT_SUCCESS; } |