From 3d30c8499ae37ca0ff837e9deaad359de0297765 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 18 Feb 2026 23:23:44 +0100 Subject: Rename all identifiers to strict Linux snake_case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Types PascalCase→snake_case, functions camelCase→snake_case, static functions get _s_ prefix, globals get g_ prefix, struct members and locals to snake_case. --- src/config.c | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 258d167..5f4d67a 100644 --- a/src/config.c +++ b/src/config.c @@ -29,7 +29,7 @@ * whitespace. */ static char * -trim (char *s) +_s_trim (char *s) { while (*s == ' ' || *s == '\t') s++; @@ -48,12 +48,13 @@ trim (char *s) * @return 0 on success, -1 on allocation failure. */ static int -configAppend (Config *cfg, const char *key, const char *value) +_s_config_append (config *cfg, const char *key, const char *value) { if (cfg->count == cfg->capacity) { - size_t newCap = cfg->capacity * 2; - ConfigEntry *tmp = realloc (cfg->entries, newCap * sizeof (ConfigEntry)); + size_t new_cap = cfg->capacity * 2; + config_entry *tmp + = realloc (cfg->entries, new_cap * sizeof (config_entry)); if (!tmp) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, @@ -61,7 +62,7 @@ configAppend (Config *cfg, const char *key, const char *value) return -1; } cfg->entries = tmp; - cfg->capacity = newCap; + cfg->capacity = new_cap; } cfg->entries[cfg->count].key = strdup (key); @@ -83,11 +84,11 @@ configAppend (Config *cfg, const char *key, const char *value) * ======================================================================== */ int -configLoad (const char *path, Config *cfg) +config_load (const char *path, config *cfg) { - memset (cfg, 0, sizeof (Config)); + memset (cfg, 0, sizeof (config)); - cfg->entries = malloc (CONFIG_INITIAL_CAPACITY * sizeof (ConfigEntry)); + cfg->entries = malloc (CONFIG_INITIAL_CAPACITY * sizeof (config_entry)); if (!cfg->entries) { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, @@ -102,16 +103,16 @@ configLoad (const char *path, Config *cfg) UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Config: cannot open '%s'", path); free (cfg->entries); - memset (cfg, 0, sizeof (Config)); + memset (cfg, 0, sizeof (config)); return -1; } char line[CONFIG_LINE_MAX]; - int lineNum = 0; + int line_num = 0; while (fgets (line, sizeof (line), fp)) { - lineNum++; + line_num++; /* Strip trailing newline / carriage return. */ size_t len = strlen (line); @@ -119,7 +120,7 @@ configLoad (const char *path, Config *cfg) line[--len] = '\0'; /* Skip blank lines and comments. */ - char *trimmed = trim (line); + char *trimmed = _s_trim (line); if (*trimmed == '\0' || *trimmed == '#') continue; @@ -130,29 +131,29 @@ configLoad (const char *path, Config *cfg) UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Config: syntax error at %s:%d " "(missing '=')", - path, lineNum); + path, line_num); fclose (fp); - configFree (cfg); + config_free (cfg); return -1; } *eq = '\0'; - char *key = trim (trimmed); - char *value = trim (eq + 1); + char *key = _s_trim (trimmed); + char *value = _s_trim (eq + 1); if (*key == '\0') { UA_LOG_ERROR (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, - "Config: empty key at %s:%d", path, lineNum); + "Config: empty key at %s:%d", path, line_num); fclose (fp); - configFree (cfg); + config_free (cfg); return -1; } - if (configAppend (cfg, key, value) != 0) + if (_s_config_append (cfg, key, value) != 0) { fclose (fp); - configFree (cfg); + config_free (cfg); return -1; } } @@ -162,7 +163,7 @@ configLoad (const char *path, Config *cfg) } const char * -configGet (const Config *cfg, const char *key) +config_get (const config *cfg, const char *key) { for (size_t i = 0; i < cfg->count; i++) { @@ -173,9 +174,9 @@ configGet (const Config *cfg, const char *key) } const char * -configRequire (const Config *cfg, const char *key, const char *program) +config_require (const config *cfg, const char *key, const char *program) { - const char *val = configGet (cfg, key); + const char *val = config_get (cfg, key); if (!val) UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "%s: missing required config key '%s'", program, key); @@ -183,9 +184,9 @@ configRequire (const Config *cfg, const char *key, const char *program) } int -configRequireInt (const Config *cfg, const char *key, const char *program) +config_require_int (const config *cfg, const char *key, const char *program) { - const char *val = configRequire (cfg, key, program); + const char *val = config_require (cfg, key, program); if (!val) return -1; @@ -202,7 +203,7 @@ configRequireInt (const Config *cfg, const char *key, const char *program) } void -configFree (Config *cfg) +config_free (config *cfg) { for (size_t i = 0; i < cfg->count; i++) { @@ -210,5 +211,5 @@ configFree (Config *cfg) free (cfg->entries[i].value); } free (cfg->entries); - memset (cfg, 0, sizeof (Config)); + memset (cfg, 0, sizeof (config)); } -- cgit v1.2.3