changeset 776:680324e43852

Rename a number of config parser variables etc.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 02 Jul 2023 00:43:59 +0300
parents 456235ae762e
children 484853471eaf
files th_config.c
diffstat 1 files changed, 58 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/th_config.c	Sat Jul 01 22:48:03 2023 +0300
+++ b/th_config.c	Sun Jul 02 00:43:59 2023 +0300
@@ -199,8 +199,8 @@
 
 typedef struct
 {
-    int ch, strDelim,
-        prevMode, nextMode, parseMode;
+    int ch, delim,
+        prev, next, mode;
 } th_cfgparserctx_t;
 
 /// @endcond
@@ -208,19 +208,19 @@
 
 static void th_cfg_set_parsemode(th_cfgparserctx_t *ctx, const int mode)
 {
-    ctx->prevMode = ctx->parseMode;
-    ctx->parseMode = mode;
+    ctx->prev = ctx->mode;
+    ctx->mode = mode;
 }
 
 
 static void th_cfg_set_next_parsemode(th_cfgparserctx_t *ctx, const int mode)
 {
     th_cfg_set_parsemode(ctx, PM_NEXT);
-    ctx->nextMode = mode;
+    ctx->next = mode;
 }
 
 
-#define VADDCH(ch) if (strPos < SET_CFG_MAX_PARSE_BUF) { tmpStr[strPos++] = ch; }
+#define VADDCH(ch) if (pos < SET_CFG_MAX_PARSE_BUF) { str[pos++] = ch; }
 
 
 static bool th_cfg_is_end(const int ch)
@@ -323,23 +323,23 @@
 {
     th_cfgparserctx_t ctx;
     th_cfgitem_t *item = NULL;
-    char *tmpStr = NULL;
-    size_t strPos;
-    bool isEscaped, isStart, fpSet;
+    char *str = NULL;
+    size_t pos;
+    bool escaped, start, fpseparator;
     int ret = THERR_OK;
 
     // Initialize values
     memset(&ctx, 0, sizeof(ctx));
     ctx.ch = -1;
-    ctx.nextMode = ctx.prevMode = ctx.parseMode = PM_IDLE;
-    isEscaped = fpSet = isStart = false;
-    strPos = 0;
+    ctx.next = ctx.prev = ctx.mode = PM_IDLE;
+    escaped = fpseparator = start = false;
+    pos = 0;
 
-    if ((tmpStr = th_malloc(SET_CFG_MAX_PARSE_BUF + 1)) == NULL)
+    if ((str = th_malloc(SET_CFG_MAX_PARSE_BUF + 1)) == NULL)
         goto out;
 
     // Parse the configuration
-    while (ctx.parseMode != PM_EOF && ctx.parseMode != PM_ERROR)
+    while (ctx.mode != PM_EOF && ctx.mode != PM_ERROR)
     {
         if (ctx.ch == -1)
         {
@@ -347,14 +347,14 @@
             switch (ctx.ch = thfgetc(fh))
             {
             case EOF:
-                if (ctx.parseMode != PM_IDLE)
+                if (ctx.mode != PM_IDLE)
                 {
                     ret = th_io_error(fh, THERR_OUT_OF_DATA,
                         "Unexpected end of file.");
                     goto out;
                 }
 
-                ctx.parseMode = PM_EOF;
+                ctx.mode = PM_EOF;
                 break;
 
             case '\n':
@@ -362,14 +362,14 @@
             }
         }
 
-        switch (ctx.parseMode)
+        switch (ctx.mode)
         {
         case PM_COMMENT:
             // Comment parsing mode
             if (ctx.ch == '\n')
             {
                 // End of line, end of comment
-                th_cfg_set_parsemode(&ctx, ctx.prevMode);
+                th_cfg_set_parsemode(&ctx, ctx.prev);
             }
             ctx.ch = -1;
             break;
@@ -406,7 +406,7 @@
             {
                 // Start of key name found
                 th_cfg_set_parsemode(&ctx, PM_KEYNAME);
-                strPos = 0;
+                pos = 0;
             }
             else
             {
@@ -444,15 +444,15 @@
                     goto out;
                 }
                 ctx.ch = -1;
-                tmpStr[strPos] = 0;
+                str[pos] = 0;
             }
             else
             {
                 // Error! Invalid character found
-                tmpStr[strPos] = 0;
+                str[pos] = 0;
                 ret = th_io_error(fh, THERR_INVALID_DATA,
                     "Unexpected character '%c' in key name '%s'.",
-                    ctx.ch, tmpStr);
+                    ctx.ch, str);
                 goto out;
             }
             break;
@@ -462,13 +462,13 @@
             {
                 // Find key from configuration
                 bool found;
-                tmpStr[strPos] = 0;
+                str[pos] = 0;
 
                 for (item = sect, found = false; item != NULL && !found; )
                 {
                     if (item->type != CFG_ITEM_COMMENT &&
                         item->name != NULL &&
-                        strcmp(item->name, tmpStr) == 0)
+                        strcmp(item->name, str) == 0)
                         found = true;
                     else
                         item = (th_cfgitem_t *) item->node.next;
@@ -479,16 +479,16 @@
                 {
                     // Okay, set next mode
                     th_cfg_set_next_parsemode(&ctx, th_cfg_get_parsemode(item->type));
-                    isStart = true;
-                    fpSet = false;
-                    strPos = 0;
+                    start = true;
+                    fpseparator = false;
+                    pos = 0;
                 }
                 else
                 {
                     // Error! No configuration key by this name found
                     ret = th_io_error(fh, THERR_INVALID_DATA,
                         "No such configuration setting: '%s'.",
-                        tmpStr);
+                        str);
                     goto out;
                 }
 
@@ -520,12 +520,12 @@
             else
             {
                 // Next item found
-                th_cfg_set_parsemode(&ctx, ctx.nextMode);
+                th_cfg_set_parsemode(&ctx, ctx.next);
             }
             break;
 
         case PM_LIST:
-            if (isStart)
+            if (start)
             {
                 th_cfg_set_parsemode(&ctx, PM_STRING);
             }
@@ -534,7 +534,7 @@
             {
                 th_cfg_set_next_parsemode(&ctx, PM_STRING);
                 ctx.ch = -1;
-                isStart = true;
+                start = true;
             }
             else
             {
@@ -564,27 +564,27 @@
 
         case PM_STRING:
             // String parsing mode
-            if (isStart)
+            if (start)
             {
                 // Start of string, get delimiter
-                ctx.strDelim = ctx.ch;
-                isStart = false;
-                strPos = 0;
-                isEscaped = false;
+                ctx.delim = ctx.ch;
+                start = false;
+                pos = 0;
+                escaped = false;
             }
             else
-            if (!isEscaped && ctx.ch == ctx.strDelim)
+            if (!escaped && ctx.ch == ctx.delim)
             {
                 // End of string, set the value
-                tmpStr[strPos] = 0;
-                if ((ret = th_cfg_set_item(&ctx, item, tmpStr)) != THERR_OK)
+                str[pos] = 0;
+                if ((ret = th_cfg_set_item(&ctx, item, str)) != THERR_OK)
                     goto out;
             }
             else
-            if (!isEscaped && ctx.ch == '\\')
+            if (!escaped && ctx.ch == '\\')
             {
                 // Escape sequence
-                isEscaped = true;
+                escaped = true;
             }
             else
             {
@@ -598,7 +598,7 @@
                         SET_CFG_MAX_PARSE_BUF);
                     goto out;
                 }
-                isEscaped = false;
+                escaped = false;
             }
 
             ctx.ch = -1;
