[BusyBox-cvs] busybox/networking ftpgetput.c,1.9,1.10

Glenn McGrath bug1 at busybox.net
Fri Dec 19 10:37:54 UTC 2003


Update of /var/cvs/busybox/networking
In directory nail:/tmp/cvs-serv20269/networking

Modified Files:
	ftpgetput.c 
Log Message:
Use getopt_ulflags


Index: ftpgetput.c
===================================================================
RCS file: /var/cvs/busybox/networking/ftpgetput.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ftpgetput.c	21 Nov 2003 22:24:57 -0000	1.9
+++ ftpgetput.c	19 Dec 2003 10:37:52 -0000	1.10
@@ -287,11 +287,25 @@
 }
 #endif
 
+#define FTPGETPUT_OPT_CONTINUE	1
+#define FTPGETPUT_OPT_VERBOSE	2
+#define FTPGETPUT_OPT_USER	4
+#define FTPGETPUT_OPT_PASSWORD	8
+#define FTPGETPUT_OPT_PORT	16
+
+static const struct option ftpgetput_long_options[] = {
+	{"continue", 1, NULL, 'c'},
+	{"verbose", 0, NULL, 'v'},
+	{"username", 1, NULL, 'u'},
+	{"password", 1, NULL, 'p'},
+	{"port", 1, NULL, 'P'},
+	{0, 0, 0, 0}
+};
+
 int ftpgetput_main(int argc, char **argv)
 {
 	/* content-length of the file */
-	int option_index = -1;
-	int opt;
+	unsigned long opt;
 
 	/* socket to ftp server */
 	FILE *control_stream;
@@ -302,15 +316,6 @@
 
 	int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL;
 
-	struct option long_options[] = {
-		{"username", 1, NULL, 'u'},
-		{"password", 1, NULL, 'p'},
-		{"port", 1, NULL, 'P'},
-		{"continue", 1, NULL, 'c'},
-		{"verbose", 0, NULL, 'v'},
-		{0, 0, 0, 0}
-	};
-
 #ifdef CONFIG_FTPPUT
 	if (bb_applet_name[3] == 'p') {
 		ftp_action = ftp_send;
@@ -330,26 +335,13 @@
 	 * Decipher the command line 
 	 */
 	server->port = "21";
-	while ((opt = getopt_long(argc, argv, "u:p:P:cv", long_options, &option_index)) != EOF) {
-		switch(opt) {
-		case 'c':
-			do_continue = 1;
-			break;
-		case 'u':
-			server->user = optarg;
-			break;
-		case 'p':
-			server->password = optarg;
-			break;
-		case 'P':
-			server->port = optarg;
-			break;
-		case 'v':
-			verbose_flag = 1;
-			break;
-		default:
-			bb_show_usage();
-		}
+	bb_applet_long_options = ftpgetput_long_options;
+	opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &server->port);
+	if (opt & FTPGETPUT_OPT_CONTINUE) {
+		do_continue = 1;
+	}
+	if (opt & FTPGETPUT_OPT_VERBOSE) {
+		verbose_flag = 1;
 	}
 
 	/*




More information about the busybox-cvs mailing list