Module Name:    src
Committed By:   lukem
Date:           Sat Jul 18 03:00:38 UTC 2020

Modified Files:
        src/usr.bin/ftp: ftp.1 main.c version.h

Log Message:
ftp: add -? for help. improve synopsis

Add -? to display usage synopsis and help to stdout.
This allows for "ftp -? | less", which is more user friendly.
Errors still show usage to stderr.
Consistency improvements in some usage text.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.141 src/usr.bin/ftp/ftp.1:1.142
--- src/usr.bin/ftp/ftp.1:1.141	Wed Jul 15 19:23:44 2020
+++ src/usr.bin/ftp/ftp.1	Sat Jul 18 03:00:37 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.141 2020/07/15 19:23:44 uwe Exp $
+.\" 	$NetBSD: ftp.1,v 1.142 2020/07/18 03:00:37 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 15, 2020
+.Dd July 18, 2020
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -65,7 +65,7 @@
 .Nd Internet file transfer program
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46AadefginpRtVv
+.Op Fl 46AadefginpRtVv?
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
@@ -121,7 +121,7 @@
 .Ar host Oo Li \&: Ar port Oc
 .Li / Ar path
 .Op Li /
-.Op Li ;type= Ar X
+.Op Li ;type= Ar type
 .Oc
 .Sm on
 .Ek
@@ -138,6 +138,19 @@
 .Oc
 .Sm on
 .Ek
+.Bk -words
+.\" [https://[user[:password]@]host[:port]/path]
+.Sm off
+.Oo
+.Li https://
+.Oo Ar user
+.Op Li \&: Ar password
+.Li \&@ Oc
+.Ar host Oo Li \&: Ar port Oc
+.Li / Ar path
+.Oc
+.Sm on
+.Ek
 .Ar \&...
 .Nm
 .Bk -words
@@ -316,6 +329,8 @@ Set the size of the socket send and rece
 Refer to
 .Ic xferbuf
 for more information.
+.It Fl ?
+Display help to stdout, and exit.
 .El
 .Pp
 The client host with which
@@ -1581,10 +1596,10 @@ of
 in the current directory.
 Otherwise, the full remote name is used as the local name,
 relative to the local root directory.
-.\" ftp://[user[:password]@]host[:port]/path[/][;type=X]
+.\" ftp://[user[:password]@]host[:port]/path[/][;type=type]
 .It Li ftp:// Ns Oo Ar user Ns Oo Ns Li \&: Ns Ar password Oc Ns Li \&@ Oc \
 Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path Ns Oo Li / Oc \
-Ns Oo Li ;type= Ns Ar X Oc
+Ns Oo Li ;type= Ns Ar type Oc
 An
 .Tn FTP
 URL, retrieved using the

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.126 src/usr.bin/ftp/main.c:1.127
--- src/usr.bin/ftp/main.c:1.126	Mon Feb  4 04:09:13 2019
+++ src/usr.bin/ftp/main.c	Sat Jul 18 03:00:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $	*/
+/*	$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $");
+__RCSID("$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,8 @@ __RCSID("$NetBSD: main.c,v 1.126 2019/02
 #define	NO_PROXY	"no_proxy"	/* env var with list of non-proxied
 					 * hosts, comma or space separated */
 
-__dead static void	usage(void);
+static int	usage(void);
+static int	usage_help(void);
 static void	setupoption(const char *, const char *, const char *);
 
 int
@@ -266,7 +267,7 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+	while ((ch = getopt(argc, argv, "?46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -378,15 +379,15 @@ main(int volatile argc, char **volatile 
 				if (*cp == '\0') {
 					warnx("Bad throttle value `%s'",
 					    optarg);
-					usage();
-					/* NOTREACHED */
+					return usage();
 				}
 				targv[targc++] = cp;
 				if (targc >= 5)
 					break;
 			}
-			if (parserate(targc, targv, 1) == -1)
-				usage();
+			if (parserate(targc, targv, 1) == -1) {
+				return usage();
+			}
 			free(oac);
 			break;
 		}
@@ -415,8 +416,14 @@ main(int volatile argc, char **volatile 
 			rcvbuf_size = sndbuf_size;
 			break;
 
+		case '?':
+			if (optopt == '?') {
+				return usage_help();
+			}
+			return usage();
+
 		default:
-			usage();
+			errx(1, "unimplemented option -%c", ch);
 		}
 	}
 			/* set line buffering on ttyout */
@@ -572,8 +579,9 @@ main(int volatile argc, char **volatile 
 			retry_connect = 0; /* connected, stop hiding msgs */
 		}
 	}
-	if (isupload)
-		usage();
+	if (isupload) {
+		return usage();
+	}
 
 #ifndef NO_EDITCOMPLETE
 	controlediting();
