[Nasm-commits] [nasm:ctype] Replace external dependencies on <ctype.h> with an internal table

nasm-bot for H. Peter Anvin hpa at zytor.com
Thu Jun 4 19:56:37 PDT 2020


Commit-ID:  3a27b17c7fea3845c63864e11008edf8cebd7e17
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=3a27b17c7fea3845c63864e11008edf8cebd7e17
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 3 Mar 2016 17:11:28 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 3 Mar 2016 17:18:38 -0800

Replace external dependencies on <ctype.h> with an internal table

Don't rely on the platform <ctype.h>; hopefully this can avoid
problems.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 Makefile.in          |   9 +--
 Mkfiles/msvc.mak     |   9 +--
 Mkfiles/netware.mak  |  11 ++--
 Mkfiles/openwcom.mak |   9 +--
 Mkfiles/owlinux.mak  |   9 +--
 ctype.c              | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++
 eval.c               |   1 -
 float.c              |   1 -
 listing.c            |   1 -
 misc/omfdump.c       |   1 -
 nasm.c               |   3 -
 nasm.h               |  21 ++----
 nasmlib.c            |  16 -----
 nasmlib.h            |  23 +++----
 ndisasm.c            |   2 -
 output/outaout.c     |   1 -
 output/outas86.c     |   1 -
 output/outbin.c      |   1 -
 output/outcoff.c     |   1 -
 output/outdbg.c      |   1 -
 output/outelf32.c    |   1 -
 output/outelf64.c    |   1 -
 output/outelfx32.c   |   1 -
 output/outieee.c     |   3 +-
 output/outmacho.c    |   1 -
 output/outobj.c      |   3 +-
 output/outrdf2.c     |   1 -
 output/stabs.h       |   1 -
 parser.c             |   1 -
 pptok.pl             |   1 -
 preproc-nop.c        |   1 -
 preproc.c            |   1 -
 rdoff/Makefile.in    |   2 +-
 rdoff/rdf2bin.c      |   3 +-
 rdoff/rdlar.c        |   1 -
 stdscan.c            |   1 -
 36 files changed, 228 insertions(+), 97 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 6ee17b49..9b274c78 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -72,7 +72,7 @@ endif
 
 
 #-- Begin File Lists --#
-NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
+NASM =	nasm.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	raa.$(O) saa.$(O) rbtree.$(O) \
 	realpath.$(O) \
 	float.$(O) insnsa.$(O) insnsb.$(O) \
@@ -95,7 +95,7 @@ NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
 	disp8.$(O) \
 	iflag.$(O)
 
-NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
+NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \
 	disp8.$(O) iflag.$(O)
 #-- End File Lists --#
@@ -307,6 +307,7 @@ assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h \
  iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \
  preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h
+ctype.$(O): ctype.c compiler.h config.h nasmlib.h
 directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 disasm.$(O): disasm.c compiler.h config.h directiv.h disasm.h disp8.h \
@@ -344,7 +345,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h \
 macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h \
  tables.h
-md5c.$(O): md5c.c md5.h
+md5c.$(O): md5c.c compiler.h config.h md5.h
 nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \
  iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \
  opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h \
@@ -405,7 +406,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h \
  tables.h
 output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
- pptok.h preproc.h raa.h regs.h saa.h tables.h
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h
 output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h \
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h \
  pptok.h preproc.h regs.h stdscan.h tables.h
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index a1bfd5eb..1a6f0877 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -43,7 +43,7 @@ X               = .exe
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
+NASM =	nasm.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	raa.$(O) saa.$(O) rbtree.$(O) \
 	realpath.$(O) \
 	float.$(O) insnsa.$(O) insnsb.$(O) \
@@ -66,7 +66,7 @@ NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
 	disp8.$(O) \
 	iflag.$(O)
 
-NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
+NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \
 	disp8.$(O) iflag.$(O)
 #-- End File Lists --#
@@ -229,6 +229,7 @@ assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \
  iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \
  regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h
+ctype.$(O): ctype.c compiler.h nasmlib.h
 directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 disasm.$(O): disasm.c compiler.h directiv.h disasm.h disp8.h iflag.h \
@@ -265,7 +266,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h
-md5c.$(O): md5c.c md5.h
+md5c.$(O): md5c.c compiler.h md5.h
 nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \
  iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \
  output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
@@ -321,7 +322,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h
 output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
