aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/catv.c5
-rw-r--r--toys/other/dos2unix.c5
-rw-r--r--toys/other/free.c9
-rw-r--r--toys/other/hello.c11
-rw-r--r--toys/other/login.c15
-rw-r--r--toys/other/mke2fs.c6
-rw-r--r--toys/other/modinfo.c6
-rw-r--r--toys/other/mountpoint.c9
-rw-r--r--toys/other/netcat.c13
-rw-r--r--toys/other/oneit.c8
-rw-r--r--toys/other/rmmod.c5
-rw-r--r--toys/other/sha1sum.c5
-rw-r--r--toys/other/swapon.c7
-rw-r--r--toys/other/switch_root.c8
-rw-r--r--toys/other/taskset.c4
-rw-r--r--toys/other/truncate.c5
-rw-r--r--toys/other/vmstat.c2
17 files changed, 49 insertions, 74 deletions
diff --git a/toys/other/catv.c b/toys/other/catv.c
index 221549f3..a0790a9b 100644
--- a/toys/other/catv.c
+++ b/toys/other/catv.c
@@ -23,12 +23,9 @@ config CATV
-v Don't use ^x or M-x escapes.
*/
+#define FOR_catv
#include "toys.h"
-#define FLAG_v 4
-#define FLAG_t 2
-#define FLAG_e 1
-
// Callback function for loopfiles()
static void do_catv(int fd, char *name)
diff --git a/toys/other/dos2unix.c b/toys/other/dos2unix.c
index 07e68055..15cc1706 100644
--- a/toys/other/dos2unix.c
+++ b/toys/other/dos2unix.c
@@ -17,14 +17,13 @@ config DOS2UNIX
If no files listed copy from stdin, "-" is a synonym for stdin.
*/
+#define FOR_dos2unix
#include "toys.h"
-DEFINE_GLOBALS(
+GLOBALS(
char *tempfile;
)
-#define TT this.dos2unix
-
static void do_dos2unix(int fd, char *name)
{
char c = toys.which->name[0];
diff --git a/toys/other/free.c b/toys/other/free.c
index b009b8b0..aa344928 100644
--- a/toys/other/free.c
+++ b/toys/other/free.c
@@ -18,6 +18,7 @@ config FREE
-bkmg Output in bytes (default), KB, MB or GB
*/
+#define FOR_free
#include "toys.h"
static unsigned long long convert(unsigned long d, unsigned int iscale,
@@ -34,10 +35,10 @@ void free_main(void)
sysinfo(&info);
if (info.mem_unit) iscale = info.mem_unit;
- if (toys.optflags & 1) oscale = 0;
- if (toys.optflags & 2) oscale = 10;
- if (toys.optflags & 4) oscale = 20;
- if (toys.optflags & 8) oscale = 30;
+ if (toys.optflags & FLAG_b) oscale = 0;
+ if (toys.optflags & FLAG_k) oscale = 10;
+ if (toys.optflags & FLAG_m) oscale = 20;
+ if (toys.optflags & FLAG_g) oscale = 30;
xprintf("\t\ttotal used free shared buffers\n");
xprintf("Mem:%17llu%12llu%12llu%12llu%12llu\n",
diff --git a/toys/other/hello.c b/toys/other/hello.c
index cfab40df..2b469591 100644
--- a/toys/other/hello.c
+++ b/toys/other/hello.c
@@ -21,11 +21,12 @@ config HELLO
occasionally nice to test kernel booting via "init=/bin/hello".
*/
+#define FOR_hello
#include "toys.h"
// Hello doesn't use these globals, they're here for example/skeleton purposes.
-DEFINE_GLOBALS(
+GLOBALS(
char *b_string;
long c_number;
struct arg_list *d_list;
@@ -34,14 +35,6 @@ DEFINE_GLOBALS(
int more_globals;
)
-#define TT this.hello
-
-#define FLAG_a 1
-#define FLAG_b 2
-#define FLAG_c 4
-#define FLAG_d 8
-#define FLAG_e 16
-
void hello_main(void)
{
printf("Hello world\n");
diff --git a/toys/other/login.c b/toys/other/login.c
index 8c542a7e..a9e7562c 100644
--- a/toys/other/login.c
+++ b/toys/other/login.c
@@ -21,6 +21,7 @@ config LOGIN
-f Do not perform authentication
*/
+#define FOR_login
#include "toys.h"
#define LOGIN_TIMEOUT 60
@@ -28,10 +29,9 @@ config LOGIN
#define USER_NAME_MAX_SIZE 32
#define HOSTNAME_SIZE 32
-DEFINE_GLOBALS(
+GLOBALS(
char *hostname;
)
-#define TT this.login
static void login_timeout_handler(int sig __attribute__((unused)))
{
@@ -162,9 +162,8 @@ void setup_environment(const struct passwd *pwd, int clear_env)
void login_main(void)
{
- int f_flag = (toys.optflags & 4) >> 2;
- int p_flag = (toys.optflags & 2) >> 1;
- int h_flag = toys.optflags & 1;
+ int f_flag = toys.optflags & FLAG_f;
+ int h_flag = toys.optflags & FLAG_h;
char username[USER_NAME_MAX_SIZE+1], *pass = NULL, **ss;
struct passwd * pwd = NULL;
struct spwd * spwd = NULL;
@@ -215,7 +214,7 @@ query_pass:
f_flag = 0;
syslog(LOG_WARNING, "invalid password for '%s' on %s %s %s", username,
- ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:"");
+ ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
sleep(LOGIN_FAIL_TIMEOUT);
puts("Login incorrect");
@@ -234,12 +233,12 @@ query_pass:
if (change_identity(pwd)) error_exit("Failed to change identity");
- setup_environment(pwd, !p_flag);
+ setup_environment(pwd, !(toys.optflags & FLAG_p));
handle_motd();
syslog(LOG_INFO, "%s logged in on %s %s %s", pwd->pw_name,
- ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:"");
+ ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
spawn_shell(pwd->pw_shell);
}
diff --git a/toys/other/mke2fs.c b/toys/other/mke2fs.c
index 837ea214..5745d519 100644
--- a/toys/other/mke2fs.c
+++ b/toys/other/mke2fs.c
@@ -73,9 +73,10 @@ config MKE2FS_EXTENDED
sparse_super Don't allocate huge numbers of redundant superblocks
*/
+#define FOR_mke2fs
#include "toys.h"
-DEFINE_GLOBALS(
+GLOBALS(
// Command line arguments.
long blocksize;
long bytes_per_inode;
@@ -102,9 +103,6 @@ DEFINE_GLOBALS(
struct ext2_superblock sb;
)
-// Shortcut to our global data structure, since we use it so much.
-#define TT this.mke2fs
-
#define INODES_RESERVED 10
static uint32_t div_round_up(uint32_t a, uint32_t b)
diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c
index c878fc4e..0c5f177f 100644
--- a/toys/other/modinfo.c
+++ b/toys/other/modinfo.c
@@ -14,14 +14,12 @@ config MODINFO
usage: modinfo [-0] [-F field] [modulename...]
*/
+#define FOR_modinfo
#include "toys.h"
-#define FLAG_0 (1 << 0)
-
-DEFINE_GLOBALS(
+GLOBALS(
char *field;
)
-#define TT this.modinfo
static const char *modinfo_tags[] = {
"alias", "license", "description", "author", "vermagic",
diff --git a/toys/other/mountpoint.c b/toys/other/mountpoint.c
index 1bb0b3a7..fe63b725 100644
--- a/toys/other/mountpoint.c
+++ b/toys/other/mountpoint.c
@@ -17,19 +17,20 @@ config MOUNTPOINT
-x Print major/minor device number of the block device
*/
+#define FOR_mountpoint
#include "toys.h"
void mountpoint_main(void)
{
struct stat st1, st2;
int res = 0;
- int quiet = toys.optflags & 0x4;
+ int quiet = toys.optflags & FLAG_q;
toys.exitval = 1; // be pessimistic
strncpy(toybuf, toys.optargs[0], sizeof(toybuf));
- if (((toys.optflags & 0x1) && lstat(toybuf, &st1)) || stat(toybuf, &st1))
+ if (((toys.optflags & FLAG_x) && lstat(toybuf, &st1)) || stat(toybuf, &st1))
perror_exit("%s", toybuf);
- if (toys.optflags & 0x1){
+ if (toys.optflags & FLAG_x){
if (S_ISBLK(st1.st_mode)) {
if (!quiet) printf("%u:%u\n", major(st1.st_rdev), minor(st1.st_rdev));
toys.exitval = 0;
@@ -48,7 +49,7 @@ void mountpoint_main(void)
res = (st1.st_dev != st2.st_dev) ||
(st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
if (!quiet) printf("%s is %sa mountpoint\n", toys.optargs[0], res ? "" : "not ");
- if (toys.optflags & 0x2)
+ if (toys.optflags & FLAG_d)
printf("%u:%u\n", major(st1.st_dev), minor(st1.st_dev));
toys.exitval = res ? 0 : 1;
}
diff --git a/toys/other/netcat.c b/toys/other/netcat.c
index 6442c09b..2e90737d 100644
--- a/toys/other/netcat.c
+++ b/toys/other/netcat.c
@@ -3,6 +3,9 @@
* netcat.c - Forward stdin/stdout to a file or network connection.
*
* Copyright 2007 Rob Landley <rob@landley.net>
+ *
+ * TODO: udp, ipv6, genericize for telnet/microcom/tail-f
+
USE_NETCAT(OLDTOY(nc, netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN))
USE_NETCAT(NEWTOY(netcat, USE_NETCAT_LISTEN("tl^L^")"w#p#s:q#f:", TOYFLAG_BIN))
@@ -40,10 +43,11 @@ config NETCAT_LISTEN
netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l
*/
+#define FOR_netcat
#include "toys.h"
#include "toynet.h"
-DEFINE_GLOBALS(
+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.
@@ -51,13 +55,6 @@ DEFINE_GLOBALS(
long wait; // -w Wait # seconds for a connection.
)
-#define TT this.netcat
-
-#define FLAG_f 1
-#define FLAG_L 32
-#define FLAG_l 64
-#define FLAG_t 128
-
static void timeout(int signum)
{
if (TT.wait) error_exit("Timeout");
diff --git a/toys/other/oneit.c b/toys/other/oneit.c
index ff7aa914..8bb482da 100644
--- a/toys/other/oneit.c
+++ b/toys/other/oneit.c
@@ -24,15 +24,14 @@ config ONEIT
which point it reboots (or with -p, powers off) the system.
*/
+#define FOR_oneit
#include "toys.h"
#include <sys/reboot.h>
-DEFINE_GLOBALS(
+GLOBALS(
char *console;
)
-#define TT this.oneit
-
// The minimum amount of work necessary to get ctrl-c and such to work is:
//
// - Fork a child (PID 1 is special: can't exit, has various signals blocked).
@@ -59,7 +58,8 @@ void oneit_main(void)
// PID 1 can't call reboot() because it kills the task that calls it,
// which causes the kernel to panic before the actual reboot happens.
- if (!vfork()) reboot((toys.optflags&1) ? RB_POWER_OFF : RB_AUTOBOOT);
+ if (!vfork())
+ reboot((toys.optflags & FLAG_p) ? RB_POWER_OFF : RB_AUTOBOOT);
sleep(5);
_exit(1);
}
diff --git a/toys/other/rmmod.c b/toys/other/rmmod.c
index cfc978ab..18ace3fa 100644
--- a/toys/other/rmmod.c
+++ b/toys/other/rmmod.c
@@ -18,6 +18,7 @@ config RMMOD
*/
+#define FOR_rmmod
#include "toys.h"
#include <sys/syscall.h>
@@ -41,8 +42,8 @@ void rmmod_main(void)
if (len > 3 && !strcmp(&mod_name[len-3], ".ko" ))
mod_name[len-3] = 0;
- if (toys.optflags & 1) flags |= O_TRUNC;
- if (toys.optflags & 2) flags &= ~O_NONBLOCK;
+ if (toys.optflags & FLAG_f) flags |= O_TRUNC;
+ if (toys.optflags & FLAG_w) flags &= ~O_NONBLOCK;
if (delete_module(mod_name, flags))
perror_exit("failed to unload %s", mod_name);
diff --git a/toys/other/sha1sum.c b/toys/other/sha1sum.c
index 3165effc..8833c8de 100644
--- a/toys/other/sha1sum.c
+++ b/toys/other/sha1sum.c
@@ -18,9 +18,10 @@ config SHA1SUM
Calculate sha1 hash of files (or stdin).
*/
+#define FOR_sha1sum
#include <toys.h>
-DEFINE_GLOBALS(
+GLOBALS(
uint32_t state[5];
uint32_t oldstate[5];
uint64_t count;
@@ -30,8 +31,6 @@ DEFINE_GLOBALS(
} buffer;
)
-#define TT this.sha1sum
-
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
// blk0() and blk() perform the initial expand.
diff --git a/toys/other/swapon.c b/toys/other/swapon.c
index 4b9734e4..db7c45b0 100644
--- a/toys/other/swapon.c
+++ b/toys/other/swapon.c
@@ -15,19 +15,18 @@ config SWAPON
Enable swapping on a given device/file.
*/
+#define FOR_swapon
#include "toys.h"
-DEFINE_GLOBALS(
+GLOBALS(
long priority;
)
-#define TT this.swapon
-
void swapon_main(void)
{
int flags = 0;
- if (toys.optflags & 1)
+ if (toys.optflags)
flags = SWAP_FLAG_PREFER | (TT.priority << SWAP_FLAG_PRIO_SHIFT);
if (swapon(*toys.optargs, flags))
diff --git a/toys/other/switch_root.c b/toys/other/switch_root.c
index b4c0b7dd..6451ec15 100644
--- a/toys/other/switch_root.c
+++ b/toys/other/switch_root.c
@@ -17,20 +17,16 @@ config SWITCH_ROOT
-h Hang instead of exiting on failure (avoids kernel panic)
*/
+#define FOR_switch_root
#include "toys.h"
#include <sys/vfs.h>
-DEFINE_GLOBALS(
+GLOBALS(
char *console;
dev_t rootdev;
)
-#define TT this.switch_root
-
-#define FLAG_h (1<<0)
-#define FLAG_c (1<<1)
-
static int del_node(struct dirtree *node)
{
if (node->st.st_dev == TT.rootdev && dirtree_notdotdot(node)) {
diff --git a/toys/other/taskset.c b/toys/other/taskset.c
index 9b219044..74cbfffa 100644
--- a/toys/other/taskset.c
+++ b/toys/other/taskset.c
@@ -22,11 +22,9 @@ config TASKSET
-a Set/get the affinity of all threads of the PID.
*/
+#define FOR_taskset
#include "toys.h"
-#define FLAG_a 0x1
-#define FLAG_p 0x2
-
// Prototype for syscall wrappers sched.h refuses to give us
int sched_setaffinity(pid_t pid, size_t size, void *cpuset);
int sched_getaffinity(pid_t pid, size_t size, void *cpuset);
diff --git a/toys/other/truncate.c b/toys/other/truncate.c
index aa952b16..47b07583 100644
--- a/toys/other/truncate.c
+++ b/toys/other/truncate.c
@@ -17,14 +17,13 @@ config TRUNCATE
-s New size
*/
+#define FOR_truncate
#include "toys.h"
-DEFINE_GLOBALS(
+GLOBALS(
long size;
)
-#define TT this.truncate
-
static void do_truncate(int fd, char *name)
{
if (fd<0) return;
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index b4858227..1c348f2a 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -122,7 +122,7 @@ void vmstat_main(void)
unsigned long io_pages_in[2], io_pages_out[2], swap_bytes_in[2], swap_bytes_out[2];
uint64_t sys_irq[2], sys_ctxt[2], cpu_user[2], cpu_sys[2], cpu_idle[2], cpu_wait[2];
int first_run = 1;
- int no_header = toys.optflags & 0x1;
+ int no_header = toys.optflags;
unsigned num_rows = 22;
if (toys.optc >= 1)