diff nnchat.c @ 64:6a3a917303e4

Some random cleanups, bring back WinSock support.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Nov 2008 22:33:35 +0200
parents afd90bbb3af6
children e763ef5cfd53
line wrap: on
line diff
--- a/nnchat.c	Tue Nov 11 22:06:07 2008 +0200
+++ b/nnchat.c	Tue Nov 11 22:33:35 2008 +0200
@@ -9,7 +9,11 @@
 #include <string.h>
 #include <errno.h>
 #include <time.h>
+#ifdef __WIN32
+#include <curses.h>
+#else
 #include <ncurses.h>
+#endif
 
 
 #define SET_MAX_BACKBUF (1024)
@@ -492,8 +496,7 @@
 		BOOL isMine = strcmp(p, optUserName) == 0;
 		t = stripXMLTags(s);
 		h = decodeStr2(t);
-		printMsg("½5½<½%d½%s½5½>½%d½ %s½0½\n",
-			isMine ? 14 : 15, p, isMine ? 16 : 0, h);
+		printMsg("½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p, h);
 		th_free(h);
 		th_free(t);
 	}
@@ -741,7 +744,19 @@
 	
 	if (!argsOK)
 		return -2;
-	
+
+
+#ifdef __WIN32
+	{
+	/* Initialize WinSock, if needed */
+	WSADATA wsaData;
+	int err = WSAStartup(0x0200, &wsaData);
+	if (err != 0) {
+		THERR("Could not initialize WinSock DLL: %d\n", err);
+		return -3;
+    }
+#endif
+
 	/* Open logfile */
 	if (optLogFilename) {
 		THMSG(1, "Opening logfile '%s'\n", optLogFilename);
@@ -777,7 +792,7 @@
 		goto err_exit;
 	} else {
 		ssize_t gotBuf;
-		char tmpBuf[4096];
+		char tmpBuf[SET_BUFSIZE];
 		gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
 		tmpBuf[gotBuf-1] = 0;
 		THMSG(2, "Probe got: %s\n", tmpBuf);