*BSD News Article 40277


Return to BSD News archive

Xref: sserve comp.os.386bsd.development:2981 comp.unix.bsd:15824
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!newsserver.trl.OZ.AU!huon!lukem
From: lukem@melb.cpr.itg.telecom.com.au (Luke Mewburn)
Newsgroups: comp.os.386bsd.development,comp.unix.bsd
Subject: adding a `mark' option to ftp
Date: 3 Jan 95 06:22:14 GMT
Organization: Telecom Research Laboratories, Melbourne, Australia.
Lines: 363
Message-ID: <lukem.789114134@huon>
Reply-To: lm@cpr.itg.telecom.com.au
NNTP-Posting-Host: 144.136.63.213
X-Newsreader: NN version 6.5.0 #2 (NOV)

The following patch (relative to NetBSD-current, mid december)
added a `mark' option to ftp. This allows you to change (from
the default of 1024) the number of bytes to be received before
a `#' is printed when `hash' is on.

There's also a couple of minor `cleanups' to tame gcc -Wall,
although I gave up on this after a while.

The patches _should_ apply rather painlessly against any
4.4BSD-lite or derived source.

Luke.


diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/cmds.c ./cmds.c
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/cmds.c	Thu Dec 15 22:23:00 1994
--- ./cmds.c	Tue Jan  3 17:02:25 1995
***************
*** 511,517 ****
  		return;
  	}
  	for (i = 1; i < argc; i++) {
! 		char **cpp, **gargs;
  		glob_t gl;
  		int flags;
  
--- 511,517 ----
  		return;
  	}
  	for (i = 1; i < argc; i++) {
! 		char **cpp;
  		glob_t gl;
  		int flags;
  
***************
*** 741,747 ****
  		if (mflag && confirm(argv[0], cp)) {
  			tp = cp;
  			if (mcase) {
! 				for (tp2 = tmpbuf; ch = *tp++;)
  					*tp2++ = isupper(ch) ? tolower(ch) : ch;
  				*tp2 = '\0';
  				tp = tmpbuf;
--- 741,747 ----
  		if (mflag && confirm(argv[0], cp)) {
  			tp = cp;
  			if (mcase) {
! 				for (tp2 = tmpbuf; (ch = *tp++) != NULL; )
  					*tp2++ = isupper(ch) ? tolower(ch) : ch;
  				*tp2 = '\0';
  				tp = tmpbuf;
***************
*** 882,889 ****
  	else {
  		printf("Nmap: off\n");
  	}
! 	printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
! 		onoff(hash), onoff(sendport));
  	if (macnum > 0) {
  		printf("Macros:\n");
  		for (i=0; i<macnum; i++) {
--- 882,889 ----
  	else {
  		printf("Nmap: off\n");
  	}
! 	printf("Hash mark printing: %s; Mark count: %d\n", onoff(hash), mark);
! 	printf("Use of PORT cmds: %s\n", onoff(sendport));
  	if (macnum > 0) {
  		printf("Macros:\n");
  		for (i=0; i<macnum; i++) {
***************
*** 937,944 ****
  	printf("Hash mark printing %s", onoff(hash));
  	code = hash;
  	if (hash)
! 		printf(" (%d bytes/hash mark)", 1024);
  	printf(".\n");
  }
  
  /*
--- 937,967 ----
  	printf("Hash mark printing %s", onoff(hash));
  	code = hash;
  	if (hash)
! 		printf(" (%d bytes/hash mark)", mark);
  	printf(".\n");
+ }
+ 
+ /*
+  * Set hash mark bytecount.
+  */
+ /*VARARGS*/
+ void
+ setmark(argc, argv)
+ 	int argc;
+ 	char *argv[];
+ {
+ 	if (argc != 2)
+ 		printf("mark: bytecount not specified\n");
+ 	else {
+ 		int nmark = atol(argv[1]);
+ 		if (nmark < 1)
+ 			printf("A hash mark bytecount of %d %s",
+ 				nmark, "is rather pointless...\n");
+ 		else {
+ 			mark = nmark;
+ 			printf("Hash mark set to %d bytes/hash mark\n", mark);
+ 		}
+ 	}
  }
  
  /*
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/cmdtab.c ./cmdtab.c
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/cmdtab.c	Tue Aug 30 01:33:07 1994
--- ./cmdtab.c	Tue Jan  3 16:55:59 1995
***************
*** 67,72 ****
--- 67,73 ----
  char	lcdhelp[] =	"change local working directory";
  char	lshelp[] =	"list contents of remote directory";
  char	macdefhelp[] =  "define a macro";
+ char	markhelp[] =	"set hashmark spacing to bytecount";
  char	mdeletehelp[] =	"delete multiple files";
  char	mdirhelp[] =	"list contents of multiple remote directories";
  char	mgethelp[] =	"get multiple files";
***************
*** 139,144 ****
--- 140,146 ----
  	{ "lcd",	lcdhelp,	0,	0,	0,	lcd },
  	{ "ls",		lshelp,		1,	1,	1,	ls },
  	{ "macdef",	macdefhelp,	0,	0,	0,	macdef },
+ 	{ "mark",	markhelp,	0,	0,	0,	setmark },
  	{ "mdelete",	mdeletehelp,	1,	1,	1,	mdelete },
  	{ "mdir",	mdirhelp,	1,	1,	1,	mls },
  	{ "mget",	mgethelp,	1,	1,	1,	mget },
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/extern.h ./extern.h
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/extern.h	Mon Aug 29 13:09:10 1994
--- ./extern.h	Tue Jan  3 16:47:23 1995
***************
*** 119,124 ****
--- 119,125 ----
  void	setftmode __P((int, char **));
  void	setglob __P((int, char **));
  void	sethash __P((int, char **));
+ void	setmark __P((int, char **));
  void	setnmap __P((int, char **));
  void	setntrans __P((int, char **));
  void	setpassive __P((int, char **));
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp.1 ./ftp.1
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp.1	Tue Aug 30 01:33:13 1994
--- ./ftp.1	Tue Jan  3 17:13:37 1995
***************
*** 312,318 ****
  .It Ic hash
  Toggle hash-sign (``#'') printing for each data block
  transferred.
! The size of a data block is 1024 bytes.
  .It Ic help Op Ar command
  Print an informative message about the meaning of
  .Ar command  .
--- 312,321 ----
  .It Ic hash
  Toggle hash-sign (``#'') printing for each data block
  transferred.
! The size of a data block defaults to 1024 bytes.
! This can be changed with the
! .Ic mark
! command.
  .It Ic help Op Ar command
  Print an informative message about the meaning of
  .Ar command  .
***************
*** 383,388 ****
--- 386,395 ----
  on the second pass it is replaced by the second argument, and so on.
  A `\e' followed by any character is replaced by that character.
  Use the `\e' to prevent special treatment of the `$'.
+ .It Ic mark Ar bytecount
+ Set the byte count between hash mark printing to
+ .Ar bytecount .
+ This defaults to 1024 bytes/hash mark.
  .It Ic mdelete Op Ar remote-files
  Delete the
  .Ar remote-files
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp.c ./ftp.c
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp.c	Tue Aug 30 01:33:14 1994
--- ./ftp.c	Tue Jan  3 16:37:03 1995
***************
*** 435,442 ****
  	longjmp(sendabort, 1);
  }
  
- #define HASHBYTES 1024
- 
  void
  sendrequest(cmd, local, remote, printnames)
  	char *cmd, *local, *remote;
--- 435,440 ----
***************
*** 448,454 ****
  	FILE *fin, *dout = 0, *popen();
  	int (*closefunc) __P((FILE *));
  	sig_t oldintr, oldintp;
! 	long bytes = 0, hashbytes = HASHBYTES;
  	char *lmode, buf[BUFSIZ], *bufp;
  
  	if (verbose && printnames) {
--- 446,452 ----
  	FILE *fin, *dout = 0, *popen();
  	int (*closefunc) __P((FILE *));
  	sig_t oldintr, oldintp;
! 	long bytes = 0, hashbytes = mark;
  	char *lmode, buf[BUFSIZ], *bufp;
  
  	if (verbose && printnames) {
***************
*** 592,604 ****
  			if (hash) {
  				while (bytes >= hashbytes) {
  					(void) putchar('#');
! 					hashbytes += HASHBYTES;
  				}
  				(void) fflush(stdout);
  			}
  		}
  		if (hash && bytes > 0) {
! 			if (bytes < HASHBYTES)
  				(void) putchar('#');
  			(void) putchar('\n');
  			(void) fflush(stdout);
--- 590,602 ----
  			if (hash) {
  				while (bytes >= hashbytes) {
  					(void) putchar('#');
! 					hashbytes += mark;
  				}
  				(void) fflush(stdout);
  			}
  		}
  		if (hash && bytes > 0) {
! 			if (bytes < mark)
  				(void) putchar('#');
  			(void) putchar('\n');
  			(void) fflush(stdout);
***************
*** 618,624 ****
  				while (hash && (bytes >= hashbytes)) {
  					(void) putchar('#');
  					(void) fflush(stdout);
! 					hashbytes += HASHBYTES;
  				}
  				if (ferror(dout))
  					break;
--- 616,622 ----
  				while (hash && (bytes >= hashbytes)) {
  					(void) putchar('#');
  					(void) fflush(stdout);
! 					hashbytes += mark;
  				}
  				if (ferror(dout))
  					break;
***************
*** 705,711 ****
  	int c, d, is_retr, tcrflag, bare_lfs = 0;
  	static int bufsize;
  	static char *buf;
! 	long bytes = 0, hashbytes = HASHBYTES;
  	struct timeval start, stop;
  	struct stat st;
  
--- 703,709 ----
  	int c, d, is_retr, tcrflag, bare_lfs = 0;
  	static int bufsize;
  	static char *buf;
! 	long bytes = 0, hashbytes = mark;
  	struct timeval start, stop;
  	struct stat st;
  
***************
*** 860,872 ****
  			if (hash) {
  				while (bytes >= hashbytes) {
  					(void) putchar('#');
! 					hashbytes += HASHBYTES;
  				}
  				(void) fflush(stdout);
  			}
  		}
  		if (hash && bytes > 0) {
! 			if (bytes < HASHBYTES)
  				(void) putchar('#');
  			(void) putchar('\n');
  			(void) fflush(stdout);
--- 858,870 ----
  			if (hash) {
  				while (bytes >= hashbytes) {
  					(void) putchar('#');
! 					hashbytes += mark;
  				}
  				(void) fflush(stdout);
  			}
  		}
  		if (hash && bytes > 0) {
! 			if (bytes < mark)
  				(void) putchar('#');
  			(void) putchar('\n');
  			(void) fflush(stdout);
***************
*** 912,918 ****
  				while (hash && (bytes >= hashbytes)) {
  					(void) putchar('#');
  					(void) fflush(stdout);
! 					hashbytes += HASHBYTES;
  				}
  				bytes++;
  				if ((c = getc(din)) != '\n' || tcrflag) {
--- 910,916 ----
  				while (hash && (bytes >= hashbytes)) {
  					(void) putchar('#');
  					(void) fflush(stdout);
! 					hashbytes += mark;
  				}
  				bytes++;
  				if ((c = getc(din)) != '\n' || tcrflag) {
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp_var.h ./ftp_var.h
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/ftp_var.h	Tue Aug 30 01:33:14 1994
--- ./ftp_var.h	Tue Jan  3 16:35:48 1995
***************
*** 43,53 ****
--- 43,57 ----
  
  #include "extern.h"
  
+ #define HASHBYTES 1024
+ 
+ 
  /*
   * Options and other state info.
   */
  int	trace;			/* trace packets exchanged */
  int	hash;			/* print # for each buffer transferred */
+ int	mark;			/* number of bytes between hashes */
  int	sendport;		/* use PORT cmd for each data connection */
  int	verbose;		/* print messages coming back from server */
  int	connected;		/* connected to server */
diff -cb /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/main.c ./main.c
*** /data/0/ftp/pub/NetBSD/NetBSD-current/src/usr.bin/ftp/main.c	Sun Dec 25 22:27:00 1994
--- ./main.c	Tue Jan  3 16:36:27 1995
***************
*** 78,83 ****
--- 78,84 ----
  	doglob = 1;
  	interactive = 1;
  	autologin = 1;
+ 	mark = HASHBYTES;
  
  	while ((ch = getopt(argc, argv, "dgintv")) != -1) {
  		switch (ch) {

--
Luke Mewburn                          UNIX Technical Support
<lm@cpr.itg.telecom.com.au>              CPR Project, ITG
Phone: +61 3 634 2112                   Telecom Australia.