summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-21 10:23:17 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-21 10:23:17 -0700
commitbda7a6e3715b270ebb0854b3cef667976d241d96 (patch)
tree86e645d4e025b1dbf0169d0a4ce1c6ec602a15d5
parent86877b294aabac1059d32611c8dce65910243454 (diff)
downloadnasm-bda7a6e3715b270ebb0854b3cef667976d241d96.tar.gz
ctype.h: wrapper ctype functions with a cast to (unsigned char)
ctype functions take an *int*, which the user is expected to have taken the input character from getc() and friends, or taken a character and cast it to (unsigned char). We don't care about EOF (-1), so use macros that cast to (unsigned char) for us.
-rw-r--r--nasm.c24
-rw-r--r--nasm.h6
-rw-r--r--nasmlib.c4
-rw-r--r--nasmlib.h24
-rw-r--r--output/outaout.c6
-rw-r--r--output/outbin.c12
-rw-r--r--output/outcoff.c14
-rw-r--r--output/outelf32.c16
-rw-r--r--output/outelf64.c16
-rw-r--r--output/outieee.c8
-rw-r--r--output/outobj.c50
-rw-r--r--output/outrdf2.c6
-rw-r--r--preproc.c18
-rw-r--r--stdscan.c2
14 files changed, 106 insertions, 100 deletions
diff --git a/nasm.c b/nasm.c
index 52009d3f..e21d0891 100644
--- a/nasm.c
+++ b/nasm.c
@@ -482,7 +482,7 @@ static char *get_param(char *p, char *q, bool *advance)
*advance = false;
if (p[2]) { /* the parameter's in the option */
p += 2;
- while (isspace(*p))
+ while (nasm_isspace(*p))
p++;
return p;
}
@@ -1001,11 +1001,11 @@ static void process_respfile(FILE * rfile)
*/
*(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
- while (p > buffer && isspace(p[-1]))
+ while (p > buffer && nasm_isspace(p[-1]))
*--p = '\0';
p = buffer;
- while (isspace(*p))
+ while (nasm_isspace(*p))
p++;
if (process_arg(prevarg, p))
@@ -1310,7 +1310,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
validid = true;
if (!isidstart(*p))
validid = false;
- while (*p && !isspace(*p)) {
+ while (*p && !nasm_isspace(*p)) {
if (!isidchar(*p))
validid = false;
p++;
@@ -1323,7 +1323,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (*p) {
int64_t size;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
*p++ = '\0';
q = p;
while (*q && *q != ':')
@@ -1348,7 +1348,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
} else if (pass0 == 2) { /* pass == 2 */
q = value;
while (*q && *q != ':') {
- if (isspace(*q))
+ if (nasm_isspace(*q))
*q = '\0';
q++;
}
@@ -1388,7 +1388,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
validid = true;
if (!isidstart(*p))
validid = false;
- while (*p && !isspace(*p)) {
+ while (*p && !nasm_isspace(*p)) {
if (!isidchar(*p))
validid = false;
*q++ = *p++;
@@ -1399,14 +1399,14 @@ static void assemble_file(char *fname, StrList **depend_ptr)
"identifier expected after DEBUG");
break;
}
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
if (pass0 == 2)
ofmt->current_dfmt->debug_directive(debugid, p);
break;
case D_WARNING: /* [WARNING {+|-}warn-name] */
if (pass1 == 1) {
- while (*value && isspace(*value))
+ while (*value && nasm_isspace(*value))
value++;
if (*value == '+' || *value == '-') {
@@ -1429,7 +1429,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
cpu = get_cpu(value);
break;
case D_LIST: /* [LIST {+|-}] */
- while (*value && isspace(*value))
+ while (*value && nasm_isspace(*value))
value++;
if (*value == '+') {
@@ -1783,7 +1783,7 @@ static enum directives getkw(char **directive, char **value)
q = p++;
while (*p && *p != ';') {
- if (!isspace(*p))
+ if (!nasm_isspace(*p))
return 0;
p++;
}
@@ -1797,7 +1797,7 @@ static enum directives getkw(char **directive, char **value)
*value = buf;
} else {
*buf++ = '\0';
- while (isspace(*buf))
+ while (nasm_isspace(*buf))
buf++; /* beppu - skip leading whitespace */
*value = buf;
while (*buf != ']')
diff --git a/nasm.h b/nasm.h
index 203750e5..5a471922 100644
--- a/nasm.h
+++ b/nasm.h
@@ -356,13 +356,13 @@ extern Preproc nasmpp;
#define isidstart(c) ( isalpha(c) || (c)=='_' || (c)=='.' || (c)=='?' \
|| (c)=='@' )
-#define isidchar(c) ( isidstart(c) || isdigit(c) || (c)=='$' || (c)=='#' \
+#define isidchar(c) ( isidstart(c) || nasm_isdigit(c) || (c)=='$' || (c)=='#' \
|| (c)=='~' )
/* Ditto for numeric constants. */
-#define isnumstart(c) ( isdigit(c) || (c)=='$' )
-#define isnumchar(c) ( isalnum(c) || (c)=='_' )
+#define isnumstart(c) ( nasm_isdigit(c) || (c)=='$' )
+#define isnumchar(c) ( nasm_isalnum(c) || (c)=='_' )
/* This returns the numeric value of a given 'digit'. */
diff --git a/nasmlib.c b/nasmlib.c
index 9a49090e..0937b664 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -235,7 +235,7 @@ char *nasm_strsep(char **stringp, const char *delim)
#endif
-#define lib_isnumchar(c) (isalnum(c) || (c) == '$' || (c) == '_')
+#define lib_isnumchar(c) (nasm_isalnum(c) || (c) == '$' || (c) == '_')
#define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0')
static int radix_letter(char c)
@@ -270,7 +270,7 @@ int64_t readnum(char *str, bool *error)
*error = false;
- while (isspace(*r))
+ while (nasm_isspace(*r))
r++; /* find start of number */
/*
diff --git a/nasmlib.h b/nasmlib.h
index 7391564c..51e787dd 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -19,6 +19,21 @@
#endif
/*
+ * tolower table -- avoids a function call on some platforms.
+ * NOTE: unlike the tolower() function in ctype, EOF is *NOT*
+ * a permitted value, for obvious reasons.
+ */
+void tolower_init(void);
+extern 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_isalnum(x) isalnum((unsigned char)(x))
+#define nasm_isdigit(x) isdigit((unsigned char)(x))
+
+/*
* If this is defined, the wrappers around malloc et al will
* transform into logging variants, which will cause NASM to create
* a file called `malloc.log' when run, and spew details of all its
@@ -176,15 +191,6 @@ void standard_extension(char *inname, char *outname, char *extension,
#define elements(x) ( sizeof(x) / sizeof(*(x)) )
/*
- * tolower table -- avoids a function call on some platforms.
- * NOTE: unlike the tolower() function in ctype, EOF is *NOT*
- * a permitted value, for obvious reasons.
- */
-void tolower_init(void);
-extern unsigned char nasm_tolower_tab[256];
-#define nasm_tolower(x) nasm_tolower_tab[(unsigned char)(x)]
-
-/*
* some handy macros that will probably be of use in more than one
* output format: convert integers into little-endian byte packed
* format in memory
diff --git a/output/outaout.c b/output/outaout.c
index f374b9e0..48a2cffd 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -279,9 +279,9 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
expr *e;
char *p = special;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
stdscan_reset();
stdscan_bufptr = p;
@@ -370,7 +370,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
error(ERR_NONFATAL, "Linux a.out does not support"
" symbol size information");
} else {
- while (special[n] && isspace(special[n]))
+ while (special[n] && nasm_isspace(special[n]))
n++;
/*
* We have a size expression; attempt to
diff --git a/output/outbin.c b/output/outbin.c
index e71a60eb..b494a97b 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -881,7 +881,7 @@ static int bin_read_attribute(char **line, int *attribute,
char *exp;
/* Skip whitespace. */
- while (**line && isspace(**line))
+ while (**line && nasm_isspace(**line))
(*line)++;
if (!**line)
return 0;
@@ -909,12 +909,12 @@ static int bin_read_attribute(char **line, int *attribute,
*line += 9;
return 1;
} else if (!nasm_strnicmp(*line, "nobits", 6) &&
- (isspace((*line)[6]) || ((*line)[6] == '\0'))) {
+ (nasm_isspace((*line)[6]) || ((*line)[6] == '\0'))) {
*attribute = ATTRIB_NOBITS;
*line += 6;
return 1;
} else if (!nasm_strnicmp(*line, "progbits", 8) &&
- (isspace((*line)[8]) || ((*line)[8] == '\0'))) {
+ (nasm_isspace((*line)[8]) || ((*line)[8] == '\0'))) {
*attribute = ATTRIB_PROGBITS;
*line += 8;
return 1;
@@ -927,7 +927,7 @@ static int bin_read_attribute(char **line, int *attribute,
if ((*line)[attrib_name_size] != '(') {
/* Single term (no parenthesis). */
exp = *line += attrib_name_size;
- while (**line && !isspace(**line))
+ while (**line && !nasm_isspace(**line))
(*line)++;
if (**line) {
**line = '\0';
@@ -1017,7 +1017,7 @@ static void bin_assign_attributes(struct Section *sec, char *astring)
break; /* End of line. */
else {
p = astring;
- while (*astring && !isspace(*astring))
+ while (*astring && !nasm_isspace(*astring))
astring++;
if (*astring) {
*astring = '\0';
@@ -1245,7 +1245,7 @@ static int32_t bin_secname(char *name, int pass, int *bits)
/* Attempt to find the requested section. If it does not
* exist, create it. */
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
diff --git a/output/outcoff.c b/output/outcoff.c
index d8d1d3df..d539900d 100644
--- a/output/outcoff.c
+++ b/output/outcoff.c
@@ -274,7 +274,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
return def_seg;
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
@@ -285,15 +285,15 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
}
flags = 0;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
while (*p) {
char *q = p;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
if (!nasm_stricmp(q, "code") || !nasm_stricmp(q, "text")) {
@@ -696,11 +696,11 @@ static int coff_directives(char *directive, char *value, int pass)
if (pass == 2)
return 1; /* ignore in pass two */
name = q = value;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
diff --git a/output/outelf32.c b/output/outelf32.c
index f97a53c3..bff264a3 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -420,21 +420,21 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
}
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
flags_and = flags_or = type = align = 0;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
while (*p) {
char *q = p;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
if (!nasm_strnicmp(q, "align=", 6)) {
@@ -550,9 +550,9 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
expr *e;
char *p = special;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
stdscan_reset();
stdscan_bufptr = p;
@@ -669,7 +669,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
n, special);
special += n;
- while (isspace(*special))
+ while (nasm_isspace(*special))
++special;
if (*special) {
n = strcspn(special, " \t");
@@ -692,7 +692,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
int fwd = 0;
char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */
- while (special[n] && isspace(special[n]))
+ while (special[n] && nasm_isspace(special[n]))
n++;
/*
* We have a size expression; attempt to
diff --git a/output/outelf64.c b/output/outelf64.c
index 3980cda8..f483393c 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -432,21 +432,21 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
}
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
flags_and = flags_or = type = align = 0;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
while (*p) {
char *q = p;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p)
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
if (!nasm_strnicmp(q, "align=", 6)) {
@@ -562,9 +562,9 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
expr *e;
char *p = special;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
stdscan_reset();
stdscan_bufptr = p;
@@ -681,7 +681,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
n, special);
special += n;
- while (isspace(*special))
+ while (nasm_isspace(*special))
++special;
if (*special) {
n = strcspn(special, " \t");
@@ -704,7 +704,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
int fwd = 0;
char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */
- while (special[n] && isspace(special[n]))
+ while (special[n] && nasm_isspace(special[n]))
n++;
/*
* We have a size expression; attempt to
diff --git a/output/outieee.c b/output/outieee.c
index c14064cb..b70d3b2d 100644
--- a/output/outieee.c
+++ b/output/outieee.c
@@ -678,19 +678,19 @@ static int32_t ieee_segment(char *name, int pass, int *bits)
while (*name == '.')
name++; /* hack, but a documented one */
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p) {
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
*p++ = '\0';
}
while (*p) {
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p) {
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
*p++ = '\0';
}
diff --git a/output/outobj.c b/output/outobj.c
index 74eb38e6..9ca368dd 100644
--- a/output/outobj.c
+++ b/output/outobj.c
@@ -1288,19 +1288,19 @@ static int32_t obj_segment(char *name, int pass, int *bits)
while (*name == '.')
name++; /* hack, but a documented one */
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p) {
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
*p++ = '\0';
}
while (*p) {
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p) {
*p++ = '\0';
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
*p++ = '\0';
}
@@ -1522,11 +1522,11 @@ static int obj_directive(char *directive, char *value, int pass)
while (*q == '.')
q++; /* hack, but a documented one */
v = q;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
/*
@@ -1565,11 +1565,11 @@ static int obj_directive(char *directive, char *value, int pass)
while (*q) {
p = q;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
/*
@@ -1630,20 +1630,20 @@ static int obj_directive(char *directive, char *value, int pass)
if (pass == 2)
return 1; /* ignore in pass two */
extname = q = value;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
libname = q;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
@@ -1679,20 +1679,20 @@ static int obj_directive(char *directive, char *value, int pass)
if (pass == 2)
return 1; /* ignore in pass two */
intname = q = value;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
extname = q;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
@@ -1706,11 +1706,11 @@ static int obj_directive(char *directive, char *value, int pass)
}
while (*q) {
v = q;
- while (*q && !isspace(*q))
+ while (*q && !nasm_isspace(*q))
q++;
- if (isspace(*q)) {
+ if (nasm_isspace(*q)) {
*q++ = '\0';
- while (*q && isspace(*q))
+ while (*q && nasm_isspace(*q))
q++;
}
if (!nasm_stricmp(v, "resident"))
diff --git a/output/outrdf2.c b/output/outrdf2.c
index b00ad43e..b502715b 100644
--- a/output/outrdf2.c
+++ b/output/outrdf2.c
@@ -155,11 +155,11 @@ static int32_t rdf2_section_names(char *name, int pass, int *bits)
/* look for segment type code following segment name */
p = name;
- while (*p && !isspace(*p))
+ while (*p && !nasm_isspace(*p))
p++;
if (*p) { /* we're now in whitespace */
*p++ = '\0';
- while (*p && isspace(80))
+ while (*p && nasm_isspace(80))
*p++ = '\0';
}
if (*p) { /* we're now in an attribute value */
@@ -418,7 +418,7 @@ static void rdf2_deflabel(char *name, int32_t segment, int64_t offset,
}
if (*special) {
- while (isspace(*special))
+ while (nasm_isspace(*special))
special++;
if (!nasm_stricmp(special, "far")) {
farsym = 1;
diff --git a/preproc.c b/preproc.c
index e3e79dbc..1489222a 100644
--- a/preproc.c
+++ b/preproc.c
@@ -417,14 +417,14 @@ static char *check_tasm_directive(char *line)
char *p = line, *oldline, oldchar;
/* Skip whitespace */
- while (isspace(*p) && *p != 0)
+ while (nasm_isspace(*p) && *p != 0)
p++;
/* Binary search for the directive name */
i = -1;
j = elements(tasm_directives);
len = 0;
- while (!isspace(p[len]) && p[len] != 0)
+ while (!nasm_isspace(p[len]) && p[len] != 0)
len++;
if (len) {
oldchar = p[len];
@@ -778,13 +778,13 @@ static Token *tokenize(char *line)
p = line;
if (*p == '%') {
p++;
- if (isdigit(*p) ||
- ((*p == '-' || *p == '+') && isdigit(p[1])) ||
- ((*p == '+') && (isspace(p[1]) || !p[1]))) {
+ if (nasm_isdigit(*p) ||
+ ((*p == '-' || *p == '+') && nasm_isdigit(p[1])) ||
+ ((*p == '+') && (nasm_isspace(p[1]) || !p[1]))) {
do {
p++;
}
- while (isdigit(*p));
+ while (nasm_isdigit(*p));
type = TOK_PREPROC_ID;
} else if (*p == '{') {
p++;
@@ -882,7 +882,7 @@ static Token *tokenize(char *line)
while (*r == '_')
r++;
- if (isdigit(*r) || (is_hex && isxdigit(*r)) ||
+ if (nasm_isdigit(*r) || (is_hex && isxdigit(*r)) ||
(!is_hex && (*r == 'e' || *r == 'E')) ||
(*r == 'p' || *r == 'P')) {
p = r;
@@ -900,10 +900,10 @@ static Token *tokenize(char *line)
}
type = is_float ? TOK_FLOAT : TOK_NUMBER;
- } else if (isspace(*p)) {
+ } else if (nasm_isspace(*p)) {
type = TOK_WHITESPACE;
p++;
- while (*p && isspace(*p))
+ while (*p && nasm_isspace(*p))
p++;
/*
* Whitespace just before end-of-line is discarded by
diff --git a/stdscan.c b/stdscan.c
index 60982a48..b7d4b80b 100644
--- a/stdscan.c
+++ b/stdscan.c
@@ -68,7 +68,7 @@ int stdscan(void *private_data, struct tokenval *tv)
(void)private_data; /* Don't warn that this parameter is unused */
- while (isspace(*stdscan_bufptr))
+ while (nasm_isspace(*stdscan_bufptr))
stdscan_bufptr++;
if (!*stdscan_bufptr)
return tv->t_type = 0;