mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-07-28 19:39:52 +02:00
maint: rename octhexdigits macros
isodigit -> isoct; octtobin -> fromoct; hextobin -> fromhex. * src/octhexdigits.h: Rename macros. * src/stat.c, src/printf.c: Use new macros.
This commit is contained in:
committed by
Pádraig Brady
parent
f069bb710a
commit
def6b33bf6
+3
-6
@@ -1,7 +1,4 @@
|
||||
#define isodigit(c) ('0' <= (c) && (c) <= '7')
|
||||
#define octtobin(c) ((c) - '0')
|
||||
/* FIXME-maybe: macros names may be misleading: "bin" may be interpreted as
|
||||
"having a value of (char)'0' or (char)'1'". Rename? `hextonative`?
|
||||
`hextoint`? */
|
||||
#define hextobin(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
|
||||
#define isoct(c) ('0' <= (c) && (c) <= '7')
|
||||
#define fromoct(c) ((c) - '0')
|
||||
#define fromhex(c) ('a' <= (c) && (c) <= 'f' ? (c) - 'a' + 10 : \
|
||||
'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0')
|
||||
|
||||
+5
-5
@@ -261,20 +261,20 @@ print_esc (char const *escstart, bool octal_0)
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 2 && c_isxdigit (to_uchar (*p));
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin (*p);
|
||||
esc_value = esc_value * 16 + fromhex (*p);
|
||||
if (esc_length == 0)
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (isodigit (*p))
|
||||
else if (isoct (*p))
|
||||
{
|
||||
/* Parse \0ooo (if octal_0 && *p == '0') or \ooo (otherwise).
|
||||
Allow \ooo if octal_0 && *p != '0'; this is an undocumented
|
||||
extension to POSIX that is compatible with Bash 2.05b. */
|
||||
for (esc_length = 0, p += octal_0 && *p == '0';
|
||||
esc_length < 3 && isodigit (*p);
|
||||
esc_length < 3 && isoct (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
esc_value = esc_value * 8 + fromoct (*p);
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (*p && strchr ("\"\\abcefnrtv", *p))
|
||||
@@ -291,7 +291,7 @@ print_esc (char const *escstart, bool octal_0)
|
||||
{
|
||||
if (! c_isxdigit (to_uchar (*p)))
|
||||
error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
|
||||
uni_value = uni_value * 16 + hextobin (*p);
|
||||
uni_value = uni_value * 16 + fromhex (*p);
|
||||
}
|
||||
|
||||
/* Error for invalid code points 0000D800 through 0000DFFF inclusive.
|
||||
|
||||
+6
-6
@@ -1199,28 +1199,28 @@ print_it (char const *format, int fd, char const *filename,
|
||||
break;
|
||||
}
|
||||
++b;
|
||||
if (isodigit (*b))
|
||||
if (isoct (*b))
|
||||
{
|
||||
int esc_value = octtobin (*b);
|
||||
int esc_value = fromoct (*b);
|
||||
int esc_length = 1; /* number of octal digits */
|
||||
for (++b; esc_length < 3 && isodigit (*b);
|
||||
for (++b; esc_length < 3 && isoct (*b);
|
||||
++esc_length, ++b)
|
||||
{
|
||||
esc_value = esc_value * 8 + octtobin (*b);
|
||||
esc_value = esc_value * 8 + fromoct (*b);
|
||||
}
|
||||
putchar (esc_value);
|
||||
--b;
|
||||
}
|
||||
else if (*b == 'x' && c_isxdigit (to_uchar (b[1])))
|
||||
{
|
||||
int esc_value = hextobin (b[1]); /* Value of \xhh escape. */
|
||||
int esc_value = fromhex (b[1]); /* Value of \xhh escape. */
|
||||
/* A hexadecimal \xhh escape sequence must have
|
||||
1 or 2 hex. digits. */
|
||||
++b;
|
||||
if (c_isxdigit (to_uchar (b[1])))
|
||||
{
|
||||
++b;
|
||||
esc_value = esc_value * 16 + hextobin (*b);
|
||||
esc_value = esc_value * 16 + fromhex (*b);
|
||||
}
|
||||
putchar (esc_value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user