changeset 419:d015ecbd231d

Use C99 style comments, too.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 May 2012 07:37:36 +0300
parents 8ca09a6cca09
children e4424de5bd16
files libnnutil.h main.c network.c util.c
diffstat 4 files changed, 100 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/libnnutil.h	Thu May 24 07:34:37 2012 +0300
+++ b/libnnutil.h	Thu May 24 07:37:36 2012 +0300
@@ -15,7 +15,7 @@
 #define NN_TMPBUF_SIZE    (4096)
 #define NN_ALLOC_SIZE     (128)
 #define NN_NUM_BUCKETS    (256)
-#define NN_BACKBUF_LEN    (512)       /* Backbuffer size (in lines) */
+#define NN_BACKBUF_LEN    (512)       // Backbuffer size (in lines)
 
 
 typedef struct _nn_user_t
@@ -75,12 +75,12 @@
 
 typedef struct
 {
-    qringbuf_t *data;   /* "Backbuffer" data for this window */
-    int pos;            /* Current position in the window, 0 = real time */
+    qringbuf_t *data;   // "Backbuffer" data for this window
+    int pos;            // Current position in the window, 0 = real time
     BOOL dirty;
 
-    char *id;           /* Chatter ID, NULL = main window */
-    int num;		/* Window number */
+    char *id;           // Chatter ID, NULL = main window
+    int num;		// Window number
 
     char *buf;
     size_t len, bufsize;
--- a/main.c	Thu May 24 07:34:37 2012 +0300
+++ b/main.c	Thu May 24 07:37:36 2012 +0300
@@ -10,7 +10,7 @@
 #include <errno.h>
 #include <time.h>
 #ifdef __WIN32
-/* Undefine because both windows.h and curses.h #define it */
+// Undefine because both windows.h and curses.h #define it
 #undef MOUSE_MOVED
 #include <shlwapi.h>
 #else
@@ -34,8 +34,8 @@
 
 #define SET_NICK_SEPARATOR ':'
 
-#define SET_MAX_HISTORY (16)        /* Command history length */
-#define SET_KEEPALIVE   (15*60)     /* Ping/keepalive period in seconds */
+#define SET_MAX_HISTORY (16)        // Command history length
+#define SET_KEEPALIVE   (15*60)     // Ping/keepalive period in seconds
 #define SET_MAX_WINDOWS (32)
 
 
@@ -470,19 +470,19 @@
     int h, offs;
     qringbuf_t *buf;
 
-    /* Check pointers */
+    // Check pointers
     if (mainWin == NULL || currWin == NULL)
         return FALSE;
 
-    /* Check if update is forced or if the window is dirty */
+    // Check if update is forced or if the window is dirty
     if (!force && !currWin->dirty)
         return FALSE;
 
-    /* Compute how many lines from backbuffer fit on the screen */
+    // Compute how many lines from backbuffer fit on the screen
     buf = currWin->data;
     h = getmaxy(mainWin);
 
-    /* Clear and redraw window */
+    // Clear and redraw window
     werase(mainWin);
     scrollok(mainWin, 1);
     for (offs = buf->size - h - currWin->pos; offs >= 0 && offs < buf->size - currWin->pos && offs < buf->size; offs++)
@@ -643,23 +643,23 @@
     BOOL isMine, isIgnored = FALSE;
     char *name, *msg, *t;
 
-    /* Find start of the message */
+    // Find start of the message
     name = conn->ptr;
     t = nn_conn_buf_strstr(conn, "</USER><MESSAGE>");
     if (!t) return 1;
     *t = 0;
     msg = conn->ptr;
 
-    /* Find end of the message */
+    // Find end of the message
     t = nn_conn_buf_strstr(conn, "</MESSAGE>");
     if (!t) return 3;
     *t = 0;
 
-    /* Decode message string */
+    // Decode message string
     msg = nn_decode_str1(msg);
     if (!msg) return -1;
 
-    /* Decode username */
+    // Decode username
     name = nn_decode_str1(name);
     if (!name)
     {
@@ -673,10 +673,10 @@
     isMine = strcmp(name, optUserName) == 0;
     isIgnored = setIgnoreMode && !isMine && checkIgnoreList(name);
 
-    /* Is it a special control message? */
+    // Is it a special control message?
     if (*msg == '/')
     {
-        /* Ignore room join/leave messages */
+        // Ignore room join/leave messages
         if (!optDebug && (strstr(msg, "left the room") || strstr(msg, "joined the room from")))
             goto done;
 
@@ -721,7 +721,7 @@
         }
         else
         {
-            /* It's an action (/me) */
+            // It's an action (/me)
             char *h = nn_decode_str2(t);
             printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
                 "½9½* %s½0½\n", h);
@@ -731,7 +731,7 @@
     }
     else
     {
-        /* It's a normal message */
+        // It's a normal message
         char *h;
         t = nn_strip_tags(msg);
         h = nn_decode_str2(t);
@@ -887,23 +887,23 @@
     char *tmpStr, tmpBuf[4096];
     BOOL result;
 
-    /* Trim right */
+    // Trim right
     bufLen--;
     buf[bufLen--] = 0;
     while (bufLen > 0 && th_isspace(buf[bufLen]))
         buf[bufLen--] = 0;
 
-    /* Decode completed usernames */
+    // Decode completed usernames
     nn_username_decode(buf);
 
-    /* Check for special user commands */
+    // Check for special user commands
     if (*buf == 0)
     {
         return 1;
     }
     else if (!th_strncasecmp(buf, "/color ", 7))
     {
-        /* Change color */
+        // Change color
         int tmpInt;
         if ((tmpInt = th_get_hex_triplet(str_trim_left(buf + 7))) < 0)
         {
@@ -920,7 +920,7 @@
         char *name = str_trim_left(buf + 7);
         if (strlen(name) > 0)
         {
-            /* Add or remove someone to/from ignore */
+            // Add or remove someone to/from ignore
             qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername);
             if (user != NULL)
             {
@@ -935,7 +935,7 @@
         }
         else
         {
-            /* Just list whomever is in ignore now */
+            // Just list whomever is in ignore now
             qlist_t *user = setIgnoreList;
             ssize_t nuser = th_llist_length(setIgnoreList);
             char *result = th_strdup_printf("Users ignored (%d): ", nuser);
@@ -979,7 +979,7 @@
     }
     else if (!th_strncasecmp(buf, "/win", 4))
     {
-        /* Change color */
+        // Change color
         char *tmp = str_trim_left(buf + 4);
         if (strlen(tmp) > 0)
         {
@@ -1030,7 +1030,7 @@
     }
     else if (!th_strncasecmp(buf, "/save", 5))
     {
-        /* Save configuration */
+        // Save configuration
         FILE *cfgfile = fopen(setConfigFile, "w");
         if (cfgfile == NULL)
         {
@@ -1047,7 +1047,7 @@
     }
     else if (!th_strncasecmp(buf, "/w ", 3))
     {
-        /* Open given username's profile via firefox in a new tab */
+        // Open given username's profile via firefox in a new tab
         char *name = str_trim_left(buf + 3);
 
         printMsg(currWin, "Opening profile for: '%s'\n", name);
@@ -1096,7 +1096,7 @@
     }
     else if (!th_strncasecmp(buf, "/who", 4))
     {
-        /* Alias /who to /listallusers */
+        // Alias /who to /listallusers
         snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
         buf = tmpBuf;
     }
@@ -1115,7 +1115,7 @@
         }
     }
 
-    /* Send double-encoded */
+    // Send double-encoded
     tmpStr = nn_dblencode_str(nn_username_decode(buf));
     if (tmpStr == 0) return -2;
     result = nn_conn_send_msg(conn, optUserNameEnc, "%s", tmpStr);
@@ -1168,7 +1168,7 @@
     int mode = 0;
     ssize_t endPos, startPos = buf->pos;
 
-    /* previous word */
+    // previous word
     if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ')
     {
         startPos -= 2;
@@ -1177,7 +1177,7 @@
         mode = 1;
     }
     else
-    /* middle of a word, new pattern */
+    // middle of a word, new pattern
     if (startPos < buf->len && str[startPos] != ' ')
     {
         endPos = startPos;
@@ -1187,7 +1187,7 @@
         mode = 2;
     }
     else
-    /* previous word, new pattern */
+    // previous word, new pattern
     if (startPos >= 1 && str[startPos - 1] != ' ')
     {
         startPos -= 1;
@@ -1222,7 +1222,7 @@
 
     if (newPattern)
     {
-        /* Get pattern, check if it matches previous pattern and set 'again' flag */
+        // 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;
@@ -1423,13 +1423,13 @@
 
     memset(histBuf, 0, sizeof(histBuf));
 
-    /* Initialize */
+    // Initialize
     th_init("NNChat", "Newbie Nudes chat client", NN_VERSION,
         "Written and designed by Anonymous Finnish Guy (C) 2008-2012",
         "This software is freeware, use and distribute as you wish.");
     th_verbosityLevel = 0;
 
-    /* Read configuration file */
+    // Read configuration file
     tmpcfg = NULL;
     th_cfg_add_comment(&tmpcfg, "General settings");
     th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL);
@@ -1511,7 +1511,7 @@
     if (setBrowser == NULL)
         setBrowser = "firefox";
 
-    /* Parse command line arguments */
+    // Parse command line arguments
     argsOK = th_args_process(argc, argv, optList, optListN,
                              argHandleOpt, argHandleFile, FALSE);
 
@@ -1524,23 +1524,23 @@
     if (!argsOK)
         return -2;
 
-    /* Allocate userhash */
+    // Allocate userhash
     if ((nnUsers = nn_userhash_new()) == NULL)
     {
         THERR("Could not allocate userhash. Fatal error.\n");
         return -105;
     }
 
-    /* If no idle messages are set, add default */
+    // If no idle messages are set, add default
     if (setIdleMessages == NULL)
     {
         th_llist_append(&setIdleMessages, th_strdup("."));
     }
 
-    /* Open logfile */
+    // Open logfile
     logFileOpen();
 
-    /* Initialize network */
+    // Initialize network
     if (!nn_network_init())
     {
         THERR("Could not initialize network subsystem.\n");
@@ -1549,7 +1549,7 @@
     else
         networkInit = TRUE;
 
-    /* Initialize NCurses */
+    // Initialize NCurses
     if (!optDaemon)
     {
         if (LINES < 0 || LINES > 1000) LINES = 24;
@@ -1599,7 +1599,7 @@
         updateStatus();
     }
 
-    /* Check if we have username and password */
+    // Check if we have username and password
     if (cursesInit && (optUserName == NULL || optPassword == NULL))
     {
         printWin(editWin, "You can avoid this prompt by issuing '/save' after logging in.\n");
@@ -1613,7 +1613,7 @@
         goto err_exit;
     }
 
-    /* Create a connection */
+    // Create a connection
     conn = nn_conn_new(errorFunc, messageFunc);
     if (conn == NULL)
     {
@@ -1621,7 +1621,7 @@
         goto err_exit;
     }
 
-    /* Are we using a proxy? */
+    // Are we using a proxy?
     if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL)
     {
         if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0)
@@ -1631,7 +1631,7 @@
         }
     }
 
-    /* Okay ... */
+    // Okay ...
     printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer);
     conn->host = th_strdup(optServer);
     conn->hst = nn_resolve_host(conn, optServer);
@@ -1672,29 +1672,29 @@
     nn_conn_close(conn);
 #endif
 
-    /* Okay, now do the proper connection ... */
+    // Okay, now do the proper connection ...
     if (nn_conn_open(conn, optPort, NULL) != 0)
     {
         errorMsg("Main connection setup failed!\n");
         goto err_exit;
     }
 
-    /* Send login command */
+    // Send login command
     optUserNameEnc = nn_dblencode_str(optUserName);
     tmpStr = nn_dblencode_str(optSite);
     nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword);
     th_free(tmpStr);
 
-    /* Initialize random numbers */
+    // Initialize random numbers
     prevTime = time(NULL);
     srandom((int) prevTime);
 
     if (cursesInit)
     {
-        /* Initialize rest of interactive UI code */
+        // Initialize rest of interactive UI code
         nn_editbuf_clear(editBuf);
 
-        /* First update of screen */
+        // First update of screen
         printEditBuf(editBuf);
         updateStatus();
 
@@ -1703,7 +1703,7 @@
         printMsg(NULL, "%s\n", th_prog_license);
     }
 
-    /* Enter mainloop */
+    // Enter mainloop
     nn_conn_reset(conn);
     while (!isError && !exitProg)
     {
@@ -1715,12 +1715,12 @@
                 int result = nn_parse_protocol(conn);
                 if (result > 0)
                 {
-                    /* Couldn't handle the message for some reason */
+                    // Couldn't handle the message for some reason
                     printMsg(currWin, "Could not handle: %s\n", conn->ptr);
                 }
                 else if (result < 0)
                 {
-                    /* Fatal error, quit */
+                    // Fatal error, quit
                     errorMsg("Fatal error with message: %s\n", conn->ptr);
                     isError = TRUE;
                 }
@@ -1735,13 +1735,13 @@
         if (!nn_conn_check(conn))
             isError = TRUE;
 
-        /* Handle user input */
+        // Handle user input
         if (cursesInit)
         {
             int c, cnt = 0;
             BOOL update = FALSE, updateMain = FALSE;
 
-            /* Handle several buffered keypresses at once */
+            // Handle several buffered keypresses at once
             do
             {
                 c = wgetch(stdscr);
@@ -1751,7 +1751,7 @@
                  */
                 if (c == 0x1b)
                 {
-                    /* ^[O */
+                    // ^[O
                     c = wgetch(stdscr);
                     if (c == 'O')
                     {
@@ -1770,7 +1770,7 @@
                             break;
                         }
                     }
-                    /* ^[[ */
+                    // ^[[
                     else if (c == '[')
                     {
                         c = wgetch(stdscr);
@@ -1811,13 +1811,13 @@
                             c = ERR;
                             break;
                         }
-                        /* Get the trailing ~ */
+                        // Get the trailing ~
                         if (c != ERR)
                             wgetch(stdscr);
                     }
                     if (c >= 0x31 && c <= 0x39)
                     {
-                        /* Chat window switching via Meta/Esc-[1..9] */
+                        // Chat window switching via Meta/Esc-[1..9]
                         int win = c - 0x31;
                         if (win < SET_MAX_WINDOWS && chatWindows[win] != NULL)
                         {
@@ -1835,7 +1835,7 @@
 #if defined(__WIN32) && defined(PDCURSES)
                 else if (c >= 0x198 && c <= 0x1a0)
                 {
-                    /* Chat window switching via Meta/Esc-[1..9] */
+                    // Chat window switching via Meta/Esc-[1..9]
                     int win = c - 0x198;
                     if (win < SET_MAX_WINDOWS && chatWindows[win] != NULL)
                     {
@@ -1866,7 +1866,7 @@
                 case KEY_ENTER:
                 case '\n':
                 case '\r':
-                    /* Call the user input handler */
+                    // Call the user input handler
                     if (editBuf->len > 0)
                     {
                         int result;
@@ -1894,7 +1894,7 @@
                         }
                         else
                         {
-                            /* Update time value of last sent message for unidle timeouts */
+                            // Update time value of last sent message for unidle timeouts
                             prevTime = time(NULL);
                         }
 
@@ -1902,7 +1902,7 @@
                     }
                     break;
 
-                case KEY_UP: /* Backwards in input history */
+                case KEY_UP: // Backwards in input history
                     if (histPos == 0)
                     {
                         nn_editbuf_free(histBuf[0]);
@@ -1917,7 +1917,7 @@
                     }
                     break;
 
-                case KEY_DOWN: /* Forwards in input history */
+                case KEY_DOWN: // Forwards in input history
                     if (histPos > 0)
                     {
                         histPos--;
@@ -1927,7 +1927,7 @@
                     }
                     break;
 
-                case 0x204: /* ctrl+left arrow = Skip words left */
+                case 0x204: // ctrl+left arrow = Skip words left
                 case 0x20b:
                     while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1]))
                         editBuf->pos--;
@@ -1936,7 +1936,7 @@
                     update = TRUE;
                     break;
 
-                case 0x206: /* ctrl+right arrow = Skip words right */
+                case 0x206: // ctrl+right arrow = Skip words right
                 case 0x210:
                     while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos]))
                         editBuf->pos++;
