(parseid): New, factored out of recvline() and recv_output().
(recvline, recv_output): Use it.
This commit is contained in:
parent
c9c9305c2f
commit
225f0f5132
3 changed files with 17 additions and 14 deletions
|
@ -58,10 +58,9 @@ 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 +83,18 @@ recvline(int s, char *buf)
|
|||
|
||||
*bp++ = ch;
|
||||
*bp = 0;
|
||||
return parseid(buf);
|
||||
}
|
||||
|
||||
id = strtol(buf, &end, 16);
|
||||
if (end == buf || *end != ' ') {
|
||||
fprintf(stderr, "Malformed id in line %s", buf);
|
||||
int
|
||||
parseid(char *line)
|
||||
{
|
||||
char *end;
|
||||
long id;
|
||||
|
||||
id = strtol(line, &end, 16);
|
||||
if (end == line || *end != ' ') {
|
||||
fprintf(stderr, "Malformed id in line %s", line);
|
||||
id = -1;
|
||||
}
|
||||
if (id > C_LAST)
|
||||
|
|
|
@ -57,6 +57,7 @@ void putso(void);
|
|||
void putse(void);
|
||||
#endif
|
||||
int recvline(int s, char *buf);
|
||||
int parseid(char *);
|
||||
int expect(int s, int match, char *buf);
|
||||
int tcp_connect(char *, char *);
|
||||
int login(int s, char *uname, char *cname, char *cpass, int kill_proc, int);
|
||||
|
|
|
@ -322,7 +322,7 @@ recv_output(int sock)
|
|||
char buf[4096];
|
||||
ssize_t n;
|
||||
int i, ch, len;
|
||||
char *line, *end;
|
||||
char *line;
|
||||
|
||||
n = read(sock, buf, sizeof(buf));
|
||||
if (n < 0)
|
||||
|
@ -337,16 +337,11 @@ recv_output(int sock)
|
|||
lbuf_init(&lbuf);
|
||||
break;
|
||||
}
|
||||
if (ch != ' ') {
|
||||
lbuf_putc(&lbuf, ch);
|
||||
lbuf_putc(&lbuf, ch);
|
||||
if (ch != ' ')
|
||||
break;
|
||||
}
|
||||
line = lbuf_line(&lbuf);
|
||||
id = strtol(line, &end, 16);
|
||||
if (end == line || *end) {
|
||||
/* FIXME gripe bad id */
|
||||
id = -1;
|
||||
}
|
||||
id = parseid(line);
|
||||
lbuf_init(&lbuf);
|
||||
|
||||
switch (id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue