]> git.pond.sub.org Git - empserver/commitdiff
(servercmd, io_gets, output): Fix client to read lines longer than
authorRon Koenderink <rkoenderink@yahoo.ca>
Sat, 12 Nov 2005 14:20:46 +0000 (14:20 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Sat, 12 Nov 2005 14:20:46 +0000 (14:20 +0000)
1024 bytes from the server.  Closes #1223255.

src/client/ioqueue.c
src/client/ioqueue.h
src/client/servcmd.c

index 681857fb91b92c495b40bdc7819bc4f0a1ef2316..7d175ebcff55e566ada780b283bf1233e204014a 100644 (file)
@@ -111,23 +111,31 @@ ioq_drain(struct ioqueue *ioq)
 }
 
 char *
-ioq_gets(struct ioqueue *ioq, char *buf, int cc)
+ioq_gets(struct ioqueue *ioq, char *buf, int cc, int *eol)
 {
     char *p;
     char *end;
     int nbytes;
 
+    *eol = 0;
+
+    cc--;
+
     nbytes = ioqtobuf(ioq, buf, cc);
-    if (nbytes < cc)
-       cc = nbytes;
-    end = &buf[cc];
+    end = &buf[nbytes];
     for (p = buf; p < end && *p; p++) {
        if (*p == '\n') {
            *p = '\0';
+           *eol = 1;
            dequeuecc(ioq, (p - buf) + 1);
            return buf;
        }
     }
+    if (cc && (p - buf) == cc) {
+       dequeuecc(ioq, cc);
+       buf[cc] = '\0';
+       return buf;
+    }
     return NULL;
 }
 
index da6ae4cbff95feb15038df1e2f3716d5d08253ef..650022b653e9c4c2dab542e1541d05332f3e6269 100644 (file)
@@ -52,4 +52,4 @@ int ioq_read(struct ioqueue *ioq, char *buf, int cc);
 void ioq_write(struct ioqueue *ioq, char *buf, int cc);
 int ioq_qsize(struct ioqueue *ioq);
 void ioq_drain(struct ioqueue *ioq);
-char *ioq_gets(struct ioqueue *ioq, char *buf, int cc);
+char *ioq_gets(struct ioqueue *ioq, char *buf, int cc, int *eol);
index 47f1ecc1489c9f88dc058bfae340349e23a95a15..7e002fbc1a58e6a0635d8b918a5c92a492c98f99 100644 (file)
@@ -62,7 +62,7 @@ static void prompt(FILE *auxfi);
 static void doredir(char *p);
 static void dopipe(char *p);
 static void doexecute(char *p, FILE *auxfi);
-static void output(int code, char *buf, FILE *auxfi);
+static void output(int code, char *buf, FILE *auxfi, int eol);
 static void screen(char *buf);
 
 void
@@ -70,17 +70,20 @@ servercmd(struct ioqueue *ioq, FILE *auxfi)
 {
     char buf[1024];
     char *p;
-    int code;
+    static int code = -1;
+    int eol;
 
-    while (ioq_gets(ioq, buf, sizeof(buf))) {
+    while (ioq_gets(ioq, buf, sizeof(buf), &eol)) {
        p = buf;
-       while (*p && !isspace(*p))
-           p++;
-       *p++ = 0;
-       if (isalpha(*buf))
-           code = 10 + (*buf - 'a');
-       else
-           code = *buf - '0';
+       if (code == -1) {
+           if (isalpha(*buf))
+               code = 10 + (*buf - 'a');
+           else
+               code = *buf - '0';
+           while (*p && !isspace(*p))
+               p++;
+           *p++ = 0;
+       }
        switch (code) {
        case C_PROMPT:
            if (sscanf(p, "%d %d", &nmin, &nbtu) != 2) {
@@ -116,9 +119,11 @@ servercmd(struct ioqueue *ioq, FILE *auxfi)
                *num_teles = '\0';
            break;
        default:
-           output(code, p, auxfi);
+           output(code, p, auxfi, eol);
            break;
        }
+       if (eol)
+           code = -1;
     }
 }
 
@@ -270,7 +275,7 @@ doexecute(char *p, FILE *auxfi)
 }
 
 static void
-output(int code, char *buf, FILE *auxfi)
+output(int code, char *buf, FILE *auxfi, int eol)
 {
     switch (code) {
     case C_NOECHO:
@@ -307,19 +312,19 @@ output(int code, char *buf, FILE *auxfi)
        fprintf(auxfi, "%s", buf);
        if (code == C_FLUSH)
            (void)fflush(auxfi);
-       else
+       else if (eol)
            (void)putc('\n', auxfi);
     }
 
     if (redir_fp)
-       fprintf(redir_fp, "%s\n", buf);
+       fprintf(redir_fp, "%s%s", buf, eol ? "\n" : "");
     else if (pipe_fp)
-       fprintf(pipe_fp, "%s\n", buf);
+       fprintf(pipe_fp, eol ? "%s\n": "%s", buf);
     else {
        screen(buf);
        if (code == C_FLUSH)
            (void)fflush(stdout);
-       else
+       else if (eol)
            (void)putc('\n', stdout);
     }
 }