clean up NO_QUAD support: create helper #defines and use as appropriate:

#define		NOQUAD		! NOQUAD
	-------		------		- ------
	QUADF		"%ld"		"%lld"
	QUADFP(x)	"%" x "ld"	"%" x "lld"
	QUADT		long		long long
	STRTOL(x,y,z)	strtol(x,y,z)	strtoll(x,y,z)
This commit is contained in:
lukem 2000-07-30 04:42:37 +00:00
parent b5e3ec56a8
commit 241987dc61
6 changed files with 63 additions and 147 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.88 2000/07/18 07:16:52 lukem Exp $ */ /* $NetBSD: cmds.c,v 1.89 2000/07/30 04:42:37 lukem Exp $ */
/*- /*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc. * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -107,7 +107,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else #else
__RCSID("$NetBSD: cmds.c,v 1.88 2000/07/18 07:16:52 lukem Exp $"); __RCSID("$NetBSD: cmds.c,v 1.89 2000/07/30 04:42:37 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -2302,11 +2302,7 @@ restart(int argc, char *argv[])
off_t rp; off_t rp;
char *ep; char *ep;
#ifndef NO_QUAD rp = STRTOLL(argv[1], &ep, 10);
rp = strtoll(argv[1], &ep, 10);
#else
rp = strtol(argv[1], &ep, 10);
#endif
if (rp < 0 || *ep != '\0') if (rp < 0 || *ep != '\0')
fprintf(ttyout, "restart: Invalid offset `%s'\n", fprintf(ttyout, "restart: Invalid offset `%s'\n",
argv[1]); argv[1]);
@ -2317,13 +2313,8 @@ restart(int argc, char *argv[])
fputs("No restart point defined.\n", ttyout); fputs("No restart point defined.\n", ttyout);
else else
fprintf(ttyout, fprintf(ttyout,
#ifndef NO_QUAD "Restarting at " QUADF " for next get, put or append\n",
"Restarting at %lld for next get, put or append\n", (QUADT)restart_point);
(long long)restart_point);
#else
"Restarting at %ld for next get, put or append\n",
(long)restart_point);
#endif
} }
/* /*
@ -2425,11 +2416,7 @@ sizecmd(int argc, char *argv[])
size = remotesize(argv[1], 1); size = remotesize(argv[1], 1);
if (size != -1) if (size != -1)
fprintf(ttyout, fprintf(ttyout,
#ifndef NO_QUAD "%s\t" QUADF "\n", argv[1], (QUADT)size);
"%s\t%lld\n", argv[1], (long long)size);
#else
"%s\t%ld\n", argv[1], (long)size);
#endif
code = (size > 0); code = (size > 0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.118 2000/07/18 06:49:21 lukem Exp $ */ /* $NetBSD: fetch.c,v 1.119 2000/07/30 04:42:37 lukem Exp $ */
/*- /*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc. * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: fetch.c,v 1.118 2000/07/18 06:49:21 lukem Exp $"); __RCSID("$NetBSD: fetch.c,v 1.119 2000/07/30 04:42:37 lukem Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -562,13 +562,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (verbose) { if (verbose) {
fprintf(ttyout, "Copying %s", decodedpath); fprintf(ttyout, "Copying %s", decodedpath);
if (restart_point) if (restart_point)
#ifndef NO_QUAD fprintf(ttyout, " (restarting at " QUADF ")",
fprintf(ttyout, " (restarting at %lld)", (QUADT)restart_point);
(long long)restart_point);
#else
fprintf(ttyout, " (restarting at %ld)",
(long)restart_point);
#endif
fputs("\n", ttyout); fputs("\n", ttyout);
} }
} else { /* ftp:// or http:// URLs */ } else { /* ftp:// or http:// URLs */
@ -813,17 +808,10 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
fprintf(fin, "Connection: close\r\n"); fprintf(fin, "Connection: close\r\n");
if (restart_point) { if (restart_point) {
fputs(leading, ttyout); fputs(leading, ttyout);
#ifndef NO_QUAD fprintf(fin, "Range: bytes=" QUADF "-\r\n",
fprintf(fin, "Range: bytes=%lld-\r\n", (QUADT)restart_point);
(long long)restart_point); fprintf(ttyout, "restarting at " QUADF,
fprintf(ttyout, "restarting at %lld", (QUADT)restart_point);
(long long)restart_point);
#else
fprintf(fin, "Range: bytes=%ld-\r\n",
(long)restart_point);
fprintf(ttyout, "restarting at %ld",
(long)restart_point);
#endif
leading = ", "; leading = ", ";
hasleading++; hasleading++;
} }
@ -901,67 +889,38 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (strncasecmp(cp, CONTENTLEN, if (strncasecmp(cp, CONTENTLEN,
sizeof(CONTENTLEN) - 1) == 0) { sizeof(CONTENTLEN) - 1) == 0) {
cp += sizeof(CONTENTLEN) - 1; cp += sizeof(CONTENTLEN) - 1;
#ifndef NO_QUAD filesize = STRTOLL(cp, &ep, 10);
filesize = strtoll(cp, &ep, 10);
#else
filesize = strtol(cp, &ep, 10);
#endif
if (filesize < 0 || *ep != '\0') if (filesize < 0 || *ep != '\0')
goto improper; goto improper;
if (debug) if (debug)
#ifndef NO_QUAD fprintf(ttyout,
fprintf(ttyout, "parsed len as: %lld\n", "parsed len as: " QUADF "\n",
(long long)filesize); (QUADT)filesize);
#else
fprintf(ttyout, "parsed len as: %ld\n",
(long)filesize);
#endif
#define CONTENTRANGE "Content-Range: bytes " #define CONTENTRANGE "Content-Range: bytes "
} else if (strncasecmp(cp, CONTENTRANGE, } else if (strncasecmp(cp, CONTENTRANGE,
sizeof(CONTENTRANGE) - 1) == 0) { sizeof(CONTENTRANGE) - 1) == 0) {
cp += sizeof(CONTENTRANGE) - 1; cp += sizeof(CONTENTRANGE) - 1;
#ifndef NO_QUAD rangestart = STRTOLL(cp, &ep, 10);
rangestart = strtoll(cp, &ep, 10);
#else
rangestart = strtol(cp, &ep, 10);
#endif
if (rangestart < 0 || *ep != '-') if (rangestart < 0 || *ep != '-')
goto improper; goto improper;
cp = ep + 1; cp = ep + 1;
rangeend = STRTOLL(cp, &ep, 10);
#ifndef NO_QUAD
rangeend = strtoll(cp, &ep, 10);
#else
rangeend = strtol(cp, &ep, 10);
#endif
if (rangeend < 0 || *ep != '/' || if (rangeend < 0 || *ep != '/' ||
rangeend < rangestart) rangeend < rangestart)
goto improper; goto improper;
cp = ep + 1; cp = ep + 1;
entitylen = STRTOLL(cp, &ep, 10);
#ifndef NO_QUAD
entitylen = strtoll(cp, &ep, 10);
#else
entitylen = strtol(cp, &ep, 10);
#endif
if (entitylen < 0 || *ep != '\0') if (entitylen < 0 || *ep != '\0')
goto improper; goto improper;
if (debug) if (debug)
#ifndef NO_QUAD
fprintf(ttyout, fprintf(ttyout,
"parsed range as: %lld-%lld/%lld\n", "parsed range as: "
(long long)rangestart, QUADF "-" QUADF "/" QUADF "\n",
(long long)rangeend, (QUADT)rangestart,
(long long)entitylen); (QUADT)rangeend,
#else (QUADT)entitylen);
fprintf(ttyout,
"parsed range as: %ld-%ld/%ld\n",
(long)rangestart,
(long)rangeend,
(long)entitylen);
#endif
if (! restart_point) { if (! restart_point) {
warnx( warnx(
"Received unexpected Content-Range header"); "Received unexpected Content-Range header");
@ -1217,14 +1176,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
goto cleanup_fetch_url; goto cleanup_fetch_url;
} }
if (debug) if (debug)
fprintf(ttyout, fprintf(ttyout, "got chunksize of " QUADF "\n",
#ifndef NO_QUAD (QUADT)chunksize);
"got chunksize of %lld\n",
(long long)chunksize);
#else
"got chunksize of %ld\n",
(long)chunksize);
#endif
if (chunksize == 0) if (chunksize == 0)
break; break;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp.c,v 1.102 2000/07/18 07:16:54 lukem Exp $ */ /* $NetBSD: ftp.c,v 1.103 2000/07/30 04:42:37 lukem Exp $ */
/*- /*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc. * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -103,7 +103,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else #else
__RCSID("$NetBSD: ftp.c,v 1.102 2000/07/18 07:16:54 lukem Exp $"); __RCSID("$NetBSD: ftp.c,v 1.103 2000/07/30 04:42:37 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -819,12 +819,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
warn("local: %s", local); warn("local: %s", local);
goto cleanupsend; goto cleanupsend;
} }
#ifndef NO_QUAD if (command("REST " QUADF, (QUADT)restart_point) != CONTINUE)
if (command("REST %lld", (long long) restart_point) !=
#else
if (command("REST %ld", (long) restart_point) !=
#endif
CONTINUE)
goto cleanupsend; goto cleanupsend;
lmode = "r+w"; lmode = "r+w";
} }
@ -1128,11 +1123,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
if (sigsetjmp(xferabort, 1)) if (sigsetjmp(xferabort, 1))
goto abort; goto abort;
if (is_retr && restart_point && if (is_retr && restart_point &&
#ifndef NO_QUAD command("REST " QUADF, (QUADT) restart_point) != CONTINUE)
command("REST %lld", (long long) restart_point) != CONTINUE)
#else
command("REST %ld", (long) restart_point) != CONTINUE)
#endif
goto cleanuprecv; goto cleanuprecv;
if (! EMPTYSTRING(remote)) { if (! EMPTYSTRING(remote)) {
if (command("%s %s", cmd, remote) != PRELIM) if (command("%s %s", cmd, remote) != PRELIM)
@ -1981,12 +1972,8 @@ proxtrans(const char *cmd, const char *local, const char *remote)
goto abort; goto abort;
oldintr = xsignal(SIGINT, abortpt); oldintr = xsignal(SIGINT, abortpt);
if ((restart_point && if ((restart_point &&
#ifndef NO_QUAD (command("REST " QUADF, (QUADT) restart_point) != CONTINUE))
(command("REST %lld", (long long) restart_point) != CONTINUE) || (command("%s %s", cmd, remote) != PRELIM)) {
#else
(command("REST %ld", (long) restart_point) != CONTINUE)
#endif
) || (command("%s %s", cmd, remote) != PRELIM)) {
(void)xsignal(SIGINT, oldintr); (void)xsignal(SIGINT, oldintr);
pswitch(1); pswitch(1);
return; return;
@ -1995,12 +1982,8 @@ proxtrans(const char *cmd, const char *local, const char *remote)
pswitch(1); pswitch(1);
secndflag++; secndflag++;
if ((restart_point && if ((restart_point &&
#ifndef NO_QUAD (command("REST " QUADF, (QUADT) restart_point) != CONTINUE))
(command("REST %lld", (long long) restart_point) != CONTINUE) || (command("%s %s", cmd2, local) != PRELIM))
#else
(command("REST %ld", (long) restart_point) != CONTINUE)
#endif
) || (command("%s %s", cmd2, local) != PRELIM))
goto abort; goto abort;
ptflag++; ptflag++;
(void)getreply(0); (void)getreply(0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.56 2000/07/28 11:03:13 lukem Exp $ */ /* $NetBSD: ftp_var.h,v 1.57 2000/07/30 04:42:38 lukem Exp $ */
/*- /*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc. * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -337,3 +337,16 @@ extern char *__progname; /* from crt0.o */
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) #define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
#define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; } #define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; }
#ifdef NO_QUAD
# define QUADF "%ld"
# define QUADFP(x) "%" x "ld"
# define QUADT long
# define STRTOLL(x,y,z) strtol(x,y,z)
#else
# define QUADF "%lld"
# define QUADFP(x) "%" x "lld"
# define QUADT long long
# define STRTOLL(x,y,z) strtoll(x,y,z)
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.97 2000/07/18 07:16:56 lukem Exp $ */ /* $NetBSD: util.c,v 1.98 2000/07/30 04:42:38 lukem Exp $ */
/*- /*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc. * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: util.c,v 1.97 2000/07/18 07:16:56 lukem Exp $"); __RCSID("$NetBSD: util.c,v 1.98 2000/07/30 04:42:38 lukem Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -655,11 +655,7 @@ remotesize(const char *file, int noisy)
cp = strchr(reply_string, ' '); cp = strchr(reply_string, ' ');
if (cp != NULL) { if (cp != NULL) {
cp++; cp++;
#ifndef NO_QUAD size = STRTOLL(cp, &ep, 10);
size = strtoll(cp, &ep, 10);
#else
size = strtol(cp, &ep, 10);
#endif
if (*ep != '\0' && !isspace((unsigned char)*ep)) if (*ep != '\0' && !isspace((unsigned char)*ep))
size = -1; size = -1;
} }
@ -938,12 +934,8 @@ progressmeter(int flag)
abbrevsize = cursize; abbrevsize = cursize;
for (i = 0; abbrevsize >= 100000 && i < sizeof(prefixes); i++) for (i = 0; abbrevsize >= 100000 && i < sizeof(prefixes); i++)
abbrevsize >>= 10; abbrevsize >>= 10;
len += snprintf(buf + len, BUFLEFT, len += snprintf(buf + len, BUFLEFT, " " QUADFP("5") " %c%c ",
#ifndef NO_QUAD (QUADT)abbrevsize,
" %5lld %c%c ", (long long)abbrevsize,
#else
" %5ld %c%c ", (long)abbrevsize,
#endif
prefixes[i], prefixes[i],
i == 0 ? ' ' : 'B'); i == 0 ? ' ' : 'B');
@ -959,11 +951,8 @@ progressmeter(int flag)
for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++) for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++)
bytespersec >>= 10; bytespersec >>= 10;
len += snprintf(buf + len, BUFLEFT, len += snprintf(buf + len, BUFLEFT,
#ifndef NO_QUAD " " QUADFP("3") ".%02d %cB/s ",
" %3lld.%02d %cB/s ", (long long)bytespersec / 1024, (QUADT)(bytespersec / 1024),
#else
" %3ld.%02d %cB/s ", (long)bytespersec / 1024,
#endif
(int)((bytespersec % 1024) * 100 / 1024), (int)((bytespersec % 1024) * 100 / 1024),
prefixes[i]); prefixes[i]);
@ -1032,13 +1021,8 @@ ptransfer(int siginfo)
bytespersec /= elapsed; bytespersec /= elapsed;
} }
len = 0; len = 0;
len += snprintf(buf + len, BUFLEFT, len += snprintf(buf + len, BUFLEFT, QUADF " byte%s %s in ",
#ifndef NO_QUAD (QUADT)bytes, bytes == 1 ? "" : "s", direction);
"%lld byte%s %s in ", (long long)bytes,
#else
"%ld byte%s %s in ", (long)bytes,
#endif
bytes == 1 ? "" : "s", direction);
remaining = (int)elapsed; remaining = (int)elapsed;
if (remaining > SECSPERDAY) { if (remaining > SECSPERDAY) {
int days; int days;
@ -1057,12 +1041,8 @@ ptransfer(int siginfo)
for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++) for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++)
bytespersec >>= 10; bytespersec >>= 10;
len += snprintf(buf + len, BUFLEFT, len += snprintf(buf + len, BUFLEFT, "(" QUADF ".%02d %cB/s)",
#ifndef NO_QUAD (QUADT)(bytespersec / 1024),
"(%lld.%02d %cB/s)", (long long)bytespersec / 1024,
#else
"(%ld.%02d %cB/s)", (long)bytespersec / 1024,
#endif
(int)((bytespersec % 1024) * 100 / 1024), (int)((bytespersec % 1024) * 100 / 1024),
prefixes[i]); prefixes[i]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.16 2000/07/28 12:01:40 lukem Exp $ */ /* $NetBSD: version.h,v 1.17 2000/07/30 04:42:38 lukem Exp $ */
/*- /*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
@ -40,5 +40,5 @@
#endif #endif
#ifndef FTP_VERSION #ifndef FTP_VERSION
#define FTP_VERSION "20000728" #define FTP_VERSION "20000730"
#endif #endif