diff th_config.c @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 29e44a58bc73
children c17eadc60c3d
line wrap: on
line diff
--- a/th_config.c	Wed Dec 07 11:58:54 2022 +0200
+++ b/th_config.c	Wed Dec 07 12:14:39 2022 +0200
@@ -125,9 +125,9 @@
 /* Add boolean type setting into given configuration
  */
 int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name,
-                    BOOL *itemData, BOOL defValue)
+                    bool *itemData, bool defValue)
 {
-    th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_BOOL, (void *) itemData);
+    th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_bool, (void *) itemData);
     if (node == NULL)
         return THERR_MALLOC;
 
@@ -189,7 +189,7 @@
     PM_KEYSET,
     PM_STRING,
     PM_NUMERIC,
-    PM_BOOL,
+    PM_bool,
     PM_SECTION,
     PM_LIST,
 
@@ -223,7 +223,7 @@
 #define VADDCH(ch) if (strPos < SET_MAX_BUF) { tmpStr[strPos++] = ch; }
 
 
-static BOOL th_cfg_is_end(const int ch)
+static bool th_cfg_is_end(const int ch)
 {
     return
         ch == '\r' ||
@@ -247,8 +247,8 @@
         case ITEM_FLOAT:
             return PM_NUMERIC;
 
-        case ITEM_BOOL:
-            return PM_BOOL;
+        case ITEM_bool:
+            return PM_bool;
 
         case ITEM_SECTION:
             return PM_SECTION;
@@ -264,7 +264,7 @@
 
 static int th_cfg_set_item(th_cfgparserctx_t *ctx, th_cfgitem_t *item, const char *str)
 {
-    BOOL res = TRUE;
+    bool res = true;
 
     switch (item->type)
     {
@@ -288,7 +288,7 @@
                     return THERR_OK;
                 }
                 else
-                    res = FALSE;
+                    res = false;
             }
             break;
 
@@ -304,12 +304,12 @@
             *(item->v.val_float) = atof(str);
             break;
 
-        case ITEM_BOOL:
+        case ITEM_bool:
             res = th_get_boolean(str, item->v.val_bool);
             break;
 
         default:
-            res = FALSE;
+            res = false;
             break;
     }
 
@@ -325,14 +325,14 @@
     th_cfgitem_t *item = NULL;
     char *tmpStr = NULL;
     size_t strPos;
-    BOOL isEscaped, isStart, fpSet;
+    bool isEscaped, isStart, fpSet;
     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;
+    isEscaped = fpSet = isStart = false;
     strPos = 0;
 
     if ((tmpStr = th_malloc(SET_MAX_BUF + 1)) == NULL)
@@ -461,15 +461,15 @@
             if (ctx.ch == '=')
             {
                 // Find key from configuration
-                BOOL found;
+                bool found;
                 tmpStr[strPos] = 0;
 
-                for (item = sect, found = FALSE; item != NULL && !found; )
+                for (item = sect, found = false; item != NULL && !found; )
                 {
                     if (item->type != ITEM_COMMENT &&
                         item->name != NULL &&
                         strcmp(item->name, tmpStr) == 0)
-                        found = TRUE;
+                        found = true;
                     else
                         item = (th_cfgitem_t *) item->node.next;
                 }
@@ -479,8 +479,8 @@
                 {
                     // Okay, set next mode
                     th_cfg_set_next_parsemode(&ctx, th_cfg_get_parsemode(item->type));
-                    isStart = TRUE;
-                    fpSet = FALSE;
+                    isStart = true;
+                    fpSet = false;
                     strPos = 0;
                 }
                 else
@@ -534,7 +534,7 @@
             {
                 th_cfg_set_next_parsemode(&ctx, PM_STRING);
                 ctx.ch = -1;
-                isStart = TRUE;
+                isStart = true;
             }
             else
             {
@@ -568,9 +568,9 @@
             {
                 // Start of string, get delimiter
                 ctx.strDelim = ctx.ch;
-                isStart = FALSE;
+                isStart = false;
                 strPos = 0;
-                isEscaped = FALSE;
+                isEscaped = false;
             }
             else
             if (!isEscaped && ctx.ch == ctx.strDelim)
@@ -584,7 +584,7 @@
             if (!isEscaped && ctx.ch == '\\')
             {
                 // Escape sequence
-                isEscaped = TRUE;
+                isEscaped = true;
             }
             else
             {
@@ -598,7 +598,7 @@
                         SET_MAX_BUF);
                     goto out;
                 }
-                isEscaped = FALSE;
+                isEscaped = false;
             }
 
             ctx.ch = -1;
