From e5354ca12a232b3f97726214254a868771cb70d1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 11 Sep 2015 16:35:14 -0500 Subject: Replace toys.exithelp with help_exit() in lib. --- toys/pending/brctl.c | 10 ++-------- toys/pending/crontab.c | 11 +++-------- toys/pending/dd.c | 5 +---- toys/pending/fdisk.c | 12 ++++-------- toys/pending/groupadd.c | 6 ++---- toys/pending/ip.c | 36 ++++++++++++++++-------------------- toys/pending/ipcrm.c | 5 +---- toys/pending/ipcs.c | 5 +---- toys/pending/modprobe.c | 3 +-- toys/pending/pgrep.c | 12 ++++-------- toys/pending/route.c | 29 +++++++++++------------------ toys/pending/tftpd.c | 5 +---- toys/pending/useradd.c | 5 +---- 13 files changed, 48 insertions(+), 96 deletions(-) (limited to 'toys/pending') diff --git a/toys/pending/brctl.c b/toys/pending/brctl.c index e3b1526c..60178518 100644 --- a/toys/pending/brctl.c +++ b/toys/pending/brctl.c @@ -320,20 +320,14 @@ void brctl_main(void) if (strcmp(t->cmd, *toys.optargs)) continue; toys.optargs++, toys.optc--; - if (toys.optc < t->nargs) { - toys.exithelp++; - error_exit("check args"); - } + if (toys.optc < t->nargs) help_exit("check args"); t->f(toys.optargs); toys.optargs += t->nargs; toys.optc -= t->nargs; break; } - if (i == ARRAY_LEN(cc)) { - toys.exithelp++; - error_exit("invalid option '%s'", *toys.optargs); - } + if (i == ARRAY_LEN(cc)) help_exit("invalid option '%s'", *toys.optargs); } xclose(TT.sockfd); } diff --git a/toys/pending/crontab.c b/toys/pending/crontab.c index 05c98f2b..67c8a543 100644 --- a/toys/pending/crontab.c +++ b/toys/pending/crontab.c @@ -346,20 +346,15 @@ void crontab_main(void) if (!toys.optc) { if (!FLAG_elr) { - if (toys.optflags & FLAG_u) { - toys.exithelp++; - error_exit("file name must be specified for replace"); - } + if (toys.optflags & FLAG_u) + help_exit("file name must be specified for replace"); do_replace(pwd->pw_name); } else if (toys.optflags & FLAG_e) do_edit(pwd); else if (toys.optflags & FLAG_l) do_list(pwd->pw_name); else if (toys.optflags & FLAG_r) do_remove(pwd->pw_name); } else { - if (FLAG_elr) { - toys.exithelp++; - error_exit("no arguments permitted after this option"); - } + if (FLAG_elr) help_exit("no arguments permitted after this option"); do_replace(pwd->pw_name); } if (!(toys.optflags & FLAG_c)) free(TT.cdir); diff --git a/toys/pending/dd.c b/toys/pending/dd.c index 366d3c54..24d95657 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -297,10 +297,7 @@ void dd_main() while (*toys.optargs) { if (!(arg = strchr(*toys.optargs, '='))) error_exit("unknown arg %s", *toys.optargs); *arg++ = '\0'; - if (!*arg) { - toys.exithelp = 1; - error_exit(""); - } + if (!*arg) help_exit(0); key.name = *toys.optargs; if (!(res = bsearch(&key, operands, ARRAY_LEN(operands), sizeof(struct pair), comp))) error_exit("unknown arg %s", key.name); diff --git a/toys/pending/fdisk.c b/toys/pending/fdisk.c index 3ee9f598..d000c055 100644 --- a/toys/pending/fdisk.c +++ b/toys/pending/fdisk.c @@ -151,9 +151,9 @@ static void read_sec_sz() if (ioctl(dev_fd, BLKSSZGET, &arg) == 0) g_sect_size = arg; if (toys.optflags & FLAG_b) { if (TT.sect_sz != 512 && TT.sect_sz != 1024 && TT.sect_sz != 2048 && - TT.sect_sz != 4096) { - toys.exithelp++; - error_exit("bad sector size"); + TT.sect_sz != 4096) + { + help_exit("bad sector size"); } g_sect_size = TT.sect_sz; } @@ -1486,11 +1486,7 @@ void fdisk_main(void) toys.exitval = 0; return; } else { - if (!toys.optc || toys.optc > 1 ) { - toys.exitval = toys.exithelp = 1; - show_help(); - return; - } + if (toys.optc != 1) help_exit(stdout); if (read_mbr(toys.optargs[0], 1)) return; while (1) { xputc('\n'); diff --git a/toys/pending/groupadd.c b/toys/pending/groupadd.c index 615c12f8..30468c94 100644 --- a/toys/pending/groupadd.c +++ b/toys/pending/groupadd.c @@ -62,10 +62,8 @@ void groupadd_main(void) struct group *grp = NULL; char *entry = NULL; - if (toys.optflags && toys.optc == 2) { - toys.exithelp = 1; - error_exit("options, user and group can't be together"); - } + if (toys.optflags && toys.optc == 2) + help_exit("options, user and group can't be together"); if (toys.optc == 2) { //add user to group //toys.optargs[0]- user, toys.optargs[1] - group diff --git a/toys/pending/ip.c b/toys/pending/ip.c index 9a01d953..90f73308 100644 --- a/toys/pending/ip.c +++ b/toys/pending/ip.c @@ -137,12 +137,6 @@ static char *idx_to_string(int idx, struct arglist *list) return NULL; } -static void iphelp(void) -{ - toys.exithelp = 1; - error_exit(NULL); -} - static void send_nlmesg(int type, int flags, int family, void *buf, int blen) { @@ -519,16 +513,16 @@ static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) for (; *argv; argv++) { int param, proto; - if ((idx = substring_to_idx(*argv++, vlan_optlist)) == -1) iphelp(); + if ((idx = substring_to_idx(*argv++, vlan_optlist)) == -1) help_exit(0); switch (idx) { case 0: // ARG_id - if (!*argv) iphelp(); + if (!*argv) help_exit(0); param = atolx(*argv); add_string_to_rtattr(n, size, IFLA_VLAN_ID, ¶m, sizeof(param)); break; case 1: // ARG_protocol if (!*argv) error_exit("Invalid vlan id."); - if ((idx = substring_to_idx(*argv, vlan_protolist)) == -1) iphelp(); + if ((idx = substring_to_idx(*argv, vlan_protolist)) == -1) help_exit(0); if (!idx) proto = ETH_P_8021Q; // PROTO_8021Q - 0 else if (idx == 1) proto = 0x88A8; // ETH Protocol - 8021AD // IFLA VLAN PROTOCOL - 5 @@ -536,7 +530,7 @@ static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) break; case 2: // ARG_reorder_hdr case 3: // ARG_gvrp - if ((param = substring_to_idx(*argv, on_off)) == -1) iphelp(); + if ((param = substring_to_idx(*argv, on_off)) == -1) help_exit(0); flags.mask |= (idx -1); // VLAN FLAG REORDER Header flags.flags &= ~(idx -1); // VLAN FLAG REORDER Header @@ -650,7 +644,7 @@ static int link_set(char **argv) fd = xsocket(AF_INET, SOCK_DGRAM, 0); xioctl(fd, SIOCGIFINDEX, &req); for (++argv; *argv;) { - if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp(); + if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) help_exit(0); switch(idx) { case 0: flags |= IFF_UP; break; @@ -659,7 +653,7 @@ static int link_set(char **argv) case 2: case 3: case 4: - if (!*argv) iphelp(); + if (!*argv) help_exit(0); else if (!strcmp(*argv, "on")) { if (idx == 2) { masks &= ~case_flags[idx-2]; @@ -670,7 +664,7 @@ static int link_set(char **argv) masks |= case_flags[idx-2]; flags |= case_flags[idx-2]; } else masks &= ~case_flags[idx-2]; - } else iphelp(); + } else help_exit(0); ++argv; break; case 5: @@ -941,7 +935,8 @@ static int iplink(char **argv) {"set", 1}, {"show", 2}, {"list", 2}, {"lst", 2}, {NULL,-1}}; if (!*argv) idx = 2; - else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp(); + else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) + help_exit(0); ipcmd = cmdobjlist[idx]; return ipcmd(argv); } @@ -1431,7 +1426,8 @@ static int ipaddr(char **argv) TT.is_addr++; if (!*argv) idx = 1; - else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) iphelp(); + else if ((idx = substring_to_idx(*argv++, cmd_objectlist)) == -1) + help_exit(0); ipcmd = cmdobjlist[idx]; return ipcmd(argv); @@ -2757,7 +2753,7 @@ void ip_main(void) struct arglist ip_aflist[] = {{"inet", AF_INET}, {"inet6", AF_INET6}, {"link", AF_PACKET}, {NULL, -1}}; - if (!*++optargv) iphelp(); + if (!*++optargv) help_exit(0); if ((TT.addressfamily = string_to_idx(*optargv, ip_aflist)) == -1) error_exit("wrong family '%s'", *optargv); } @@ -2766,7 +2762,7 @@ void ip_main(void) case 2: TT.stats++; break; - default: iphelp(); + default: help_exit(0); break; // unreachable code. } } @@ -2778,15 +2774,15 @@ void ip_main(void) struct arglist ip_objectlist[] = { {"address", 0}, {"link", 1}, {"route", 2}, {"rule", 3}, {"tunnel", 4}, {"tunl", 4}, {NULL, -1}}; - if ((idx = substring_to_idx(*optargv, ip_objectlist)) == -1) iphelp(); + if ((idx = substring_to_idx(*optargv, ip_objectlist)) == -1) help_exit(0); ipcmd = cmdobjlist[idx]; toys.exitval = ipcmd(++optargv); - } else iphelp(); + } else help_exit(0); } else { struct arglist ip_objectlist[] = { {"ipaddr", 0}, {"iplink", 1}, {"iproute", 2}, {"iprule", 3}, {"iptunnel", 4}, {NULL, -1}}; if ((idx = string_to_idx(toys.which->name, ip_objectlist)) == -1) - iphelp(); + help_exit(0); ipcmd = cmdobjlist[idx]; toys.exitval = ipcmd(optargv); } diff --git a/toys/pending/ipcrm.c b/toys/pending/ipcrm.c index 21f436d3..cec1b12f 100644 --- a/toys/pending/ipcrm.c +++ b/toys/pending/ipcrm.c @@ -83,9 +83,6 @@ void ipcrm_main(void) for (tmp = TT.qid; tmp; tmp = tmp->next) do_ipcrm(0, 2, tmp->arg); for (tmp = TT.skey; tmp; tmp = tmp->next) do_ipcrm(1, 3, tmp->arg); for (tmp = TT.sid; tmp; tmp = tmp->next) do_ipcrm(0, 3, tmp->arg); - if (toys.optc) { - toys.exithelp++; - error_exit("unknown argument: %s", *toys.optargs); - } + if (toys.optc) help_exit("unknown argument: %s", *toys.optargs); } } diff --git a/toys/pending/ipcs.c b/toys/pending/ipcs.c index d974a519..b5986af7 100644 --- a/toys/pending/ipcs.c +++ b/toys/pending/ipcs.c @@ -425,10 +425,7 @@ void ipcs_main(void) if (flag(m)) show_shm_id(); else if (flag(s)) show_sem_id(); else if (flag(q)) show_msg_id(); - else { - toys.exithelp++; - error_exit(NULL); - } + else help_exit(0); return; } diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c index 07c53fc2..6813dec3 100644 --- a/toys/pending/modprobe.c +++ b/toys/pending/modprobe.c @@ -495,8 +495,7 @@ void modprobe_main(void) if ((toys.optc < 1) && (((flags & FLAG_r) && (flags & FLAG_l)) ||(!((flags & FLAG_r)||(flags & FLAG_l))))) { - toys.exithelp++; - error_exit("bad syntax"); + help_exit("bad syntax"); } // Check for -r flag without arg if yes then do auto remove. if ((flags & FLAG_r) && !toys.optc) { diff --git a/toys/pending/pgrep.c b/toys/pending/pgrep.c index 59767b9f..9117a6d5 100644 --- a/toys/pending/pgrep.c +++ b/toys/pending/pgrep.c @@ -91,14 +91,10 @@ void pgrep_main(void) error_exit("Unknown signal '%s'", arg); } else signum = SIGTERM; } - if (!(flag_chk(FLAG_s) || flag_chk(FLAG_P)) && !*toys.optargs) { - toys.exithelp++; - error_exit("missing argument"); - } - if (*(toys.optargs+1) && !(flag_chk(FLAG_s) || flag_chk(FLAG_P))) { - toys.exithelp++; - error_exit("max argument > 1"); - } + if (!(flag_chk(FLAG_s) || flag_chk(FLAG_P)) && !*toys.optargs) + help_exit("missing argument"); + if (*(toys.optargs+1) && !(flag_chk(FLAG_s) || flag_chk(FLAG_P))) + help_exit("max argument > 1"); if (*toys.optargs) { /* compile regular expression(PATTERN) */ if ((eval = regcomp(&rp, *toys.optargs, REG_EXTENDED | REG_NOSUB)) != 0) { char errbuf[256]; diff --git a/toys/pending/route.c b/toys/pending/route.c index ac1bbef5..02b59cfb 100644 --- a/toys/pending/route.c +++ b/toys/pending/route.c @@ -32,7 +32,7 @@ GLOBALS( #define INVALID_ADDR 0xffffffffUL #define IPV6_ADDR_LEN 40 //32 + 7 (':') + 1 ('\0') -#define TEST_ARGV(argv) if (!*argv) show_route_help() +#define TEST_ARGV(argv) if (!*argv) help_exit(0) struct _arglist { char *arg; @@ -49,13 +49,6 @@ static struct _arglist arglist2[] = { { NULL, 0 } }; -// display help info and exit. -static void show_route_help(void) -{ - toys.exithelp = 1; - error_exit("Invalid Argument"); -} - // to get the host name from the given ip. static int get_hostname(char *ipstr, struct sockaddr_in *sockin) { @@ -205,7 +198,7 @@ static void get_next_params(char **argv, struct rtentry *rt, char **netmask) //when adding a network route, the netmask to be used. struct sockaddr sock; unsigned int addr_mask = (((struct sockaddr_in *)&((rt)->rt_genmask))->sin_addr.s_addr); - if (addr_mask) show_route_help(); + if (addr_mask) help_exit("dup netmask"); argv++; TEST_ARGV(argv); *netmask = *argv; @@ -224,7 +217,7 @@ static void get_next_params(char **argv, struct rtentry *rt, char **netmask) argv++; } else if (ishost < 0) perror_exit("resolving '%s'", *argv); else perror_exit("gateway '%s' is a NETWORK", *argv); - } else show_route_help(); + } else help_exit("dup gw"); } else if (!strcmp(*argv, "mss")) { //set the TCP Maximum Segment Size for connections over this route. argv++; @@ -265,7 +258,7 @@ static void get_next_params(char **argv, struct rtentry *rt, char **netmask) } else if (!strcmp(*argv, "reinstate")) { rt->rt_flags |= RTF_REINSTATE; argv++; - } else show_route_help(); //No match found; exit form the application. + } else help_exit("no '%s'", *argv); //No match found; exit form the application. }//end of while loop. if (!rt->rt_dev && (rt->rt_flags & RTF_REJECT)) rt->rt_dev = (char *)"lo"; @@ -295,10 +288,10 @@ static void setroute(char **argv) int is_net_or_host = 0, sokfd, arg2_action; int action = get_action(&argv, arglist1); //verify the arg for add/del. - if (!action || !*argv) show_route_help(); + if (!action || !*argv) help_exit("setroute"); arg2_action = get_action(&argv, arglist2); //verify the arg for -net or -host - if (!*argv) show_route_help(); + if (!*argv) help_exit("setroute"); memset(&rt, 0, sizeof(struct rtentry)); targetip = *argv++; @@ -364,7 +357,7 @@ static void get_next_params_inet6(char **argv, struct sockaddr_in6 *sock_in6, st rt->rtmsg_flags |= RTF_GATEWAY; argv++; } else perror_exit("resolving '%s'", *argv); - } else show_route_help(); + } else help_exit(0); } else if (!strcmp(*argv, "dev")) { argv++; TEST_ARGV(argv); @@ -376,7 +369,7 @@ static void get_next_params_inet6(char **argv, struct sockaddr_in6 *sock_in6, st } else if (!strcmp(*argv, "dyn")) { rt->rtmsg_flags |= RTF_DYNAMIC; argv++; - } else show_route_help(); + } else help_exit(0); }//end of while loop. } @@ -388,7 +381,7 @@ static void setroute_inet6(char **argv) char *targetip; int sockfd, action = get_action(&argv, arglist1); - if (!action || !*argv) show_route_help(); + if (!action || !*argv) help_exit(0); memset(&sock_in6, 0, sizeof(struct sockaddr_in6)); memset(&rt, 0, sizeof(struct in6_rtmsg)); targetip = *argv++; @@ -418,7 +411,7 @@ static void setroute_inet6(char **argv) if (action == 1) xioctl(sockfd, SIOCADDRT, &rt); else xioctl(sockfd, SIOCDELRT, &rt); xclose(sockfd); - } else show_route_help(); + } else help_exit(0); } /* @@ -489,7 +482,7 @@ void route_main(void) if (!*toys.optargs) { if (!strcmp(TT.family, "inet")) display_routes(); else if (!strcmp(TT.family, "inet6")) display_routes6(); - else show_route_help(); + else help_exit(0); return; }//End of if statement. diff --git a/toys/pending/tftpd.c b/toys/pending/tftpd.c index 31af44be..806326eb 100644 --- a/toys/pending/tftpd.c +++ b/toys/pending/tftpd.c @@ -242,10 +242,7 @@ void tftpd_main(void) char *buf = toybuf; memset(&srcaddr, 0, sizeof(srcaddr)); - if (getsockname(0, (struct sockaddr *)&srcaddr, &socklen)) { - toys.exithelp = 1; - error_exit(NULL); - } + if (getsockname(0, (struct sockaddr *)&srcaddr, &socklen)) help_exit(0); if (TT.user) TT.pw = xgetpwnam(TT.user); if (*toys.optargs) xchroot(*toys.optargs); diff --git a/toys/pending/useradd.c b/toys/pending/useradd.c index 4d4c671e..d0ad03ab 100644 --- a/toys/pending/useradd.c +++ b/toys/pending/useradd.c @@ -46,10 +46,7 @@ void useradd_main(void) // Act like groupadd? if (toys.optc == 2) { - if (toys.optflags) { - toys.exithelp = 1; - error_exit("options with USER GROUP"); - } + if (toys.optflags) help_exit("options with USER GROUP"); xexec((char *[]){"groupadd", toys.optargs[0], toys.optargs[1], 0}); } -- cgit v1.2.3