]> git.pond.sub.org Git - empserver/blobdiff - src/client/expect.c
Update copyright notice.
[empserver] / src / client / expect.c
index 6a82a8da306c60ab952cb90bca5b79da1233b6bd..84a9bb7d87d1916de30bbe14654d61cf815da04e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *      Steve McClure, 1998
  */
 
-#include "misc.h"
+#include <config.h>
 
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
 #ifndef _WIN32
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <unistd.h>
-#else
-#include <winsock.h>
 #endif
+#include "misc.h"
 
 int
-expect(int s, int match, char *buf)
+recvline(int s, char *buf)
 {
     int size;
     char *p;
@@ -62,7 +61,6 @@ expect(int s, int match, char *buf)
     ptr = buf;
     n = recv(s, ptr, size, MSG_PEEK);
     if (n <= 0) {
-       fprintf(stderr, "Expecting code %d\n", match);
 #ifdef _WIN32
        errno = WSAGetLastError();
 #endif
@@ -91,7 +89,10 @@ expect(int s, int match, char *buf)
            }
            ptr += n;
            if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) {
-               fprintf(stderr, "Expecting %d, got %s\n", match, buf);
+#ifdef _WIN32
+               errno = WSAGetLastError();
+#endif
+               perror("recv");
                return 0;
            }
            size -= n;
@@ -123,7 +124,7 @@ expect(int s, int match, char *buf)
     (void)alarm(0);
 #endif
     if (!isxdigit(*buf)) {
-       fprintf(stderr, "Expecting %d, got %s\n", match, buf);
+       fprintf(stderr, "Malformed line %s\n", buf);
        return 0;
     }
     if (isdigit(*buf))
@@ -133,9 +134,14 @@ expect(int s, int match, char *buf)
            *buf = tolower(*buf);
        code = 10 + *buf - 'a';
     }
-    if (code == match)
-       return 1;
-    return 0;
+    return code;
+}
+
+int
+expect(int s, int match, char *buf)
+{
+    int code = recvline(s, buf);
+    return code == match;
 }
 
 void