- preproc.h raa.h regs.h saa.h tables.h
+ preproc.h raa.h rbtree.h regs.h saa.h tables.h
 output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h regs.h stdscan.h tables.h
diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak
index d897f440..8be92275 100644
--- a/Mkfiles/netware.mak
+++ b/Mkfiles/netware.mak
@@ -30,7 +30,7 @@ O = o
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	nasm.o nasmlib.o ver.o \
+NASM =	nasm.o nasmlib.o ctype.o ver.o \
 	raa.o saa.o rbtree.o \
 	realpath.o \
 	float.o insnsa.o insnsb.o \
@@ -53,7 +53,7 @@ NASM =	nasm.o nasmlib.o ver.o \
 	disp8.o \
 	iflag.o
 
-NDISASM = ndisasm.o disasm.o sync.o nasmlib.o ver.o \
+NDISASM = ndisasm.o disasm.o sync.o nasmlib.o ctype.o ver.o \
 	insnsd.o insnsb.o insnsn.o regs.o regdis.o \
 	disp8.o iflag.o
 #-- End File Lists --#
@@ -137,6 +137,7 @@ assemble.o: assemble.c assemble.h compiler.h config.h directiv.h disp8.h \
  iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h \
  preproc.h regs.h tables.h tokens.h
 crc64.o: crc64.c compiler.h config.h hashtbl.h nasmlib.h
+ctype.o: ctype.c compiler.h config.h nasmlib.h
 directiv.o: directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 disasm.o: disasm.c compiler.h config.h directiv.h disasm.h disp8.h iflag.h \
@@ -173,7 +174,7 @@ listing.o: listing.c compiler.h config.h directiv.h insnsi.h listing.h \
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 macros.o: macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h
-md5c.o: md5c.c md5.h
+md5c.o: md5c.c compiler.h config.h md5.h
 nasm.o: nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \
  iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \
  opflags.h outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
@@ -224,8 +225,8 @@ outieee.o: outieee.c compiler.h config.h directiv.h insnsi.h nasm.h \
 outlib.o: outlib.c compiler.h config.h directiv.h insnsi.h nasm.h nasmlib.h \
  opflags.h outlib.h pptok.h preproc.h regs.h tables.h
 outmacho.o: outmacho.c compiler.h config.h directiv.h insnsi.h nasm.h \
- nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h \
- tables.h
+ nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h raa.h rbtree.h \
+ regs.h saa.h tables.h
 outobj.o: outobj.c compiler.h config.h directiv.h eval.h insnsi.h nasm.h \
  nasmlib.h opflags.h outform.h outlib.h pptok.h preproc.h regs.h stdscan.h \
  tables.h
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index 351df72c..2e2f22fd 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -46,7 +46,7 @@ X               = .exe
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) &
+NASM =	nasm.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) &
 	raa.$(O) saa.$(O) rbtree.$(O) &
 	realpath.$(O) &
 	float.$(O) insnsa.$(O) insnsb.$(O) &
@@ -69,7 +69,7 @@ NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) &
 	disp8.$(O) &
 	iflag.$(O)
 
-NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) &
+NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) &
 	insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) &
 	disp8.$(O) iflag.$(O)
 #-- End File Lists --#
@@ -274,6 +274,7 @@ assemble.$(O): assemble.c assemble.h compiler.h config.h directiv.h disp8.h &
  iflag.h iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h &
  preproc.h regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h config.h hashtbl.h nasmlib.h
+ctype.$(O): ctype.c compiler.h config.h nasmlib.h
 directiv.$(O): directiv.c compiler.h config.h directiv.h hashtbl.h insnsi.h &
  nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 disasm.$(O): disasm.c compiler.h config.h directiv.h disasm.h disp8.h &
@@ -311,7 +312,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h &
 macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h &
  nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h &
  tables.h
-md5c.$(O): md5c.c md5.h
+md5c.$(O): md5c.c compiler.h config.h md5.h
 nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h &
  iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h &
  opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h &
@@ -372,7 +373,7 @@ output/outlib.$(O): output/outlib.c compiler.h config.h directiv.h insnsi.h &
  tables.h
 output/outmacho.$(O): output/outmacho.c compiler.h config.h directiv.h &
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h &
- pptok.h preproc.h raa.h regs.h saa.h tables.h
+ pptok.h preproc.h raa.h rbtree.h regs.h saa.h tables.h
 output/outobj.$(O): output/outobj.c compiler.h config.h directiv.h eval.h &
  insnsi.h nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h &
  pptok.h preproc.h regs.h stdscan.h tables.h
diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak
index 256abba8..12878425 100644
--- a/Mkfiles/owlinux.mak
+++ b/Mkfiles/owlinux.mak
@@ -57,7 +57,7 @@ X               = .exe
 
 #-- Begin File Lists --#
 # Edit in Makefile.in, not here!
-NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
+NASM =	nasm.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	raa.$(O) saa.$(O) rbtree.$(O) \
 	realpath.$(O) \
 	float.$(O) insnsa.$(O) insnsb.$(O) \
@@ -80,7 +80,7 @@ NASM =	nasm.$(O) nasmlib.$(O) ver.$(O) \
 	disp8.$(O) \
 	iflag.$(O)
 
-NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
+NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ctype.$(O) ver.$(O) \
 	insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \
 	disp8.$(O) iflag.$(O)
 #-- End File Lists --#
@@ -243,6 +243,7 @@ assemble.$(O): assemble.c assemble.h compiler.h directiv.h disp8.h iflag.h \
  iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \
  regs.h tables.h tokens.h
 crc64.$(O): crc64.c compiler.h hashtbl.h nasmlib.h
+ctype.$(O): ctype.c compiler.h nasmlib.h
 directiv.$(O): directiv.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 disasm.$(O): disasm.c compiler.h directiv.h disasm.h disp8.h iflag.h \
@@ -279,7 +280,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \
  nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
 macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h
-md5c.$(O): md5c.c md5.h
+md5c.$(O): md5c.c compiler.h md5.h
 nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \
  iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \
  output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
@@ -335,7 +336,7 @@ output/outlib.$(O): output/outlib.c compiler.h directiv.h insnsi.h nasm.h \
  nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h
 output/outmacho.$(O): output/outmacho.c compiler.h directiv.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
- preproc.h raa.h regs.h saa.h tables.h
+ preproc.h raa.h rbtree.h regs.h saa.h tables.h
 output/outobj.$(O): output/outobj.c compiler.h directiv.h eval.h insnsi.h \
  nasm.h nasmlib.h opflags.h output/outform.h output/outlib.h pptok.h \
  preproc.h regs.h stdscan.h tables.h
diff --git a/ctype.c b/ctype.c
new file mode 100644
index 00000000..18a46ca4
--- /dev/null
+++ b/ctype.c
@@ -0,0 +1,181 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2016 The NASM Authors - All Rights Reserved
+ *   See the file AUTHORS included with the NASM distribution for
+ *   the specific copyright holders.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following
+ *   conditions are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials provided
+ *     with the distribution.
+ *
+ *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * ctype.c
+ *
+ * Replacement for <ctype.h>
+ *
+ * We require that the input format is a superset of ASCII, so we
+ * might as well hard-code these rather than rely on the platform.
+ * This also avoids potential strangeness related to locale.
+ *
+ * We treat all bytes >= 0x80 as alphabetic.  This is a hack but
+ * allows us to handle symbol names in Unicode or other extended
+ * character sets, although it will not support case conversion for
+ * those.  It is as good as we can do without actually being
+ * multibyte-character aware.
+ */
+
+#include "compiler.h"
+#include "nasmlib.h"
+
+const unsigned char nasm_tolower_tab[256] =
+{
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+
+    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+    0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+
+    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+    0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+};
+
+const unsigned char nasm_toupper_tab[256] =
+{
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+
+    0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+    0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+
+    0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+    0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+};
+
+#define S 0x01                  /* Space */
+#define A 0x62                  /* Upper case alphabetic non-hex digit */
+#define X 0x6a                  /* Upper case alphabetic hex digit */
+#define a 0x62                  /* Lower case alphabetic non-hex digit */
+#define x 0x6a                  /* Lower case alphabetic hex digit */
+#define T 0x62                  /* Other character valid in all alpha tokens */
+#define D 0xcc                  /* Decimal digit */
+#define C 0x10                  /* Control */
+#define Z 0x11                  /* Control whitespace */
+#define P 0x00                  /* Other printable symbol */
+#define F 0x60                  /* Other char allowed to start ID */
+#define M 0x40                  /* Other char allowed in ID */
+#define B 0x20                  /* Character allowed inside {} */
+#define N (0x80|M)              /* Other char allowed to start number (+M) */
+
+const unsigned char nasm_ctype_tab[256] =
+{
+    C,C,C,C,C,C,C,C, Z,Z,Z,Z,Z,Z,C,C, C,C,C,C,C,C,C,C, C,C,C,C,C,C,C,C,
+    S,P,P,M,N,P,P,P, P,P,P,P,P,B,F,P, D,D,D,D,D,D,D,D, D,D,P,P,P,P,P,F,
+    F,X,X,X,X,X,X,A, A,A,A,A,A,A,A,A, A,A,A,A,A,A,A,A, A,A,A,P,P,P,P,T,
+    P,x,x,x,x,x,x,a, a,a,a,a,a,a,a,a, a,a,a,a,a,a,a,a, a,a,a,P,P,P,M,C,
+
+    T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T,
+    T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T,
+    T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T,
+    T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T, T,T,T,T,T,T,T,T
+};
diff --git a/eval.c b/eval.c
index 72e13c9d..e348e829 100644
--- a/eval.c
+++ b/eval.c
@@ -41,7 +41,6 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/float.c b/float.c
index e30e1eff..6dddea97 100644
--- a/float.c
+++ b/float.c
@@ -37,7 +37,6 @@
 
 #include "compiler.h"
 
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/listing.c b/listing.c
index fa850448..c1e566fc 100644
--- a/listing.c
+++ b/listing.c
@@ -41,7 +41,6 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/misc/omfdump.c b/misc/omfdump.c
index 322971e9..85bc9eaa 100644
--- a/misc/omfdump.c
+++ b/misc/omfdump.c
@@ -10,7 +10,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
-#include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
diff --git a/nasm.c b/nasm.c
index 0520500c..437987e8 100644
--- a/nasm.c
+++ b/nasm.c
@@ -41,7 +41,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <time.h>
@@ -336,8 +335,6 @@ int main(int argc, char **argv)
 
     error_file = stderr;
 
-    tolower_init();
-
     offsets = raa_init();
     forwrefs = saa_init((int32_t)sizeof(struct forwrefinfo));
 
diff --git a/nasm.h b/nasm.h
index ff2acfe7..d50e6152 100644
--- a/nasm.h
+++ b/nasm.h
@@ -428,25 +428,14 @@ extern struct preproc_ops preproc_nop;
  * decorator. E.g. {rn-sae}, {1to8}, {k1}{z}
  */
 
-#define isidstart(c) (nasm_isalpha(c)   ||  \
-                      (c) == '_'        ||  \
-                      (c) == '.'        ||  \
-                      (c) == '?'        ||  \
-                      (c) == '@')
-
-#define isidchar(c) (isidstart(c)       ||  \
-                     nasm_isdigit(c)    ||  \
-                     (c) == '$'         ||  \
-                     (c) == '#'         ||  \
-                     (c) == '~')
-
-#define isbrcchar(c) (isidchar(c)       ||  \
-                      (c) == '-')
+#define isidstart(c) ((nasm_ctype_tab[(unsigned char)c] & 0x60) >= 0x60)
+#define isidchar(c)  ((nasm_ctype_tab[(unsigned char)c] & 0x60) >= 0x40)
+#define isbrcchar(c) ((nasm_ctype_tab[(unsigned char)c] & 0x60) >= 0x20)
 
 /* Ditto for numeric constants. */
 
-#define isnumstart(c)  (nasm_isdigit(c) || (c) == '$')
-#define isnumchar(c)   (nasm_isalnum(c) || (c) == '_')
+#define isnumstart(c) (!!(nasm_ctype_tab[(unsigned char)c] & 0x80))
+#define isnumchar(c)  nasm_isalnum(c)
 
 /*
  * Data-type flags that get passed to listing-file routines.
diff --git a/nasmlib.c b/nasmlib.c
index a1a3191f..d9315f7c 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -40,7 +40,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <errno.h>
 #include <inttypes.h>
 
@@ -54,21 +53,6 @@ vefunc nasm_verror;    /* Global error handling function */
 /* Uninitialized -> all zero by C spec */
 const uint8_t zero_buffer[ZERO_BUF_SIZE];
 