@@ -1970,58 +1970,58 @@
                     update = TRUE;
                     break;
 
-                case KEY_DC: /* Delete character */
+                case KEY_DC: // Delete character
                     nn_editbuf_delete(editBuf, editBuf->pos);
                     update = TRUE;
                     break;
 
 
-                case KEY_IC: /* Ins = Toggle insert / overwrite mode */
+                case KEY_IC: // Ins = Toggle insert / overwrite mode
                     insertMode = !insertMode;
                     update = TRUE;
                     break;
 
-                case KEY_F(1): /* F1 = Print help */
+                case KEY_F(1): // F1 = Print help
                     printHelp();
                     updateMain = TRUE;
                     break;
 
-                case KEY_F(2): /* F2 = Clear editbuffer */
+                case KEY_F(2): // F2 = Clear editbuffer
                     nn_editbuf_clear(editBuf);
                     update = TRUE;
                     break;
 
-                case KEY_F(5): /* F5 = Ignore mode */
+                case KEY_F(5): // F5 = Ignore mode
                     setIgnoreMode = !setIgnoreMode;
                     printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
                     break;
 
 #if 0
-                case KEY_F(8): /* F8 = Debug */
+                case KEY_F(8): // F8 = Debug
                     optDebug = !optDebug;
                     update = TRUE;
                     break;
 #endif
 
-                case 0x03: /* ^C = quit */
-                case KEY_F(9): /* F9 = Quit */
+                case 0x03: // ^C = quit
+                case KEY_F(9): // F9 = Quit
                     printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
                     exitProg = TRUE;
                     break;
 
-                case 0x09: /* Tab = complete username */
+                case 0x09: // Tab = complete username
                     performTabCompletion(editBuf);
                     update = TRUE;
                     break;
 
-                case 0x0c: /* Ctrl + L */
+                case 0x0c: // Ctrl + L
                     updateWindows();
                     update = updateMain = TRUE;
                     break;
 
                 case KEY_NPAGE:
                 case KEY_PPAGE:
-                    /* Page Up / Page Down */
+                    // Page Up / Page Down
                     if (currWin != NULL)
                     {
                         int oldPos = currWin->pos;
@@ -2039,7 +2039,7 @@
                     break;
 
                 case ERR:
-                    /* Ignore */
+                    // Ignore
                     break;
 
                 default:
@@ -2066,13 +2066,13 @@
 
             if (update || firstUpdate)
             {
-                /* Update edit line */
+                // Update edit line
                 updateStatus();
                 printEditBuf(editBuf);
-                firstUpdate = FALSE; /* a nasty hack ... */
+                firstUpdate = FALSE; // a nasty hack ...
             }
 
-        } /* cursesInit */
+        } // cursesInit
 
         if (++updateCount > 10)
         {
@@ -2098,7 +2098,7 @@
 
     }
 
-    /* Shutdown */
+    // Shutdown
 err_exit:
     th_cfg_free(cfg);
     th_free(homeDir);
--- a/network.c	Thu May 24 07:34:37 2012 +0300
+++ b/network.c	Thu May 24 07:37:36 2012 +0300
@@ -167,7 +167,7 @@
 
     nn_get_addr(&(conn->addr), conn->hst);
 
-    /* Prepare for connection */
+    // Prepare for connection
     dest.sin_family = AF_INET;
 
     if (conn->proxy.type > NN_PROXY_NONE && conn->proxy.type < NN_PROXY_LAST)
@@ -207,7 +207,7 @@
     FD_ZERO(&(conn->sockfds));
     FD_SET(conn->socket, &(conn->sockfds));
 
-    /* Proxy-specific setup */
+    // Proxy-specific setup
     if (conn->proxy.type == NN_PROXY_SOCKS4 || conn->proxy.type == NN_PROXY_SOCKS4A)
     {
         struct nn_socks_t *socksh;
@@ -226,7 +226,7 @@
             goto error;
         }
 
-        /* Create SOCKS 4/4A request */
+        // Create SOCKS 4/4A request
         nn_conn_msg(conn, "Initializing proxy negotiation.\n");
         socksh = (struct nn_socks_t *) buf;
         socksh->version = 4;