@@ -624,7 +624,7 @@
             else
             if (isStart && item->type == ITEM_FLOAT && ctx.ch == '.')
             {
-                fpSet = TRUE;
+                fpSet = true;
                 VADDCH('0')
                 else
                 ret = THERR_INVALID_DATA;
@@ -636,7 +636,7 @@
             else
             if (item->type == ITEM_FLOAT && ctx.ch == '.' && !fpSet)
             {
-                fpSet = TRUE;
+                fpSet = true;
                 VADDCH(ctx.ch)
                 else
                 ret = THERR_INVALID_DATA;
@@ -677,15 +677,15 @@
                 goto out;
             }
 
-            isStart = FALSE;
+            isStart = false;
             ctx.ch = -1;
             break;
 
-        case PM_BOOL:
+        case PM_bool:
             // Boolean parsing mode
             if (isStart)
             {
-                isStart = FALSE;
+                isStart = false;
                 strPos = 0;
             }
 
@@ -736,21 +736,21 @@
 
 /* Write a configuration into file
  */
-static BOOL th_print_indent_a(th_ioctx *fh, const int nesting, const char *fmt, va_list ap)
+static bool th_print_indent_a(th_ioctx *fh, const int nesting, const char *fmt, va_list ap)
 {
     for (int i = 0; i < nesting * 4; i++)
     {
         if (thfputc(' ', fh) == EOF)
-            return FALSE;
+            return false;
     }
 
     return thvfprintf(fh, fmt, ap) >= 0;
 }
 
 
-static BOOL th_print_indent(th_ioctx *fh, const int nesting, const char *fmt, ...)
+static bool th_print_indent(th_ioctx *fh, const int nesting, const char *fmt, ...)
 {
-    BOOL ret;
+    bool ret;
     va_list ap;
     va_start(ap, fmt);
     ret = th_print_indent_a(fh, nesting, fmt, ap);
@@ -759,7 +759,7 @@
 }
 
 
-static BOOL th_cfg_is_item_valid(const th_cfgitem_t *item)
+static bool th_cfg_is_item_valid(const th_cfgitem_t *item)
 {
     switch (item->type)
     {
@@ -770,22 +770,22 @@
             return (*(item->v.list) != NULL);
 
         case ITEM_SECTION:
-            return TRUE;
+            return true;
 
         case ITEM_INT:
         case ITEM_UINT:
         case ITEM_FLOAT:
-        case ITEM_BOOL:
+        case ITEM_bool:
         case ITEM_HEX_TRIPLET:
-            return TRUE;
+            return true;
 
         default:
-            return FALSE;
+            return false;
     }
 }
 
 
-static BOOL th_cfg_write_string_escaped(th_ioctx *fh, const char *str, const char delim)
+static bool th_cfg_write_string_escaped(th_ioctx *fh, const char *str, const char delim)
 {
     for (const char *ptr = str; *ptr; ptr++)
     {
@@ -793,16 +793,16 @@
         {
             if (thfputc('\\', fh) == EOF ||
                 thfputc(*ptr, fh) == EOF)
-                return FALSE;
+                return false;
         }
         else
         {
             if (thfputc(*ptr, fh) == EOF)
-                return FALSE;
+                return false;
         }
     }
 
-    return TRUE;
+    return true;
 }
 
 
@@ -827,7 +827,7 @@
         case ITEM_FLOAT:
             return thfprintf(fh, "%1.5f", *(item->v.val_float));
 
-        case ITEM_BOOL:
+        case ITEM_bool:
             return thfprintf(fh, "%s", *(item->v.val_bool) ? "yes" : "no");
 
         case ITEM_HEX_TRIPLET:
@@ -848,28 +848,28 @@
 
         if (item->type == ITEM_COMMENT)
         {
-            BOOL lineStart = TRUE, lineFeed = FALSE;
+            bool lineStart = true, lineFeed = false;
 
             for (const char *ptr = item->name; *ptr; ptr++)
             switch (*ptr)
             {
                 case '\r':
                 case '\n':
-                    lineStart = lineFeed = TRUE;
+                    lineStart = lineFeed = true;
                     break;
 
                 default:
                     if (lineFeed)
                     {
                         thfprintf(fh, "\n");
-                        lineFeed = FALSE;
+                        lineFeed = false;
                     }
                     if (lineStart)
                     {
                         if (!th_print_indent(fh, nesting, "# "))
                             return THERR_FWRITE;
 
-                        lineStart = FALSE;
+                        lineStart = false;
                     }
 
                     if (thfputc(*ptr, fh) == EOF)
@@ -958,16 +958,16 @@
 {
     while (item != NULL)
     {
-        BOOL match = TRUE;
+        bool match = true;
 
         // Has type check been set, and does it match?
         if (type != -1 && item->type != type)
-            match = FALSE;
+            match = false;
 
         // Check item name
         if (name != NULL && item->name != NULL &&
             strcmp(name, item->name) != 0)
-            match = FALSE;
+            match = false;
 
         // Recurse to section
         if (!match && item->type == ITEM_SECTION)