diff main.c @ 713:93d0e1547842

th-libs now uses stdbool.h if possible, so we need to rename all BOOL/TRUE/FALSE to bool/true/false.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 13:20:25 +0200
parents 84d7b33c4e83
children 66b9d7b861d1
line wrap: on
line diff
--- a/main.c	Wed Dec 07 13:19:25 2022 +0200
+++ b/main.c	Wed Dec 07 13:20:25 2022 +0200
@@ -86,14 +86,14 @@
         *optSite = "NN",
         *optNickSepStr = NULL;
 char    optNickSep;
-BOOL    optDaemon = FALSE,
-        optProxyEnable = FALSE,
-        setIgnoreMode = FALSE,
-        optDebug = FALSE,
-        optLogEnable = FALSE,
-        optLogDaily = FALSE,
-        optOnlyFriendPrv = FALSE,
-        optShowHelp = FALSE;
+bool    optDaemon = false,
+        optProxyEnable = false,
+        setIgnoreMode = false,
+        optDebug = false,
+        optLogEnable = false,
+        optLogDaily = false,
+        optOnlyFriendPrv = false,
+        optShowHelp = false;
 
 char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL;
 th_llist_t *setIgnoreList = NULL,
@@ -178,7 +178,7 @@
 }
 
 
-BOOL argSplitStr(const char *src, const char *at, char **res1, char **res2)
+bool argSplitStr(const char *src, const char *at, char **res1, char **res2)
 {
     char *pos, *tmp = th_strdup(src);
 
@@ -189,29 +189,29 @@
         *res1 = th_strdup_trim(tmp, TH_TRIM_BOTH);
         *res2 = th_strdup_trim(pos, TH_TRIM_BOTH);
         th_free(tmp);
-        return TRUE;
+        return true;
     }
     else
     {
         th_free(tmp);
-        return FALSE;
+        return false;
     }
 }
 
 
-BOOL argHandleProxyURI(const char *uri)
+bool argHandleProxyURI(const char *uri)
 {
     // Attempt to parse the proxy URI
-    BOOL ret = FALSE;
+    bool ret = false;
     char *proto = NULL, *rest = NULL, *host = NULL,
          *auth = NULL, *port = NULL;
     size_t len;
 
-    optProxyEnable = FALSE;
+    optProxyEnable = false;
 
     // Handle disable case
     if (th_strncasecmp(uri, "disab", 5) == 0)
-        return TRUE;
+        return true;
 
     // Split the URI
     if (!argSplitStr(uri, "://", &proto, &rest))
@@ -276,8 +276,8 @@
     else
         optProxyAuthType = TH_PROXY_AUTH_NONE;
 
-    optProxyEnable = TRUE;
-    ret = TRUE;
+    optProxyEnable = true;
+    ret = true;
 
 out:
     th_free(proto);
@@ -290,12 +290,12 @@
 }
 
 
-BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
+bool argHandleOpt(const int optN, char *optArg, char *currArg)
 {
     switch (optN)
     {
     case 0:
-        optShowHelp = TRUE;
+        optShowHelp = true;
         break;
 
     case 1:
@@ -315,7 +315,7 @@
         {
             THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n",
                 optArg);
-            return FALSE;
+            return false;
         }
         THMSG(1, "Using color #%06x\n", optUserColor);
         break;
@@ -325,19 +325,19 @@
         break;
 
     case 6:
-        optDaemon = TRUE;
+        optDaemon = true;
         THMSG(1, "Running in pseudo-daemon mode.\n");
         break;
 
     case 8:
-        optDebug = TRUE;
+        optDebug = true;
         THMSG(1, "Debug mode enabled.\n");
         break;
 
 
     case 10:
         if (!argHandleProxyURI(optArg))
-            return FALSE;
+            return false;
         break;
 
     case 13:
@@ -347,24 +347,24 @@
             if (!th_strcasecmp(nn_room_data[i].name, optArg))
             {
                 optPort = nn_room_data[i].port;
-                return TRUE;
+                return true;
             }
 
             THERR("Unsupported room '%s'.\n", optArg);
-            return FALSE;
+            return false;
         }
         break;
 
     default:
         THERR("Unknown option '%s'.\n", currArg);