@@ -246,7 +246,7 @@
             strcpy(ptr, conn->host);
         }
 
-        /* Send request */
+        // Send request
         nn_conn_reset(conn);
         if (!nn_conn_send_buf(conn, buf, bufsiz))
         {
@@ -256,7 +256,7 @@
         }
         th_free(buf);
 
-        /* Wait for SOCKS server to reply */
+        // Wait for SOCKS server to reply
         for (status = tries = 1; tries <= 20 && status > 0; tries++)
         {
 #ifdef __WIN32
@@ -268,7 +268,7 @@
             status = nn_conn_pull(conn);
         }
 
-        /* Check results */
+        // Check results
         if (status == 0)
         {
             struct nn_socks_res_t *res = (struct nn_socks_res_t *) &(conn->buf);
@@ -379,7 +379,7 @@
     if (conn == NULL)
         return -10;
 
-    /* Prod the input buffer */
+    // Prod the input buffer
     if (conn->in_ptr > conn->buf && conn->in_ptr - conn->ptr > 0)
     {
         size_t delta = conn->in_ptr - conn->ptr;
@@ -389,7 +389,7 @@
         conn->total_bytes -= delta;
     }
 
-    /* Check for incoming data */
+    // Check for incoming data
     socktv.tv_sec = 0;
     socktv.tv_usec = NN_DELAY_USEC;
     tmpfds = conn->sockfds;
@@ -443,7 +443,7 @@
 BOOL nn_network_init(void)
 {
 #ifdef __WIN32
-    /* Initialize WinSock, if needed */
+    // Initialize WinSock, if needed
     WSADATA wsaData;
     int err = WSAStartup(0x0101, &wsaData);
     if (err != 0)
--- a/util.c	Thu May 24 07:34:37 2012 +0300
+++ b/util.c	Thu May 24 07:37:36 2012 +0300
@@ -89,7 +89,7 @@
             break;
 
         case '½':
-            /* Escape these .. */
+            // Escape these ..
             PUSHCHAR('½');
             PUSHCHAR('½');
             s++;
@@ -557,15 +557,15 @@
     uint8_t hash;
     nn_user_t *user;
 
-    /* Check arguments */
+    // Check arguments
     if (list == NULL || name == NULL)
         return -1;
 
-    /* Check if username is already there */
+    // Check if username is already there
     if (nn_user_find(list, name) != NULL)
         return 1;
 
-    /* No, we'll add it */
+    // No, we'll add it
     if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL)
         return -3;
 
@@ -584,11 +584,11 @@
 {
     uint8_t hash;
 
-    /* Check arguments */
+    // Check arguments
     if (list == NULL || name == NULL)
         return -1;
 
-    /* Check if username is already there */
+    // Check if username is already there
     hash = nn_hash_user(name);
     if (list->buckets[hash] != NULL)
     {
@@ -629,7 +629,7 @@
     if ((user = th_calloc(1, sizeof(nn_user_t))) == NULL)
         return NULL;
 
-    /* Copy relevant data */
+    // Copy relevant data
     user->name = th_strdup(src->name);
     user->lastspoke = src->lastspoke;
     user->joined = src->joined;