diff options
author | Rob Landley <rob@landley.net> | 2018-11-02 20:07:02 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-11-02 20:07:02 -0500 |
commit | 6a73e13d75d31da2c3f1145d8487725f0073a4b8 (patch) | |
tree | 17b5bb8b6b5e94b1c93818954cf322a39941a4be | |
parent | 49e1d8733ebcaf130623c68a2393a3c43702a524 (diff) | |
download | toybox-6a73e13d75d31da2c3f1145d8487725f0073a4b8.tar.gz |
Convert more option vars to the new (single letter) coding style.
-rw-r--r-- | toys/other/mix.c | 24 | ||||
-rw-r--r-- | toys/other/mkpasswd.c | 25 | ||||
-rw-r--r-- | toys/other/modinfo.c | 12 | ||||
-rw-r--r-- | toys/other/oneit.c | 4 | ||||
-rw-r--r-- | toys/other/shred.c | 20 | ||||
-rw-r--r-- | toys/other/stat.c | 4 | ||||
-rw-r--r-- | toys/other/swapon.c | 5 | ||||
-rw-r--r-- | toys/other/switch_root.c | 8 | ||||
-rw-r--r-- | toys/other/timeout.c | 13 | ||||
-rw-r--r-- | toys/other/xxd.c | 6 | ||||
-rw-r--r-- | toys/posix/grep.c | 27 | ||||
-rw-r--r-- | toys/posix/uniq.c | 14 |
12 files changed, 72 insertions, 90 deletions
diff --git a/toys/other/mix.c b/toys/other/mix.c index 845aac1f..d0f65618 100644 --- a/toys/other/mix.c +++ b/toys/other/mix.c @@ -24,10 +24,8 @@ config MIX #include <linux/soundcard.h> GLOBALS( - long right; - long level; - char *dev; - char *chan; + long r, l; + char *d, *c; ) void mix_main(void) @@ -35,31 +33,31 @@ void mix_main(void) const char *channels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; int mask, channel = -1, level, fd; - if (!TT.dev) TT.dev = "/dev/mixer"; - fd = xopen(TT.dev, O_RDWR|O_NONBLOCK); + if (!TT.d) TT.d = "/dev/mixer"; + fd = xopen(TT.d, O_RDWR|O_NONBLOCK); xioctl(fd, SOUND_MIXER_READ_DEVMASK, &mask); for (channel = 0; channel < SOUND_MIXER_NRDEVICES; channel++) { if ((1<<channel) & mask) { - if (TT.chan) { - if (!strcmp(channels[channel], TT.chan)) break; + if (TT.c) { + if (!strcmp(channels[channel], TT.c)) break; } else if (toys.optflags & FLAG_l) break; else printf("%s\n", channels[channel]); } } if (!(toys.optflags & (FLAG_c|FLAG_l))) return; - else if (channel == SOUND_MIXER_NRDEVICES) error_exit("bad -c '%s'", TT.chan); + else if (channel == SOUND_MIXER_NRDEVICES) error_exit("bad -c '%s'", TT.c); if (!(toys.optflags & FLAG_l)) { xioctl(fd, MIXER_READ(channel), &level); if (level > 0xFF) xprintf("%s:%s = left:%d\t right:%d\n", - TT.dev, channels[channel], level>>8, level & 0xFF); - else xprintf("%s:%s = %d\n", TT.dev, channels[channel], level); + TT.d, channels[channel], level>>8, level & 0xFF); + else xprintf("%s:%s = %d\n", TT.d, channels[channel], level); } else { - level = TT.level; - if (!(toys.optflags & FLAG_r)) level = TT.right | (level<<8); + level = TT.l; + if (!(toys.optflags & FLAG_r)) level = TT.r | (level<<8); xioctl(fd, MIXER_WRITE(channel), &level); } diff --git a/toys/other/mkpasswd.c b/toys/other/mkpasswd.c index fe1bd26f..b4151363 100644 --- a/toys/other/mkpasswd.c +++ b/toys/other/mkpasswd.c @@ -25,9 +25,8 @@ config MKPASSWD #include "toys.h" GLOBALS( - long pfd; - char *method; - char *salt; + long P; + char *m, *S; ) void mkpasswd_main(void) @@ -35,27 +34,27 @@ void mkpasswd_main(void) char salt[MAX_SALT_LEN] = {0,}; int i; - if (!TT.method) TT.method = "des"; + if (!TT.m) TT.m = "des"; if (toys.optc == 2) { - if (TT.salt) error_exit("duplicate salt"); - TT.salt = toys.optargs[1]; + if (TT.S) error_exit("duplicate salt"); + TT.S = toys.optargs[1]; } - if (-1 == (i = get_salt(salt, TT.method))) error_exit("bad -m"); - if (TT.salt) { - char *s = TT.salt; + if (-1 == (i = get_salt(salt, TT.m))) error_exit("bad -m"); + if (TT.S) { + char *s = TT.S; // In C locale, isalnum() means [A-Za-Z0-0] while (isalnum(*s) || *s == '.' || *s == '/') s++; if (*s) error_exit("salt not in [./A-Za-z0-9]"); - snprintf(salt+i, sizeof(salt)-i, "%s", TT.salt); + snprintf(salt+i, sizeof(salt)-i, "%s", TT.S); } // Because read_password() doesn't have an fd argument - if (TT.pfd) { - if (dup2(TT.pfd, 0) == -1) perror_exit("fd"); - close(TT.pfd); + if (TT.P) { + if (dup2(TT.P, 0) == -1) perror_exit("fd"); + close(TT.P); } // If we haven't got a password on the command line, read it from tty or FD diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c index 1178d675..d631b3b3 100644 --- a/toys/other/modinfo.c +++ b/toys/other/modinfo.c @@ -20,17 +20,15 @@ config MODINFO #include "toys.h" GLOBALS( - char *field; - char *knam; - char *base; + char *F, *k, *b; long mod; ) static void output_field(char *field, char *value) { - if (!TT.field) xprintf("%s:%*c", field, 15-(int)strlen(field), ' '); - else if (strcmp(TT.field, field)) return; + if (!TT.F) xprintf("%s:%*c", field, 15-(int)strlen(field), ' '); + else if (strcmp(TT.F, field)) return; xprintf("%s", value); xputc((toys.optflags & FLAG_0) ? 0 : '\n'); } @@ -111,8 +109,8 @@ void modinfo_main(void) if (uname(&uts) < 0) perror_exit("bad uname"); if (snprintf(toybuf, sizeof(toybuf), "%s/lib/modules/%s", - (toys.optflags & FLAG_b) ? TT.base : "", - (toys.optflags & FLAG_k) ? TT.knam : uts.release) >= sizeof(toybuf)) + (toys.optflags & FLAG_b) ? TT.b : "", + (toys.optflags & FLAG_k) ? TT.k : uts.release) >= sizeof(toybuf)) perror_exit("basedir/kernrelease too long"); dirtree_read(toybuf, check_module); } diff --git a/toys/other/oneit.c b/toys/other/oneit.c index 681eb12f..2ee21768 100644 --- a/toys/other/oneit.c +++ b/toys/other/oneit.c @@ -32,7 +32,7 @@ config ONEIT #include <sys/reboot.h> GLOBALS( - char *console; + char *c; ) // The minimum amount of work necessary to get ctrl-c and such to work is: @@ -97,7 +97,7 @@ void oneit_main(void) for (i=0; i<3; i++) { close(i); // Remember, O_CLOEXEC is backwards for xopen() - xopen_stdio(TT.console ? TT.console : "/dev/tty0", O_RDWR|O_CLOEXEC); + xopen_stdio(TT.c ? TT.c : "/dev/tty0", O_RDWR|O_CLOEXEC); } // Can't xexec() here, we vforked so we don't want to error_exit(). diff --git a/toys/other/shred.c b/toys/other/shred.c index 680320ec..1bac75c5 100644 --- a/toys/other/shred.c +++ b/toys/other/shred.c @@ -30,22 +30,20 @@ config SHRED #include "toys.h" GLOBALS( - long offset; - long iterations; - long size; + long o, n, s; ) void shred_main(void) { char **try; - if (!(toys.optflags & FLAG_n)) TT.iterations++; + if (!(toys.optflags & FLAG_n)) TT.n++; // We don't use loopfiles() here because "-" isn't stdin, and want to // respond to files we can't open via chmod. for (try = toys.optargs; *try; try++) { - off_t pos = 0, len = TT.size; + off_t pos = 0, len = TT.s; int fd = open(*try, O_RDWR), iter = 0, throw; // do -f chmod if necessary @@ -72,19 +70,19 @@ void shred_main(void) if (pos >= len) { pos = -1; - if (++iter == TT.iterations && (toys.optargs && FLAG_z)) { + if (++iter == TT.n && (toys.optargs && FLAG_z)) { memset(toybuf, 0, sizeof(toybuf)); continue; } - if (iter >= TT.iterations) break; + if (iter >= TT.n) break; } - if (pos < TT.offset) { - if (TT.offset != lseek(fd, TT.offset, SEEK_SET)) { + if (pos < TT.o) { + if (TT.o != lseek(fd, TT.o, SEEK_SET)) { perror_msg_raw(*try); break; } - pos = TT.offset; + pos = TT.o; } // Determine length, read random data if not zeroing, write. @@ -93,7 +91,7 @@ void shred_main(void) if (toys.optflags & FLAG_x) if (len-pos < throw) throw = len-pos; - if (iter != TT.iterations) xgetrandom(toybuf, throw, 0); + if (iter != TT.n) xgetrandom(toybuf, throw, 0); if (throw != writeall(fd, toybuf, throw)) perror_msg_raw(*try); pos += throw; } diff --git a/toys/other/stat.c b/toys/other/stat.c index a1233650..f571857a 100644 --- a/toys/other/stat.c +++ b/toys/other/stat.c @@ -40,7 +40,7 @@ config STAT #include "toys.h" GLOBALS( - char *fmt; + char *c; union { struct stat st; @@ -182,7 +182,7 @@ void stat_main(void) "Access: (0%a/%A)\tUid: (%5u/%8U)\tGid: (%5g/%8G)\n" "Access: %x\nModify: %y\nChange: %z"; - if (toys.optflags & FLAG_c) format = TT.fmt; + if (toys.optflags & FLAG_c) format = TT.c; for (i = 0; toys.optargs[i]; i++) { int L = toys.optflags & FLAG_L; diff --git a/toys/other/swapon.c b/toys/other/swapon.c index 0d65040a..2eb5b93c 100644 --- a/toys/other/swapon.c +++ b/toys/other/swapon.c @@ -13,13 +13,14 @@ config SWAPON Enable swapping on a given device/file. -d Discard freed SSD pages + -p Priority (highest priority areas allocated first) */ #define FOR_swapon #include "toys.h" GLOBALS( - long priority; + long p; ) void swapon_main(void) @@ -28,7 +29,7 @@ void swapon_main(void) int flags = (toys.optflags&FLAG_d)*0x70000; if (toys.optflags) - flags |= SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT); + flags |= SWAP_FLAG_PREFER | (TT.p << SWAP_FLAG_PRIO_SHIFT); if (swapon(*toys.optargs, flags)) perror_exit("Couldn't swapon '%s'", *toys.optargs); diff --git a/toys/other/switch_root.c b/toys/other/switch_root.c index acbae2bb..eb1e2b0c 100644 --- a/toys/other/switch_root.c +++ b/toys/other/switch_root.c @@ -22,7 +22,7 @@ config SWITCH_ROOT #include <sys/vfs.h> GLOBALS( - char *console; + char *c; dev_t rootdev; ) @@ -78,8 +78,8 @@ void switch_root_main(void) goto panic; } - if (TT.console && -1 == (console = open(TT.console, O_RDWR))) { - perror_msg("bad console '%s'", TT.console); + if (TT.c && -1 == (console = open(TT.c, O_RDWR))) { + perror_msg("bad console '%s'", TT.c); goto panic; } @@ -104,7 +104,7 @@ void switch_root_main(void) goto panic; } - if (TT.console) { + if (TT.c) { int i; for (i=0; i<3; i++) if (console != i) dup2(console, i); if (console>2) close(console); diff --git a/toys/other/timeout.c b/toys/other/timeout.c index b903c3ec..51e3a7e3 100644 --- a/toys/other/timeout.c +++ b/toys/other/timeout.c @@ -28,8 +28,7 @@ config TIMEOUT #include "toys.h" GLOBALS( - char *s_signal; - char *k_timeout; + char *s, *k; int nextsig; pid_t pid; @@ -43,8 +42,8 @@ static void handler(int i) fprintf(stderr, "timeout pid %d signal %d\n", TT.pid, TT.nextsig); kill(TT.pid, TT.nextsig); - if (TT.k_timeout) { - TT.k_timeout = 0; + if (TT.k) { + TT.k = 0; TT.nextsig = SIGKILL; xsignal(SIGALRM, handler); TT.itv.it_value = TT.ktv; @@ -66,11 +65,11 @@ void timeout_main(void) { // Parse early to get any errors out of the way. xparsetimeval(*toys.optargs, &TT.itv.it_value); - if (TT.k_timeout) xparsetimeval(TT.k_timeout, &TT.ktv); + if (TT.k) xparsetimeval(TT.k, &TT.ktv); TT.nextsig = SIGTERM; - if (TT.s_signal && -1 == (TT.nextsig = sig_to_num(TT.s_signal))) - error_exit("bad -s: '%s'", TT.s_signal); + if (TT.s && -1 == (TT.nextsig = sig_to_num(TT.s))) + error_exit("bad -s: '%s'", TT.s); if (!(TT.pid = XVFORK())) xexec(toys.optargs+1); else { diff --git a/toys/other/xxd.c b/toys/other/xxd.c index 80892fb5..99321eef 100644 --- a/toys/other/xxd.c +++ b/toys/other/xxd.c @@ -35,11 +35,7 @@ config XXD #include "toys.h" GLOBALS( - long s; - long g; - long o; - long l; - long c; + long s, g, o, l, c; ) static void do_xxd(int fd, char *name) diff --git a/toys/posix/grep.c b/toys/posix/grep.c index c63c1f87..f0332cee 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -4,11 +4,11 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html * - * TODO: --color + * TODO: --color * * Posix doesn't even specify -r, documenting deviations from it is silly. -USE_GREP(NEWTOY(grep, "S(exclude)*M(include)*C#B#A#ZzEFHIabhinorsvwclqe*f*m#x[!wx][!EFw]", TOYFLAG_BIN)) +USE_GREP(NEWTOY(grep, "S(exclude)*M(include)*ZzEFHIabhinorsvwclqe*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN)) USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN)) USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN)) @@ -64,14 +64,8 @@ config FGREP #include <regex.h> GLOBALS( - long m; - struct arg_list *f; - struct arg_list *e; - long a; - long b; - long c; - struct arg_list *M; - struct arg_list *S; + long m, A, B, C; + struct arg_list *f, *e, *M, *S; char indelim, outdelim; int found; @@ -85,6 +79,7 @@ static void outline(char *line, char dash, char *name, long lcount, long bcount, if (!line || (lcount && (toys.optflags&FLAG_n))) printf("%ld%c", lcount, line ? dash : TT.outdelim); if (bcount && (toys.optflags&FLAG_b)) printf("%ld%c", bcount-1, dash); +// Support embedded NUL bytes in output if (line) xprintf("%.*s%c", trim, line, TT.outdelim); } @@ -246,7 +241,7 @@ static void do_grep(int fd, char *name) } outline(line, ':', name, lcount, bcount, -1); - if (TT.a) after = TT.a+1; + if (TT.A) after = TT.A+1; } else outline(start+matches.rm_so, ':', name, lcount, bcount, matches.rm_eo-matches.rm_so); } @@ -258,16 +253,16 @@ static void do_grep(int fd, char *name) if (mmatch) mcount++; else { - int discard = (after || TT.b); + int discard = (after || TT.B); if (after && --after) { outline(line, '-', name, lcount, 0, -1); discard = 0; } - if (discard && TT.b) { + if (discard && TT.B) { dlist_add(&dlb, line); line = 0; - if (++before>TT.b) { + if (++before>TT.B) { struct double_list *dl; dl = dlist_pop(&dlb); @@ -389,8 +384,8 @@ void grep_main(void) // Grep exits with 2 for errors toys.exitval = 2; - if (!TT.a) TT.a = TT.c; - if (!TT.b) TT.b = TT.c; + if (!TT.A) TT.A = TT.C; + if (!TT.B) TT.B = TT.C; TT.indelim = '\n' * !(toys.optflags&FLAG_z); TT.outdelim = '\n' * !(toys.optflags&FLAG_Z); diff --git a/toys/posix/uniq.c b/toys/posix/uniq.c index 114fc19b..78c82544 100644 --- a/toys/posix/uniq.c +++ b/toys/posix/uniq.c @@ -28,16 +28,14 @@ config UNIQ #include "toys.h" GLOBALS( - long maxchars; - long nchars; - long nfields; + long w, s, f; long repeats; ) static char *skip(char *str) { - long nchars = TT.nchars, nfields = TT.nfields; + long nchars = TT.s, nfields = TT.f; // Skip fields first while (nfields--) { @@ -77,7 +75,7 @@ void uniq_main(void) char *t1, *t2; // If requested get the chosen fields + character offsets. - if (TT.nfields || TT.nchars) { + if (TT.f || TT.s) { t1 = skip(thisline); t2 = skip(prevline); } else { @@ -85,10 +83,10 @@ void uniq_main(void) t2 = prevline; } - if (TT.maxchars == 0) + if (!TT.w) diff = !(toys.optflags & FLAG_i) ? strcmp(t1, t2) : strcasecmp(t1, t2); - else diff = !(toys.optflags & FLAG_i) ? strncmp(t1, t2, TT.maxchars) - : strncasecmp(t1, t2, TT.maxchars); + else diff = !(toys.optflags & FLAG_i) ? strncmp(t1, t2, TT.w) + : strncasecmp(t1, t2, TT.w); if (!diff) TT.repeats++; else { |