-        return FALSE;
+        return false;
     }
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL argHandleFile(char *currArg)
+bool argHandleFile(char *currArg)
 {
     if (!optUserNameCmd)
         optUserNameCmd = currArg;
@@ -373,19 +373,19 @@
     else
     {
         THERR("Username '%s' already specified on commandline!\n", optUserNameCmd);
-        return FALSE;
+        return false;
     }
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL nn_conn_send_msg(th_conn_t *conn, const char *user, const char *str)
+bool nn_conn_send_msg(th_conn_t *conn, const char *user, const char *str)
 {
     char *msg;
 
     if (str == NULL)
-        return FALSE;
+        return false;
 
     msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str);
 
@@ -396,13 +396,13 @@
         return ret == THERR_OK;
     }
     else
-        return FALSE;
+        return false;
 }
 
 
-BOOL nn_conn_send_msg_v(th_conn_t *conn, const char *user, const char *fmt, ...)
+bool nn_conn_send_msg_v(th_conn_t *conn, const char *user, const char *fmt, ...)
 {
-    BOOL res;
+    bool res;
     char *tmp;
     va_list ap;
 
@@ -463,7 +463,7 @@
 
 
 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...);
-BOOL nn_log_reopen(nn_window_t *win);
+bool nn_log_reopen(nn_window_t *win);
 
 
 void printMsgConst(nn_window_t *win, int flags, const char *msg)
@@ -628,23 +628,23 @@
 }
 
 
-BOOL nn_check_name_list(th_llist_t *list, const char *name)
+bool nn_check_name_list(th_llist_t *list, const char *name)
 {
     th_llist_t *node;
 
     for (node = list; node != NULL; node = node->next)
     {
         if (th_strcasecmp(name, (char *) node->data) == 0)
-            return TRUE;
+            return true;
     }
 
-    return FALSE;
+    return false;
 }
 
 
 int nnproto_parse_user(th_conn_t *conn)
 {
-    BOOL isMine, isIgnored = FALSE;
+    bool isMine, isIgnored = false;
     char *name, *msg, *t;
 
     // Find start of the message
@@ -903,7 +903,7 @@
 
 int nn_parse_protocol(th_conn_t *conn)
 {
-    static BOOL protoCmdsInit = FALSE;
+    static bool protoCmdsInit = false;
     int i;
 
     if (!protoCmdsInit)
@@ -911,7 +911,7 @@
         for (i = 0; i < nprotoCmds; i++)
             protoCmds[i].len = strlen(protoCmds[i].name);
 
-        protoCmdsInit = TRUE;
+        protoCmdsInit = true;
     }
 
     for (i = 0; i < nprotoCmds; i++)
@@ -1104,7 +1104,7 @@
         {
             name = nn_username_decode(th_strdup(user->name));
             printMsgQ(currWin, "Opening PRV query for '%s'.\n", name);
-            if (nnwin_open(name, TRUE))
+            if (nnwin_open(name, true))
                 printMsgQ(currWin, "In PRV query with '%s'.\n", name);
             th_free(name);
             return 0;
@@ -1315,7 +1315,7 @@
     (void) conn;
     (void) buf;
 
-    appQuitFlag = TRUE;
+    appQuitFlag = true;
     return 0;
 }
 
@@ -1431,7 +1431,7 @@
             {
                 // Server-side commands are just pass-through here
                 char *tmp = nn_dblencode_str(buf);
-                BOOL result;
+                bool result;
                 if (tmp == NULL) return -2;
                 result = nn_conn_send_msg(conn, optUserNameEnc, tmp);
                 th_free(tmp);
@@ -1458,7 +1458,7 @@
 }
 
 
-nn_usercmd_t *nn_usercmd_match(th_llist_t *list, const char *pattern, const char *current, BOOL again)
+nn_usercmd_t *nn_usercmd_match(th_llist_t *list, const char *pattern, const char *current, bool again)
 {
     nn_usercmd_t *curr;
     size_t len;
@@ -1493,7 +1493,7 @@
 
 int nn_handle_input(th_conn_t *conn, char *buf, size_t bufLen)
 {
-    BOOL result;
+    bool result;
     char *tmp;
 
     // Trim right side
@@ -1566,12 +1566,12 @@
 }
 
 
-BOOL nn_tabcomplete_buffer(nn_editbuf_t *buf)
+bool nn_tabcomplete_buffer(nn_editbuf_t *buf)
 {
     static char *previous = NULL, *pattern = NULL;
     char *str = buf->data;
-    BOOL again = FALSE, hasSeparator = FALSE,
-         hasSpace, newPattern = FALSE, isCommand;
+    bool again = false, hasSeparator = false,
+         hasSpace, newPattern = false, isCommand;
     size_t endPos, startPos = buf->pos;
 
     // previous word
@@ -1588,7 +1588,7 @@
         endPos = startPos;
         while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
         while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++;
-        newPattern = TRUE;
+        newPattern = true;
     }
     else
     // previous word, new pattern
@@ -1597,10 +1597,10 @@
         startPos -= 1;
         endPos = startPos;
         while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
-        newPattern = TRUE;
+        newPattern = true;
     }
     else
-        return FALSE;
+        return false;
 
     // Check if this is a command completion
     isCommand = (str[0] == '/' && startPos == 0);
@@ -1609,8 +1609,8 @@
     {
         endPos--;
         if (startPos > 0)
-            return FALSE;
-        hasSeparator = TRUE;
+            return false;
+        hasSeparator = true;
     }
 
     hasSpace = (buf->pos > 0 && str[buf->pos - 1] == ' ') ||
@@ -1621,7 +1621,7 @@
         // Get pattern, check if it matches previous pattern and set 'again' flag
         char *npattern = nn_editbuf_get_string(buf, startPos, endPos);
         if (pattern && npattern && th_strcasecmp(npattern, pattern) == 0)
-            again = TRUE;
+            again = true;
 
         th_free(pattern);
         pattern = npattern;
@@ -1633,7 +1633,7 @@
     }
 
     if (!pattern)