@@ -606,7 +606,7 @@
 
         case PM_NUMERIC:
             // Integer parsing mode
-            if (isStart && item->type == CFG_ITEM_UINT && ctx.ch == '-')
+            if (start && item->type == CFG_ITEM_UINT && ctx.ch == '-')
             {
                 // Error! Negative values not allowed for unsigned ints
                 ret = th_io_error(fh, THERR_INVALID_DATA,
@@ -615,16 +615,16 @@
                 goto out;
             }
             else
-            if (isStart && (ctx.ch == '-' || ctx.ch == '+'))
+            if (start && (ctx.ch == '-' || ctx.ch == '+'))
             {
                 VADDCH(ctx.ch)
                 else
                 ret = THERR_INVALID_DATA;
             }
             else
-            if (isStart && item->type == CFG_ITEM_FLOAT && ctx.ch == '.')
+            if (start && item->type == CFG_ITEM_FLOAT && ctx.ch == '.')
             {
-                fpSet = true;
+                fpseparator = true;
                 VADDCH('0')
                 else
                 ret = THERR_INVALID_DATA;
@@ -634,9 +634,9 @@
                 ret = THERR_INVALID_DATA;
             }
             else
-            if (item->type == CFG_ITEM_FLOAT && ctx.ch == '.' && !fpSet)
+            if (item->type == CFG_ITEM_FLOAT && ctx.ch == '.' && !fpseparator)
             {
-                fpSet = true;
+                fpseparator = true;
                 VADDCH(ctx.ch)
                 else
                 ret = THERR_INVALID_DATA;
@@ -652,9 +652,9 @@
             if (th_cfg_is_end(ctx.ch))
             {
                 // End of integer parsing mode
-                tmpStr[strPos] = 0;
+                str[pos] = 0;
 
-                if ((ret = th_cfg_set_item(&ctx, item, tmpStr)) != THERR_OK)
+                if ((ret = th_cfg_set_item(&ctx, item, str)) != THERR_OK)
                     goto out;
 
                 th_cfg_set_parsemode(&ctx, PM_IDLE);
@@ -677,16 +677,16 @@
                 goto out;
             }
 
-            isStart = false;
+            start = false;
             ctx.ch = -1;
             break;
 
         case PM_BOOL:
             // Boolean parsing mode
-            if (isStart)
+            if (start)
             {
-                isStart = false;
-                strPos = 0;
+                start = false;
+                pos = 0;
             }
 
             if (th_isalnum(ctx.ch))
@@ -698,8 +698,8 @@
             else
             if (th_cfg_is_end(ctx.ch))
             {
-                tmpStr[strPos] = 0;
-                ret = th_cfg_set_item(&ctx, item, tmpStr);
+                str[pos] = 0;
+                ret = th_cfg_set_item(&ctx, item, str);
             }
 
             if (ret != THERR_OK)
@@ -715,10 +715,10 @@
     }
 
 out:
-    th_free(tmpStr);
+    th_free(str);
 
     // Return result
-    if (ret == THERR_OK && ctx.parseMode == PM_ERROR)
+    if (ret == THERR_OK && ctx.mode == PM_ERROR)
         ret = THERR_INVALID_DATA;
 
     return ret;