@@ -836,7 +844,6 @@ slurpstring(void)
 				slrflag++;
 				INC_CHKCURSOR(stringbase);
 				return ((*sb == '!') ? bangstr : dollarstr);
-				/* NOTREACHED */
 			case 1:
 				slrflag++;
 				altarg = stringbase;
@@ -965,7 +972,7 @@ help(int argc, char *argv[])
 	cmd = argv[0];
 	isusage = (strcmp(cmd, "usage") == 0);
 	if (argc == 0 || (isusage && argc == 1)) {
-		UPRINTF("usage: %s [command [...]]\n", cmd);
+		UPRINTF("usage: %s [command ...]\n", cmd);
 		return;
 	}
 	if (argc == 1) {
@@ -1044,20 +1051,69 @@ setupoption(const char *name, const char
 	set_option(name, value ? value : defaultvalue, 0);
 }
 
-void
-usage(void)
+static void
+synopsis(FILE * stream)
 {
-	const char *progname = getprogname();
+	const char * progname = getprogname();
 
-	(void)fprintf(stderr,
-"usage: %s [-46AadefginpRtVv] [-N netrc] [-o outfile] [-P port] [-q quittime]\n"
-"           [-r retry] [-s srcaddr] [-T dir,max[,inc]] [-x xferbufsize]\n"
-"           [[user@]host [port]] [host:path[/]] [file:///file]\n"
-"           [ftp://[user[:pass]@]host[:port]/path[/]]\n";
-"           [http://[user[:pass]@]host[:port]/path] [...]\n"
+	fprintf(stream,
+"usage: %s [-46AadefginpRtVv] [-N NETRC] [-o OUTPUT] [-P PORT] [-q QUITTIME]\n"
+"           [-r RETRY] [-s SRCADDR] [-T DIR,MAX[,INC]] [-x XFERSIZE]\n"
+"           [[USER@]HOST [PORT]]\n"
+"           [[USER@]HOST:[PATH][/]]\n"
+"           [file:///PATH]\n"
+"           [ftp://[USER[:PASSWORD]@]HOST[:PORT]/PATH[/][;type=TYPE]]\n";
+"           [http://[USER[:PASSWORD]@]HOST[:PORT]/PATH]\n";
 #ifdef WITH_SSL
-"           [https://[user[:pass]@]host[:port]/path] [...]\n"
+"           [https://[USER[:PASSWORD]@]HOST[:PORT]/PATH]\n";
 #endif
-"       %s -u URL file [...]\n", progname, progname);
-	exit(1);
+"           ...\n"
+"       %s -u URL FILE ...\n"
+"       %s -?\n",
+		progname, progname, progname);
+}
+
+static int
+usage_help(void)
+{
+	synopsis(stdout);
+#ifndef NO_USAGE
+	printf(
+"  -4            Only use IPv4 addresses\n"
+"  -6            Only use IPv6 addresses\n"
+"  -A            Force active mode\n"
+"  -a            Use anonymous login\n"
+"  -d            Enable debugging\n"
+"  -e            Disable command-line editing\n"
+"  -f            Force cache reload for FTP or HTTP proxy transfers\n"
+"  -g            Disable file name globbing\n"
+"  -i            Disable interactive prompt during multiple file transfers\n"
+"  -N NETRC      Use NETRC instead of ~/.netrc\n"
+"  -n            Disable auto-login\n"
+"  -o OUTPUT     Save auto-fetched files to OUTPUT\n"
+"  -P PORT       Use port PORT\n"
+"  -p            Force passive mode\n"
+"  -q QUITTIME   Quit if connection stalls for QUITTIME seconds\n"
+"  -R            Restart non-proxy auto-fetch\n"
+"  -r RETRY      Retry failed connection attempts after RETRY seconds\n"
+"  -s SRCADDR    Use source address SRCADDR\n"
+"  -t            Enable packet tracing\n"
+"  -T DIR,MAX[,INC]\n"
+"                Set maximum transfer rate for direction DIR to MAX bytes/s,\n"
+"                with optional increment INC bytes/s\n"
+"  -u URL        URL to upload file arguments to\n"
+"  -V            Disable verbose and progress\n"
+"  -v            Enable verbose and progress\n"
+"  -x XFERSIZE   Set socket send and receive size to XFERSIZE\n"
+"  -?            Display this help and exit\n"
+		);
+#endif
+	return EXIT_SUCCESS;
+}
+
+static int
+usage(void)
+{
+	synopsis(stderr);
+	return EXIT_FAILURE;
 }

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.90 src/usr.bin/ftp/version.h:1.91
--- src/usr.bin/ftp/version.h:1.90	Sat Jul 11 02:19:31 2020
+++ src/usr.bin/ftp/version.h	Sat Jul 18 03:00:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.90 2020/07/11 02:19:31 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.91 2020/07/18 03:00:37 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2020 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20200711"
+#define	FTP_VERSION	"20200718"
 #endif

Reply via email to