diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 02:02:45 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-07 02:02:45 +0300 |
commit | e3a41da5a0a3d70ac53591f2b66144f2be2b3871 (patch) | |
tree | 789cc69b05f2447c11f04dbb6ae972ffa0acd1c9 /src/revela.c | |
download | revela-e3a41da5a0a3d70ac53591f2b66144f2be2b3871.tar.gz revela-e3a41da5a0a3d70ac53591f2b66144f2be2b3871.zip |
Initial commit.
Almost functional but still missing features and lacking testing.
Diffstat (limited to 'src/revela.c')
-rw-r--r-- | src/revela.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/revela.c b/src/revela.c new file mode 100644 index 0000000..89a7a7a --- /dev/null +++ b/src/revela.c @@ -0,0 +1,74 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <dirent.h> + +#include "fs.h" +#include "log.h" +#include "site.h" +#include "config.h" +#include "bstree.h" +#include "template.h" + +static const char *usage = + "Usage: %s [options] [-i <input dir>] -o <output dir>\n"; + +static struct site site = {0}; +static enum log_level loglvl = LOG_DETAIL; + +static void +bad_arguments(const char *cmd) +{ + fprintf(stderr, usage, cmd); + exit(1); +} + +static void +parse_arguments(int argc, char *argv[]) +{ + int opt; + char *cmd = argv[0]; + while ((opt = getopt(argc, argv, "i:o:n")) != -1) { + switch (opt) { + case 'i': + site.root_dir = strdup(optarg); + break; + case 'o': + site.output_dir = optarg; + break; + case 'n': + site.dry_run = true; + break; + default: + bad_arguments(cmd); + } + } + if (site.output_dir == NULL) { + bad_arguments(cmd); + } +} + +int +main(int argc, char *argv[]) +{ + int ret = EXIT_SUCCESS; + + parse_arguments(argc, argv); + +#ifdef DEBUG + log_set_verbosity(LOG_DEBUG); +#else + log_set_verbosity(loglvl); +#endif + + ret = site_init(&site) && site_load(&site) && site_build(&site) + ? EXIT_SUCCESS : EXIT_FAILURE; + + if (site.dry_run) { + log_printl(LOG_INFO, "==== [DRY RUN] ===="); + } + + site_deinit(&site); + return ret; +} |