Commit f6bbde28 by Zack Weinberg

safe-ctype.h: New file.

include:
	* safe-ctype.h: New file.
libiberty:
	* safe-ctype.c: New file.
	* Makefile.in (CFILES): Add safe-ctype.c.
	(REQUIRED_OFILES): Add safe-ctype.o.

	* argv.c: Define ISBLANK and use it, not isspace.
	* basename.c, cplus-dem.c, fnmatch.c, pexecute.c, strtod.c,
	strtol.c, strtoul.c: Include safe-ctype.h, not ctype.h.  Use
	uppercase ctype macros.  Don't test ISUPPER(c)/ISLOWER(c)
	before calling TOLOWER(c)/TOUPPER(c).
gcc:
	* Makefile.in (HOST_RTL): Add safe-ctype.o.
	(safe-ctype.o): New rule.
	* system.h: Include safe-ctype.h, not ctype.h.  No need to
	wrap ctype macros.

	* cpphash.h: Zap IStable and related macros.  Define is_* in
	terms of safe-ctype.h macros.
	* cppinit.c: Delete the IStable and all related code.

	* tradcpp.c: Delete is_idchar, is_idstart, is_hor_space, and
	is_space arrays.  Delete initialize_char_syntax.  Change all
	references to the above arrays to use macros instead.
	* tradcpp.h: Define is_idchar, is_idstart, is_space, and
	is_nvspace in terms of safe_ctype.h's macros.
	* tradcif.y: is_idchar, is_idstart are macros not arrays.

	* config/i370/i370.c, config/winnt/dirent.c,
	config/winnt/fixinc-nt.c, config/winnt/ld.c:
	Use uppercase ctype macros.  If we included ctype.h,
	include safe-ctype.h instead.

	* fixinc/fixfixes.c: Use uppercase ctype macros.  Don't test
	ISLOWER(c) before calling TOUPPER(c).
	* fixinc/fixincl.c (extract_quoted_files): Simplify out some gunk.
	* fixinc/gnu-regex.c: Include safe-ctype.h, not ctype.h.  No need to
	wrap ctype macros.  Don't test ISUPPER(x) before calling TOLOWER(x).
gcc/ch:
	* lex.c: Don't bother checking whether ISUPPER(c) before
	calling TOLOWER(c).  Don't bother checking whether isascii(c)
	before testing ISSPACE(c); ISSPACE(c) includes '\n'.
gcc/f:
	* Make-lang.in: Link f/fini with safe-ctype.o.
	* bad.c: Don't test ISUPPER(c) || ISLOWER(c) before calling TOUPPER(c).
	* com.c: Use TOUPPER, not ffesrc_toupper.
	* fini.c: Don't test ISALPHA(c) before calling TOUPPER(c)/TOLOWER(c).
	* intrin.c: Don't test IN_CTYPE_DOMAIN(c).
	* src.c: Delete ffesrc_toupper_ and ffesrc_tolower_ and their
	initializing code; use TOUPPER and TOLOWER instead of
	ffesrc_toupper and ffesrc_tolower.
	* src.h: Don't declare ffesrc_toupper_ or ffesrc_tolower_.
	Don't define ffesrc_toupper or ffesrc_tolower.
gcc/java:
	* jvgenmain.c: Use ISPRINT not isascii.

From-SVN: r38124
parent f3588f1a
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* Makefile.in (HOST_RTL): Add safe-ctype.o.
(safe-ctype.o): New rule.
* system.h: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros.
* cpphash.h: Zap IStable and related macros. Define is_* in
terms of safe-ctype.h macros.
* cppinit.c: Delete the IStable and all related code.
* tradcpp.c: Delete is_idchar, is_idstart, is_hor_space, and
is_space arrays. Delete initialize_char_syntax. Change all
references to the above arrays to use macros instead.
* tradcpp.h: Define is_idchar, is_idstart, is_space, and
is_nvspace in terms of safe_ctype.h's macros.
* tradcif.y: is_idchar, is_idstart are macros not arrays.
* config/i370/i370.c, config/winnt/dirent.c,
config/winnt/fixinc-nt.c, config/winnt/ld.c:
Use uppercase ctype macros. If we included ctype.h,
include safe-ctype.h instead.
* fixinc/fixfixes.c: Use uppercase ctype macros. Don't test
ISLOWER(c) before calling TOUPPER(c).
* fixinc/fixincl.c (extract_quoted_files): Simplify out some gunk.
* fixinc/gnu-regex.c: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros. Don't test ISUPPER(x) before calling TOLOWER(x).
2000-12-07 DJ Delorie <dj@redhat.com> 2000-12-07 DJ Delorie <dj@redhat.com>
* c-decl.c (grokdeclarator): preserve previous alignments when * c-decl.c (grokdeclarator): preserve previous alignments when
......
...@@ -627,7 +627,7 @@ HOST_LIBS = $(USE_HOST_OBSTACK) $(USE_HOST_ALLOCA) $(USE_HOST_MALLOC) \ ...@@ -627,7 +627,7 @@ HOST_LIBS = $(USE_HOST_OBSTACK) $(USE_HOST_ALLOCA) $(USE_HOST_MALLOC) \
$(USE_HOST_VFPRINTF) $(USE_HOST_DOPRINT) $(HOST_CLIB) $(USE_HOST_VFPRINTF) $(USE_HOST_DOPRINT) $(HOST_CLIB)
HOST_RTL = $(HOST_PREFIX)rtl.o $(HOST_PREFIX)bitmap.o \ HOST_RTL = $(HOST_PREFIX)rtl.o $(HOST_PREFIX)bitmap.o \
$(HOST_PREFIX)ggc-none.o gensupport.o hashtab.o $(HOST_PREFIX)ggc-none.o gensupport.o hashtab.o safe-ctype.o
HOST_PRINT = $(HOST_PREFIX)print-rtl.o HOST_PRINT = $(HOST_PREFIX)print-rtl.o
HOST_ERRORS = $(HOST_PREFIX)errors.o HOST_ERRORS = $(HOST_PREFIX)errors.o
...@@ -1672,6 +1672,11 @@ hashtab.o: $(srcdir)/../libiberty/hashtab.c $(GCONFIG_H) ...@@ -1672,6 +1672,11 @@ hashtab.o: $(srcdir)/../libiberty/hashtab.c $(GCONFIG_H)
$(LN_S) $(srcdir)/../libiberty/hashtab.c hashtab.c $(LN_S) $(srcdir)/../libiberty/hashtab.c hashtab.c
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) hashtab.c $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) hashtab.c
safe-ctype.o: $(srcdir)/../libiberty/safe-ctype.c $(GCONFIG_H)
rm -f safe-ctype.c
$(LN_S) $(srcdir)/../libiberty/safe-ctype.c safe-ctype.c
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) safe-ctype.c
genconfig : genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS) genconfig : genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS) genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS)
......
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* lex.c: Don't bother checking whether ISUPPER(c) before
calling TOLOWER(c). Don't bother checking whether isascii(c)
before testing ISSPACE(c); ISSPACE(c) includes '\n'.
2000-12-06 Rodney Brown <RodneyBrown@mynd.com> 2000-12-06 Rodney Brown <RodneyBrown@mynd.com>
* actions.h: Standarize copyright statement. * actions.h: Standarize copyright statement.
......
...@@ -889,7 +889,6 @@ maybe_downcase (str) ...@@ -889,7 +889,6 @@ maybe_downcase (str)
return; return;
while (*str) while (*str)
{ {
if (ISUPPER ((unsigned char) *str))
*str = TOLOWER (*str); *str = TOLOWER (*str);
str++; str++;
} }
...@@ -1526,8 +1525,8 @@ handle_generic_pragma (buffer) ...@@ -1526,8 +1525,8 @@ handle_generic_pragma (buffer)
* buff ++ = c; * buff ++ = c;
c = getc (finput); c = getc (finput);
} }
while (c != EOF && isascii (c) && ! ISSPACE (c) && c != '\n' while (c != EOF && ! ISSPACE (c) && buff < buffer + 128);
&& buff < buffer + 128); /* XXX shared knowledge about size of buffer. */ /* XXX shared knowledge about size of buffer. */
ungetc (c, finput); ungetc (c, finput);
......
...@@ -906,11 +906,11 @@ mvs_need_alias (realname) ...@@ -906,11 +906,11 @@ mvs_need_alias (realname)
return 1; return 1;
if (strchr (realname, '_') != 0) if (strchr (realname, '_') != 0)
return 1; return 1;
if (isupper (realname[0])) if (ISUPPER (realname[0]))
{ {
for (i = 1; i < j; i++) for (i = 1; i < j; i++)
{ {
if (islower (realname[i])) if (ISLOWER (realname[i]))
return 1; return 1;
} }
} }
...@@ -918,7 +918,7 @@ mvs_need_alias (realname) ...@@ -918,7 +918,7 @@ mvs_need_alias (realname)
{ {
for (i = 1; i < j; i++) for (i = 1; i < j; i++)
{ {
if (isupper (realname[i])) if (ISUPPER (realname[i]))
return 1; return 1;
} }
} }
...@@ -951,9 +951,9 @@ mvs_get_alias (realname, aliasname) ...@@ -951,9 +951,9 @@ mvs_get_alias (realname, aliasname)
c1 = realname[0]; c1 = realname[0];
c2 = realname[1]; c2 = realname[1];
if (islower (c1)) c1 = toupper (c1); if (ISLOWER (c1)) c1 = TOUPPER (c1);
else if (c1 == '_') c1 = 'A'; else if (c1 == '_') c1 = 'A';
if (islower (c2)) c2 = toupper (c2); if (ISLOWER (c2)) c2 = TOUPPER (c2);
else if (c2 == '_' || c2 == '\0') c2 = '#'; else if (c2 == '_' || c2 == '\0') c2 = '#';
sprintf (aliasname, "%c%c%06d", c1, c2, mvs_hash_alias (realname)); sprintf (aliasname, "%c%c%06d", c1, c2, mvs_hash_alias (realname));
...@@ -998,9 +998,9 @@ mvs_check_alias (realname, aliasname) ...@@ -998,9 +998,9 @@ mvs_check_alias (realname, aliasname)
c1 = realname[0]; c1 = realname[0];
c2 = realname[1]; c2 = realname[1];
if (islower (c1)) c1 = toupper (c1); if (ISLOWER (c1)) c1 = TOUPPER (c1);
else if (c1 == '_') c1 = 'A'; else if (c1 == '_') c1 = 'A';
if (islower (c2)) c2 = toupper (c2); if (ISLOWER (c2)) c2 = TOUPPER (c2);
else if (c2 == '_' || c2 == '\0') c2 = '#'; else if (c2 == '_' || c2 == '\0') c2 = '#';
sprintf (aliasname, "%c%c%06d", c1, c2, mvs_hash_alias (realname)); sprintf (aliasname, "%c%c%06d", c1, c2, mvs_hash_alias (realname));
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <ctype.h> #include <safe-ctype.h>
#include <errno.h> #include <errno.h>
#include <dirent.h> #include <dirent.h>
...@@ -332,8 +332,8 @@ IsHPFSFileSystem (directory) ...@@ -332,8 +332,8 @@ IsHPFSFileSystem (directory)
unsigned int nDrive; unsigned int nDrive;
char szCurDir [MAX_PATH]; char szCurDir [MAX_PATH];
if (isalpha (directory[0]) && (directory[1] == ':')) if (ISALPHA (directory[0]) && (directory[1] == ':'))
nDrive = toupper (directory[0]) - '@'; nDrive = TOUPPER (directory[0]) - '@';
else else
{ {
......
...@@ -64,7 +64,7 @@ newname (olddirname) ...@@ -64,7 +64,7 @@ newname (olddirname)
char *newname = strdup (olddirname); char *newname = strdup (olddirname);
if ((strlen (newname) >= 2) if ((strlen (newname) >= 2)
&& (isalpha (newname[0]) && newname[1] == ':')) && (ISALPHA (newname[0]) && newname[1] == ':'))
newname [1] = '-'; newname [1] = '-';
else if ((strlen (newname) >= 1) else if ((strlen (newname) >= 1)
&& (newname [0] == '/' || newname [0] == '\\')) && (newname [0] == '/' || newname [0] == '\\'))
......
...@@ -86,7 +86,7 @@ locate_file (file_name, path_val) ...@@ -86,7 +86,7 @@ locate_file (file_name, path_val)
/* Handle absolute pathnames */ /* Handle absolute pathnames */
if (file_name [0] == '/' || file_name [0] == DIR_SEPARATOR if (file_name [0] == '/' || file_name [0] == DIR_SEPARATOR
|| isalpha (file_name [0]) && file_name [1] == ':') || ISALPHA (file_name [0]) && file_name [1] == ':')
{ {
strncpy (buf, file_name, sizeof buf); strncpy (buf, file_name, sizeof buf);
buf[sizeof buf - 1] = '\0'; buf[sizeof buf - 1] = '\0';
......
...@@ -135,39 +135,30 @@ struct cpp_buffer ...@@ -135,39 +135,30 @@ struct cpp_buffer
unsigned char sysp; unsigned char sysp;
}; };
/* Character classes. /* Character classes. Based on the more primitive macros in safe-ctype.h.
If the definition of `numchar' looks odd to you, please look up the If the definition of `numchar' looks odd to you, please look up the
definition of a pp-number in the C standard [section 6.4.8 of C99]. definition of a pp-number in the C standard [section 6.4.8 of C99].
In the unlikely event that characters other than \r and \n enter In the unlikely event that characters other than \r and \n enter
the set is_vspace, the macro handle_newline() in cpplex.c must be the set is_vspace, the macro handle_newline() in cpplex.c must be
updated. */ updated. */
#define ISidnum 0x01 /* a-zA-Z0-9_ */
#define ISidstart 0x02 /* _a-zA-Z */
#define ISnumstart 0x04 /* 0-9 */
#define IShspace 0x08 /* ' ' \t */
#define ISvspace 0x10 /* \r \n */
#define ISspace 0x20 /* ' ' \t \r \n \f \v \0 */
#define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
#define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x)) #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x))
#define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x)) #define is_numchar(x) ISIDNUM(x)
#define is_numchar(x) (_cpp_IStable[x] & ISidnum) #define is_idstart(x) (ISIDST(x) || _dollar_ok(x))
#define is_numstart(x) (_cpp_IStable[x] & ISnumstart) #define is_numstart(x) ISDIGIT(x)
#define is_hspace(x) (_cpp_IStable[x] & IShspace) #define is_hspace(x) ISBLANK(x)
#define is_vspace(x) (_cpp_IStable[x] & ISvspace) #define is_vspace(x) IS_VSPACE(x)
#define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace) #define is_nvspace(x) IS_NVSPACE(x)
#define is_space(x) (_cpp_IStable[x] & ISspace) #define is_space(x) IS_SPACE_OR_NUL(x)
/* These tables are constant if they can be initialized at compile time, /* This table is constant if it can be initialized at compile time,
which is the case if cpp was compiled with GCC >=2.7, or another which is the case if cpp was compiled with GCC >=2.7, or another
compiler that supports C99. */ compiler that supports C99. */
#if HAVE_DESIGNATED_INITIALIZERS #if HAVE_DESIGNATED_INITIALIZERS
extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#else #else
extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
#endif #endif
......
...@@ -125,9 +125,6 @@ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; ...@@ -125,9 +125,6 @@ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
runtime. */ runtime. */
#if HAVE_DESIGNATED_INITIALIZERS #if HAVE_DESIGNATED_INITIALIZERS
#define init_IStable() /* Nothing. */
#define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = {
#define init_trigraph_map() /* Nothing. */ #define init_trigraph_map() /* Nothing. */
#define TRIGRAPH_MAP \ #define TRIGRAPH_MAP \
__extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
...@@ -137,10 +134,6 @@ __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { ...@@ -137,10 +134,6 @@ __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
#else #else
#define ISTABLE unsigned char _cpp_IStable[UCHAR_MAX + 1] = { 0 }; \
static void init_IStable PARAMS ((void)) { \
unsigned char *x = _cpp_IStable;
#define TRIGRAPH_MAP U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \ #define TRIGRAPH_MAP U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
static void init_trigraph_map PARAMS ((void)) { \ static void init_trigraph_map PARAMS ((void)) { \
unsigned char *x = _cpp_trigraph_map; unsigned char *x = _cpp_trigraph_map;
...@@ -150,45 +143,13 @@ __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { ...@@ -150,45 +143,13 @@ __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
#endif #endif
#define A(x) s(x, ISidnum|ISidstart)
#define N(x) s(x, ISidnum|ISnumstart)
#define H(x) s(x, IShspace|ISspace)
#define V(x) s(x, ISvspace|ISspace)
#define S(x) s(x, ISspace)
ISTABLE
A('_')
A('a') A('b') A('c') A('d') A('e') A('f') A('g') A('h') A('i')
A('j') A('k') A('l') A('m') A('n') A('o') A('p') A('q') A('r')
A('s') A('t') A('u') A('v') A('w') A('x') A('y') A('z')
A('A') A('B') A('C') A('D') A('E') A('F') A('G') A('H') A('I')
A('J') A('K') A('L') A('M') A('N') A('O') A('P') A('Q') A('R')
A('S') A('T') A('U') A('V') A('W') A('X') A('Y') A('Z')
N('1') N('2') N('3') N('4') N('5') N('6') N('7') N('8') N('9') N('0')
H(' ') H('\t')
V('\n') V('\r')
S('\0') S('\v') S('\f')
END
TRIGRAPH_MAP TRIGRAPH_MAP
s('=', '#') s(')', ']') s('!', '|') s('=', '#') s(')', ']') s('!', '|')
s('(', '[') s('\'', '^') s('>', '}') s('(', '[') s('\'', '^') s('>', '}')
s('/', '\\') s('<', '{') s('-', '~') s('/', '\\') s('<', '{') s('-', '~')
END END
#undef A
#undef N
#undef H
#undef V
#undef S
#undef s #undef s
#undef ISTABLE
#undef END #undef END
#undef TRIGRAPH_MAP #undef TRIGRAPH_MAP
...@@ -507,11 +468,9 @@ initialize () ...@@ -507,11 +468,9 @@ initialize ()
qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
#endif #endif
/* Set up the trigraph map and the IStable. These don't need to do /* Set up the trigraph map. This doesn't need to do anything if we were
anything if we were compiled with a compiler that supports C99 compiled with a compiler that supports C99 designated initializers. */
designated initializers. */
init_trigraph_map (); init_trigraph_map ();
init_IStable ();
initialized = 1; initialized = 1;
} }
......
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* Make-lang.in: Link f/fini with safe-ctype.o.
* bad.c: Don't test ISUPPER(c) || ISLOWER(c) before calling TOUPPER(c).
* com.c: Use TOUPPER, not ffesrc_toupper.
* fini.c: Don't test ISALPHA(c) before calling TOUPPER(c)/TOLOWER(c).
* intrin.c: Don't test IN_CTYPE_DOMAIN(c).
* src.c: Delete ffesrc_toupper_ and ffesrc_tolower_ and their
initializing code; use TOUPPER and TOLOWER instead of
ffesrc_toupper and ffesrc_tolower.
* src.h: Don't declare ffesrc_toupper_ or ffesrc_tolower_.
Don't define ffesrc_toupper or ffesrc_tolower.
2000-11-28 Richard Henderson <rth@redhat.com> 2000-11-28 Richard Henderson <rth@redhat.com>
* com.c (ffecom_member_phase2_): Set TREE_USED on the debugging decl. * com.c (ffecom_member_phase2_): Set TREE_USED on the debugging decl.
......
...@@ -137,9 +137,9 @@ f/str-op.h f/str-op.j: f/fini$(build_exeext) f/str-op.fin ...@@ -137,9 +137,9 @@ f/str-op.h f/str-op.j: f/fini$(build_exeext) f/str-op.fin
f/str-ot.h f/str-ot.j: f/fini$(build_exeext) f/str-ot.fin f/str-ot.h f/str-ot.j: f/fini$(build_exeext) f/str-ot.fin
./f/fini$(build_exeext) $(srcdir)/f/str-ot.fin f/str-ot.j f/str-ot.h ./f/fini$(build_exeext) $(srcdir)/f/str-ot.fin f/str-ot.j f/str-ot.h
f/fini$(build_exeext): f/fini.o f/proj-h.o f/fini$(build_exeext): f/fini.o f/proj-h.o safe-ctype.o
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o f/fini$(build_exeext) \ $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o f/fini$(build_exeext) \
f/fini.o f/proj-h.o f/fini.o f/proj-h.o safe-ctype.o
f/fini.o: f/fini.o:
$(HOST_CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ $(HOST_CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \
......
...@@ -457,7 +457,7 @@ ffebad_finish () ...@@ -457,7 +457,7 @@ ffebad_finish ()
if (ffebad_places_ == 0) if (ffebad_places_ == 0)
{ {
/* Didn't output "warning:" string, capitalize it for message. */ /* Didn't output "warning:" string, capitalize it for message. */
if ((s[0] != '\0') && ISALPHA (s[0]) && ISLOWER (s[0])) if (s[0] != '\0')
{ {
char c; char c;
......
...@@ -1840,7 +1840,7 @@ ffecom_build_f2c_string_ (int i, const char *s) ...@@ -1840,7 +1840,7 @@ ffecom_build_f2c_string_ (int i, const char *s)
tmp = &space[0]; tmp = &space[0];
for (p = s, q = tmp; *p != '\0'; ++p, ++q) for (p = s, q = tmp; *p != '\0'; ++p, ++q)
*q = ffesrc_toupper (*p); *q = TOUPPER (*p);
*q = '\0'; *q = '\0';
t = build_string (i, tmp); t = build_string (i, tmp);
......
...@@ -381,16 +381,10 @@ main (int argc, char **argv) ...@@ -381,16 +381,10 @@ main (int argc, char **argv)
for (i = 0; i < newname->namelen; ++i) for (i = 0; i < newname->namelen; ++i)
{ {
cc = buf[i]; cc = buf[i];
if (ISALPHA (cc))
{
newname->name_uc[i] = TOUPPER (cc); newname->name_uc[i] = TOUPPER (cc);
newname->name_lc[i] = TOLOWER (cc); newname->name_lc[i] = TOLOWER (cc);
newname->name_ic[i] = cc; newname->name_ic[i] = cc;
} }
else
newname->name_uc[i] = newname->name_lc[i] = newname->name_ic[i]
= cc;
}
newname->name_uc[i] = newname->name_lc[i] = newname->name_ic[i] = '\0'; newname->name_uc[i] = newname->name_lc[i] = newname->name_ic[i] = '\0';
/* Warn user if names aren't alphabetically ordered. */ /* Warn user if names aren't alphabetically ordered. */
......
...@@ -1581,10 +1581,6 @@ ffeintrin_init_0 () ...@@ -1581,10 +1581,6 @@ ffeintrin_init_0 ()
p3 = ffeintrin_names_[i].name_ic; p3 = ffeintrin_names_[i].name_ic;
for (; *p1 != '\0' && *p2 != '\0' && *p3 != '\0'; ++p1, ++p2, ++p3) for (; *p1 != '\0' && *p2 != '\0' && *p3 != '\0'; ++p1, ++p2, ++p3)
{ {
if (! IN_CTYPE_DOMAIN (*p1)
|| ! IN_CTYPE_DOMAIN (*p2)
|| ! IN_CTYPE_DOMAIN (*p3))
break;
if ((ISDIGIT (*p1) || (*p1 == '_')) && (*p1 == *p2) && (*p1 == *p3)) if ((ISDIGIT (*p1) || (*p1 == '_')) && (*p1 == *p2) && (*p1 == *p3))
continue; continue;
if (! ISUPPER ((unsigned char)*p1) || ! ISLOWER ((unsigned char)*p2) if (! ISUPPER ((unsigned char)*p1) || ! ISLOWER ((unsigned char)*p2)
......
...@@ -32,16 +32,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -32,16 +32,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "src.h" #include "src.h"
#include "top.h" #include "top.h"
/* This array does a toupper (), but any valid char type is valid as an
index and returns identity if not a lower-case character. */
char ffesrc_toupper_[256];
/* This array does a tolower (), but any valid char type is valid as an
index and returns identity if not an upper-case character. */
char ffesrc_tolower_[256];
/* This array is set up so that, given a source-mapped character, the result /* This array is set up so that, given a source-mapped character, the result
of indexing into this array will match an upper-cased character depending of indexing into this array will match an upper-cased character depending
on the source-mapped character's case and the established ffe_case_match() on the source-mapped character's case and the established ffe_case_match()
...@@ -113,18 +103,10 @@ ffesrc_init_1 () ...@@ -113,18 +103,10 @@ ffesrc_init_1 ()
ffesrc_char_match_noninit_[i] = i; ffesrc_char_match_noninit_[i] = i;
ffesrc_char_source_[i] = i; ffesrc_char_source_[i] = i;
ffesrc_char_internal_init_[i] = i; ffesrc_char_internal_init_[i] = i;
ffesrc_toupper_[i] = i;
ffesrc_tolower_[i] = i;
ffesrc_bad_symbol_init_[i] = FFEBAD; ffesrc_bad_symbol_init_[i] = FFEBAD;
ffesrc_bad_symbol_noninit_[i] = FFEBAD; ffesrc_bad_symbol_noninit_[i] = FFEBAD;
} }
for (i = 'A'; i <= 'Z'; ++i)
ffesrc_tolower_[i] = TOLOWER (i);
for (i = 'a'; i <= 'z'; ++i)
ffesrc_toupper_[i] = TOUPPER (i);
ffesrc_check_symbol_ = (ffe_case_symbol () != FFE_caseNONE); ffesrc_check_symbol_ = (ffe_case_symbol () != FFE_caseNONE);
ffesrc_ok_match_init_upper_ = (ffe_case_match () != FFE_caseLOWER); ffesrc_ok_match_init_upper_ = (ffe_case_match () != FFE_caseLOWER);
...@@ -230,8 +212,8 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len, ...@@ -230,8 +212,8 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len,
for (; len > 0; --len, ++var, ++str_ic) for (; len > 0; --len, ++var, ++str_ic)
{ {
c = ffesrc_char_source (*var); /* Transform source. */ c = ffesrc_char_source (*var); /* Transform source. */
c = ffesrc_toupper (c); /* Upcase source. */ c = TOUPPER (c); /* Upcase source. */
d = ffesrc_toupper (*str_ic); /* Upcase InitialCaps char. */ d = TOUPPER (*str_ic); /* Upcase InitialCaps char. */
if (c != d) if (c != d)
{ {
if ((d != '\0') && (c < d)) if ((d != '\0') && (c < d))
...@@ -246,7 +228,7 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len, ...@@ -246,7 +228,7 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len,
for (; len > 0; --len, ++var, ++str_ic) for (; len > 0; --len, ++var, ++str_ic)
{ {
c = ffesrc_char_source (*var); /* Transform source. */ c = ffesrc_char_source (*var); /* Transform source. */
d = ffesrc_toupper (*str_ic); /* Transform InitialCaps char. */ d = TOUPPER (*str_ic); /* Transform InitialCaps char. */
if (c != d) if (c != d)
{ {
if ((d != '\0') && (c < d)) if ((d != '\0') && (c < d))
...@@ -261,7 +243,7 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len, ...@@ -261,7 +243,7 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len,
for (; len > 0; --len, ++var, ++str_ic) for (; len > 0; --len, ++var, ++str_ic)
{ {
c = ffesrc_char_source (*var); /* Transform source. */ c = ffesrc_char_source (*var); /* Transform source. */
d = ffesrc_tolower (*str_ic); /* Transform InitialCaps char. */ d = TOLOWER (*str_ic); /* Transform InitialCaps char. */
if (c != d) if (c != d)
{ {
if ((d != '\0') && (c < d)) if ((d != '\0') && (c < d))
...@@ -279,14 +261,14 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len, ...@@ -279,14 +261,14 @@ ffesrc_strcmp_1ns2i (ffeCase mcase, const char *var, int len,
d = *str_ic; /* No transform of InitialCaps char. */ d = *str_ic; /* No transform of InitialCaps char. */
if (c != d) if (c != d)
{ {
c = ffesrc_toupper (c); c = TOUPPER (c);
d = ffesrc_toupper (d); d = TOUPPER (d);
while ((len > 0) && (c == d)) while ((len > 0) && (c == d))
{ /* Skip past equivalent (case-ins) chars. */ { /* Skip past equivalent (case-ins) chars. */
--len, ++var, ++str_ic; --len, ++var, ++str_ic;
if (len > 0) if (len > 0)
c = ffesrc_toupper (*var); c = TOUPPER (*var);
d = ffesrc_toupper (*str_ic); d = TOUPPER (*str_ic);
} }
if ((d != '\0') && (c < d)) if ((d != '\0') && (c < d))
return -1; return -1;
...@@ -323,7 +305,7 @@ ffesrc_strcmp_2c (ffeCase mcase, const char *var, const char *str_uc, ...@@ -323,7 +305,7 @@ ffesrc_strcmp_2c (ffeCase mcase, const char *var, const char *str_uc,
case FFE_caseNONE: case FFE_caseNONE:
for (; *var != '\0'; ++var, ++str_uc) for (; *var != '\0'; ++var, ++str_uc)
{ {
c = ffesrc_toupper (*var); /* Upcase source. */ c = TOUPPER (*var); /* Upcase source. */
if (c != *str_uc) if (c != *str_uc)
{ {
if ((*str_uc != '\0') && (c < *str_uc)) if ((*str_uc != '\0') && (c < *str_uc))
...@@ -349,11 +331,11 @@ ffesrc_strcmp_2c (ffeCase mcase, const char *var, const char *str_uc, ...@@ -349,11 +331,11 @@ ffesrc_strcmp_2c (ffeCase mcase, const char *var, const char *str_uc,
{ {
if (*var != *str_ic) if (*var != *str_ic)
{ {
c = ffesrc_toupper (*var); c = TOUPPER (*var);
while ((c != '\0') && (c == *str_uc)) while ((c != '\0') && (c == *str_uc))
{ /* Skip past equivalent (case-ins) chars. */ { /* Skip past equivalent (case-ins) chars. */
++var, ++str_uc; ++var, ++str_uc;
c = ffesrc_toupper (*var); c = TOUPPER (*var);
} }
if ((*str_uc != '\0') && (c < *str_uc)) if ((*str_uc != '\0') && (c < *str_uc))
return -1; return -1;
...@@ -393,7 +375,7 @@ ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc, ...@@ -393,7 +375,7 @@ ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc,
case FFE_caseNONE: case FFE_caseNONE:
for (; len > 0; ++var, ++str_uc, --len) for (; len > 0; ++var, ++str_uc, --len)
{ {
c = ffesrc_toupper (*var); /* Upcase source. */ c = TOUPPER (*var); /* Upcase source. */
if (c != *str_uc) if (c != *str_uc)
{ {
if (c < *str_uc) if (c < *str_uc)
...@@ -417,12 +399,12 @@ ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc, ...@@ -417,12 +399,12 @@ ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc,
{ {
if (*var != *str_ic) if (*var != *str_ic)
{ {
c = ffesrc_toupper (*var); c = TOUPPER (*var);
while ((len > 0) && (c == *str_uc)) while ((len > 0) && (c == *str_uc))
{ /* Skip past equivalent (case-ins) chars. */ { /* Skip past equivalent (case-ins) chars. */
--len, ++var, ++str_uc; --len, ++var, ++str_uc;
if (len > 0) if (len > 0)
c = ffesrc_toupper (*var); c = TOUPPER (*var);
} }
if ((len > 0) && (c < *str_uc)) if ((len > 0) && (c < *str_uc))
return -1; return -1;
......
...@@ -33,8 +33,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -33,8 +33,6 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "bad.h" #include "bad.h"
#include "top.h" #include "top.h"
extern char ffesrc_toupper_[256];
extern char ffesrc_tolower_[256];
extern char ffesrc_char_match_init_[256]; extern char ffesrc_char_match_init_[256];
extern char ffesrc_char_match_noninit_[256]; extern char ffesrc_char_match_noninit_[256];
extern char ffesrc_char_source_[256]; extern char ffesrc_char_source_[256];
...@@ -136,8 +134,6 @@ int ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc, ...@@ -136,8 +134,6 @@ int ffesrc_strncmp_2c (ffeCase mcase, const char *var, const char *str_uc,
#define ffesrc_terminate_2() #define ffesrc_terminate_2()
#define ffesrc_terminate_3() #define ffesrc_terminate_3()
#define ffesrc_terminate_4() #define ffesrc_terminate_4()
#define ffesrc_toupper(c) (ffesrc_toupper_[(unsigned int) (c)])
#define ffesrc_tolower(c) (ffesrc_tolower_[(unsigned int) (c)])
/* End of #include file. */ /* End of #include file. */
......
...@@ -156,7 +156,7 @@ emit_gnu_type ( text, rm ) ...@@ -156,7 +156,7 @@ emit_gnu_type ( text, rm )
char* pD = z_TYPE; char* pD = z_TYPE;
while (ps < pe) while (ps < pe)
*(pD++) = toupper( *(pd++) = *(ps++) ); *(pD++) = TOUPPER( *(pd++) = *(ps++) );
*pD = *pd = NUL; *pD = *pd = NUL;
} }
...@@ -612,20 +612,16 @@ FIX_PROC_HEAD( wrap_fix ) ...@@ -612,20 +612,16 @@ FIX_PROC_HEAD( wrap_fix )
"wrap-fix" ); "wrap-fix" );
for (;;) { for (;;) {
char ch = *(pz_src++); char ch = *pz_src++;
if (ISLOWER (ch)) if (ch == NUL) {
*(pz_dst++) = TOUPPER ( ch ); *pz_dst++ = ch;
else if (ISALNUM ( ch ))
*(pz_dst++) = ch;
else if (ch == NUL) {
*(pz_dst++) = ch;
break; break;
} else if (! ISALNUM (ch)) {
*pz_dst++ = '_';
} else {
*pz_dst++ = TOUPPER (ch);
} }
else
*(pz_dst++) = '_';
if (++len >= sizeof( z_fixname )) { if (++len >= sizeof( z_fixname )) {
void* p = xmalloc( len + strlen( pz_src ) + 1 ); void* p = xmalloc( len + strlen( pz_src ) + 1 );
......
...@@ -771,14 +771,8 @@ extract_quoted_files (pz_data, pz_fixed_file, p_re_match) ...@@ -771,14 +771,8 @@ extract_quoted_files (pz_data, pz_fixed_file, p_re_match)
pz_incl_quot += p_re_match->rm_so; pz_incl_quot += p_re_match->rm_so;
/* Skip forward to the included file name */ /* Skip forward to the included file name */
while (ISSPACE (*pz_incl_quot)) while (*pz_incl_quot != '"')
pz_incl_quot++; pz_incl_quot++;
/* ISSPACE() may evaluate its argument more than once! */
while (++pz_incl_quot, ISSPACE (*pz_incl_quot))
;
pz_incl_quot += sizeof ("include") - 1;
while (*pz_incl_quot++ != '"')
;
if (quoted_file_exists (pz_src_dir, pz_fixed_file, pz_incl_quot)) if (quoted_file_exists (pz_src_dir, pz_fixed_file, pz_incl_quot))
{ {
......
...@@ -198,50 +198,10 @@ init_syntax_once () ...@@ -198,50 +198,10 @@ init_syntax_once ()
/* GCC LOCAL: call it gnu-regex.h, not regex.h, to avoid name conflicts */ /* GCC LOCAL: call it gnu-regex.h, not regex.h, to avoid name conflicts */
#include "gnu-regex.h" #include "gnu-regex.h"
/* isalpha etc. are used for the character classes. */ /* ISALPHA etc. are used for the character classes. */
#include <ctype.h> /* GCC LOCAL: use libiberty's safe-ctype.h, don't bother defining
wrapper macros ourselves. */
/* Jim Meyering writes: #include <safe-ctype.h>
"... Some ctype macros are valid only for character codes that
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
using /bin/cc or gcc but without giving an ansi option). So, all
ctype uses should be through macros like ISPRINT... If
STDC_HEADERS is defined, then autoconf has verified that the ctype
macros don't need to be guarded with references to isascii. ...
Defining isascii to 1 should let any compiler worth its salt
eliminate the && through constant folding."
Solaris defines some of these symbols so we must undefine them first. */
#undef ISASCII
#if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
# define ISASCII(c) 1
#else
# define ISASCII(c) isascii(c)
#endif
#ifdef isblank
# define ISBLANK(c) (ISASCII (c) && isblank (c))
#else
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
#endif
#ifdef isgraph
# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
#else
# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
#endif
#undef ISPRINT
#define ISPRINT(c) (ISASCII (c) && isprint (c))
#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
#define ISALNUM(c) (ISASCII (c) && isalnum (c))
#define ISALPHA(c) (ISASCII (c) && isalpha (c))
#define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
#define ISLOWER(c) (ISASCII (c) && islower (c))
#define ISPUNCT(c) (ISASCII (c) && ispunct (c))
#define ISSPACE(c) (ISASCII (c) && isspace (c))
#define ISUPPER(c) (ISASCII (c) && isupper (c))
#define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
#ifndef NULL #ifndef NULL
# define NULL (void *)0 # define NULL (void *)0
...@@ -5613,7 +5573,7 @@ regcomp (preg, pattern, cflags) ...@@ -5613,7 +5573,7 @@ regcomp (preg, pattern, cflags)
/* Map uppercase characters to corresponding lowercase ones. */ /* Map uppercase characters to corresponding lowercase ones. */
for (i = 0; i < CHAR_SET_SIZE; i++) for (i = 0; i < CHAR_SET_SIZE; i++)
preg->translate[i] = ISUPPER (i) ? tolower (i) : i; preg->translate[i] = TOLOWER (i);
} }
else else
preg->translate = NULL; preg->translate = NULL;
......
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* jvgenmain.c: Use ISPRINT not isascii.
2000-12-06 Alexandre Petit-Bianco <apbianco@cygnus.com> 2000-12-06 Alexandre Petit-Bianco <apbianco@cygnus.com>
* parse.y (end_artificial_method_body): Fixed typo. * parse.y (end_artificial_method_body): Fixed typo.
......
...@@ -144,7 +144,7 @@ main (int argc, const char **argv) ...@@ -144,7 +144,7 @@ main (int argc, const char **argv)
fprintf (stream, " \""); fprintf (stream, " \"");
for (p = &argv[i][2]; *p; ++p) for (p = &argv[i][2]; *p; ++p)
{ {
if (! isascii (*p)) if (! ISPRINT (*p))
fprintf (stream, "\\%o", *p); fprintf (stream, "\\%o", *p);
else if (*p == '\\' || *p == '"') else if (*p == '\\' || *p == '"')
fprintf (stream, "\\%c", *p); fprintf (stream, "\\%c", *p);
......
...@@ -75,91 +75,12 @@ extern int fputs_unlocked PARAMS ((const char *, FILE *)); ...@@ -75,91 +75,12 @@ extern int fputs_unlocked PARAMS ((const char *, FILE *));
# endif # endif
#endif #endif
#include <ctype.h> /* There are an extraordinary number of issues with <ctype.h>.
The last straw is that it varies with the locale. Use libiberty's
replacement instead. */
#include <safe-ctype.h>
/* Jim Meyering writes: /* Define a default escape character; it's different for EBCDIC. */
"... Some ctype macros are valid only for character codes that
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
using /bin/cc or gcc but without giving an ansi option). So, all
ctype uses should be through macros like ISPRINT... If
STDC_HEADERS is defined, then autoconf has verified that the ctype
macros don't need to be guarded with references to isascii. ...
Defining isascii to 1 should let any compiler worth its salt
eliminate the && through constant folding."
Bruno Haible adds:
"... Furthermore, isupper(c) etc. have an undefined result if c is
outside the range -1 <= c <= 255. One is tempted to write isupper(c)
with c being of type `char', but this is wrong if c is an 8-bit
character >= 128 which gets sign-extended to a negative value.
The macro ISUPPER protects against this as well." */
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) || defined(HOST_EBCDIC)
# define IN_CTYPE_DOMAIN(c) 1
#else
# define IN_CTYPE_DOMAIN(c) isascii(c)
#endif
/* The ctype functions are often implemented as macros which do
lookups in arrays using the parameter as the offset. If the ctype
function parameter is a char, then gcc will (appropriately) warn
that a "subscript has type char". Using a (signed) char as a subscript
is bad because you may get negative offsets and thus it is not 8-bit
safe. The CTYPE_CONV macro ensures that the parameter is cast to an
unsigned char when a char is passed in. When an int is passed in, the
parameter is left alone so we don't lose EOF.
*/
#define CTYPE_CONV(CH) \
(sizeof(CH) == sizeof(unsigned char) ? (int)(unsigned char)(CH) : (int)(CH))
/* WARNING! The argument to the ctype replacement macros below is
evaluated more than once so it must not have side effects! */
#ifdef isblank
# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (CTYPE_CONV(c)))
#else
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
#endif
#ifdef isgraph
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (CTYPE_CONV(c)))
#else
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)) && !isspace (CTYPE_CONV(c)))
#endif
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (CTYPE_CONV(c)))
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (CTYPE_CONV(c)))
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (CTYPE_CONV(c)))
#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (CTYPE_CONV(c)))
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (CTYPE_CONV(c)))
#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (CTYPE_CONV(c)))
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (CTYPE_CONV(c)))
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (CTYPE_CONV(c)))
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (CTYPE_CONV(c)))
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (CTYPE_CONV(c)))
#if STDC_HEADERS
# define TOLOWER(c) (tolower (CTYPE_CONV(c)))
# define TOUPPER(c) (toupper (CTYPE_CONV(c)))
#else
# define TOLOWER(c) (ISUPPER (c) ? tolower (CTYPE_CONV(c)) : (c))
# define TOUPPER(c) (ISLOWER (c) ? toupper (CTYPE_CONV(c)) : (c))
#endif
/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
- Its arg may be any int or unsigned int; it need not be an unsigned char.
- It's guaranteed to evaluate its argument exactly once.
- It's typically faster.
Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
it's important to use the locale's definition of `digit' even when the
host does not conform to Posix. */
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
/* Define a default escape character; its different for EBCDIC. */
#ifndef TARGET_ESC #ifndef TARGET_ESC
#define TARGET_ESC 033 #define TARGET_ESC 033
#endif #endif
......
...@@ -402,13 +402,13 @@ yylex () ...@@ -402,13 +402,13 @@ yylex ()
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
/* It's a number */ /* It's a number */
for (namelen = 0; for (namelen = 0;
c = tokstart[namelen], is_idchar[c] || c == '.'; c = tokstart[namelen], is_idchar (c) || c == '.';
namelen++) namelen++)
; ;
return parse_number (namelen); return parse_number (namelen);
} }
if (!is_idstart[c]) { if (!is_idstart (c)) {
yyerror ("Invalid token in expression"); yyerror ("Invalid token in expression");
return ERROR; return ERROR;
} }
...@@ -416,7 +416,7 @@ yylex () ...@@ -416,7 +416,7 @@ yylex ()
/* It is a name. See how long it is. */ /* It is a name. See how long it is. */
for (namelen = 0; for (namelen = 0;
is_idchar[(int)(unsigned char)tokstart[namelen]]; is_idchar (tokstart[namelen]);
namelen++) namelen++)
; ;
......
...@@ -376,7 +376,6 @@ static void output_line_command PARAMS ((FILE_BUF *, FILE_BUF *, ...@@ -376,7 +376,6 @@ static void output_line_command PARAMS ((FILE_BUF *, FILE_BUF *,
static int eval_if_expression PARAMS ((const U_CHAR *, int)); static int eval_if_expression PARAMS ((const U_CHAR *, int));
static void initialize_char_syntax PARAMS ((void));
static void initialize_builtins PARAMS ((void)); static void initialize_builtins PARAMS ((void));
static void run_directive PARAMS ((const char *, size_t, static void run_directive PARAMS ((const char *, size_t,
enum node_type)); enum node_type));
...@@ -424,17 +423,8 @@ struct directive directive_table[] = { ...@@ -424,17 +423,8 @@ struct directive directive_table[] = {
{ -1, 0, "", T_UNUSED}, { -1, 0, "", T_UNUSED},
}; };
/* table to tell if char can be part of a C identifier. */ #define SKIP_WHITE_SPACE(p) do { while (is_nvspace(*p)) p++; } while (0)
U_CHAR is_idchar[256]; #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space(*p)) p++; } while (0)
/* table to tell if char can be first char of a c identifier. */
U_CHAR is_idstart[256];
/* table to tell if c is horizontal space. */
U_CHAR is_hor_space[256];
/* table to tell if c is horizontal or vertical space. */
U_CHAR is_space[256];
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
int errors = 0; /* Error counter for exit code */ int errors = 0; /* Error counter for exit code */
...@@ -522,9 +512,6 @@ main (argc, argv) ...@@ -522,9 +512,6 @@ main (argc, argv)
in_fname = NULL; in_fname = NULL;
out_fname = NULL; out_fname = NULL;
/* Initialize is_idchar to allow $. */
initialize_char_syntax ();
no_line_commands = 0; no_line_commands = 0;
dump_macros = 0; dump_macros = 0;
no_output = 0; no_output = 0;
...@@ -726,11 +713,7 @@ main (argc, argv) ...@@ -726,11 +713,7 @@ main (argc, argv)
if (user_label_prefix == 0) if (user_label_prefix == 0)
user_label_prefix = USER_LABEL_PREFIX; user_label_prefix = USER_LABEL_PREFIX;
/* Initialize is_idchar. */ /* Install __LINE__, etc. Must follow option processing. */
initialize_char_syntax ();
/* Install __LINE__, etc. Must follow initialize_char_syntax
and option processing. */
initialize_builtins (); initialize_builtins ();
/* Do defines specified with -D and undefines specified with -U. */ /* Do defines specified with -D and undefines specified with -U. */
...@@ -1052,14 +1035,14 @@ name_newline_fix (bp) ...@@ -1052,14 +1035,14 @@ name_newline_fix (bp)
/* What follows the backslash-newlines is not embarrassing. */ /* What follows the backslash-newlines is not embarrassing. */
if (count == 0 || !is_idchar[*p]) if (count == 0 || !is_idchar (*p))
return; return;
/* Copy all potentially embarrassing characters /* Copy all potentially embarrassing characters
that follow the backslash-newline pairs that follow the backslash-newline pairs
down to where the pairs originally started. */ down to where the pairs originally started. */
while (is_idchar[*p]) while (is_idchar (*p))
*bp++ = *p++; *bp++ = *p++;
/* Now write the same number of pairs after the embarrassing chars. */ /* Now write the same number of pairs after the embarrassing chars. */
...@@ -1463,7 +1446,7 @@ do { ip = &instack[indepth]; \ ...@@ -1463,7 +1446,7 @@ do { ip = &instack[indepth]; \
/* If expanding a macro arg, keep the newline -. */ /* If expanding a macro arg, keep the newline -. */
*obp++ = '-'; *obp++ = '-';
} }
} else if (is_space[*ibp]) { } else if (is_space (*ibp)) {
/* Newline Space does not prevent expansion of preceding token /* Newline Space does not prevent expansion of preceding token
so expand the preceding token and then come back. */ so expand the preceding token and then come back. */
if (ident_length > 0) if (ident_length > 0)
...@@ -1514,7 +1497,7 @@ do { ip = &instack[indepth]; \ ...@@ -1514,7 +1497,7 @@ do { ip = &instack[indepth]; \
ibp--; ibp--;
/* If we have an identifier that ends here, process it now, so /* If we have an identifier that ends here, process it now, so
we get the right error for recursion. */ we get the right error for recursion. */
if (ident_length && ! is_idchar[*instack[indepth - 1].bufp]) { if (ident_length && ! is_idchar (*instack[indepth - 1].bufp)) {
redo_char = 1; redo_char = 1;
goto randomchar; goto randomchar;
} }
...@@ -1642,7 +1625,7 @@ randomchar: ...@@ -1642,7 +1625,7 @@ randomchar:
*obp++ = '/'; *obp++ = '/';
} }
} }
else if (is_space[*ibp]) { else if (is_space (*ibp)) {
*obp++ = *ibp++; *obp++ = *ibp++;
if (ibp[-1] == '\n') { if (ibp[-1] == '\n') {
if (ip->macro == 0) { if (ip->macro == 0) {
...@@ -1837,7 +1820,7 @@ handle_directive (ip, op) ...@@ -1837,7 +1820,7 @@ handle_directive (ip, op)
bp = ip->bufp; bp = ip->bufp;
/* Skip whitespace and \-newline. */ /* Skip whitespace and \-newline. */
while (1) { while (1) {
if (is_hor_space[*bp]) if (is_nvspace (*bp))
bp++; bp++;
else if (*bp == '/' && (newline_fix (bp + 1), bp[1]) == '*') { else if (*bp == '/' && (newline_fix (bp + 1), bp[1]) == '*') {
ip->bufp = bp; ip->bufp = bp;
...@@ -1854,12 +1837,12 @@ handle_directive (ip, op) ...@@ -1854,12 +1837,12 @@ handle_directive (ip, op)
cp = bp; cp = bp;
while (1) { while (1) {
if (is_idchar[*cp]) if (is_idchar (*cp))
cp++; cp++;
else { else {
if (*cp == '\\' && cp[1] == '\n') if (*cp == '\\' && cp[1] == '\n')
name_newline_fix (cp); name_newline_fix (cp);
if (is_idchar[*cp]) if (is_idchar (*cp))
cp++; cp++;
else break; else break;
} }
...@@ -1996,11 +1979,11 @@ handle_directive (ip, op) ...@@ -1996,11 +1979,11 @@ handle_directive (ip, op)
if (*xp == '\n') { if (*xp == '\n') {
xp++; xp++;
cp--; cp--;
if (cp != buf && is_space[cp[-1]]) { if (cp != buf && is_space (cp[-1])) {
while (cp != buf && is_space[cp[-1]]) cp--; while (cp != buf && is_space(cp[-1])) cp--;
cp++; cp++;
SKIP_WHITE_SPACE (xp); SKIP_WHITE_SPACE (xp);
} else if (is_space[*xp]) { } else if (is_space (*xp)) {
*cp++ = *xp++; *cp++ = *xp++;
SKIP_WHITE_SPACE (xp); SKIP_WHITE_SPACE (xp);
} }
...@@ -2172,11 +2155,11 @@ special_symbol (hp, op) ...@@ -2172,11 +2155,11 @@ special_symbol (hp, op)
SKIP_WHITE_SPACE (ip->bufp); SKIP_WHITE_SPACE (ip->bufp);
} }
if (!is_idstart[*ip->bufp]) if (!is_idstart (*ip->bufp))
goto oops; goto oops;
if (lookup (ip->bufp, -1, -1)) if (lookup (ip->bufp, -1, -1))
buf = " 1 "; buf = " 1 ";
while (is_idchar[*ip->bufp]) while (is_idchar (*ip->bufp))
++ip->bufp; ++ip->bufp;
SKIP_WHITE_SPACE (ip->bufp); SKIP_WHITE_SPACE (ip->bufp);
if (paren) { if (paren) {
...@@ -2235,7 +2218,7 @@ get_filename: ...@@ -2235,7 +2218,7 @@ get_filename:
SKIP_WHITE_SPACE (fbeg); SKIP_WHITE_SPACE (fbeg);
/* Discard trailing whitespace so we can easily see /* Discard trailing whitespace so we can easily see
if we have parsed all the significant chars we were given. */ if we have parsed all the significant chars we were given. */
while (limit != fbeg && is_hor_space[limit[-1]]) limit--; while (limit != fbeg && is_nvspace (limit[-1])) limit--;
switch (*fbeg++) { switch (*fbeg++) {
case '\"': case '\"':
...@@ -2514,17 +2497,17 @@ do_define (buf, limit, op) ...@@ -2514,17 +2497,17 @@ do_define (buf, limit, op)
bp = buf; bp = buf;
while (is_hor_space[*bp]) while (is_nvspace (*bp))
bp++; bp++;
symname = bp; /* remember where it starts */ symname = bp; /* remember where it starts */
while (is_idchar[*bp] && bp < limit) { while (is_idchar (*bp) && bp < limit) {
bp++; bp++;
} }
sym_length = bp - symname; sym_length = bp - symname;
if (sym_length == 0) if (sym_length == 0)
error ("invalid macro name"); error ("invalid macro name");
else if (!is_idstart[*symname]) { else if (!is_idstart (*symname)) {
U_CHAR *msg; /* what pain... */ U_CHAR *msg; /* what pain... */
msg = (U_CHAR *) alloca (sym_length + 1); msg = (U_CHAR *) alloca (sym_length + 1);
memcpy (msg, symname, sym_length); memcpy (msg, symname, sym_length);
...@@ -2556,11 +2539,11 @@ do_define (buf, limit, op) ...@@ -2556,11 +2539,11 @@ do_define (buf, limit, op)
temp->argno = argno++; temp->argno = argno++;
arg_ptrs = temp; arg_ptrs = temp;
if (!is_idstart[*bp]) if (!is_idstart (*bp))
warning ("parameter name starts with a digit in #define"); warning ("parameter name starts with a digit in #define");
/* Find the end of the arg name. */ /* Find the end of the arg name. */
while (is_idchar[*bp]) { while (is_idchar (*bp)) {
bp++; bp++;
} }
temp->length = bp - temp->name; temp->length = bp - temp->name;
...@@ -2581,7 +2564,7 @@ do_define (buf, limit, op) ...@@ -2581,7 +2564,7 @@ do_define (buf, limit, op)
} }
++bp; /* skip paren */ ++bp; /* skip paren */
while (is_hor_space[*bp]) /* and leading whitespace */ while (is_nvspace (*bp)) /* and leading whitespace */
++bp; ++bp;
/* now everything from bp before limit is the definition. */ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs); defn = collect_expansion (bp, limit, argno, arg_ptrs);
...@@ -2608,7 +2591,7 @@ do_define (buf, limit, op) ...@@ -2608,7 +2591,7 @@ do_define (buf, limit, op)
} }
} else { } else {
/* simple expansion or empty definition; skip leading whitespace */ /* simple expansion or empty definition; skip leading whitespace */
while (is_hor_space[*bp]) while (is_nvspace (*bp))
++bp; ++bp;
/* now everything from bp before limit is the definition. */ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, 0); defn = collect_expansion (bp, limit, -1, 0);
...@@ -2689,17 +2672,17 @@ comp_def_part (first, beg1, len1, beg2, len2, last) ...@@ -2689,17 +2672,17 @@ comp_def_part (first, beg1, len1, beg2, len2, last)
register const U_CHAR *end1 = beg1 + len1; register const U_CHAR *end1 = beg1 + len1;
register const U_CHAR *end2 = beg2 + len2; register const U_CHAR *end2 = beg2 + len2;
if (first) { if (first) {
while (beg1 != end1 && is_space[*beg1]) beg1++; while (beg1 != end1 && is_space (*beg1)) beg1++;
while (beg2 != end2 && is_space[*beg2]) beg2++; while (beg2 != end2 && is_space (*beg2)) beg2++;
} }
if (last) { if (last) {
while (beg1 != end1 && is_space[end1[-1]]) end1--; while (beg1 != end1 && is_space (end1[-1])) end1--;
while (beg2 != end2 && is_space[end2[-1]]) end2--; while (beg2 != end2 && is_space (end2[-1])) end2--;
} }
while (beg1 != end1 && beg2 != end2) { while (beg1 != end1 && beg2 != end2) {
if (is_space[*beg1] && is_space[*beg2]) { if (is_space (*beg1) && is_space (*beg2)) {
while (beg1 != end1 && is_space[*beg1]) beg1++; while (beg1 != end1 && is_space (*beg1)) beg1++;
while (beg2 != end2 && is_space[*beg2]) beg2++; while (beg2 != end2 && is_space (*beg2)) beg2++;
} else if (*beg1 == *beg2) { } else if (*beg1 == *beg2) {
beg1++; beg2++; beg1++; beg2++;
} else break; } else break;
...@@ -2756,8 +2739,8 @@ collect_expansion (buf, end, nargs, arglist) ...@@ -2756,8 +2739,8 @@ collect_expansion (buf, end, nargs, arglist)
/* Find end of leading whitespace. */ /* Find end of leading whitespace. */
limit = end; limit = end;
p = buf; p = buf;
while (p < limit && is_space[limit[-1]]) limit--; while (p < limit && is_space (limit[-1])) limit--;
while (p < limit && is_space[*p]) p++; while (p < limit && is_space (*p)) p++;
/* Allocate space for the text in the macro definition. /* Allocate space for the text in the macro definition.
Leading and trailing whitespace chars need 2 bytes each. Leading and trailing whitespace chars need 2 bytes each.
...@@ -2776,7 +2759,7 @@ collect_expansion (buf, end, nargs, arglist) ...@@ -2776,7 +2759,7 @@ collect_expansion (buf, end, nargs, arglist)
p = buf; p = buf;
/* Convert leading whitespace to Newline-markers. */ /* Convert leading whitespace to Newline-markers. */
while (p < limit && is_space[*p]) { while (p < limit && is_space (*p)) {
*exp_p++ = '\n'; *exp_p++ = '\n';
*exp_p++ = *p++; *exp_p++ = *p++;
} }
...@@ -2826,15 +2809,15 @@ collect_expansion (buf, end, nargs, arglist) ...@@ -2826,15 +2809,15 @@ collect_expansion (buf, end, nargs, arglist)
break; break;
} }
if (is_idchar[c] && nargs > 0) { if (is_idchar (c) && nargs > 0) {
U_CHAR *id_beg = p - 1; U_CHAR *id_beg = p - 1;
int id_len; int id_len;
--exp_p; --exp_p;
while (p != limit && is_idchar[*p]) p++; while (p != limit && is_idchar (*p)) p++;
id_len = p - id_beg; id_len = p - id_beg;
if (is_idstart[c]) { if (is_idstart (c)) {
register struct arglist *arg; register struct arglist *arg;
for (arg = arglist; arg != NULL; arg = arg->next) { for (arg = arglist; arg != NULL; arg = arg->next) {
...@@ -2887,7 +2870,7 @@ collect_expansion (buf, end, nargs, arglist) ...@@ -2887,7 +2870,7 @@ collect_expansion (buf, end, nargs, arglist)
if (limit < end) { if (limit < end) {
/* Convert trailing whitespace to Newline-markers. */ /* Convert trailing whitespace to Newline-markers. */
while (limit < end && is_space[*limit]) { while (limit < end && is_space (*limit)) {
*exp_p++ = '\n'; *exp_p++ = '\n';
*exp_p++ = *limit++; *exp_p++ = *limit++;
} }
...@@ -2941,7 +2924,7 @@ do_line (buf, limit, op) ...@@ -2941,7 +2924,7 @@ do_line (buf, limit, op)
bp++; bp++;
#if 0 /* #line 10"foo.c" is supposed to be allowed. */ #if 0 /* #line 10"foo.c" is supposed to be allowed. */
if (*bp && !is_space[*bp]) { if (*bp && !is_space (*bp)) {
error ("invalid format #line command"); error ("invalid format #line command");
return; return;
} }
...@@ -3030,7 +3013,7 @@ do_undef (buf, limit, op) ...@@ -3030,7 +3013,7 @@ do_undef (buf, limit, op)
SKIP_WHITE_SPACE (buf); SKIP_WHITE_SPACE (buf);
if (! strncmp ((const char *)buf, "defined", 7) && ! is_idchar[buf[7]]) if (! strncmp ((const char *)buf, "defined", 7) && ! is_idchar (buf[7]))
warning ("undefining `defined'"); warning ("undefining `defined'");
while ((hp = lookup (buf, -1, -1)) != NULL) { while ((hp = lookup (buf, -1, -1)) != NULL) {
...@@ -3121,11 +3104,11 @@ parse_assertion (buf, limit, answerp, type) ...@@ -3121,11 +3104,11 @@ parse_assertion (buf, limit, answerp, type)
unsigned int len; unsigned int len;
bp = symname; bp = symname;
if (bp < climit && is_idstart[*bp]) if (bp < climit && is_idstart (*bp))
{ {
do do
bp++; bp++;
while (bp < climit && is_idchar[*bp]); while (bp < climit && is_idchar (*bp));
} }
len = bp - symname; len = bp - symname;
...@@ -3177,9 +3160,9 @@ test_assertion (pbuf) ...@@ -3177,9 +3160,9 @@ test_assertion (pbuf)
/* Yuk. We update pbuf to point after the assertion test. /* Yuk. We update pbuf to point after the assertion test.
First, move past the identifier. */ First, move past the identifier. */
if (is_space[*buf]) if (is_space (*buf))
buf++; buf++;
while (is_idchar[*buf]) while (is_idchar (*buf))
buf++; buf++;
/* If we have an answer, we need to move past the parentheses. */ /* If we have an answer, we need to move past the parentheses. */
if (answer) if (answer)
...@@ -3292,11 +3275,11 @@ canonicalize_text (buf, limit, climit) ...@@ -3292,11 +3275,11 @@ canonicalize_text (buf, limit, climit)
for (dest = result; buf < limit;) for (dest = result; buf < limit;)
{ {
if (! is_space[*buf]) if (! is_space (*buf))
*dest++ = *buf++; *dest++ = *buf++;
else else
{ {
while (++buf < limit && is_space [*buf]) while (++buf < limit && is_space (*buf))
; ;
if (dest != result && buf != limit) if (dest != result && buf != limit)
*dest++ = ' '; *dest++ = ' ';
...@@ -3411,10 +3394,10 @@ do_xifdef (buf, limit, type) ...@@ -3411,10 +3394,10 @@ do_xifdef (buf, limit, type)
/* Discard leading and trailing whitespace. */ /* Discard leading and trailing whitespace. */
SKIP_WHITE_SPACE (buf); SKIP_WHITE_SPACE (buf);
while (limit != buf && is_hor_space[limit[-1]]) limit--; while (limit != buf && is_nvspace (limit[-1])) limit--;
/* Find the end of the identifier at the beginning. */ /* Find the end of the identifier at the beginning. */
for (end = buf; is_idchar[*end]; end++); for (end = buf; is_idchar (*end); end++);
if (end == buf) if (end == buf)
skip = (type == T_IFDEF); skip = (type == T_IFDEF);
...@@ -3521,7 +3504,7 @@ skip_if_group (ip, any) ...@@ -3521,7 +3504,7 @@ skip_if_group (ip, any)
If not, this # is not special. */ If not, this # is not special. */
bp = beg_of_line; bp = beg_of_line;
while (1) { while (1) {
if (is_hor_space[*bp]) if (is_nvspace (*bp))
bp++; bp++;
else if (*bp == '\\' && bp[1] == '\n') else if (*bp == '\\' && bp[1] == '\n')
bp += 2; bp += 2;
...@@ -3545,7 +3528,7 @@ skip_if_group (ip, any) ...@@ -3545,7 +3528,7 @@ skip_if_group (ip, any)
/* Skip whitespace and \-newline. */ /* Skip whitespace and \-newline. */
while (1) { while (1) {
if (is_hor_space[*bp]) if (is_nvspace (*bp))
bp++; bp++;
else if (*bp == '\\' && bp[1] == '\n') else if (*bp == '\\' && bp[1] == '\n')
bp += 2; bp += 2;
...@@ -3565,12 +3548,12 @@ skip_if_group (ip, any) ...@@ -3565,12 +3548,12 @@ skip_if_group (ip, any)
symbol-constituents so that we end up with a contiguous name. */ symbol-constituents so that we end up with a contiguous name. */
while (1) { while (1) {
if (is_idchar[*bp]) if (is_idchar (*bp))
bp++; bp++;
else { else {
if (*bp == '\\' && bp[1] == '\n') if (*bp == '\\' && bp[1] == '\n')
name_newline_fix (bp); name_newline_fix (bp);
if (is_idchar[*bp]) if (is_idchar (*bp))
bp++; bp++;
else break; else break;
} }
...@@ -3579,7 +3562,7 @@ skip_if_group (ip, any) ...@@ -3579,7 +3562,7 @@ skip_if_group (ip, any)
for (kt = directive_table; kt->length >= 0; kt++) { for (kt = directive_table; kt->length >= 0; kt++) {
IF_STACK_FRAME *temp; IF_STACK_FRAME *temp;
if (strncmp ((const char *)cp, kt->name, kt->length) == 0 if (strncmp ((const char *)cp, kt->name, kt->length) == 0
&& !is_idchar[cp[kt->length]]) { && !is_idchar (cp[kt->length])) {
/* If we are asked to return on next directive, /* If we are asked to return on next directive,
do so now. */ do so now. */
...@@ -3926,7 +3909,7 @@ macroexpand (hp, op) ...@@ -3926,7 +3909,7 @@ macroexpand (hp, op)
if (i == 1) { if (i == 1) {
register const U_CHAR *bp = args[0].raw; register const U_CHAR *bp = args[0].raw;
register const U_CHAR *lim = bp + args[0].raw_length; register const U_CHAR *lim = bp + args[0].raw_length;
while (bp != lim && is_space[*bp]) bp++; while (bp != lim && is_space (*bp)) bp++;
if (bp == lim) if (bp == lim)
i = 0; i = 0;
} }
...@@ -3994,10 +3977,10 @@ macroexpand (hp, op) ...@@ -3994,10 +3977,10 @@ macroexpand (hp, op)
int c; int c;
i = 0; i = 0;
while (i < arglen while (i < arglen
&& (c = arg->raw[i], is_space[c])) && (c = arg->raw[i], is_space (c)))
i++; i++;
while (i < arglen while (i < arglen
&& (c = arg->raw[arglen - 1], is_space[c])) && (c = arg->raw[arglen - 1], is_space (c)))
arglen--; arglen--;
for (; i < arglen; i++) { for (; i < arglen; i++) {
c = arg->raw[i]; c = arg->raw[i];
...@@ -4012,13 +3995,13 @@ macroexpand (hp, op) ...@@ -4012,13 +3995,13 @@ macroexpand (hp, op)
/* Internal sequences of whitespace are replaced by one space /* Internal sequences of whitespace are replaced by one space
except within an string or char token. */ except within an string or char token. */
if (! in_string if (! in_string
&& (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c])) { && (c == '\n' ? arg->raw[i+1] == '\n' : is_space (c))) {
while (1) { while (1) {
/* Note that Newline Space does occur within whitespace /* Note that Newline Space does occur within whitespace
sequences; consider it part of the sequence. */ sequences; consider it part of the sequence. */
if (c == '\n' && is_space[arg->raw[i+1]]) if (c == '\n' && is_space (arg->raw[i+1]))
i += 2; i += 2;
else if (c != '\n' && is_space[c]) else if (c != '\n' && is_space (c))
i++; i++;
else break; else break;
c = arg->raw[i]; c = arg->raw[i];
...@@ -4054,8 +4037,8 @@ macroexpand (hp, op) ...@@ -4054,8 +4037,8 @@ macroexpand (hp, op)
const U_CHAR *l1 = p1 + arg->raw_length; const U_CHAR *l1 = p1 + arg->raw_length;
if (ap->raw_before) { if (ap->raw_before) {
while (p1 != l1 && is_space[*p1]) p1++; while (p1 != l1 && is_space (*p1)) p1++;
while (p1 != l1 && is_idchar[*p1]) while (p1 != l1 && is_idchar (*p1))
xbuf[totlen++] = *p1++; xbuf[totlen++] = *p1++;
/* Delete any no-reexpansion marker that follows /* Delete any no-reexpansion marker that follows
an identifier at the beginning of the argument an identifier at the beginning of the argument
...@@ -4067,7 +4050,7 @@ macroexpand (hp, op) ...@@ -4067,7 +4050,7 @@ macroexpand (hp, op)
/* Arg is concatenated after: delete trailing whitespace, /* Arg is concatenated after: delete trailing whitespace,
whitespace markers, and no-reexpansion markers. */ whitespace markers, and no-reexpansion markers. */
while (p1 != l1) { while (p1 != l1) {
if (is_space[l1[-1]]) l1--; if (is_space (l1[-1])) l1--;
else if (l1[-1] == '-') { else if (l1[-1] == '-') {
const U_CHAR *p2 = l1 - 1; const U_CHAR *p2 = l1 - 1;
/* If a `-' is preceded by an odd number of newlines then it /* If a `-' is preceded by an odd number of newlines then it
...@@ -4681,7 +4664,7 @@ install (name, len, type, hash) ...@@ -4681,7 +4664,7 @@ install (name, len, type, hash)
if (len < 0) { if (len < 0) {
p = name; p = name;
while (is_idchar[*p]) while (is_idchar (*p))
p++; p++;
len = p - name; len = p - name;
} }
...@@ -4725,7 +4708,7 @@ lookup (name, len, hash) ...@@ -4725,7 +4708,7 @@ lookup (name, len, hash)
register HASHNODE *bucket; register HASHNODE *bucket;
if (len < 0) { if (len < 0) {
for (bp = name; is_idchar[*bp]; bp++) ; for (bp = name; is_idchar (*bp); bp++) ;
len = bp - name; len = bp - name;
} }
...@@ -4897,44 +4880,6 @@ dump_arg_n (defn, argnum) ...@@ -4897,44 +4880,6 @@ dump_arg_n (defn, argnum)
} }
} }
/* Initialize syntactic classifications of characters. */
static void
initialize_char_syntax ()
{
register int i;
/*
* Set up is_idchar and is_idstart tables. These should be
* faster than saying (is_alpha (c) || c == '_'), etc.
* Must do set up these things before calling any routines tthat
* refer to them.
*/
for (i = 'a'; i <= 'z'; i++) {
is_idchar[i - 'a' + 'A'] = 1;
is_idchar[i] = 1;
is_idstart[i - 'a' + 'A'] = 1;
is_idstart[i] = 1;
}
for (i = '0'; i <= '9'; i++)
is_idchar[i] = 1;
is_idchar['_'] = 1;
is_idstart['_'] = 1;
/* horizontal space table */
is_hor_space[' '] = 1;
is_hor_space['\t'] = 1;
is_hor_space['\v'] = 1;
is_hor_space['\f'] = 1;
is_hor_space['\r'] = 1;
is_space[' '] = 1;
is_space['\t'] = 1;
is_space['\v'] = 1;
is_space['\f'] = 1;
is_space['\n'] = 1;
is_space['\r'] = 1;
}
/* Initialize the built-in macros. */ /* Initialize the built-in macros. */
#define DSC(x) U x, sizeof x - 1 #define DSC(x) U x, sizeof x - 1
#define install_spec(name, type) \ #define install_spec(name, type) \
......
...@@ -36,7 +36,9 @@ extern struct hashnode *lookup PARAMS ((const unsigned char *, int, int)); ...@@ -36,7 +36,9 @@ extern struct hashnode *lookup PARAMS ((const unsigned char *, int, int));
extern int parse_c_expression PARAMS ((const char *)); /* in tradcif.y */ extern int parse_c_expression PARAMS ((const char *)); /* in tradcif.y */
extern int test_assertion PARAMS ((unsigned char **)); extern int test_assertion PARAMS ((unsigned char **));
/* some external tables of character types */ #define is_idchar(x) ISIDNUM(x)
extern unsigned char is_idstart[], is_idchar[]; #define is_idstart(x) ISIDST(x)
#define is_space(x) ISSPACE(x)
#define is_nvspace(x) IS_NVSPACE(x)
#endif /* ! _TRADCPP_H_ */ #endif /* ! _TRADCPP_H_ */
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* safe-ctype.h: New file.
2000-12-06 Rodney Brown <RodneyBrown@mynd.com> 2000-12-06 Rodney Brown <RodneyBrown@mynd.com>
* getopt.h obstack.h: Standarize copyright statement. * getopt.h obstack.h: Standarize copyright statement.
......
/* <ctype.h> replacement macros.
Copyright (C) 2000 Free Software Foundation, Inc.
Contributed by Zack Weinberg <zackw@stanford.edu>.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Libiberty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This is a compatible replacement of the standard C library's <ctype.h>
with the following properties:
- Implements all isxxx() macros required by C99.
- Also implements some character classes useful when
parsing C-like languages.
- Does not change behavior depending on the current locale.
- Behaves properly for all values in the range of a signed or
unsigned char.
To avoid conflicts, this header defines the isxxx functions in upper
case, e.g. ISALPHA not isalpha. */
#ifndef SAFE_CTYPE_H
#define SAFE_CTYPE_H
#ifdef isalpha
#error "safe-ctype.h and ctype.h may not be used simultaneously"
#else
/* Categories. */
enum {
/* In C99 */
_sch_isblank = 0x0001, /* space \t */
_sch_iscntrl = 0x0002, /* nonprinting characters */
_sch_isdigit = 0x0004, /* 0-9 */
_sch_islower = 0x0008, /* a-z */
_sch_isprint = 0x0010, /* any printing character including ' ' */
_sch_ispunct = 0x0020, /* all punctuation */
_sch_isspace = 0x0040, /* space \t \n \r \f \v */
_sch_isupper = 0x0080, /* A-Z */
_sch_isxdigit = 0x0100, /* 0-9A-Fa-f */
/* Extra categories useful to cpplib. */
_sch_isidst = 0x0200, /* A-Za-z_ */
_sch_isvsp = 0x0400, /* \n \r */
_sch_isnvsp = 0x0800, /* space \t \f \v \0 */
/* Combinations of the above. */
_sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */
_sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */
_sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */
_sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */
_sch_iscppsp = _sch_isvsp|_sch_isnvsp /* isspace + \0 */
};
/* This code fundamentally assumes that a byte is 8 bits. Test this
at compile time. */
extern int a_byte_isnt_eight_bits[(unsigned char)256 == 0 ? 1 : -1];
/* Character classification. */
extern const unsigned short _sch_istable[256];
#define _sch_test(c, bit) (_sch_istable[(int)(unsigned char)(c)] & (bit))
#define ISALPHA(c) _sch_test(c, _sch_isalpha)
#define ISALNUM(c) _sch_test(c, _sch_isalnum)
#define ISBLANK(c) _sch_test(c, _sch_isblank)
#define ISCNTRL(c) _sch_test(c, _sch_iscntrl)
#define ISDIGIT(c) _sch_test(c, _sch_isdigit)
#define ISGRAPH(c) _sch_test(c, _sch_isgraph)
#define ISLOWER(c) _sch_test(c, _sch_islower)
#define ISPRINT(c) _sch_test(c, _sch_isprint)
#define ISPUNCT(c) _sch_test(c, _sch_ispunct)
#define ISSPACE(c) _sch_test(c, _sch_isspace)
#define ISUPPER(c) _sch_test(c, _sch_isupper)
#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
#define ISIDNUM(c) _sch_test(c, _sch_isidnum)
#define ISIDST(c) _sch_test(c, _sch_isidst)
#define IS_VSPACE(c) _sch_test(c, _sch_isvsp)
#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp)
#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp)
/* Character transformation. */
extern const unsigned char _sch_toupper[256];
extern const unsigned char _sch_tolower[256];
#define TOUPPER(c) _sch_toupper[(int)(unsigned char)(c)]
#define TOLOWER(c) _sch_tolower[(int)(unsigned char)(c)]
#endif /* no ctype.h */
#endif /* SAFE_CTYPE_H */
2000-12-07 Zack Weinberg <zack@wolery.stanford.edu>
* safe-ctype.c: New file.
* Makefile.in (CFILES): Add safe-ctype.c.
(REQUIRED_OFILES): Add safe-ctype.o.
* argv.c: Define ISBLANK and use it, not isspace.
* basename.c, cplus-dem.c, fnmatch.c, pexecute.c, strtod.c,
strtol.c, strtoul.c: Include safe-ctype.h, not ctype.h. Use
uppercase ctype macros. Don't test ISUPPER(c)/ISLOWER(c)
before calling TOLOWER(c)/TOUPPER(c).
2000-12-07 Mike Stump <mrs@wrs.com> 2000-12-07 Mike Stump <mrs@wrs.com>
* Makefile.in (distclean): When cleaning, remove testsuite. * Makefile.in (distclean): When cleaning, remove testsuite.
......
...@@ -128,22 +128,22 @@ CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \ ...@@ -128,22 +128,22 @@ CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \
bzero.c calloc.c choose-temp.c clock.c concat.c cplus-dem.c \ bzero.c calloc.c choose-temp.c clock.c concat.c cplus-dem.c \
cp-demangle.c dyn-string.c fdmatch.c fnmatch.c getcwd.c \ cp-demangle.c dyn-string.c fdmatch.c fnmatch.c getcwd.c \
getpwd.c getopt.c getopt1.c getpagesize.c getruntime.c \ getpwd.c getopt.c getopt1.c getpagesize.c getruntime.c \
floatformat.c hashtab.c hex.c index.c insque.c md5.c memchr.c memcmp.c\ floatformat.c hashtab.c hex.c index.c insque.c md5.c memchr.c \
memcpy.c memmove.c memset.c mkstemps.c objalloc.c obstack.c \ memcmp.c memcpy.c memmove.c memset.c mkstemps.c objalloc.c obstack.c \
partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c \ partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c \
sigsetmask.c sort.c spaces.c splay-tree.c strcasecmp.c strncasecmp.c \ sigsetmask.c safe-ctype.c sort.c spaces.c splay-tree.c strcasecmp.c \
strchr.c strdup.c strerror.c strncmp.c strrchr.c strsignal.c strstr.c \ strncasecmp.c strchr.c strdup.c strerror.c strncmp.c strrchr.c \
strtod.c strtol.c strtoul.c tmpnam.c vasprintf.c vfork.c vfprintf.c \ strsignal.c strstr.c strtod.c strtol.c strtoul.c tmpnam.c vasprintf.c \
vprintf.c vsprintf.c waitpid.c xatexit.c xexit.c xmalloc.c \ vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c xatexit.c xexit.c \
xmemdup.c xstrdup.c xstrerror.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
# These are always included in the library. # These are always included in the library.
REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o cp-demangle.o \ REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o cp-demangle.o \
dyn-string.o fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o \ dyn-string.o fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o \
getruntime.o hashtab.o hex.o floatformat.o md5.o objalloc.o obstack.o \ getruntime.o hashtab.o hex.o floatformat.o md5.o objalloc.o obstack.o \
partition.o pexecute.o sort.o spaces.o splay-tree.o strerror.o \ partition.o pexecute.o safe-ctype.o sort.o spaces.o splay-tree.o \
strsignal.o xatexit.o xexit.o xmalloc.o xmemdup.o xstrdup.o \ strerror.o strsignal.o xatexit.o xexit.o xmalloc.o xmemdup.o \
xstrerror.o xstrdup.o xstrerror.o
$(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA) $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA)
rm -f $(TARGETLIB) rm -f $(TARGETLIB)
......
...@@ -25,10 +25,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -25,10 +25,7 @@ Boston, MA 02111-1307, USA. */
#include "ansidecl.h" #include "ansidecl.h"
#include "libiberty.h" #include "libiberty.h"
#ifdef isspace #define ISBLANK(ch) ((ch) == ' ' || (ch) == '\t')
#undef isspace
#endif
#define isspace(ch) ((ch) == ' ' || (ch) == '\t')
/* Routines imported from standard C runtime libraries. */ /* Routines imported from standard C runtime libraries. */
...@@ -227,7 +224,7 @@ char *input; ...@@ -227,7 +224,7 @@ char *input;
do do
{ {
/* Pick off argv[argc] */ /* Pick off argv[argc] */
while (isspace (*input)) while (ISBLANK (*input))
{ {
input++; input++;
} }
...@@ -260,7 +257,7 @@ char *input; ...@@ -260,7 +257,7 @@ char *input;
arg = copybuf; arg = copybuf;
while (*input != EOS) while (*input != EOS)
{ {
if (isspace (*input) && !squote && !dquote && !bsquote) if (ISBLANK (*input) && !squote && !dquote && !bsquote)
{ {
break; break;
} }
...@@ -326,7 +323,7 @@ char *input; ...@@ -326,7 +323,7 @@ char *input;
argc++; argc++;
argv[argc] = NULL; argv[argc] = NULL;
while (isspace (*input)) while (ISBLANK (*input))
{ {
input++; input++;
} }
......
...@@ -20,7 +20,7 @@ BUGS ...@@ -20,7 +20,7 @@ BUGS
#include "ansidecl.h" #include "ansidecl.h"
#include "libiberty.h" #include "libiberty.h"
#include <ctype.h> #include "safe-ctype.h"
#ifndef DIR_SEPARATOR #ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/' #define DIR_SEPARATOR '/'
...@@ -50,7 +50,7 @@ basename (name) ...@@ -50,7 +50,7 @@ basename (name)
#if defined (HAVE_DOS_BASED_FILE_SYSTEM) #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over the disk name in MSDOS pathnames. */ /* Skip over the disk name in MSDOS pathnames. */
if (isalpha (name[0]) && name[1] == ':') if (ISALPHA (name[0]) && name[1] == ':')
name += 2; name += 2;
#endif #endif
......
...@@ -34,7 +34,8 @@ Boston, MA 02111-1307, USA. */ ...@@ -34,7 +34,8 @@ Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#endif #endif
#include <ctype.h> #include "safe-ctype.h"
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
...@@ -544,10 +545,10 @@ consume_count (type) ...@@ -544,10 +545,10 @@ consume_count (type)
{ {
int count = 0; int count = 0;
if (! isdigit ((unsigned char)**type)) if (! ISDIGIT ((unsigned char)**type))
return -1; return -1;
while (isdigit ((unsigned char)**type)) while (ISDIGIT ((unsigned char)**type))
{ {
count *= 10; count *= 10;
...@@ -558,7 +559,7 @@ consume_count (type) ...@@ -558,7 +559,7 @@ consume_count (type)
ten. */ ten. */
if ((count % 10) != 0) if ((count % 10) != 0)
{ {
while (isdigit ((unsigned char) **type)) while (ISDIGIT ((unsigned char) **type))
(*type)++; (*type)++;
return -1; return -1;
} }
...@@ -584,7 +585,7 @@ consume_count_with_underscores (mangled) ...@@ -584,7 +585,7 @@ consume_count_with_underscores (mangled)
if (**mangled == '_') if (**mangled == '_')
{ {
(*mangled)++; (*mangled)++;
if (!isdigit ((unsigned char)**mangled)) if (!ISDIGIT ((unsigned char)**mangled))
return -1; return -1;
idx = consume_count (mangled); idx = consume_count (mangled);
...@@ -716,8 +717,8 @@ cplus_demangle_opname (opname, result, options) ...@@ -716,8 +717,8 @@ cplus_demangle_opname (opname, result, options)
} }
} }
else if (opname[0] == '_' && opname[1] == '_' else if (opname[0] == '_' && opname[1] == '_'
&& islower((unsigned char)opname[2]) && ISLOWER((unsigned char)opname[2])
&& islower((unsigned char)opname[3])) && ISLOWER((unsigned char)opname[3]))
{ {
if (opname[4] == '\0') if (opname[4] == '\0')
{ {
...@@ -1003,8 +1004,8 @@ ada_demangle (mangled, option) ...@@ -1003,8 +1004,8 @@ ada_demangle (mangled, option)
sizeof (char)); sizeof (char));
demangled = demangling_buffer; demangled = demangling_buffer;
if (isdigit ((unsigned char) mangled[len0 - 1])) { if (ISDIGIT ((unsigned char) mangled[len0 - 1])) {
for (i = len0 - 2; i >= 0 && isdigit ((unsigned char) mangled[i]); i -= 1) for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1)
; ;
if (i > 1 && mangled[i] == '_' && mangled[i - 1] == '_') if (i > 1 && mangled[i] == '_' && mangled[i - 1] == '_')
{ {
...@@ -1018,7 +1019,7 @@ ada_demangle (mangled, option) ...@@ -1018,7 +1019,7 @@ ada_demangle (mangled, option)
} }
} }
for (i = 0, j = 0; i < len0 && ! isalpha ((unsigned char)mangled[i]); for (i = 0, j = 0; i < len0 && ! ISALPHA ((unsigned char)mangled[i]);
i += 1, j += 1) i += 1, j += 1)
demangled[j] = mangled[i]; demangled[j] = mangled[i];
...@@ -1042,7 +1043,7 @@ ada_demangle (mangled, option) ...@@ -1042,7 +1043,7 @@ ada_demangle (mangled, option)
demangled[j] = '\000'; demangled[j] = '\000';
for (i = 0; demangled[i] != '\0'; i += 1) for (i = 0; demangled[i] != '\0'; i += 1)
if (isupper ((unsigned char)demangled[i]) || demangled[i] == ' ') if (ISUPPER ((unsigned char)demangled[i]) || demangled[i] == ' ')
goto Suppress; goto Suppress;
if (! changed) if (! changed)
...@@ -1532,7 +1533,7 @@ demangle_signature (work, mangled, declp) ...@@ -1532,7 +1533,7 @@ demangle_signature (work, mangled, declp)
if (HP_DEMANGLING) if (HP_DEMANGLING)
{ {
(*mangled)++; (*mangled)++;
while (**mangled && isdigit ((unsigned char)**mangled)) while (**mangled && ISDIGIT ((unsigned char)**mangled))
(*mangled)++; (*mangled)++;
} }
else else
...@@ -1865,7 +1866,7 @@ demangle_real_value (work, mangled, s) ...@@ -1865,7 +1866,7 @@ demangle_real_value (work, mangled, s)
string_appendn (s, "-", 1); string_appendn (s, "-", 1);
(*mangled)++; (*mangled)++;
} }
while (isdigit ((unsigned char)**mangled)) while (ISDIGIT ((unsigned char)**mangled))
{ {
string_appendn (s, *mangled, 1); string_appendn (s, *mangled, 1);
(*mangled)++; (*mangled)++;
...@@ -1874,7 +1875,7 @@ demangle_real_value (work, mangled, s) ...@@ -1874,7 +1875,7 @@ demangle_real_value (work, mangled, s)
{ {
string_appendn (s, ".", 1); string_appendn (s, ".", 1);
(*mangled)++; (*mangled)++;
while (isdigit ((unsigned char)**mangled)) while (ISDIGIT ((unsigned char)**mangled))
{ {
string_appendn (s, *mangled, 1); string_appendn (s, *mangled, 1);
(*mangled)++; (*mangled)++;
...@@ -1884,7 +1885,7 @@ demangle_real_value (work, mangled, s) ...@@ -1884,7 +1885,7 @@ demangle_real_value (work, mangled, s)
{ {
string_appendn (s, "e", 1); string_appendn (s, "e", 1);
(*mangled)++; (*mangled)++;
while (isdigit ((unsigned char)**mangled)) while (ISDIGIT ((unsigned char)**mangled))
{ {
string_appendn (s, *mangled, 1); string_appendn (s, *mangled, 1);
(*mangled)++; (*mangled)++;
...@@ -2735,20 +2736,20 @@ demangle_prefix (work, mangled, declp) ...@@ -2735,20 +2736,20 @@ demangle_prefix (work, mangled, declp)
} }
else if (work -> static_type) else if (work -> static_type)
{ {
if (!isdigit ((unsigned char)scan[0]) && (scan[0] != 't')) if (!ISDIGIT ((unsigned char)scan[0]) && (scan[0] != 't'))
{ {
success = 0; success = 0;
} }
} }
else if ((scan == *mangled) else if ((scan == *mangled)
&& (isdigit ((unsigned char)scan[2]) || (scan[2] == 'Q') && (ISDIGIT ((unsigned char)scan[2]) || (scan[2] == 'Q')
|| (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H'))) || (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H')))
{ {
/* The ARM says nothing about the mangling of local variables. /* The ARM says nothing about the mangling of local variables.
But cfront mangles local variables by prepending __<nesting_level> But cfront mangles local variables by prepending __<nesting_level>
to them. As an extension to ARM demangling we handle this case. */ to them. As an extension to ARM demangling we handle this case. */
if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING) if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
&& isdigit ((unsigned char)scan[2])) && ISDIGIT ((unsigned char)scan[2]))
{ {
*mangled = scan + 2; *mangled = scan + 2;
consume_count (mangled); consume_count (mangled);
...@@ -2785,7 +2786,7 @@ demangle_prefix (work, mangled, declp) ...@@ -2785,7 +2786,7 @@ demangle_prefix (work, mangled, declp)
/* EDG template? */ /* EDG template? */
demangle_arm_hp_template (work, mangled, strlen (*mangled), declp); demangle_arm_hp_template (work, mangled, strlen (*mangled), declp);
} }
else if ((scan == *mangled) && !isdigit ((unsigned char)scan[2]) else if ((scan == *mangled) && !ISDIGIT ((unsigned char)scan[2])
&& (scan[2] != 't')) && (scan[2] != 't'))
{ {
/* Mangled name starts with "__". Skip over any leading '_' characters, /* Mangled name starts with "__". Skip over any leading '_' characters,
...@@ -2907,7 +2908,7 @@ gnu_special (work, mangled, declp) ...@@ -2907,7 +2908,7 @@ gnu_special (work, mangled, declp)
1); 1);
break; break;
default: default:
if (isdigit((unsigned char)*mangled[0])) if (ISDIGIT((unsigned char)*mangled[0]))
{ {
n = consume_count(mangled); n = consume_count(mangled);
/* We may be seeing a too-large size, or else a /* We may be seeing a too-large size, or else a
...@@ -3434,13 +3435,13 @@ get_count (type, count) ...@@ -3434,13 +3435,13 @@ get_count (type, count)
const char *p; const char *p;
int n; int n;
if (!isdigit ((unsigned char)**type)) if (!ISDIGIT ((unsigned char)**type))
return (0); return (0);
else else
{ {
*count = **type - '0'; *count = **type - '0';
(*type)++; (*type)++;
if (isdigit ((unsigned char)**type)) if (ISDIGIT ((unsigned char)**type))
{ {
p = *type; p = *type;
n = *count; n = *count;
...@@ -3450,7 +3451,7 @@ get_count (type, count) ...@@ -3450,7 +3451,7 @@ get_count (type, count)
n += *p - '0'; n += *p - '0';
p++; p++;
} }
while (isdigit ((unsigned char)*p)); while (ISDIGIT ((unsigned char)*p));
if (*p == '_') if (*p == '_')
{ {
*type = p + 1; *type = p + 1;
...@@ -3580,7 +3581,7 @@ do_type (work, mangled, result) ...@@ -3580,7 +3581,7 @@ do_type (work, mangled, result)
if (**mangled != 'Q') if (**mangled != 'Q')
string_prepend (&decl, SCOPE_STRING (work)); string_prepend (&decl, SCOPE_STRING (work));
if (isdigit ((unsigned char)**mangled)) if (ISDIGIT ((unsigned char)**mangled))
{ {
n = consume_count (mangled); n = consume_count (mangled);
if (n == -1 if (n == -1
...@@ -3900,7 +3901,7 @@ demangle_fund_type (work, mangled, result) ...@@ -3900,7 +3901,7 @@ demangle_fund_type (work, mangled, result)
break; break;
case 'G': case 'G':
(*mangled)++; (*mangled)++;
if (!isdigit ((unsigned char)**mangled)) if (!ISDIGIT ((unsigned char)**mangled))
{ {
success = 0; success = 0;
break; break;
...@@ -4012,12 +4013,12 @@ do_hpacc_template_const_value (work, mangled, result) ...@@ -4012,12 +4013,12 @@ do_hpacc_template_const_value (work, mangled, result)
} }
/* We have to be looking at an integer now */ /* We have to be looking at an integer now */
if (!(isdigit ((unsigned char)**mangled))) if (!(ISDIGIT ((unsigned char)**mangled)))
return 0; return 0;
/* We only deal with integral values for template /* We only deal with integral values for template
parameters -- so it's OK to look only for digits */ parameters -- so it's OK to look only for digits */
while (isdigit ((unsigned char)**mangled)) while (ISDIGIT ((unsigned char)**mangled))
{ {
char_str[0] = **mangled; char_str[0] = **mangled;
string_append (result, char_str); string_append (result, char_str);
...@@ -4096,10 +4097,10 @@ snarf_numeric_literal (args, arg) ...@@ -4096,10 +4097,10 @@ snarf_numeric_literal (args, arg)
else if (**args == '+') else if (**args == '+')
(*args)++; (*args)++;
if (!isdigit ((unsigned char)**args)) if (!ISDIGIT ((unsigned char)**args))
return 0; return 0;
while (isdigit ((unsigned char)**args)) while (ISDIGIT ((unsigned char)**args))
{ {
char_str[0] = **args; char_str[0] = **args;
string_append (arg, char_str); string_append (arg, char_str);
...@@ -4663,8 +4664,8 @@ demangle_function_name (work, mangled, declp, scan) ...@@ -4663,8 +4664,8 @@ demangle_function_name (work, mangled, declp, scan)
} }
} }
else if (declp->b[0] == '_' && declp->b[1] == '_' else if (declp->b[0] == '_' && declp->b[1] == '_'
&& islower((unsigned char)declp->b[2]) && ISLOWER((unsigned char)declp->b[2])
&& islower((unsigned char)declp->b[3])) && ISLOWER((unsigned char)declp->b[3]))
{ {
if (declp->b[4] == '\0') if (declp->b[4] == '\0')
{ {
...@@ -5125,7 +5126,7 @@ main (argc, argv) ...@@ -5125,7 +5126,7 @@ main (argc, argv)
int i = 0; int i = 0;
c = getchar (); c = getchar ();
/* Try to read a label. */ /* Try to read a label. */
while (c != EOF && (isalnum (c) || strchr (valid_symbols, c))) while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c)))
{ {
if (i >= MBUF_SIZE-1) if (i >= MBUF_SIZE-1)
break; break;
......
...@@ -45,8 +45,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -45,8 +45,7 @@ Boston, MA 02111-1307, USA. */
#include <errno.h> #include <errno.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <ctype.h> #include <safe-ctype.h>
/* Comment out all this code if we are using the GNU C Library, and are not /* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C actually compiling the library itself. This code is part of the GNU C
...@@ -74,8 +73,7 @@ fnmatch (pattern, string, flags) ...@@ -74,8 +73,7 @@ fnmatch (pattern, string, flags)
register const char *p = pattern, *n = string; register const char *p = pattern, *n = string;
register unsigned char c; register unsigned char c;
/* Note that this evalutes C many times. */ #define FOLD(c) ((flags & FNM_CASEFOLD) ? TOLOWER (c) : (c))
#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
while ((c = *p++) != '\0') while ((c = *p++) != '\0')
{ {
......
...@@ -41,12 +41,12 @@ extern int errno; ...@@ -41,12 +41,12 @@ extern int errno;
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#define ISSPACE (x) isspace(x)
#ifdef HAVE_SYS_WAIT_H #ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h> #include <sys/wait.h>
#endif #endif
#include "libiberty.h" #include "libiberty.h"
#include "safe-ctype.h"
/* stdin file number. */ /* stdin file number. */
#define STDIN_FILE_NO 0 #define STDIN_FILE_NO 0
......
/* <ctype.h> replacement macros.
Copyright (C) 2000 Free Software Foundation, Inc.
Contributed by Zack Weinberg <zackw@stanford.edu>.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Libiberty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This is a compatible replacement of the standard C library's <ctype.h>
with the following properties:
- Implements all isxxx() macros required by C99.
- Also implements some character classes useful when
parsing C-like languages.
- Does not change behavior depending on the current locale.
- Behaves properly for all values in the range of a signed or
unsigned char. */
#include <safe-ctype.h>
#include <stdio.h> /* for EOF */
/* Shorthand */
#define bl _sch_isblank
#define cn _sch_iscntrl
#define di _sch_isdigit
#define is _sch_isidst
#define lo _sch_islower
#define nv _sch_isnvsp
#define pn _sch_ispunct
#define pr _sch_isprint
#define sp _sch_isspace
#define up _sch_isupper
#define vs _sch_isvsp
#define xd _sch_isxdigit
/* Masks. */
#define L lo|is |pr /* lower case letter */
#define XL lo|is|xd|pr /* lowercase hex digit */
#define U up|is |pr /* upper case letter */
#define XU up|is|xd|pr /* uppercase hex digit */
#define D di |xd|pr /* decimal digit */
#define P pn |pr /* punctuation */
#define _ pn|is |pr /* underscore */
#define C cn /* control character */
#define Z nv |cn /* NUL */
#define M nv|sp |cn /* cursor movement: \f \v */
#define V vs|sp |cn /* vertical space: \r \n */
#define T nv|sp|bl|cn /* tab */
#define S nv|sp|bl|pr /* space */
/* Are we ASCII? */
#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
&& 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
&& EOF == -1
const unsigned short _sch_istable[256] =
{
Z, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */
C, T, V, M, M, V, C, C, /* BS HT LF VT FF CR SO SI */
C, C, C, C, C, C, C, C, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */
C, C, C, C, C, C, C, C, /* CAN EM SUB ESC FS GS RS US */
S, P, P, P, P, P, P, P, /* SP ! " # $ % & ' */
P, P, P, P, P, P, P, P, /* ( ) * + , - . / */
D, D, D, D, D, D, D, D, /* 0 1 2 3 4 5 6 7 */
D, D, P, P, P, P, P, P, /* 8 9 : ; < = > ? */
P, XU, XU, XU, XU, XU, XU, U, /* @ A B C D E F G */
U, U, U, U, U, U, U, U, /* H I J K L M N O */
U, U, U, U, U, U, U, U, /* P Q R S T U V W */
U, U, U, P, P, P, P, _, /* X Y Z [ \ ] ^ _ */
P, XL, XL, XL, XL, XL, XL, L, /* ` a b c d e f g */
L, L, L, L, L, L, L, L, /* h i j k l m n o */
L, L, L, L, L, L, L, L, /* p q r s t u v w */
L, L, L, P, P, P, P, C, /* x y z { | } ~ DEL */
/* high half of unsigned char is locale-specific, so all tests are
false in "C" locale */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const unsigned char _sch_tolower[256] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64,
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
91, 92, 93, 94, 95, 96,
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
123,124,125,126,127,
128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
};
const unsigned char _sch_toupper[256] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64,
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
91, 92, 93, 94, 95, 96,
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
123,124,125,126,127,
128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
};
#else
#error "Unsupported host character set"
#endif /* not ASCII */
...@@ -22,7 +22,7 @@ the resulting executable to be covered by the GNU General Public License. ...@@ -22,7 +22,7 @@ the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */ the executable file might be covered by the GNU General Public License. */
#include <ctype.h> #include "safe-ctype.h"
extern double atof (); extern double atof ();
...@@ -42,7 +42,7 @@ strtod (str, ptr) ...@@ -42,7 +42,7 @@ strtod (str, ptr)
p = str; p = str;
while (isspace (*p)) while (ISSPACE (*p))
++p; ++p;
if (*p == '+' || *p == '-') if (*p == '+' || *p == '-')
...@@ -88,10 +88,10 @@ strtod (str, ptr) ...@@ -88,10 +88,10 @@ strtod (str, ptr)
} }
/* digits, with 0 or 1 periods in it. */ /* digits, with 0 or 1 periods in it. */
if (isdigit (*p) || *p == '.') if (ISDIGIT (*p) || *p == '.')
{ {
int got_dot = 0; int got_dot = 0;
while (isdigit (*p) || (!got_dot && *p == '.')) while (ISDIGIT (*p) || (!got_dot && *p == '.'))
{ {
if (*p == '.') if (*p == '.')
got_dot = 1; got_dot = 1;
...@@ -105,9 +105,9 @@ strtod (str, ptr) ...@@ -105,9 +105,9 @@ strtod (str, ptr)
i = 1; i = 1;
if (p[i] == '+' || p[i] == '-') if (p[i] == '+' || p[i] == '-')
++i; ++i;
if (isdigit (p[i])) if (ISDIGIT (p[i]))
{ {
while (isdigit (p[i])) while (ISDIGIT (p[i]))
++i; ++i;
*ptr = p + i; *ptr = p + i;
return atof (str); return atof (str);
......
...@@ -37,15 +37,11 @@ ...@@ -37,15 +37,11 @@
#ifdef HAVE_SYS_PARAM_H #ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> #include <sys/param.h>
#endif #endif
#include <ctype.h>
#include <errno.h> #include <errno.h>
#ifdef NEED_DECLARATION_ERRNO #ifdef NEED_DECLARATION_ERRNO
extern int errno; extern int errno;
#endif #endif
#if 0 #include "safe-ctype.h"
#include <stdlib.h>
#endif
#include "ansidecl.h"
/* FIXME: It'd be nice to configure around these, but the include files are too /* FIXME: It'd be nice to configure around these, but the include files are too
painful. These macros should at least be more portable than hardwired hex painful. These macros should at least be more portable than hardwired hex
...@@ -88,7 +84,7 @@ strtol(nptr, endptr, base) ...@@ -88,7 +84,7 @@ strtol(nptr, endptr, base)
*/ */
do { do {
c = *s++; c = *s++;
} while (isspace(c)); } while (ISSPACE(c));
if (c == '-') { if (c == '-') {
neg = 1; neg = 1;
c = *s++; c = *s++;
...@@ -124,10 +120,10 @@ strtol(nptr, endptr, base) ...@@ -124,10 +120,10 @@ strtol(nptr, endptr, base)
cutlim = cutoff % (unsigned long)base; cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base; cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) { for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) if (ISDIGIT(c))
c -= '0'; c -= '0';
else if (isalpha(c)) else if (ISALPHA(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10; c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10;
else else
break; break;
if (c >= base) if (c >= base)
......
...@@ -74,7 +74,7 @@ strtoul(nptr, endptr, base) ...@@ -74,7 +74,7 @@ strtoul(nptr, endptr, base)
*/ */
do { do {
c = *s++; c = *s++;
} while (isspace(c)); } while (ISSPACE(c));
if (c == '-') { if (c == '-') {
neg = 1; neg = 1;
c = *s++; c = *s++;
...@@ -91,10 +91,10 @@ strtoul(nptr, endptr, base) ...@@ -91,10 +91,10 @@ strtoul(nptr, endptr, base)
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) { for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) if (ISDIGIT(c))
c -= '0'; c -= '0';
else if (isalpha(c)) else if (ISALPHA(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10; c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10;
else else
break; break;
if (c >= base) if (c >= base)
......
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