Commit 21d74553 authored by Leah Neukirchen's avatar Leah Neukirchen

print_format: add escapes for octal and hex bytes

parent 603c12cd
......@@ -157,8 +157,12 @@ Implies
format strings support the following escape sequences:
.Pp
.Bl -tag -compact -width Ds
.It Ic \ea , \eb , \ef , \en , \er , \ev , \e0
.It Ic \ea , \eb , \ef , \en , \er , \ev
Special characters as in C.
.It Ic \e Ns Ar ddd
Byte with one, two or three-digit octal value.
.It Ic \ex Ns Ar dd
Byte with one or two-digit hexadecimal value.
.It Ic \&%%
A plain
.Sq % .
......
......@@ -1831,6 +1831,7 @@ hyperlink_off()
void
print_format(struct fileinfo *fi)
{
int c, v;
char *s;
for (s = format; *s; s++) {
if (*s == '\\') {
......@@ -1842,8 +1843,32 @@ print_format(struct fileinfo *fi)
case 'r': putchar('\r'); break;
case 't': putchar('\t'); break;
case 'v': putchar('\v'); break;
case '0': putchar('\0'); break;
// TODO: \NNN
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
for (c = 3, v = 0;
c > 0 && *s >= '0' && *s <= '7';
s++, c--) {
v = (v << 3) + ((*s) - '0');
}
s--;
putchar(v & 0xff);
break;
case 'x':
s++;
for (c = 2, v = 0;
c > 0 && isxdigit((unsigned char)*s);
s++, c--) {
v <<= 4;
if (*s >= 'A' && *s <= 'F')
v += *s - 'A' + 10;
else if (*s >= 'a' && *s <= 'f')
v += *s - 'a' + 10;
else
v += *s - '0';
}
s--;
putchar(v);
break;
default: putchar(*s);
}
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment