]> git.pond.sub.org Git - empserver/blobdiff - src/client/expect.c
Use src/lib/w32/w32sockets.c for client
[empserver] / src / client / expect.c
index cb0e9571ce2d9f370a6eb459ae50a3ad3cec2041..50aa789161f7278fb1b85f62bfe7334c95951d1e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  expect.c: Read from the socket, expecting to see a particular code.
- * 
+ *
  *  Known contributors to this file:
  *      Steve McClure, 1998
  *      Markus Armbruster, 2007
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef _WIN32
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <unistd.h>
-#endif
 #include "misc.h"
 #include "proto.h"
 
-#ifdef _WIN32
-#define read(sock, buffer, buf_size) \
-       w32_recv((sock), (buffer), (buf_size), 0)
-#define write(sock, buffer, buf_size) \
-       w32_send((sock), (buffer), (buf_size), 0)
-#endif
-
 int
 recvline(int s, char *buf)
 {
     int sz = 1024;
-    char *bp, *end;
+    char *bp;
     char ch;
     ssize_t n;
-    long id;
 
     bp = buf;
     for (;;) {
@@ -84,10 +74,18 @@ recvline(int s, char *buf)
 
     *bp++ = ch;
     *bp = 0;
+    return parseid(buf);
+}
+
+int
+parseid(char *line)
+{
+    char *end;
+    long id;
 
-    id = strtol(buf, &end, 16);
-    if (end == buf || *end != ' ') {
-       fprintf(stderr, "Malformed id in line %s", buf);
+    id = strtol(line, &end, 36);
+    if (end == line || *end != ' ') {
+       fprintf(stderr, "Malformed id in line %s", line);
        id = -1;
     }
     if (id > C_LAST)
@@ -98,8 +96,7 @@ recvline(int s, char *buf)
 int
 expect(int s, int match, char *buf)
 {
-    int code = recvline(s, buf);
-    return code == match;
+    return recvline(s, buf) == match;
 }
 
 void