-/*
- * Prepare a table of tolower() results.  This avoids function calls
- * on some platforms.
- */
-
-unsigned char nasm_tolower_tab[256];
-
-void tolower_init(void)
-{
-    int i;
-
-    for (i = 0; i < 256; i++)
-	nasm_tolower_tab[i] = tolower(i);
-}
-
 void nasm_error(int severity, const char *fmt, ...)
 {
     va_list ap;
diff --git a/nasmlib.h b/nasmlib.h
index 96c488a4..84efeb01 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -48,21 +48,22 @@
 #endif
 
 /*
- * tolower table -- avoids a function call on some platforms.
- * NOTE: unlike the tolower() function in ctype, EOF is *NOT*
+ * tolower/toupper tables -- avoids a function call on some platforms.
+ * NOTE: unlike the to*() and is*() functions in ctype.h, EOF is *NOT*
  * a permitted value, for obvious reasons.
  */
-void tolower_init(void);
-extern unsigned char nasm_tolower_tab[256];
+extern const unsigned char nasm_tolower_tab[256];
 #define nasm_tolower(x) nasm_tolower_tab[(unsigned char)(x)]
 
-/* Wrappers around <ctype.h> functions */
-/* These are only valid for values that cannot include EOF */
-#define nasm_isspace(x)  isspace((unsigned char)(x))
-#define nasm_isalpha(x)  isalpha((unsigned char)(x))
-#define nasm_isdigit(x)  isdigit((unsigned char)(x))
-#define nasm_isalnum(x)  isalnum((unsigned char)(x))
-#define nasm_isxdigit(x) isxdigit((unsigned char)(x))
+extern const unsigned char nasm_toupper_tab[256];
+#define nasm_toupper(x) nasm_toupper_tab[(unsigned char)(x)]
+
+extern const unsigned char nasm_ctype_tab[256];
+#define nasm_isspace(x)  (!!(nasm_ctype_tab[(unsigned char)(x)] & 0x01))
+#define nasm_isalpha(x)  (!!(nasm_ctype_tab[(unsigned char)(x)] & 0x02))
+#define nasm_isdigit(x)  (!!(nasm_ctype_tab[(unsigned char)(x)] & 0x04))
+#define nasm_isalnum(x)  (!!(nasm_ctype_tab[(unsigned char)(x)] & 0x06))
+#define nasm_isxdigit(x) (!!(nasm_ctype_tab[(unsigned char)(x)] & 0x08))
 
 /*
  * -------------------------
diff --git a/ndisasm.c b/ndisasm.c
index 754033c4..644b9eb2 100644
--- a/ndisasm.c
+++ b/ndisasm.c
@@ -41,7 +41,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <errno.h>
 #include <inttypes.h>
 
@@ -93,7 +92,6 @@ int main(int argc, char **argv)
     int32_t offset;
     FILE *fp;
 
-    tolower_init();
     nasm_set_verror(ndisasm_verror);
     iflag_clear_all(&prefer);
 
diff --git a/output/outaout.c b/output/outaout.c
index 66045519..7d85986a 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outas86.c b/output/outas86.c
index 84e3035c..0aa19fa5 100644
--- a/output/outas86.c
+++ b/output/outas86.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outbin.c b/output/outbin.c
index 915dc45f..7b1eba87 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -78,7 +78,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outcoff.c b/output/outcoff.c
index 9587f352..33604e30 100644
--- a/output/outcoff.c
+++ b/output/outcoff.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <time.h>
 #include <inttypes.h>
 
diff --git a/output/outdbg.c b/output/outdbg.c
index 034a6152..f5013f2e 100644
--- a/output/outdbg.c
+++ b/output/outdbg.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outelf32.c b/output/outelf32.c
index 0af2420b..4203cf5f 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 #include <limits.h>
 
diff --git a/output/outelf64.c b/output/outelf64.c
index 5b4eee86..f99de658 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outelfx32.c b/output/outelfx32.c
index 49ed945e..3346896c 100644
--- a/output/outelfx32.c
+++ b/output/outelfx32.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outieee.c b/output/outieee.c
index 2415bc74..54ac42a4 100644
--- a/output/outieee.c
+++ b/output/outieee.c
@@ -72,7 +72,6 @@
 #include <string.h>
 #include <time.h>
 #include <stdarg.h>             /* Note: we need the ANSI version of stdarg.h */
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
@@ -1294,7 +1293,7 @@ static void ieee_unqualified_name(char *dest, char *source)
 {
     if (ieee_uppercase) {
         while (*source)
-            *dest++ = toupper(*source++);
+            *dest++ = nasm_toupper(*source++);
         *dest = 0;
     } else
         strcpy(dest, source);
diff --git a/output/outmacho.c b/output/outmacho.c
index b67561c6..96c8fdd4 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/output/outobj.c b/output/outobj.c
index 74f43ced..4c605916 100644
--- a/output/outobj.c
+++ b/output/outobj.c
@@ -41,7 +41,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 #include <limits.h>
 
@@ -428,7 +427,7 @@ static ObjRecord *obj_name(ObjRecord * orp, const char *name)
     orp->used += len + 1;
     if (obj_uppercase)
         while (--len >= 0) {
-            *ptr++ = toupper(*name);
+            *ptr++ = nasm_toupper(*name);
             name++;
     } else
         memcpy(ptr, name, len);
diff --git a/output/outrdf2.c b/output/outrdf2.c
index e6dcda98..a9dfa2e8 100644
--- a/output/outrdf2.c
+++ b/output/outrdf2.c
@@ -42,7 +42,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <assert.h>
 #include <inttypes.h>
 
diff --git a/output/stabs.h b/output/stabs.h
index 3a09c415..3287d612 100644
--- a/output/stabs.h
+++ b/output/stabs.h
@@ -34,7 +34,6 @@
 #ifndef STABS_H_
 #define STABS_H_
 
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "compiler.h"
diff --git a/parser.c b/parser.c
index 5107860e..43ad9d3d 100644
--- a/parser.c
+++ b/parser.c
@@ -41,7 +41,6 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"
diff --git a/pptok.pl b/pptok.pl
index 53a1c92c..c8f33e19 100755
--- a/pptok.pl
+++ b/pptok.pl
@@ -180,7 +180,6 @@ if ($what eq 'c') {
 
     print OUT "#include \"compiler.h\"\n";
     print OUT "#include <inttypes.h>\n";
-    print OUT "#include <ctype.h>\n";
     print OUT "#include \"nasmlib.h\"\n";
     print OUT "#include \"hashtbl.h\"\n";
     print OUT "#include \"preproc.h\"\n";
diff --git a/preproc-nop.c b/preproc-nop.c
index 353e269b..8ce0d4fb 100644
--- a/preproc-nop.c
+++ b/preproc-nop.c
@@ -43,7 +43,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <time.h>
diff --git a/preproc.c b/preproc.c
index b43cd617..9b997628 100644
--- a/preproc.c
+++ b/preproc.c
@@ -67,7 +67,6 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
-#include <ctype.h>
 #include <limits.h>
 #include <inttypes.h>
 
diff --git a/rdoff/Makefile.in b/rdoff/Makefile.in
index 41fc5f1a..9c9855a2 100644
--- a/rdoff/Makefile.in
+++ b/rdoff/Makefile.in
@@ -32,7 +32,7 @@ MKDIR		= mkdir
 LDRDFLIBS 	= rdoff.$(O) symtab.$(O) collectn.$(O) \
 		  rdlib.$(O) segtab.$(O) hash.$(O)
 RDXLIBS 	= rdoff.$(O) rdfload.$(O) symtab.$(O) collectn.$(O) hash.$(O)
-NASMLIB		= ../nasmlib.$(O)
+NASMLIB		= ../nasmlib.$(O) ../ctype.$(O)
 
 # Binary suffixes
 O               = @OBJEXT@
diff --git a/rdoff/rdf2bin.c b/rdoff/rdf2bin.c
index 1e33075c..555297ca 100644
--- a/rdoff/rdf2bin.c
+++ b/rdoff/rdf2bin.c
@@ -40,7 +40,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <ctype.h>
 #include <errno.h>
 
 #include "rdfload.h"
@@ -263,7 +262,7 @@ static const char *getformat(const char *pathname)
 	if (!nasm_stricmp(p, "rdf2")) {
 	    const char *q = p+4;
 	    char *r = fmt_buf;
-	    while (isalnum(*q) && r < fmt_buf+sizeof fmt_buf-1)
+	    while (nasm_isalnum(*q) && r < fmt_buf+sizeof fmt_buf-1)
 		*r++ = *q++;
 	    *r = '\0';
 	    if (fmt_buf[0])
diff --git a/rdoff/rdlar.c b/rdoff/rdlar.c
index 98b0f8f6..81ff4939 100644
--- a/rdoff/rdlar.c
+++ b/rdoff/rdlar.c
@@ -39,7 +39,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <ctype.h>
 #include <stdarg.h>
 #include <string.h>
 #include <errno.h>
diff --git a/stdscan.c b/stdscan.c
index ea7537dd..76577ec1 100644
--- a/stdscan.c
+++ b/stdscan.c
@@ -36,7 +36,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <inttypes.h>
 
 #include "nasm.h"


More information about the Nasm-commits mailing list