-        return FALSE;
+        return false;
 
     if (isCommand)
     {
@@ -1647,7 +1647,7 @@
                 nn_editbuf_insert(buf, i++, ' ');
 
             nn_tabcomplete_finish(buf, &previous, startPos, cmd->name);
-            return TRUE;
+            return true;
         }
     }
     else
@@ -1672,15 +1672,15 @@
                 nn_editbuf_insert(buf, i++, ' ');
 
             nn_tabcomplete_finish(buf, &previous, startPos, user->name);
-            return TRUE;
+            return true;
         }
     }
 
-    return FALSE;
+    return false;
 }
 
 
-BOOL processUserInput(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
+bool processUserInput(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
 {
     // Chat window switching via Meta/Esc-[1..9]
     if (c >= 0x5001 && c <= 0x5009)
@@ -1689,7 +1689,7 @@
         if (win != NULL)
         {
             currWin = win;
-            editState->update = TRUE;
+            editState->update = true;
         }
     }
     else
@@ -1721,7 +1721,7 @@
             if (result < 0)
             {
                 errorMsg("Fatal error handling user input: %s\n", editBuf->data);
-                editState->isError = TRUE;
+                editState->isError = true;
             }
             else
             {
@@ -1746,7 +1746,7 @@
                 currWin->pos = 0;
 
             if (oldPos != currWin->pos)
-                editState->update = TRUE;
+                editState->update = true;
         }
         break;
 
@@ -1783,7 +1783,7 @@
 
     case KEY_F(9): // F9 = Quit
         printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
-        appQuitFlag = TRUE;
+        appQuitFlag = true;
         break;
 
     case 0x09: // Tab = complete username or command
@@ -1791,33 +1791,33 @@
         break;
 
     default:
-        return FALSE;
+        return false;
     }
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
+bool processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
 {
     (void) editBuf;
 
     switch (c)
     {
     case KEY_ENTER:
-        editState->done = TRUE;
+        editState->done = true;
         break;
 
     case KEY_F(9): // F9 = Quit
         printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
-        appQuitFlag = TRUE;
+        appQuitFlag = true;
         break;
 
     default:
-        return FALSE;
+        return false;
     }
 
-    return TRUE;
+    return true;
 }
 
 
@@ -1830,12 +1830,12 @@
 void clearEditState(nn_editstate_t *st)
 {
     memset(st, 0, sizeof(nn_editstate_t));
-    st->insertMode = TRUE;
+    st->insertMode = true;
     st->debugMsg = debugMsg;
 }
 
 
-BOOL nn_log_open(nn_window_t *win)
+bool nn_log_open(nn_window_t *win)
 {
     char *path = NULL, *plt;
 #ifndef TH_PLAT_WINDOWS
@@ -1843,7 +1843,7 @@
 #endif
 
     if (!optLogEnable || optLogPath == NULL)
-        return FALSE;
+        return false;
 
     plt = strrchr(optLogPath, TH_DIR_SEPARATOR_CHR);
     if (plt == NULL || plt[1] != 0)
@@ -1875,7 +1875,7 @@
         char *cleaned;
 
         if ((cleaned = th_strdup(win->id)) == NULL)
-            return FALSE;
+            return false;
 
         for (pos = 0; cleaned[pos] != 0; pos++)
         {
@@ -1909,7 +1909,7 @@
     printMsg(win, "Logging to '%s'.\n", win->logFilename);
 
     th_free(path);
-    return TRUE;
+    return true;
 
 error:
     th_free(path);
@@ -1921,7 +1921,7 @@
     if (logFd >= 0)
         close(logFd);
 #endif
-    return FALSE;
+    return false;
 }
 
 
@@ -1935,7 +1935,7 @@
 }
 
 
-BOOL nn_log_reopen(nn_window_t *win)
+bool nn_log_reopen(nn_window_t *win)
 {
     nn_log_close(win);
     return nn_log_open(win);
@@ -1961,7 +1961,7 @@
 {
     char *tmpStr;
     int index, updateCount = 0, ret;
-    BOOL argsOK, colorSet = FALSE;
+    bool argsOK, colorSet = false;
     th_conn_t *conn = NULL;
     nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE);
     nn_editstate_t editState;
@@ -2190,7 +2190,7 @@
         printMsg(NULL, "%s\n", th_prog_author);
         printMsg(NULL, "%s\n", th_prog_license);
 
-        nnwin_update(TRUE, FALSE, NULL, optUserName, optUserColor);
+        nnwin_update(true, false, NULL, optUserName, optUserColor);
 
         // Check if we have username and password
         if (optUserName == NULL || optPassword == NULL)
@@ -2199,14 +2199,14 @@
             printMsg(NULL, "You can avoid doing this every time by issuing '/save' after logging in.\n");
 
             printMsg(NULL, "Enter your NN username ...\n");
-            optUserName = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt);
+            optUserName = nnwin_prompt_requester(false, &editState, processUserPrompt, updateUserPrompt);
             if (appQuitFlag)
                 goto err_exit;
 
-            editState.mask = TRUE;
+            editState.mask = true;
             printMsg(NULL, "Enter your NN password ...\n");
-            optPassword = nnwin_prompt_requester(TRUE, &editState, processUserPrompt, updateUserPrompt);
-            editState.mask = FALSE;
+            optPassword = nnwin_prompt_requester(true, &editState, processUserPrompt, updateUserPrompt);
+            editState.mask = false;
             if (appQuitFlag)
                 goto err_exit;
         }
