Indented with src/scripts/indent-emp.

This commit is contained in:
Markus Armbruster 2003-09-02 20:48:48 +00:00
parent 5f263a7753
commit 9b7adfbecc
437 changed files with 52211 additions and 51052 deletions

View file

@ -47,129 +47,126 @@
int
expect(s, match, buf)
int s;
int match;
s_char *buf;
int s;
int match;
s_char *buf;
{
int size;
s_char *p;
int n;
int code;
int newline;
s_char *ptr;
int cc;
int size;
s_char *p;
int n;
int code;
int newline;
s_char *ptr;
int cc;
size = 1024;
size = 1024;
#ifndef _WIN32
(void) alarm(30);
(void)alarm(30);
#endif
ptr = buf;
n = recv(s, ptr, size, MSG_PEEK);
if (n <= 0) {
fprintf(stderr, "Expecting code %d\n", match);
ptr = buf;
n = recv(s, ptr, size, MSG_PEEK);
if (n <= 0) {
fprintf(stderr, "Expecting code %d\n", match);
#ifdef _WIN32
errno = WSAGetLastError();
errno = WSAGetLastError();
#endif
perror("recv");
return 0;
}
size -= n;
buf[n] = '\0';
if ((p = strchr(ptr, '\n')) == 0) {
do {
perror("recv");
return 0;
}
size -= n;
buf[n] = '\0';
if ((p = strchr(ptr, '\n')) == 0) {
do {
#ifndef _WIN32
cc = read(s, ptr, n);
cc = read(s, ptr, n);
#else
cc = recv(s, ptr, n, 0);
cc = recv(s, ptr, n, 0);
#endif
if (cc < 0) {
if (cc < 0) {
#ifdef _WIN32
errno = WSAGetLastError();
#endif
perror("expect: read");
return 0;
}
if (cc != n) {
fprintf(stderr,
"expect: short read (%d not %d)\n",
cc, n);
return 0;
}
ptr += n;
if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) {
fprintf(stderr, "Expecting %d, got %s\n",
match, buf);
return 0;
}
size -= n;
ptr[n] = '\0';
} while ((p = index(ptr, '\n')) == 0);
newline = 1 + p - buf;
*p = 0;
} else
newline = 1 + p - ptr;
#ifndef _WIN32
cc = read(s, buf, newline);
#else
cc = recv(s, buf, newline, 0);
#endif
if (cc < 0) {
#ifdef _WIN32
errno = WSAGetLastError();
#endif
perror("expect: read #2");
perror("expect: read");
return 0;
}
if (cc != newline) {
fprintf(stderr, "expect: short read #2 (%d not %d)\n",
cc, newline);
}
if (cc != n) {
fprintf(stderr, "expect: short read (%d not %d)\n", cc, n);
return 0;
}
buf[newline] = '\0';
#ifndef _WIN32
(void) alarm(0);
#endif
if (!isxdigit(*buf)) {
}
ptr += n;
if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) {
fprintf(stderr, "Expecting %d, got %s\n", match, buf);
return 0;
}
if (isdigit(*buf))
code = *buf - '0';
else {
if (isupper(*buf))
*buf = tolower(*buf);
code = 10 + *buf - 'a';
}
if (code == match)
return 1;
}
size -= n;
ptr[n] = '\0';
} while ((p = index(ptr, '\n')) == 0);
newline = 1 + p - buf;
*p = 0;
} else
newline = 1 + p - ptr;
#ifndef _WIN32
cc = read(s, buf, newline);
#else
cc = recv(s, buf, newline, 0);
#endif
if (cc < 0) {
#ifdef _WIN32
errno = WSAGetLastError();
#endif
perror("expect: read #2");
return 0;
}
if (cc != newline) {
fprintf(stderr, "expect: short read #2 (%d not %d)\n",
cc, newline);
return 0;
}
buf[newline] = '\0';
#ifndef _WIN32
(void)alarm(0);
#endif
if (!isxdigit(*buf)) {
fprintf(stderr, "Expecting %d, got %s\n", match, buf);
return 0;
}
if (isdigit(*buf))
code = *buf - '0';
else {
if (isupper(*buf))
*buf = tolower(*buf);
code = 10 + *buf - 'a';
}
if (code == match)
return 1;
return 0;
}
void
sendcmd(s, cmd, arg)
int s;
int cmd;
s_char *arg;
int s;
int cmd;
s_char *arg;
{
extern struct fn fnlist[];
s_char buf[128];
int cc;
int len;
extern struct fn fnlist[];
s_char buf[128];
int cc;
int len;
(void) sprintf(buf, "%s %s\n", fnlist[cmd].name, arg != 0 ? arg : "");
len = strlen(buf);
(void)sprintf(buf, "%s %s\n", fnlist[cmd].name, arg != 0 ? arg : "");
len = strlen(buf);
#ifndef _WIN32
cc = write(s, buf, len);
cc = write(s, buf, len);
#else
cc = send(s, buf, len, 0);
cc = send(s, buf, len, 0);
#endif
if (cc < 0) {
if (cc < 0) {
#ifdef _WIN32
errno = WSAGetLastError();
errno = WSAGetLastError();
#endif
perror("sendcmd: write");
}
if (cc != len) {
fprintf(stderr, "sendcmd: short write (%d not %d)\n", cc, len);
}
perror("sendcmd: write");
}
if (cc != len) {
fprintf(stderr, "sendcmd: short write (%d not %d)\n", cc, len);
}
}