[BusyBox] Re: hexdump -C [PATCH]
Shaun Jackman
sjackman at gmail.com
Wed Jul 20 00:11:30 UTC 2005
I forgot to add the -C option to the usage statement. Incidentally, I
also forgot to actually add the -C option to hexdump_opts (donning
paper bag). Here's the updated patch.
Cheers,
Shaun
2005-07-19 Shaun Jackman <sjackman at gmail.com>
* libbb/dump.c (bpad): Bug fix: update pr->nospace. Use
library functions to reduce code size.
* util-linux/hexdump.c (hexdump_main): Add the -C option.
* include/usage.h (hexdump_full_usage): Ditto.
Index: libbb/dump.c
===================================================================
--- libbb/dump.c (revision 10867)
+++ libbb/dump.c (working copy)
@@ -438,17 +438,16 @@
static void bpad(PR * pr)
{
- register char *p1, *p2;
-
/*
* remove all conversion flags; '-' is the only one valid
* with %s, and it's not useful here.
*/
+ char *p = strchr(pr->fmt, '%') + 1;
+ int n = strspn(p, " -0+#");
pr->flags = F_BPAD;
*pr->cchar = 's';
- for (p1 = pr->fmt; *p1 != '%'; ++p1);
- for (p2 = ++p1; *p1 && strchr(" -0+#", *p1); ++p1);
- while ((*p2++ = *p1++) != 0);
+ pr->nospace -= n;
+ strcpy(p, p + n);
}
static const char conv_str[] =
Index: include/usage.h
===================================================================
--- include/usage.h (revision 10867)
+++ include/usage.h (working copy)
@@ -1014,6 +1014,7 @@
"format\n" \
"\t-b\t\tOne-byte octal display\n" \
"\t-c\t\tOne-byte character display\n" \
+ "\t-C\t\tCanonical hex+ASCII display\n" \
"\t-d\t\tTwo-byte decimal display\n" \
"\t-e FORMAT STRING\n" \
"\t-f FORMAT FILE\n" \
Index: util-linux/hexdump.c
===================================================================
--- util-linux/hexdump.c (revision 10867)
+++ util-linux/hexdump.c (working copy)
@@ -47,9 +47,11 @@
fclose(fp);
}
+#define NUM_FORMATS 6
static const char * const add_strings[] = {
"\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"", /* b */
"\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"", /* c */
+ "\"%07.7_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ", /* C */
"\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"", /* d */
"\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"", /* o */
"\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"", /* x */
@@ -57,7 +59,7 @@
static const char add_first[] = "\"%07.7_Ax\n\"";
-static const char hexdump_opts[] = "bcdoxe:f:n:s:v";
+static const char hexdump_opts[] = "bcCdoxe:f:n:s:v";
static const struct suffix_mult suffixes[] = {
{"b", 512 },
@@ -77,9 +79,11 @@
while ((ch = getopt(argc, argv, hexdump_opts)) > 0) {
if ((p = strchr(hexdump_opts, ch)) != NULL) {
- if ((p - hexdump_opts) < 5) {
+ if ((p - hexdump_opts) < NUM_FORMATS) {
bb_dump_add(add_first);
bb_dump_add(add_strings[(int)(p - hexdump_opts)]);
+ if (ch == 'C')
+ bb_dump_add("\" |\" 16/1 \"%_p\" \"|\\n\"");
} else {
/* Sae a little bit of space below by omitting the 'else's. */
if (ch == 'e') {
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: busybox-hexdump-C.diff
Url: http://lists.busybox.net/pipermail/busybox/attachments/20050719/8edb7a98/attachment.diff
More information about the busybox
mailing list