aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-30 14:01:59 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-30 14:01:59 +0530
commitf57f335603a13c70168b1f46332a8827c32477b2 (patch)
tree06fe50976f3f72b3bcc063ec8f91156d6c08e003 /src
parent9aba370924df4c471b8527f08d2c60cacb8989d9 (diff)
msg: get output directory from getopt
Diffstat (limited to 'src')
-rw-r--r--src/copy.c2
-rw-r--r--src/main.c8
-rw-r--r--src/msg.c10
3 files changed, 12 insertions, 8 deletions
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;