@@ -2300,7 +2300,7 @@
     while (!editState.isError && !appQuitFlag)
     {
         int retries = 3, cres;
-        editState.update = FALSE;
+        editState.update = false;
 
 packet_retry:
         cres = th_conn_pull(conn);
@@ -2328,20 +2328,20 @@
                     th_conn_buf_skip(conn, strlen(conn->base.ptr) + 1);
                 }
                 else
-                    editState.isError = TRUE;
+                    editState.isError = true;
             }
         }
         else
         if (cres < TH_CONN_ERROR || !th_conn_check(conn))
-            editState.isError = TRUE;
+            editState.isError = true;
 
         // Handle user input
-        BOOL flushed = FALSE;
+        bool flushed = false;
         if (appCursesInit)
         {
             nnwin_input_process(editBuf, &editState, processUserInput);
             nnwin_update(editState.update, editState.mask, editBuf, optUserName, optUserColor);
-            flushed = TRUE;
+            flushed = true;
         }
 
         if (++updateCount > 10)
@@ -2357,13 +2357,13 @@
 
             if (!colorSet)
             {
-                colorSet = TRUE;
+                colorSet = true;
                 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
             }
 
             if (appCursesInit && !flushed)
             {
-                nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor);
+                nnwin_update(false, editState.mask, editBuf, optUserName, optUserColor);
             }
 
             updateCount = 0;
@@ -2377,7 +2377,7 @@
         char *tmp;
         printMsg(NULL, "Press enter to exit.\n");
         clearEditState(&editState);
-        tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt);
+        tmp = nnwin_prompt_requester(false, &editState, processUserPrompt, updateUserPrompt);
         th_free(tmp);
     }