From f2a908beca4087a2bf6f8b265040f09f4188af7e Mon Sep 17 00:00:00 2001 From: nishi Date: Sun, 5 May 2024 04:47:29 +0000 Subject: [PATCH] kinda works git-svn-id: file:///raid/svn-main/nishi-clover/trunk@4 cc13bd98-b292-b64a-ad22-c0789b689ca7 --- clover.c | 42 ++++++++++++++++++++++++++++++++++++++---- clover.conf | 4 ++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 clover.conf diff --git a/clover.c b/clover.c index 72bb1f8..e8307b1 100644 --- a/clover.c +++ b/clover.c @@ -1,6 +1,8 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ +/* HTML 2.0 compliant static site generator */ +/* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ /* ation, are permitted provided that the following conditions are met: */ @@ -43,6 +45,17 @@ char* concat_str(const char* str1, const char* str2) { return r; } +char* dup_str(const char* str) { + char* r = malloc(strlen(str) + 1); + memcpy(r, str, strlen(str)); + r[strlen(str)] = 0; + return r; +} + +char* input_dir; +char* output_dir; +char* title; + int parse_config(const char* path) { FILE* f = fopen(path, "r"); if(f == NULL) { @@ -66,10 +79,22 @@ int parse_config(const char* path) { break; } } - if(strcmp(str, "output") == 0) { + if(str[0] == '#') { + } else if(strcmp(str, "output") == 0) { if(found) { + free(output_dir); + output_dir = dup_str(str + i); mkdir(str + i, 0775); - chdir(str + i); + } + } else if(strcmp(str, "input") == 0) { + if(found) { + free(input_dir); + input_dir = dup_str(str + i); + } + } else if(strcmp(str, "title") == 0) { + if(found) { + free(title); + title = dup_str(str + i); } } free(str); @@ -88,9 +113,18 @@ int parse_config(const char* path) { } int main(int argc, char** argv) { + output_dir = dup_str("webroot"); + input_dir = dup_str("input"); + title = dup_str("Unnamed"); + int r; if(argv[1] == NULL) { - return parse_config("clover.conf"); + r = parse_config("clover.conf"); } else { - return parse_config(argv[1]); + r = parse_config(argv[1]); } + printf("Clover %s Copyright (c) 2024 Nishi\n", CLOVER_VERSION); + printf(" Title: %s\n", title); + printf(" Input: %s\n", input_dir); + printf("Output: %s\n", output_dir); + if(r != 0) return r; } diff --git a/clover.conf b/clover.conf new file mode 100644 index 0000000..c6d4093 --- /dev/null +++ b/clover.conf @@ -0,0 +1,4 @@ +#comment +title Example +output webroot +input example -- 2.43.0