]> git.pond.sub.org Git - empserver/blobdiff - src/client/expect.c
(expect): Simplify, no functional change.
[empserver] / src / client / expect.c
index 7e27b515df39e9b4c37ea2eba81055c3e604f941..4d29a53697c212887cd61b4d9f27b86f8b5ef540 100644 (file)
@@ -45,6 +45,7 @@
 #include <unistd.h>
 #endif
 #include "misc.h"
+#include "proto.h"
 
 #ifdef _WIN32
 #define read(sock, buffer, buf_size) \
@@ -82,19 +83,29 @@ recvline(int s, char *buf)
 
     *bp++ = ch;
     *bp = 0;
+    return parseid(buf);
+}
+
+int
+parseid(char *line)
+{
+    char *end;
+    long id;
 
-    if (!isxdigit(buf[0]) || buf[1] != ' ') {
-       fprintf(stderr, "Malformed line %s\n", buf);
-       return 0;
+    id = strtol(line, &end, 16);
+    if (end == line || *end != ' ') {
+       fprintf(stderr, "Malformed id in line %s", line);
+       id = -1;
     }
-    return strtol(buf, NULL, 16);
+    if (id > C_LAST)
+       id = -1;
+    return id;
 }
 
 int
 expect(int s, int match, char *buf)
 {
-    int code = recvline(s, buf);
-    return code == match;
+    return recvline(s, buf) == match;
 }
 
 void