From f57f335603a13c70168b1f46332a8827c32477b2 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Wed, 30 Jul 2025 14:01:59 +0530 Subject: msg: get output directory from getopt --- src/copy.c | 2 +- src/main.c | 8 ++++---- src/msg.c | 10 +++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/copy.c b/src/copy.c index 9a2816c..e5053bd 100644 --- a/src/copy.c +++ b/src/copy.c @@ -42,7 +42,7 @@ copy_recursively(const char *fpath, const char *path = fpath + strlen(msg->base_directory) + 1; char *output_path = NULL; - asprintf(&output_path, "%s/%s", OUTPUT, path); + asprintf(&output_path, "%s/%s", msg->output_directory, path); if (typeflag == FTW_D) goto exit; diff --git a/src/main.c b/src/main.c index 2977ceb..bfe7473 100644 --- a/src/main.c +++ b/src/main.c @@ -39,11 +39,13 @@ main(int argc, char **argv) { int opt; msg = malloc(sizeof(msg_t)); + msg->base_directory = "."; + msg->output_directory = "dist"; while ((opt = getopt(argc, argv, "o:h")) != -1) { switch (opt) { case 'o': - /* msg.output_directory = optarg; */ + msg->output_directory = optarg; break; case 'h': default: @@ -52,9 +54,7 @@ main(int argc, char **argv) } } - if (optind == argc) - msg->base_directory = "."; - else + if (optind < argc) msg->base_directory = argv[optind]; int r = run(); diff --git a/src/msg.c b/src/msg.c index fc385b8..5e6092e 100644 --- a/src/msg.c +++ b/src/msg.c @@ -49,9 +49,13 @@ handle_file(const char *path) char *dot = strrchr(inpath, '.'); if (dot && strcmp(dot, ".md") == 0) { - asprintf(&outpath, "%s/%.*s.html", OUTPUT, (int) strlen(path) - 3, path); + asprintf(&outpath, + "%s/%.*s.html", + msg->output_directory, + (int) strlen(path) - 3, + path); } else { - asprintf(&outpath, "%s/%s", OUTPUT, path); + asprintf(&outpath, "%s/%s", msg->output_directory, path); } char *temp_outpath = strdup(outpath); @@ -118,7 +122,7 @@ run(void) base_template = template_create(); - int err = mkdir(OUTPUT, 0700); + int err = mkdir(msg->output_directory, 0700); if (err != 0 && errno != EEXIST) { perror("mkdir"); return EXIT_FAILURE; -- cgit v1.2.3