From 9f174157a10a3c5bc3ccc9b53c6fd3f34682f672 Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Fri, 27 Sep 2024 09:28:21 +0200 Subject: [PATCH 1/2] Rename `tok` variable to `delim` `delim` reflects the purpose of that variable. --- swege.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/swege.c b/swege.c index 2e1be18..8454b4e 100644 --- a/swege.c +++ b/swege.c @@ -503,33 +503,33 @@ int read_config(const char *path) { char buf[BUF_CONF]; /* To read config lines into, for fgets(). */ - char *tok; /* To keep track of the delimiter, for strtok(). */ + char *delim; /* To keep track of the delimiter, for strtok(). */ FILE *config_fp; config_fp = fopen(path, "r"); if (!config_fp) PrintErr(path); while (fgets(buf, BUF_CONF, config_fp)) { - tok = strtok(buf, CFGDLIM); - if (!strcmp("title", tok)) { + delim = strtok(buf, CFGDLIM); + if (!strcmp("title", delim)) { config.site_title = strdup(strtok(NULL, CFGDLIM "\n")); continue; } - if (!strcmp("source", tok)) { + if (!strcmp("source", delim)) { config.src_dir = strdup(strtok(NULL, CFGDLIM "\n")); continue; } - if (!strcmp("destination", tok)) { + if (!strcmp("destination", delim)) { config.dst_dir = strdup(strtok(NULL, CFGDLIM "\n")); continue; } - if (!strcmp("header", tok)) { + if (!strcmp("header", delim)) { config.header_file = strdup(strtok(NULL, CFGDLIM "\n")); continue; } - if (!strcmp("footer", tok)) { + if (!strcmp("footer", delim)) { config.footer_file = strdup(strtok(NULL, CFGDLIM "\n")); continue; From f4695cd826dcaab38f19a413c4c213645160ae8e Mon Sep 17 00:00:00 2001 From: Ivan Kovmir Date: Fri, 27 Sep 2024 09:30:45 +0200 Subject: [PATCH 2/2] Rename macros to match the overall codestyle Look at: define BUF_SIZE 1048 define BUF_CONF 128 define TITLE_SIZE 50 --- swege.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/swege.c b/swege.c index 8454b4e..792b5e1 100644 --- a/swege.c +++ b/swege.c @@ -51,12 +51,12 @@ #define MANIFESTF ".manifest" -#define CFGFILE "swege.cfg" /* Config file name. */ -#define CFGDLIM ":" /* Config file option-value delimiter. */ +#define CFG_FILE "swege.cfg" /* Config file name. */ +#define CFG_DELIM ":" /* Config file option-value delimiter. */ #define FORCE_UPDATE \ (file_is_newer(config.footer_file) || file_is_newer(config.header_file) || \ - file_is_newer(CFGFILE)) + file_is_newer(CFG_FILE)) #define PrintErr(path) \ do { \ @@ -510,28 +510,28 @@ read_config(const char *path) PrintErr(path); while (fgets(buf, BUF_CONF, config_fp)) { - delim = strtok(buf, CFGDLIM); + delim = strtok(buf, CFG_DELIM); if (!strcmp("title", delim)) { config.site_title = - strdup(strtok(NULL, CFGDLIM "\n")); + strdup(strtok(NULL, CFG_DELIM "\n")); continue; } if (!strcmp("source", delim)) { - config.src_dir = strdup(strtok(NULL, CFGDLIM "\n")); + config.src_dir = strdup(strtok(NULL, CFG_DELIM "\n")); continue; } if (!strcmp("destination", delim)) { - config.dst_dir = strdup(strtok(NULL, CFGDLIM "\n")); + config.dst_dir = strdup(strtok(NULL, CFG_DELIM "\n")); continue; } if (!strcmp("header", delim)) { config.header_file = - strdup(strtok(NULL, CFGDLIM "\n")); + strdup(strtok(NULL, CFG_DELIM "\n")); continue; } if (!strcmp("footer", delim)) { config.footer_file = - strdup(strtok(NULL, CFGDLIM "\n")); + strdup(strtok(NULL, CFG_DELIM "\n")); continue; } /* Ignore unknown entries. */ @@ -568,8 +568,8 @@ main(int argc, char *argv[]) usage(); } - if (!read_config(CFGFILE)) { - printf("Invalid " CFGFILE "\n"); + if (!read_config(CFG_FILE)) { + printf("Invalid " CFG_FILE "\n"); return 1; }