changeset 861:35b059e1654b

Isaac Dunham's help string cleanup.
author Rob Landley <rob@landley.net>
date Tue, 16 Apr 2013 22:55:14 -0500
parents a612857eb52d
children 53cee02f1811
files toys/pending/ifconfig.c
diffstat 1 files changed, 22 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/ifconfig.c	Tue Apr 16 22:45:47 2013 -0500
+++ b/toys/pending/ifconfig.c	Tue Apr 16 22:55:14 2013 -0500
@@ -392,17 +392,6 @@
 
 IFACE_LIST *iface_list_head;
 
-/*
- * display help info and exit from application.
- */
-static void show_help(void)
-{
-  char **arg = xzalloc(sizeof(char*) *3);
-  arg[0] = "help";
-  arg[1] = xstrdup(toys.which->name);
-  toy_exec(arg);
-}
-
 void ifconfig_main(void)
 {
   char **argv = toys.optargs;
@@ -465,99 +454,54 @@
         set_flags(sockfd, &ifre, 0, IFF_POINTOPOINT);
       /*value setup */
       else if (!strcmp(*argv, "pointopoint")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_address(sockfd, *argv, &ifre, SIOCSIFDSTADDR, "SIOCSIFDSTADDR");
         set_flags(sockfd, &ifre, IFF_POINTOPOINT, 0);
       } else if (!strcmp(*argv, "netmask")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_address(sockfd, *argv, &ifre, SIOCSIFNETMASK, "SIOCSIFNETMASK");
       } else if (!strcmp(*argv, "-broadcast")) {
         set_flags(sockfd, &ifre, 0, IFF_BROADCAST);
       } else if (!strcmp(*argv, "broadcast")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_address(sockfd, *argv, &ifre, SIOCSIFBRDADDR, "SIOCSIFBRDADDR");
         set_flags(sockfd, &ifre, IFF_BROADCAST, 0);
       } else if (!strcmp(*argv, "dstaddr")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_address(sockfd, *argv, &ifre, SIOCSIFDSTADDR, "SIOCSIFDSTADDR");
       } else if (!strcmp(*argv, "hw")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_hw_address(sockfd, &argv, &ifre, SIOCSIFHWADDR, "SIOCSIFHWADDR");
       } else if (!strcmp(*argv, "mtu")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_mtu(sockfd, &ifre, *argv);
       } else if (!strcmp(*argv, "metric")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_metric(sockfd, &ifre, *argv);
       } else if (!strcmp(*argv, "txqueuelen")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_qlen(sockfd, &ifre, *argv);
       } else if (!strcmp(*argv, "keepalive")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_data(sockfd, &ifre, *argv, SIOCSKEEPALIVE, "SIOCSKEEPALIVE");
       }//end of keepalive
       else if (!strcmp(*argv, "outfill")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_data(sockfd, &ifre, *argv, SIOCSOUTFILL, "SIOCSOUTFILL");
       } else if (!strcmp(*argv, "add")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_ipv6_addr(sockfd, &ifre, *argv, SIOCSIFADDR, "SIOCSIFADDR");
       } else if (!strcmp(*argv, "del")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_ipv6_addr(sockfd, &ifre, *argv, SIOCDIFADDR, "SIOCDIFADDR");
       } else if (!strcmp(*argv, "mem_start")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_memstart(sockfd, &ifre, *argv, SIOCSIFMAP, "SIOCSIFMAP");
       } else if (!strcmp(*argv, "io_addr")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_ioaddr(sockfd, &ifre, *argv, SIOCSIFMAP, "SIOCSIFMAP");
       } else if (!strcmp(*argv, "irq")) {
-        if(*++argv == NULL) {
-          errno = EINVAL;
-          show_help();
-        }
+        show_help();
         set_irq(sockfd, &ifre, *argv, SIOCSIFMAP, "SIOCSIFMAP");
       } else {
         if(isdigit(**argv) || !strcmp(*argv, "default")) {
@@ -578,7 +522,8 @@
           continue;
         else {
           errno = EINVAL;
-          show_help();
+	  toys.exithelp++;
+	  error_exit("bad argument");
         }
       }
 
@@ -756,8 +701,11 @@
     hw_class = 1;
   else if(strcmp(hw_class_strings[1], **argv) == 0)
     hw_class = 2;
-  if(!hw_class || !(*argv += 1))
-    show_help();
+  if(!hw_class || !(*argv += 1)) {
+    errno = EINVAL;
+    toys.exithelp++;
+    error_exit("bad hardware class");
+  }
 
   memset(&sock, 0, sizeof(struct sockaddr));
   hw_addr = **argv;