From 009b55edc4bad5b46ace88f3c255bbff8671d137 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 26 Aug 2018 14:16:49 -0500 Subject: Convert more commands to the new option/GLOBALS code style. --- toys/posix/od.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'toys/posix/od.c') diff --git a/toys/posix/od.c b/toys/posix/od.c index ea7f6ac5..c9c5c486 100644 --- a/toys/posix/od.c +++ b/toys/posix/od.c @@ -27,11 +27,9 @@ config OD #include "toys.h" GLOBALS( - struct arg_list *output_base; - char *address_base; - long max_count; - long width; - long jump_bytes; + struct arg_list *t; + char *A; + long N, w, j; int address_idx; unsigned types, leftover, star; @@ -131,11 +129,11 @@ static void od_outline(void) struct odtype *types = (struct odtype *)toybuf; int i, j, len, pad; - if (TT.leftover TT.pos) { - off_t pos = TT.jump_bytes-TT.pos, off = lskip(fd, pos); + if (TT.j > TT.pos) { + off_t pos = TT.j-TT.pos, off = lskip(fd, pos); if (off >= 0) TT.pos += pos-off; - if (TT.jump_bytes > TT.pos) return; + if (TT.j > TT.pos) return; } for(;;) { char *buf = TT.buf + TT.leftover; - int len = TT.width - TT.leftover; + int len = TT.w - TT.leftover; if (toys.optflags & FLAG_N) { - if (!TT.max_count) break; - if (TT.max_count < len) len = TT.max_count; + if (!TT.N) break; + if (TT.N < len) len = TT.N; } len = readall(fd, buf, len); @@ -211,9 +209,9 @@ static void do_od(int fd, char *name) perror_msg_raw(name); break; } - if (TT.max_count) TT.max_count -= len; + if (TT.N) TT.N -= len; TT.leftover += len; - if (TT.leftover < TT.width) break; + if (TT.leftover < TT.w) break; od_outline(); } @@ -265,17 +263,17 @@ void od_main(void) { struct arg_list *arg; - TT.bufs[0] = xzalloc(TT.width); - TT.bufs[1] = xzalloc(TT.width); + TT.bufs[0] = xzalloc(TT.w); + TT.bufs[1] = xzalloc(TT.w); TT.buf = TT.bufs[0]; - if (!TT.address_base) TT.address_idx = 2; - else if (0>(TT.address_idx = stridx("ndox", *TT.address_base))) - error_exit("bad -A '%c'", *TT.address_base); + if (!TT.A) TT.address_idx = 2; + else if (0>(TT.address_idx = stridx("ndox", *TT.A))) + error_exit("bad -A '%c'", *TT.A); // Collect -t entries - for (arg = TT.output_base; arg; arg = arg->next) append_base(arg->arg); + for (arg = TT.t; arg; arg = arg->next) append_base(arg->arg); if (toys.optflags & FLAG_b) append_base("o1"); if (toys.optflags & FLAG_c) append_base("c"); if (toys.optflags & FLAG_d) append_base("u2"); -- cgit v1.2.3