summaryrefslogtreecommitdiff
path: root/util-linux/hexdump.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-16 11:00:16 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-16 11:00:16 +0000
commit55f7912ddaea7c21068a48841a6eb933e5f286ee (patch)
tree8e048772811061a8db2429c3ef99e8205e1de1f6 /util-linux/hexdump.c
parent8ddb6410edb0c4e87b4c6b9d0887868977c8eff5 (diff)
downloadbusybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.tar.gz
busybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.tar.bz2
busybox-w32-55f7912ddaea7c21068a48841a6eb933e5f286ee.zip
libbb: get rid of statics in dump.c; code shrinks a lot too
function old new delta alloc_dumper - 26 +26 hexdump_main 600 601 +1 static.done 1 - -1 static.ateof 1 - -1 bb_dump_vflag 1 - -1 static.savp 4 - -4 static.nextfs 4 - -4 static.curp 4 - -4 exitval 4 - -4 endfu 4 - -4 bb_dump_length 4 - -4 bb_dump_fshead 4 - -4 bb_dump_blocksize 4 - -4 _argv 4 - -4 bb_dump_add 365 358 -7 savaddress 8 - -8 eaddress 8 - -8 bb_dump_skip 8 - -8 address 8 - -8 bb_dump_dump 2748 2672 -76 next 538 445 -93 ------------------------------------------------------------------------------ (add/remove: 1/16 grow/shrink: 1/3 up/down: 27/-247) Total: -220 bytes text data bss dec hex filename 789458 607 6764 796829 c289d busybox_old 789309 601 6696 796606 c27be busybox_unstripped
Diffstat (limited to 'util-linux/hexdump.c')
-rw-r--r--util-linux/hexdump.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c
index 7630153e7..4d2b0592b 100644
--- a/util-linux/hexdump.c
+++ b/util-linux/hexdump.c
@@ -15,7 +15,7 @@
15/* This is a NOEXEC applet. Be very careful! */ 15/* This is a NOEXEC applet. Be very careful! */
16 16
17 17
18static void bb_dump_addfile(char *name) 18static void bb_dump_addfile(dumper_t *dumper, char *name)
19{ 19{
20 char *p; 20 char *p;
21 FILE *fp; 21 FILE *fp;
@@ -27,7 +27,7 @@ static void bb_dump_addfile(char *name)
27 p = skip_whitespace(buf); 27 p = skip_whitespace(buf);
28 28
29 if (*p && (*p != '#')) { 29 if (*p && (*p != '#')) {
30 bb_dump_add(p); 30 bb_dump_add(dumper, p);
31 } 31 }
32 free(buf); 32 free(buf);
33 } 33 }
@@ -56,6 +56,7 @@ static const struct suffix_mult suffixes[] = {
56int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 56int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
57int hexdump_main(int argc, char **argv) 57int hexdump_main(int argc, char **argv)
58{ 58{
59 dumper_t *dumper = alloc_dumper();
59 const char *p; 60 const char *p;
60 int ch; 61 int ch;
61#if ENABLE_FEATURE_HEXDUMP_REVERSE 62#if ENABLE_FEATURE_HEXDUMP_REVERSE
@@ -63,9 +64,6 @@ int hexdump_main(int argc, char **argv)
63 smallint rdump = 0; 64 smallint rdump = 0;
64#endif 65#endif
65 66
66 bb_dump_vflag = FIRST;
67 bb_dump_length = -1;
68
69 if (ENABLE_HD && !applet_name[2]) { /* we are "hd" */ 67 if (ENABLE_HD && !applet_name[2]) { /* we are "hd" */
70 ch = 'C'; 68 ch = 'C';
71 goto hd_applet; 69 goto hd_applet;
@@ -78,30 +76,30 @@ int hexdump_main(int argc, char **argv)
78 if (!p) 76 if (!p)
79 bb_show_usage(); 77 bb_show_usage();
80 if ((p - hexdump_opts) < 5) { 78 if ((p - hexdump_opts) < 5) {
81 bb_dump_add(add_first); 79 bb_dump_add(dumper, add_first);
82 bb_dump_add(add_strings[(int)(p - hexdump_opts)]); 80 bb_dump_add(dumper, add_strings[(int)(p - hexdump_opts)]);
83 } 81 }
84 /* Save a little bit of space below by omitting the 'else's. */ 82 /* Save a little bit of space below by omitting the 'else's. */
85 if (ch == 'C') { 83 if (ch == 'C') {
86 hd_applet: 84 hd_applet:
87 bb_dump_add("\"%08.8_Ax\n\""); 85 bb_dump_add(dumper, "\"%08.8_Ax\n\"");
88 bb_dump_add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" "); 86 bb_dump_add(dumper, "\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
89 bb_dump_add("\" |\" 16/1 \"%_p\" \"|\\n\""); 87 bb_dump_add(dumper, "\" |\" 16/1 \"%_p\" \"|\\n\"");
90 } 88 }
91 if (ch == 'e') { 89 if (ch == 'e') {
92 bb_dump_add(optarg); 90 bb_dump_add(dumper, optarg);
93 } /* else */ 91 } /* else */
94 if (ch == 'f') { 92 if (ch == 'f') {
95 bb_dump_addfile(optarg); 93 bb_dump_addfile(dumper, optarg);
96 } /* else */ 94 } /* else */
97 if (ch == 'n') { 95 if (ch == 'n') {
98 bb_dump_length = xatoi_u(optarg); 96 dumper->dump_length = xatoi_u(optarg);
99 } /* else */ 97 } /* else */
100 if (ch == 's') { 98 if (ch == 's') {
101 bb_dump_skip = xatoul_range_sfx(optarg, 0, LONG_MAX, suffixes); 99 dumper->dump_skip = xatoul_range_sfx(optarg, 0, LONG_MAX, suffixes);
102 } /* else */ 100 } /* else */
103 if (ch == 'v') { 101 if (ch == 'v') {
104 bb_dump_vflag = ALL; 102 dumper->dump_vflag = ALL;
105 } 103 }
106#if ENABLE_FEATURE_HEXDUMP_REVERSE 104#if ENABLE_FEATURE_HEXDUMP_REVERSE
107 if (ch == 'R') { 105 if (ch == 'R') {
@@ -110,18 +108,18 @@ int hexdump_main(int argc, char **argv)
110#endif 108#endif
111 } 109 }
112 110
113 if (!bb_dump_fshead) { 111 if (!dumper->fshead) {
114 bb_dump_add(add_first); 112 bb_dump_add(dumper, add_first);
115 bb_dump_add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\""); 113 bb_dump_add(dumper, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
116 } 114 }
117 115
118 argv += optind; 116 argv += optind;
119 117
120#if !ENABLE_FEATURE_HEXDUMP_REVERSE 118#if !ENABLE_FEATURE_HEXDUMP_REVERSE
121 return bb_dump_dump(argv); 119 return bb_dump_dump(dumper, argv);
122#else 120#else
123 if (!rdump) { 121 if (!rdump) {
124 return bb_dump_dump(argv); 122 return bb_dump_dump(dumper, argv);
125 } 123 }
126 124
127 /* -R: reverse of 'hexdump -Cv' */ 125 /* -R: reverse of 'hexdump -Cv' */