* src/octhexdigits.h: isodigit, hextobin, octtobin macros * src/stat.c, src/printf.c: use octhexdigits.h * src/local.mk: corresponding adjustments --- src/local.mk | 1 + src/octhexdigits.h | 7 +++++++ src/printf.c | 6 +----- src/stat.c | 7 +------ 4 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 src/octhexdigits.h
diff --git a/src/local.mk b/src/local.mk index afae907..b8d3173 100644 --- a/src/local.mk +++ b/src/local.mk @@ -54,6 +54,7 @@ noinst_HEADERS = \ src/iopoll.h \ src/longlong.h \ src/ls.h \ + src/octhexdigits.h \ src/operand2sig.h \ src/prog-fprintf.h \ src/remove.h \ diff --git a/src/octhexdigits.h b/src/octhexdigits.h new file mode 100644 index 0000000..d947715 --- /dev/null +++ b/src/octhexdigits.h @@ -0,0 +1,7 @@ +#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 : \ + 'A' <= (c) && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0') diff --git a/src/printf.c b/src/printf.c index 9be4f23..d6d3609 100644 --- a/src/printf.c +++ b/src/printf.c @@ -58,6 +58,7 @@ #include "system.h" #include "c-ctype.h" #include "cl-strtod.h" +#include "octhexdigits.h" #include "quote.h" #include "unicodeio.h" #include "xprintf.h" @@ -67,11 +68,6 @@ #define AUTHORS proper_name ("David MacKenzie") -#define isodigit(c) ((c) >= '0' && (c) <= '7') -#define hextobin(c) ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \ - (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0') -#define octtobin(c) ((c) - '0') - /* The value to return to the calling program. */ static int exit_status; diff --git a/src/stat.c b/src/stat.c index 4a04bd9..632f81c 100644 --- a/src/stat.c +++ b/src/stat.c @@ -64,6 +64,7 @@ #include "filemode.h" #include "fs.h" #include "mountlist.h" +#include "octhexdigits.h" #include "quote.h" #include "stat-size.h" #include "stat-time.h" @@ -167,12 +168,6 @@ statfs (char const *filename, struct fs_info *buf) # include <sys/nvpair.h> #endif -/* FIXME: these are used by printf.c, too */ -#define isodigit(c) ('0' <= (c) && (c) <= '7') -#define octtobin(c) ((c) - '0') -#define hextobin(c) ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \ - (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : (c) - '0') - static char const digits[] = "0123456789"; /* Flags that are portable for use in printf, for at least one -- 2.45.0