hexdump: formatting and variable name cleanup
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
This commit is contained in:
parent
dabfe2ad7c
commit
d6e5614e5d
|
@ -73,12 +73,12 @@ conv_c(PR *pr, u_char *p)
|
||||||
}
|
}
|
||||||
if (isprint(*p)) {
|
if (isprint(*p)) {
|
||||||
*pr->cchar = 'c';
|
*pr->cchar = 'c';
|
||||||
(void)printf(pr->fmt, *p);
|
printf(pr->fmt, *p);
|
||||||
} else {
|
} else {
|
||||||
(void)sprintf(buf, "%03o", (int)*p);
|
sprintf(buf, "%03o", (int)*p);
|
||||||
str = buf;
|
str = buf;
|
||||||
strpr: *pr->cchar = 's';
|
strpr: *pr->cchar = 's';
|
||||||
(void)printf(pr->fmt, str);
|
printf(pr->fmt, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,15 +95,15 @@ conv_u(PR *pr, u_char *p)
|
||||||
/* od used nl, not lf */
|
/* od used nl, not lf */
|
||||||
if (*p <= 0x1f) {
|
if (*p <= 0x1f) {
|
||||||
*pr->cchar = 's';
|
*pr->cchar = 's';
|
||||||
(void)printf(pr->fmt, list[*p]);
|
printf(pr->fmt, list[*p]);
|
||||||
} else if (*p == 0x7f) {
|
} else if (*p == 0x7f) {
|
||||||
*pr->cchar = 's';
|
*pr->cchar = 's';
|
||||||
(void)printf(pr->fmt, "del");
|
printf(pr->fmt, "del");
|
||||||
} else if (isprint(*p)) {
|
} else if (isprint(*p)) {
|
||||||
*pr->cchar = 'c';
|
*pr->cchar = 'c';
|
||||||
(void)printf(pr->fmt, *p);
|
printf(pr->fmt, *p);
|
||||||
} else {
|
} else {
|
||||||
*pr->cchar = 'x';
|
*pr->cchar = 'x';
|
||||||
(void)printf(pr->fmt, (int)*p);
|
printf(pr->fmt, (int)*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,9 +162,17 @@ static void bpad(PR *pr)
|
||||||
pr->flags = F_BPAD;
|
pr->flags = F_BPAD;
|
||||||
pr->cchar[0] = 's';
|
pr->cchar[0] = 's';
|
||||||
pr->cchar[1] = 0;
|
pr->cchar[1] = 0;
|
||||||
for (p1 = pr->fmt; *p1 != '%'; ++p1);
|
|
||||||
for (p2 = ++p1; *p1 && strchr(spec, *p1); ++p1);
|
p1 = pr->fmt;
|
||||||
while ((*p2++ = *p1++) != 0) ;
|
while (*p1 != '%')
|
||||||
|
++p1;
|
||||||
|
|
||||||
|
p2 = ++p1;
|
||||||
|
while (*p1 && strchr(spec, *p1))
|
||||||
|
++p1;
|
||||||
|
|
||||||
|
while ((*p2++ = *p1++))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(void)
|
void display(void)
|
||||||
|
|
|
@ -78,10 +78,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rewrite the rules, do syntax checking */
|
/* rewrite the rules, do syntax checking */
|
||||||
list_for_each(p, &fshead) {
|
list_for_each(p, &fshead)
|
||||||
tfs = list_entry(p, FS, nextfs);
|
rewrite(list_entry(p, FS, nextfs));
|
||||||
rewrite(tfs);
|
|
||||||
}
|
|
||||||
|
|
||||||
next(argv);
|
next(argv);
|
||||||
display();
|
display();
|
||||||
|
|
|
@ -56,7 +56,7 @@ newsyntax(int argc, char ***argvp)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
char **argv;
|
char **argv;
|
||||||
char *hex_offt_fmt = "\"%07.7_Ax\n\"";
|
char *hex_offt = "\"%07.7_Ax\n\"";
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{"one-byte-octal", no_argument, NULL, 'b'},
|
{"one-byte-octal", no_argument, NULL, 'b'},
|
||||||
|
@ -79,11 +79,11 @@ newsyntax(int argc, char ***argvp)
|
||||||
while ((ch = getopt_long(argc, argv, "bcCde:f:n:os:vxhV", longopts, NULL)) != -1) {
|
while ((ch = getopt_long(argc, argv, "bcCde:f:n:os:vxhV", longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
|
add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
|
add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
@ -92,7 +92,7 @@ newsyntax(int argc, char ***argvp)
|
||||||
add("\" |\" 16/1 \"%_p\" \"|\\n\"");
|
add("\" |\" 16/1 \"%_p\" \"|\\n\"");
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
|
add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
|
@ -105,7 +105,7 @@ newsyntax(int argc, char ***argvp)
|
||||||
length = strtosize_or_err(optarg, _("failed to parse length"));
|
length = strtosize_or_err(optarg, _("failed to parse length"));
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
|
add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -115,7 +115,7 @@ newsyntax(int argc, char ***argvp)
|
||||||
vflag = ALL;
|
vflag = ALL;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
|
add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -130,7 +130,7 @@ newsyntax(int argc, char ***argvp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_empty(&fshead)) {
|
if (list_empty(&fshead)) {
|
||||||
add(hex_offt_fmt);
|
add(hex_offt);
|
||||||
add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
|
add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ void add(const char *fmt)
|
||||||
tfu->reps = atoi((char *)savep);
|
tfu->reps = atoi((char *)savep);
|
||||||
tfu->flags = F_SETREP;
|
tfu->flags = F_SETREP;
|
||||||
/* skip trailing white space */
|
/* skip trailing white space */
|
||||||
while (++p && isspace(*p))
|
while (isspace(*++p))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ void add(const char *fmt)
|
||||||
badfmt(fmt);
|
badfmt(fmt);
|
||||||
tfu->bcnt = atoi((char *)savep);
|
tfu->bcnt = atoi((char *)savep);
|
||||||
/* skip trailing white space */
|
/* skip trailing white space */
|
||||||
while (++p && isspace(*p))
|
while (isspace(*++p))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,10 +455,10 @@ void rewrite(FS *fs)
|
||||||
if (fu->reps > 1) {
|
if (fu->reps > 1) {
|
||||||
if (!list_empty(&fu->nextpr)) {
|
if (!list_empty(&fu->nextpr)) {
|
||||||
pr = list_last_entry(&fu->nextpr, PR, nextpr);
|
pr = list_last_entry(&fu->nextpr, PR, nextpr);
|
||||||
for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
|
for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
|
||||||
p2 = isspace(*p1) ? p1 : NULL;
|
p2 = isspace(*p1) ? p1 : NULL;
|
||||||
if (p2)
|
if (p2)
|
||||||
pr->nospace = p2;
|
pr->nospace = p2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue