Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/pkg_install/lib Indent, and remove some #if 0-ed code.
details: https://anonhg.NetBSD.org/src/rev/2b7f8cba948e
branches: trunk
changeset: 552815:2b7f8cba948e
user: wiz <wiz%NetBSD.org@localhost>
date: Fri Oct 03 19:55:34 2003 +0000
description:
Indent, and remove some #if 0-ed code.
diffstat:
usr.sbin/pkg_install/lib/ftpio.c | 556 +++++++++++++++-----------------------
1 files changed, 217 insertions(+), 339 deletions(-)
diffs (truncated from 671 to 300 lines):
diff -r d63bda3ecb72 -r 2b7f8cba948e usr.sbin/pkg_install/lib/ftpio.c
--- a/usr.sbin/pkg_install/lib/ftpio.c Fri Oct 03 18:46:22 2003 +0000
+++ b/usr.sbin/pkg_install/lib/ftpio.c Fri Oct 03 19:55:34 2003 +0000
@@ -1,8 +1,8 @@
-/* $NetBSD: ftpio.c,v 1.58 2003/10/03 15:40:27 wiz Exp $ */
+/* $NetBSD: ftpio.c,v 1.59 2003/10/03 19:55:34 wiz Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.58 2003/10/03 15:40:27 wiz Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.59 2003/10/03 19:55:34 wiz Exp $");
#endif
/*-
@@ -138,126 +138,126 @@
static int
expect(int fd, const char *str, int *ftprc)
{
- int rc;
- char buf[90];
+ int rc;
+ char buf[90];
#if EXPECT_DEBUG
- char *vstr;
+ char *vstr;
#endif /* EXPECT_DEBUG */
- regex_t rstr;
- int done;
- struct pollfd set[1];
- int retval;
- regmatch_t match;
- int verbose_expect=0;
+ regex_t rstr;
+ int done;
+ struct pollfd set[1];
+ int retval;
+ regmatch_t match;
+ int verbose_expect=0;
#if EXPECT_DEBUG
- vstr=malloc(2*sizeof(buf));
- if (vstr == NULL)
- err(EXIT_FAILURE, "expect: malloc() failed");
- strvis(vstr, str, VIS_NL|VIS_SAFE|VIS_CSTYLE);
+ vstr=malloc(2*sizeof(buf));
+ if (vstr == NULL)
+ err(EXIT_FAILURE, "expect: malloc() failed");
+ strvis(vstr, str, VIS_NL|VIS_SAFE|VIS_CSTYLE);
#endif /* EXPECT_DEBUG */
- if (regcomp(&rstr, str, REG_EXTENDED) != 0)
- err(EXIT_FAILURE, "expect: regcomp() failed");
+ if (regcomp(&rstr, str, REG_EXTENDED) != 0)
+ err(EXIT_FAILURE, "expect: regcomp() failed");
#if EXPECT_DEBUG
- if (expect_debug)
- printf("expecting \"%s\" on fd %d ...\n", vstr, fd);
+ if (expect_debug)
+ printf("expecting \"%s\" on fd %d ...\n", vstr, fd);
#endif /* EXPECT_DEBUG */
- if(0) setbuf(stdout, NULL);
+ if(0) setbuf(stdout, NULL);
- memset(buf, '\n', sizeof(buf));
+ memset(buf, '\n', sizeof(buf));
- done=0;
- retval=0;
- set[0].fd = fd;
- set[0].events = POLLIN;
- while(!done) {
- rc = poll(set, 1, 10*60*1000); /* seconds until next message from tar */
- switch (rc) {
- case -1:
- if (errno == EINTR)
- break;
- warn("expect: poll() failed (probably ftp died because of bad args)");
- done = 1;
- retval = -1;
- break;
- case 0:
- warnx("expect: poll() timeout");
- /* need to send ftp coprocess SIGINT to make it stop
- * downloading into dir that we'll blow away in a second */
- kill(ftp_pid, SIGINT);
+ done=0;
+ retval=0;
+ set[0].fd = fd;
+ set[0].events = POLLIN;
+ while(!done) {
+ rc = poll(set, 1, 10*60*1000); /* seconds until next message from tar */
+ switch (rc) {
+ case -1:
+ if (errno == EINTR)
+ break;
+ warn("expect: poll() failed (probably ftp died because of bad args)");
+ done = 1;
+ retval = -1;
+ break;
+ case 0:
+ warnx("expect: poll() timeout");
+ /* need to send ftp coprocess SIGINT to make it stop
+ * downloading into dir that we'll blow away in a second */
+ kill(ftp_pid, SIGINT);
- /* Wait until ftp coprocess is responsive again
- * XXX Entering recursion here!
- */
- rc = ftp_cmd("cd .\n", "\n(550|250).*\n");
- if (rc != 250) {
- /* now we have a really good reason to bail out ;) */
- }
- /* ftp is at command prompt again, and will wait for our
- * next command. If we were downloading, we can now safely
- * continue and remove the dir that the tar command was
- * expanding to */
+ /* Wait until ftp coprocess is responsive again
+ * XXX Entering recursion here!
+ */
+ rc = ftp_cmd("cd .\n", "\n(550|250).*\n");
+ if (rc != 250) {
+ /* now we have a really good reason to bail out ;) */
+ }
+ /* ftp is at command prompt again, and will wait for our
+ * next command. If we were downloading, we can now safely
+ * continue and remove the dir that the tar command was
+ * expanding to */
- done = 1; /* hope that's ok */
- retval = -1;
- break;
- default:
- if (set[0].revents & POLLHUP) {
- done = 1;
- retval = -1;
- break;
- }
+ done = 1; /* hope that's ok */
+ retval = -1;
+ break;
+ default:
+ if (set[0].revents & POLLHUP) {
+ done = 1;
+ retval = -1;
+ break;
+ }
- rc = read(fd, &buf[sizeof(buf) - 1], 1);
- if (rc <= 0) {
- done = 1;
- retval = -1;
- break;
- }
+ rc = read(fd, &buf[sizeof(buf) - 1], 1);
+ if (rc <= 0) {
+ done = 1;
+ retval = -1;
+ break;
+ }
- if (verbose_expect)
- putchar(buf[sizeof(buf)-1]);
+ if (verbose_expect)
+ putchar(buf[sizeof(buf)-1]);
#if EXPECT_DEBUG
- {
- char *v=malloc(2*sizeof(buf));
- strvis(v, buf, VIS_NL|VIS_SAFE|VIS_CSTYLE);
- if (expect_debug)
- printf("expect=<%s>, buf=<%*s>\n", vstr, strlen(v), v);
- free(v);
- }
+ {
+ char *v=malloc(2*sizeof(buf));
+ strvis(v, buf, VIS_NL|VIS_SAFE|VIS_CSTYLE);
+ if (expect_debug)
+ printf("expect=<%s>, buf=<%*s>\n", vstr, strlen(v), v);
+ free(v);
+ }
#endif /* EXPECT_DEBUG */
- if (regexec(&rstr, buf, 1, &match, 0) == 0) {
+ if (regexec(&rstr, buf, 1, &match, 0) == 0) {
#if EXPECT_DEBUG
- if (expect_debug)
- printf("Gotcha -> %s!\n", buf+match.rm_so+1);
- fflush(stdout);
+ if (expect_debug)
+ printf("Gotcha -> %s!\n", buf+match.rm_so+1);
+ fflush(stdout);
#endif /* EXPECT_DEBUG */
- if (ftprc && isdigit(buf[match.rm_so+1]))
- *ftprc = atoi(buf+match.rm_so+1);
+ if (ftprc && isdigit(buf[match.rm_so+1]))
+ *ftprc = atoi(buf+match.rm_so+1);
- done=1;
- retval=0;
- }
+ done=1;
+ retval=0;
+ }
- memmove(buf, buf+1, sizeof(buf)-1); /* yes, this is non-performant */
- break;
+ memmove(buf, buf+1, sizeof(buf)-1); /* yes, this is non-performant */
+ break;
+ }
}
- }
#if EXPECT_DEBUG
- printf("done.\n");
+ printf("done.\n");
- if (str)
- free(vstr);
+ if (str)
+ free(vstr);
#endif /* EXPECT_DEBUG */
- return retval;
+ return retval;
}
/*
@@ -268,29 +268,29 @@
int
ftp_cmd(const char *cmd, const char *expectstr)
{
- int rc=0, verbose_ftp=0;
- int len;
+ int rc=0, verbose_ftp=0;
+ int len;
- if (Verbose)
- verbose_ftp=1;
+ if (Verbose)
+ verbose_ftp=1;
- if (verbose_ftp)
- fprintf(stderr, "\n%sftp> %s%s", bold_on, cmd, bold_off);
+ if (verbose_ftp)
+ fprintf(stderr, "\n%sftp> %s%s", bold_on, cmd, bold_off);
- fflush(stdout);
- len = write(ftpio.command, cmd, strlen(cmd));
- if (len == strlen(cmd)) {
- if (expectstr) {
- /* set "rc" to the FTP error code: */
- if (expect(ftpio.answer, expectstr, &rc) == -1)
- rc = -1; /* some error occurred */
- }
- } else {
- if (Verbose)
- warn("short write");
- }
+ fflush(stdout);
+ len = write(ftpio.command, cmd, strlen(cmd));
+ if (len == strlen(cmd)) {
+ if (expectstr) {
+ /* set "rc" to the FTP error code: */
+ if (expect(ftpio.answer, expectstr, &rc) == -1)
+ rc = -1; /* some error occurred */
+ }
+ } else {
+ if (Verbose)
+ warn("short write");
+ }
- return rc;
+ return rc;
}
@@ -300,85 +300,85 @@
static int
setupCoproc(const char *base)
{
- int command_pipe[2];
- int answer_pipe[2];
- int rc1, rc2;
- char buf[20];
- char *argv0 = strrchr(FTP_CMD, '/');
- if (argv0 == NULL)
- argv0 = FTP_CMD;
- else
- argv0++;
+ int command_pipe[2];
+ int answer_pipe[2];
+ int rc1, rc2;
+ char buf[20];
+ char *argv0 = strrchr(FTP_CMD, '/');
+ if (argv0 == NULL)
+ argv0 = FTP_CMD;
+ else
Home |
Main Index |
Thread Index |
Old Index