aboutsummaryrefslogtreecommitdiff
path: root/util-linux/hexdump.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/hexdump.c')
-rw-r--r--util-linux/hexdump.c61
1 files changed, 2 insertions, 59 deletions
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c
index 065b83980..2174c3008 100644
--- a/util-linux/hexdump.c
+++ b/util-linux/hexdump.c
@@ -15,16 +15,6 @@
15//config: The hexdump utility is used to display binary data in a readable 15//config: The hexdump utility is used to display binary data in a readable
16//config: way that is comparable to the output from most hex editors. 16//config: way that is comparable to the output from most hex editors.
17//config: 17//config:
18//config:config FEATURE_HEXDUMP_REVERSE
19//config: bool "Support -R, reverse of 'hexdump -Cv'"
20//config: default y
21//config: depends on HEXDUMP
22//config: help
23//config: The hexdump utility is used to display binary data in an ascii
24//config: readable way. This option creates binary data from an ascii input.
25//config: NB: this option is non-standard. It's unwise to use it in scripts
26//config: aimed to be portable.
27//config:
28//config:config HD 18//config:config HD
29//config: bool "hd (7.8 kb)" 19//config: bool "hd (7.8 kb)"
30//config: default y 20//config: default y
@@ -38,7 +28,7 @@
38//kbuild:lib-$(CONFIG_HD) += hexdump.o 28//kbuild:lib-$(CONFIG_HD) += hexdump.o
39 29
40//usage:#define hexdump_trivial_usage 30//usage:#define hexdump_trivial_usage
41//usage: "[-bcCdefnosvx" IF_FEATURE_HEXDUMP_REVERSE("R") "] [FILE]..." 31//usage: "[-bcCdefnosvx] [FILE]..."
42//usage:#define hexdump_full_usage "\n\n" 32//usage:#define hexdump_full_usage "\n\n"
43//usage: "Display FILEs (or stdin) in a user specified format\n" 33//usage: "Display FILEs (or stdin) in a user specified format\n"
44//usage: "\n -b 1-byte octal display" 34//usage: "\n -b 1-byte octal display"
@@ -53,9 +43,6 @@
53// exactly the same help text lines in hexdump and xxd: 43// exactly the same help text lines in hexdump and xxd:
54//usage: "\n -n LENGTH Show only first LENGTH bytes" 44//usage: "\n -n LENGTH Show only first LENGTH bytes"
55//usage: "\n -s OFFSET Skip OFFSET bytes" 45//usage: "\n -s OFFSET Skip OFFSET bytes"
56//usage: IF_FEATURE_HEXDUMP_REVERSE(
57//usage: "\n -R Reverse of 'hexdump -Cv'")
58// TODO: NONCOMPAT!!! move -R to xxd -r
59//usage: 46//usage:
60//usage:#define hd_trivial_usage 47//usage:#define hd_trivial_usage
61//usage: "FILE..." 48//usage: "FILE..."
@@ -94,7 +81,7 @@ static const char *const add_strings[] = {
94 81
95static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\""; 82static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\"";
96 83
97static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v" IF_FEATURE_HEXDUMP_REVERSE("R"); 84static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v";
98 85
99int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 86int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
100int hexdump_main(int argc, char **argv) 87int hexdump_main(int argc, char **argv)
@@ -102,10 +89,6 @@ int hexdump_main(int argc, char **argv)
102 dumper_t *dumper = alloc_dumper(); 89 dumper_t *dumper = alloc_dumper();
103 const char *p; 90 const char *p;
104 int ch; 91 int ch;
105#if ENABLE_FEATURE_HEXDUMP_REVERSE
106 FILE *fp;
107 smallint rdump = 0;
108#endif
109 92
110 if (ENABLE_HD 93 if (ENABLE_HD
111 && (!ENABLE_HEXDUMP || !applet_name[2]) 94 && (!ENABLE_HEXDUMP || !applet_name[2])
@@ -153,11 +136,6 @@ int hexdump_main(int argc, char **argv)
153 if (ch == 'v') { 136 if (ch == 'v') {
154 dumper->dump_vflag = ALL; 137 dumper->dump_vflag = ALL;
155 } 138 }
156#if ENABLE_FEATURE_HEXDUMP_REVERSE
157 if (ch == 'R') {
158 rdump = 1;
159 }
160#endif
161 } 139 }
162 140
163 if (!dumper->fshead) { 141 if (!dumper->fshead) {
@@ -167,40 +145,5 @@ int hexdump_main(int argc, char **argv)
167 145
168 argv += optind; 146 argv += optind;
169 147
170#if !ENABLE_FEATURE_HEXDUMP_REVERSE
171 return bb_dump_dump(dumper, argv); 148 return bb_dump_dump(dumper, argv);
172#else
173 if (!rdump) {
174 return bb_dump_dump(dumper, argv);
175 }
176
177 /* -R: reverse of 'hexdump -Cv' */
178 fp = stdin;
179 if (!*argv) {
180 argv--;
181 goto jump_in;
182 }
183
184 do {
185 char *buf;
186 fp = xfopen_for_read(*argv);
187 jump_in:
188 while ((buf = xmalloc_fgetline(fp)) != NULL) {
189 p = buf;
190 while (1) {
191 /* skip address or previous byte */
192 while (isxdigit(*p)) p++;
193 while (*p == ' ') p++;
194 /* '|' char will break the line */
195 if (!isxdigit(*p) || sscanf(p, "%x ", &ch) != 1)
196 break;
197 putchar(ch);
198 }
199 free(buf);
200 }
201 fclose(fp);
202 } while (*++argv);
203
204 fflush_stdout_and_exit(EXIT_SUCCESS);
205#endif
206} 149}