diff options
author | Ondrej Oprala | 2013-09-23 15:39:09 +0200 |
---|---|---|
committer | Karel Zak | 2013-11-08 12:54:52 +0100 |
commit | 9db5120719a4ff650f2e8b9c3c4081ee46f6f374 (patch) | |
tree | 85161ac4570af2a4032654a37241a889112f25ba /text-utils/hexdump.c | |
parent | hexdump: add basic tests (diff) | |
download | kernel-qcow2-util-linux-9db5120719a4ff650f2e8b9c3c4081ee46f6f374.tar.gz kernel-qcow2-util-linux-9db5120719a4ff650f2e8b9c3c4081ee46f6f374.tar.xz kernel-qcow2-util-linux-9db5120719a4ff650f2e8b9c3c4081ee46f6f374.zip |
hexdump: use list.h queues and rewrite redundant for cycles
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'text-utils/hexdump.c')
-rw-r--r-- | text-utils/hexdump.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index e966cc313..18b3ec23f 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -41,40 +41,47 @@ #include <stdlib.h> #include "hexdump.h" +#include "list.h" #include "nls.h" #include "c.h" #include "closestream.h" -FS *fshead; /* head of format strings */ +struct list_head fshead; /* head of format strings */ ssize_t blocksize; /* data block size */ int exitval; /* final exit value */ ssize_t length = -1; /* max bytes to read */ int main(int argc, char **argv) { + struct list_head *p; FS *tfs; - char *p; + char *c; + INIT_LIST_HEAD(&fshead); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); - if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od")) { + if (!(c = strrchr(argv[0], 'o')) || strcmp(c, "od")) { newsyntax(argc, &argv); } else errx(EXIT_FAILURE, _("calling hexdump as od has been deprecated " "in favour to GNU coreutils od.")); /* figure out the data block size */ - for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) { - tfs->bcnt = block_size(tfs); - if (blocksize < tfs->bcnt) + blocksize = 0; + list_for_each(p, &fshead) { + tfs = list_entry(p, FS, nextfs); + if ((tfs->bcnt = block_size(tfs)) > blocksize) blocksize = tfs->bcnt; } + /* rewrite the rules, do syntax checking */ - for (tfs = fshead; tfs; tfs = tfs->nextfs) + list_for_each(p, &fshead) { + tfs = list_entry(p, FS, nextfs); rewrite(tfs); + } (void)next(argv); display(); |