Subject: bin/683: adding `mark' option to ftp
To: None <gnats-admin@NetBSD.ORG>
From: Luke Mewburn <lukem@dodo.melb.cpr.itg.telecom.com.au>
List: netbsd-bugs
Date: 01/02/1995 22:20:04
>Number:         683
>Category:       bin
>Synopsis:       adding `mark' command to change bytecount between hashmarks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   lm
>Arrival-Date:   Mon Jan  2 22:20:02 1995
>Originator:     Luke Mewburn
>Organization:
	Werj
>Release:        1.0
>Environment:
System: NetBSD dodo 1.0 NetBSD 1.0 (DODO) #7: Fri Dec 16 17:01:27 EST 1994 simonb@dodo:/slab/0/src/sys/arch/i386/compile/DODO i386


>Description:
	Currently the ftp command prints a `#' for each 1K transferred.
	On fast (or slow) links, this is often unsuitable. The ability
	to user-define this setting would be useful.

	It's useful on fast links to set the mark to 10K or even 100K.  On
	slow slip links, maybe 256 or 500 bytes could be a useful setting.

	Also, a couple of minor cleanups to shut up gcc -Wall (before I
	gave up and turned off -Wall.)

>How-To-Repeat:
	run ftp. turn on hash mark printing. transfer a _big_ file (e.g,
	gcc-2.6.3.tar.gz, @ ~6.5MB) and watch your screen fill up with `#'s.

>Fix:
	Apply this patch.
	I've added the `mark' command which allows the user to specify at
	what interval the `#' is printed.  Checks for at least 1 byte/hask
	mark being requested, etc...


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) {
>Audit-Trail:
>Unformatted: