xxd: '-p -c 0' outputs a single line
No binary (build failed)
—
(log yok)
| @@ -79,4 +79,12 @@ testing 'xxd -p -r ignores the nibble with 2nd char bad' \ | |
| 36 | |
| " | |
| + | testing 'xxd -p -c0 outputs a single line' \ |
| + | 'xxd -p -c0' \ |
| + | "\ |
| + | 68656c6c6f20776f726c640a68656c6c6f20776f726c640a68656c6c6f20776f726c640a |
| + | " \ |
| + | '' \ |
| + | 'hello world\nhello world\nhello world\n' |
| + | |
| exit $FAILCOUNT | |
| @@ -50,7 +50,7 @@ | |
| //usage: "Hex dump FILE (or stdin)\n" | |
| //usage: "\n -g N Bytes per group (default 2)" | |
| //usage: "\n -c N Bytes per line (default:16, -ps:30, -i:12)" | |
| - | //usage: "\n -ps Show only hex bytes (no offset/spaces)" |
| + | //usage: "\n -ps Show only hex bytes (-c 0: output as one line)" |
| //usage: "\n -i C include file style" | |
| // exactly the same help text lines in hexdump and xxd: | |
| //usage: "\n -l LENGTH Show only first LENGTH bytes" | |
| @@ -238,6 +238,7 @@ int xxd_main(int argc UNUSED_PARAM, char **argv) | |
| unsigned bytes = 2; | |
| unsigned cols = 0; | |
| unsigned opt; | |
| + | int omit_newline = FALSE; |
| int r; | |
| setup_common_bufsiz(); | |
| @@ -278,8 +279,11 @@ int xxd_main(int argc UNUSED_PARAM, char **argv) | |
| } | |
| if (opt & OPT_p) { | |
| - | if (cols == 0) |
| + | if (cols == 0) { |
| + | // '-p -c 0' prints as a single line |
| + | omit_newline = opt & OPT_c; |
| cols = 30; | |
| + | } |
| bytes = cols; /* -p ignores -gN */ | |
| } else { | |
| if (cols == 0) | |
| @@ -329,7 +333,8 @@ int xxd_main(int argc UNUSED_PARAM, char **argv) | |
| sprintf(buf, "\" \"%u/1 \"%%_p\"\"\n\"", cols); // " ASCII\n" | |
| bb_dump_add(dumper, buf); | |
| } else { | |
| - | bb_dump_add(dumper, "\"\n\""); |
| + | if (!omit_newline) |
| + | bb_dump_add(dumper, "\"\n\""); |
| dumper->xxd_eofstring = "\n"; | |
| } | |