aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-11-17 18:25:08 -0600
committerRob Landley <rob@landley.net>2018-11-17 18:25:08 -0600
commit503e6362290d56bce0ed71f8164f24e25108bbbc (patch)
tree06d962fb5a547aa07f387d879cb28ff84fd23b78
parent7d26f1071d17dc2980280008fbbcd8a6a376d387 (diff)
downloadtoybox-503e6362290d56bce0ed71f8164f24e25108bbbc.tar.gz
Convert more GLOBALS argument vars to the new single letter code style.
-rw-r--r--toys/android/log.c13
-rw-r--r--toys/example/skeleton.c29
-rw-r--r--toys/lsb/dmesg.c7
-rw-r--r--toys/lsb/killall.c8
-rw-r--r--toys/lsb/mknod.c7
-rw-r--r--toys/lsb/mktemp.c10
-rw-r--r--toys/lsb/passwd.c5
-rw-r--r--toys/net/ftpget.c16
-rw-r--r--toys/net/netcat.c38
-rw-r--r--toys/net/ping.c5
-rw-r--r--toys/net/tunctl.c4
-rw-r--r--toys/other/base64.c4
12 files changed, 67 insertions, 79 deletions
diff --git a/toys/android/log.c b/toys/android/log.c
index 09e36d7b..f9545ab8 100644
--- a/toys/android/log.c
+++ b/toys/android/log.c
@@ -22,8 +22,7 @@ config LOG
#include "toys.h"
GLOBALS(
- char *tag;
- char *pri;
+ char *t, *p;
)
void log_main(void)
@@ -32,14 +31,14 @@ void log_main(void)
char *s = toybuf;
int i;
- if (TT.pri) {
- i = stridx("defisvw", tolower(*TT.pri));
- if (i==-1 || strlen(TT.pri)!=1) error_exit("bad -p '%s'", TT.pri);
+ if (TT.p) {
+ i = stridx("defisvw", tolower(*TT.p));
+ if (i==-1 || strlen(TT.p)!=1) error_exit("bad -p '%s'", TT.p);
pri = (android_LogPriority []){ANDROID_LOG_DEBUG, ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL, ANDROID_LOG_INFO, ANDROID_LOG_SILENT,
ANDROID_LOG_VERBOSE, ANDROID_LOG_WARN}[i];
}
- if (!TT.tag) TT.tag = "log";
+ if (!TT.t) TT.t = "log";
for (i = 0; toys.optargs[i]; i++) {
if (i) *s++ = ' ';
@@ -53,5 +52,5 @@ void log_main(void)
s = stpcpy(s, toys.optargs[i]);
}
- __android_log_write(pri, TT.tag, toybuf);
+ __android_log_write(pri, TT.t, toybuf);
}
diff --git a/toys/example/skeleton.c b/toys/example/skeleton.c
index 666e804a..b8dd102a 100644
--- a/toys/example/skeleton.c
+++ b/toys/example/skeleton.c
@@ -45,15 +45,14 @@ config SKELETON_ALIAS
GLOBALS(
union {
struct {
- char *b_string;
- long c_number;
- struct arg_list *d_list;
- long e_count;
- char *also_string;
- char *blubber_string;
+ char *b;
+ long c;
+ struct arg_list *d;
+ long e;
+ char *also, *blubber;
} s;
struct {
- long b_number;
+ long b;
} a;
};
@@ -74,17 +73,17 @@ void skeleton_main(void)
// from main.c using the optstring in the NEWTOY macros. Display results.
if (toys.optflags) printf("flags=%llx\n", toys.optflags);
if (toys.optflags & FLAG_a) printf("Saw a\n");
- if (toys.optflags & FLAG_b) printf("b=%s\n", TT.s.b_string);
- if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.s.c_number);
- while (TT.s.d_list) {
- printf("d=%s\n", TT.s.d_list->arg);
- TT.s.d_list = TT.s.d_list->next;
+ if (toys.optflags & FLAG_b) printf("b=%s\n", TT.s.b);
+ if (toys.optflags & FLAG_c) printf("c=%ld\n", TT.s.c);
+ while (TT.s.d) {
+ printf("d=%s\n", TT.s.d->arg);
+ TT.s.d = TT.s.d->next;
}
- if (TT.s.e_count) printf("e was seen %ld times\n", TT.s.e_count);
+ if (TT.s.e) printf("e was seen %ld times\n", TT.s.e);
for (optargs = toys.optargs; *optargs; optargs++)
printf("optarg=%s\n", *optargs);
if (toys.optflags & FLAG_walrus) printf("Saw --walrus\n");
- if (TT.s.blubber_string) printf("--blubber=%s\n", TT.s.blubber_string);
+ if (TT.s.blubber) printf("--blubber=%s\n", TT.s.blubber);
printf("Other globals should start zeroed: %d\n", TT.more_globals);
}
@@ -101,5 +100,5 @@ void skeleton_alias_main(void)
// Note, this FLAG_b is a different bit position than the other FLAG_b,
// and fills out a different variable of a different type.
- if (toys.optflags & FLAG_b) printf("b=%ld", TT.a.b_number);
+ if (toys.optflags & FLAG_b) printf("b=%ld", TT.a.b);
}
diff --git a/toys/lsb/dmesg.c b/toys/lsb/dmesg.c
index 30f90e3a..42f642ce 100644
--- a/toys/lsb/dmesg.c
+++ b/toys/lsb/dmesg.c
@@ -34,8 +34,7 @@ config DMESG
#include <sys/klog.h>
GLOBALS(
- long level;
- long size;
+ long n, s;
int use_color;
time_t tea;
@@ -157,7 +156,7 @@ void dmesg_main(void)
klogctl_mode:
// Figure out how much data we need, and fetch it.
- if (!(size = TT.size)) size = xklogctl(10, 0, 0);
+ if (!(size = TT.s)) size = xklogctl(10, 0, 0);
data = from = xmalloc(size+1);
data[size = xklogctl(3+(toys.optflags&FLAG_c), data, size)] = 0;
@@ -175,7 +174,7 @@ klogctl_mode:
no_output:
// Set the log level?
- if (toys.optflags & FLAG_n) xklogctl(8, 0, TT.level);
+ if (toys.optflags & FLAG_n) xklogctl(8, 0, TT.n);
// Clear the buffer?
if (toys.optflags & (FLAG_C|FLAG_c)) xklogctl(5, 0, 0);
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c
index 2772b432..d524107c 100644
--- a/toys/lsb/killall.c
+++ b/toys/lsb/killall.c
@@ -25,7 +25,7 @@ config KILLALL
#include "toys.h"
GLOBALS(
- char *sig;
+ char *s;
int signum;
pid_t cur_pid;
@@ -72,12 +72,12 @@ void killall_main(void)
return;
}
- if (TT.sig || (*TT.names && **TT.names == '-')) {
- if (0 > (TT.signum = sig_to_num(TT.sig ? TT.sig : (*TT.names)+1))) {
+ if (TT.s || (*TT.names && **TT.names == '-')) {
+ if (0 > (TT.signum = sig_to_num(TT.s ? TT.s : (*TT.names)+1))) {
if (toys.optflags & FLAG_q) exit(1);
error_exit("Invalid signal");
}
- if (!TT.sig) {
+ if (!TT.s) {
TT.names++;
toys.optc--;
}
diff --git a/toys/lsb/mknod.c b/toys/lsb/mknod.c
index 8148c857..f8c33183 100644
--- a/toys/lsb/mknod.c
+++ b/toys/lsb/mknod.c
@@ -31,8 +31,7 @@ config MKNOD_Z
#include "toys.h"
GLOBALS(
- char *arg_context;
- char *m;
+ char *Z, *m;
)
void mknod_main(void)
@@ -51,8 +50,8 @@ void mknod_main(void)
}
if (toys.optflags & FLAG_Z)
- if (-1 == lsm_set_create(TT.arg_context))
- perror_exit("-Z '%s' failed", TT.arg_context);
+ if (-1 == lsm_set_create(TT.Z))
+ perror_exit("-Z '%s' failed", TT.Z);
if (mknod(*toys.optargs, mode|modes[type], dev_makedev(major, minor)))
perror_exit_raw(*toys.optargs);
}
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 118daccf..21bb9b36 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -28,7 +28,7 @@ config MKTEMP
#include "toys.h"
GLOBALS(
- char *tmpdir;
+ char *p;
)
void mktemp_main(void)
@@ -38,16 +38,16 @@ void mktemp_main(void)
if (!template) template = "tmp.XXXXXX";
- if (!TT.tmpdir) TT.tmpdir = getenv("TMPDIR");
- if (!TT.tmpdir || !*TT.tmpdir) TT.tmpdir = "/tmp";
+ if (!TT.p) TT.p = getenv("TMPDIR");
+ if (!TT.p || !*TT.p) TT.p = "/tmp";
template = strchr(template, '/') ? xstrdup(template)
- : xmprintf("%s/%s", TT.tmpdir, template);
+ : xmprintf("%s/%s", TT.p, template);
if (d_flag ? !mkdtemp(template) : mkstemp(template) == -1) {
if (toys.optflags & FLAG_q) toys.exitval = 1;
else perror_exit("Failed to create %s %s/%s",
- d_flag ? "directory" : "file", TT.tmpdir, template);
+ d_flag ? "directory" : "file", TT.p, template);
} else {
if (toys.optflags & FLAG_u) unlink(template);
xputs(template);
diff --git a/toys/lsb/passwd.c b/toys/lsb/passwd.c
index e23de1c6..0f51c0c0 100644
--- a/toys/lsb/passwd.c
+++ b/toys/lsb/passwd.c
@@ -36,7 +36,7 @@ config PASSWD_SAD
#include "toys.h"
GLOBALS(
- char *algo;
+ char *a;
)
// Sad advisory heuristic, won't find password1 password2 password3...
@@ -84,8 +84,7 @@ void passwd_main(void)
printf("Deleting password for '%s'\n", name);
encrypted = "";
} else {
- if (get_salt(salt, TT.algo ? TT.algo : "des")<0)
- error_exit("bad -a '%s'", TT.algo);
+ if (get_salt(salt, TT.a ? TT.a : "des")<0) error_exit("bad -a '%s'", TT.a);
printf("Changing password for %s\n", name);
if (myuid) {
diff --git a/toys/net/ftpget.c b/toys/net/ftpget.c
index 9d6f6fd7..ad3c3030 100644
--- a/toys/net/ftpget.c
+++ b/toys/net/ftpget.c
@@ -46,9 +46,7 @@ config FTPPUT
#include "toys.h"
GLOBALS(
- char *user;
- char *port;
- char *password;
+ char *u, *p, *P;
int fd;
)
@@ -101,20 +99,20 @@ void ftpget_main(void)
if (!(toys.optflags&(FLAG_v-1)))
toys.optflags |= (toys.which->name[3]=='g') ? FLAG_g : FLAG_s;
- if (!TT.user) TT.user = "anonymous";
- if (!TT.password) TT.password = "ftpget@";
- if (!TT.port) TT.port = "21";
+ if (!TT.u) TT.u = "anonymous";
+ if (!TT.P) TT.P = "ftpget@";
+ if (!TT.p) TT.p = "21";
if (!remote) remote = toys.optargs[1];
// connect
- TT.fd = xconnect(xgetaddrinfo(*toys.optargs, TT.port, 0, SOCK_STREAM, 0,
+ TT.fd = xconnect(xgetaddrinfo(*toys.optargs, TT.p, 0, SOCK_STREAM, 0,
AI_ADDRCONFIG));
if (getpeername(TT.fd, (void *)&si6, &sl)) perror_exit("getpeername");
// Login
ftp_line(0, 0, 220);
- rc = ftp_line("USER", TT.user, 0);
- if (rc == 331) rc = ftp_line("PASS", TT.password, 0);
+ rc = ftp_line("USER", TT.u, 0);
+ if (rc == 331) rc = ftp_line("PASS", TT.P, 0);
if (rc != 230) error_exit_raw(toybuf);
if (toys.optflags & FLAG_m) {
diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index 039b1944..54700c36 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -7,7 +7,7 @@
* netcat -L zombies
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
-USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("^tlL")"w#<1W#<1p#<1>65535s:q#<1f:"USE_NETCAT_LISTEN("[!tlL][!Lw]"), TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("^tlL")"w#<1W#<1p#<1>65535q#<1s:f:"USE_NETCAT_LISTEN("[!tlL][!Lw]"), TOYFLAG_BIN))
config NETCAT
bool "netcat"
@@ -20,7 +20,7 @@ config NETCAT
-q quit SECONDS after EOF on stdin, even if stdout hasn't closed yet
-s local source address
-w SECONDS timeout to establish connection
- -W SECONDS timeout for idle connection
+ -W SECONDS timeout for more data on an idle connection
Use "stty 115200 -F /dev/ttyS0 && stty raw -echo -ctlecho" with
netcat -f to connect to a serial port.
@@ -49,18 +49,14 @@ config NETCAT_LISTEN
#include "toys.h"
GLOBALS(
- char *filename; // -f read from filename instead of network
- long quit_delay; // -q Exit after EOF from stdin after # seconds.
- char *source_address; // -s Bind to a specific source address.
- long port; // -p Bind to a specific source port.
- long idle; // -W Wait # seconds for more data
- long wait; // -w Wait # seconds for a connection.
+ char *f, *s;
+ long q, p, W, w;
)
static void timeout(int signum)
{
- if (TT.wait) error_exit("Timeout");
- // This should be xexit() but would need siglongjmp()...
+ if (TT.w) error_exit("Timeout");
+ // TODO This should be xexit() but would need siglongjmp()...
exit(0);
}
@@ -102,10 +98,10 @@ void netcat_main(void)
pid_t child;
// Addjust idle and quit_delay to miliseconds or -1 for no timeout
- TT.idle = TT.idle ? TT.idle*1000 : -1;
- TT.quit_delay = TT.quit_delay ? TT.quit_delay*1000 : -1;
+ TT.W = TT.W ? TT.W*1000 : -1;
+ TT.q = TT.q ? TT.q*1000 : -1;
- set_alarm(TT.wait);
+ set_alarm(TT.w);
// The argument parsing logic can't make "<2" conditional on other
// arguments like -f and -l, so do it by hand here.
@@ -113,17 +109,17 @@ void netcat_main(void)
(!(toys.optflags&(FLAG_l|FLAG_L)) && toys.optc!=2))
help_exit("bad argument count");
- if (TT.filename) in1 = out2 = xopen(TT.filename, O_RDWR);
+ if (TT.f) in1 = out2 = xopen(TT.f, O_RDWR);
else {
// Setup socket
sockfd = xsocket(AF_INET, SOCK_STREAM, 0);
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &out1, sizeof(out1));
address->sin_family = AF_INET;
- if (TT.source_address || TT.port) {
- address->sin_port = SWAP_BE16(TT.port);
- if (TT.source_address)
- lookup_name(TT.source_address, (uint32_t *)&(address->sin_addr));
+ if (TT.s || TT.p) {
+ address->sin_port = SWAP_BE16(TT.p);
+ if (TT.s)
+ lookup_name(TT.s, (uint32_t *)&(address->sin_addr));
if (bind(sockfd, (struct sockaddr *)address, sizeof(*address)))
perror_exit("bind");
}
@@ -143,13 +139,13 @@ void netcat_main(void)
in1 = out2 = sockfd;
- pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay);
+ pollinate(in1, in2, out1, out2, TT.W, TT.q);
} else {
// Listen for incoming connections
socklen_t len = sizeof(*address);
if (listen(sockfd, 5)) error_exit("listen");
- if (!TT.port) {
+ if (!TT.p) {
getsockname(sockfd, (struct sockaddr *)address, &len);
printf("%d\n", SWAP_BE16(address->sin_port));
fflush(stdout);
@@ -188,7 +184,7 @@ void netcat_main(void)
xexec(toys.optargs);
}
- pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay);
+ pollinate(in1, in2, out1, out2, TT.W, TT.q);
close(in1);
} while (!(toys.optflags&FLAG_l));
}
diff --git a/toys/net/ping.c b/toys/net/ping.c
index ad7679fd..1829af71 100644
--- a/toys/net/ping.c
+++ b/toys/net/ping.c
@@ -11,7 +11,7 @@
* Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint...
// -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes
-USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i%W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN))
+USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56i%W#<0=3w#<0qf46I:[-46]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
config PING
@@ -47,9 +47,8 @@ config PING
#include <netinet/ip_icmp.h>
GLOBALS(
- long w, W, i;
char *I;
- long s, c, t, m;
+ long w, W, i, s, c, t, m;
struct sockaddr *sa;
int sock;
diff --git a/toys/net/tunctl.c b/toys/net/tunctl.c
index 1aafebfd..6a2cf1ee 100644
--- a/toys/net/tunctl.c
+++ b/toys/net/tunctl.c
@@ -32,13 +32,13 @@ config TUNCTL
#include <linux/if_tun.h>
GLOBALS(
- char *user;
+ char *u;
)
void tunctl_main(void)
{
struct ifreq *ifr = (void *)toybuf;
- uid_t u = TT.user ? xgetuid(TT.user) : 0;
+ uid_t u = TT.u ? xgetuid(TT.u) : 0;
int fd = xopen("/dev/net/tun", O_RDWR);
// Associate filehandle with device
diff --git a/toys/other/base64.c b/toys/other/base64.c
index 33155bc5..87887cda 100644
--- a/toys/other/base64.c
+++ b/toys/other/base64.c
@@ -23,7 +23,7 @@ config BASE64
#include "toys.h"
GLOBALS(
- long columns;
+ long w;
unsigned total;
)
@@ -32,7 +32,7 @@ static void wraputchar(int c, int *x)
{
putchar(c);
TT.total++;
- if (TT.columns && ++*x == TT.columns) {
+ if (TT.w && ++*x == TT.w) {
*x = 0;
xputc('\n');
};