aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-22 11:08:02 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-22 11:08:02 -0200
commit1f4ee4a4d2462edbb1e0811ef1e317f4778e619d (patch)
tree71f85cae36fb5faa9f20d95c8304b32bbe8c5e3b
parent6a9efa8b8e15693a9a1fea0d9c3d93b6c8606d8e (diff)
downloadlua-1f4ee4a4d2462edbb1e0811ef1e317f4778e619d.tar.gz
lua-1f4ee4a4d2462edbb1e0811ef1e317f4778e619d.tar.bz2
lua-1f4ee4a4d2462edbb1e0811ef1e317f4778e619d.zip
ANSI ctype only works for unsigned chars (or EOF)
-rw-r--r--lex.c19
-rw-r--r--strlib.c30
2 files changed, 26 insertions, 23 deletions
diff --git a/lex.c b/lex.c
index eb92d6fc..6906037b 100644
--- a/lex.c
+++ b/lex.c
@@ -1,4 +1,4 @@
1char *rcs_lex = "$Id: lex.c,v 2.39 1996/11/08 19:08:30 roberto Exp roberto $"; 1char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $";
2 2
3 3
4#include <ctype.h> 4#include <ctype.h>
@@ -85,7 +85,7 @@ static int inclinenumber (int pragma_allowed)
85 char *buff = luaI_buffer(MINBUFF+1); 85 char *buff = luaI_buffer(MINBUFF+1);
86 int i = 0; 86 int i = 0;
87 next(); /* skip $ */ 87 next(); /* skip $ */
88 while (isalnum(current)) { 88 while (isalnum((unsigned char)current)) {
89 if (i >= MINBUFF) luaI_syntaxerror("pragma too long"); 89 if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
90 buff[i++] = current; 90 buff[i++] = current;
91 next(); 91 next();
@@ -259,7 +259,9 @@ int luaY_lex (void)
259 case '_': 259 case '_':
260 { 260 {
261 TaggedString *ts; 261 TaggedString *ts;
262 do { save_and_next(); } while (isalnum(current) || current == '_'); 262 do {
263 save_and_next();
264 } while (isalnum((unsigned char)current) || current == '_');
263 save(0); 265 save(0);
264 ts = lua_createstring(yytext); 266 ts = lua_createstring(yytext);
265 if (ts->marked > 2) 267 if (ts->marked > 2)
@@ -281,7 +283,7 @@ int luaY_lex (void)
281 } 283 }
282 else return CONC; /* .. */ 284 else return CONC; /* .. */
283 } 285 }
284 else if (!isdigit(current)) return '.'; 286 else if (!isdigit((unsigned char)current)) return '.';
285 /* current is a digit: goes through to number */ 287 /* current is a digit: goes through to number */
286 a=0.0; 288 a=0.0;
287 goto fraction; 289 goto fraction;
@@ -292,7 +294,7 @@ int luaY_lex (void)
292 do { 294 do {
293 a=10.0*a+(current-'0'); 295 a=10.0*a+(current-'0');
294 save_and_next(); 296 save_and_next();
295 } while (isdigit(current)); 297 } while (isdigit((unsigned char)current));
296 if (current == '.') { 298 if (current == '.') {
297 save_and_next(); 299 save_and_next();
298 if (current == '.') 300 if (current == '.')
@@ -301,7 +303,7 @@ int luaY_lex (void)
301 } 303 }
302 fraction: 304 fraction:
303 { double da=0.1; 305 { double da=0.1;
304 while (isdigit(current)) 306 while (isdigit((unsigned char)current))
305 { 307 {
306 a+=(current-'0')*da; 308 a+=(current-'0')*da;
307 da/=10.0; 309 da/=10.0;
@@ -315,11 +317,12 @@ int luaY_lex (void)
315 save_and_next(); 317 save_and_next();
316 neg=(current=='-'); 318 neg=(current=='-');
317 if (current == '+' || current == '-') save_and_next(); 319 if (current == '+' || current == '-') save_and_next();
318 if (!isdigit(current)) { save(0); return WRONGTOKEN; } 320 if (!isdigit((unsigned char)current)) {
321 save(0); return WRONGTOKEN; }
319 do { 322 do {
320 e=10.0*e+(current-'0'); 323 e=10.0*e+(current-'0');
321 save_and_next(); 324 save_and_next();
322 } while (isdigit(current)); 325 } while (isdigit((unsigned char)current));
323 for (ea=neg?0.1:10.0; e>0; e>>=1) 326 for (ea=neg?0.1:10.0; e>0; e>>=1)
324 { 327 {
325 if (e & 1) a*=ea; 328 if (e & 1) a*=ea;
diff --git a/strlib.c b/strlib.c
index cb5537c2..776e3e37 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.32 1996/11/07 20:26:19 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.33 1996/11/20 13:47:59 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -154,7 +154,7 @@ static void str_lower (void)
154 char *s = lua_check_string(1, "strlower"); 154 char *s = lua_check_string(1, "strlower");
155 luaI_addchar(0); 155 luaI_addchar(0);
156 while (*s) 156 while (*s)
157 luaI_addchar(tolower(*s++)); 157 luaI_addchar(tolower((unsigned char)*s++));
158 lua_pushstring(luaI_addchar(0)); 158 lua_pushstring(luaI_addchar(0));
159} 159}
160 160
@@ -166,7 +166,7 @@ static void str_upper (void)
166 char *s = lua_check_string(1, "strupper"); 166 char *s = lua_check_string(1, "strupper");
167 luaI_addchar(0); 167 luaI_addchar(0);
168 while (*s) 168 while (*s)
169 luaI_addchar(toupper(*s++)); 169 luaI_addchar(toupper((unsigned char)*s++));
170 lua_pushstring(luaI_addchar(0)); 170 lua_pushstring(luaI_addchar(0));
171} 171}
172 172
@@ -222,18 +222,18 @@ char *item_end (char *p)
222static int matchclass (int c, int cl) 222static int matchclass (int c, int cl)
223{ 223{
224 int res; 224 int res;
225 switch (tolower(cl)) { 225 switch (tolower((unsigned char)cl)) {
226 case 'a' : res = isalpha(c); break; 226 case 'a' : res = isalpha((unsigned char)c); break;
227 case 'c' : res = iscntrl(c); break; 227 case 'c' : res = iscntrl((unsigned char)c); break;
228 case 'd' : res = isdigit(c); break; 228 case 'd' : res = isdigit((unsigned char)c); break;
229 case 'l' : res = islower(c); break; 229 case 'l' : res = islower((unsigned char)c); break;
230 case 'p' : res = ispunct(c); break; 230 case 'p' : res = ispunct((unsigned char)c); break;
231 case 's' : res = isspace(c); break; 231 case 's' : res = isspace((unsigned char)c); break;
232 case 'u' : res = isupper(c); break; 232 case 'u' : res = isupper((unsigned char)c); break;
233 case 'w' : res = isalnum(c); break; 233 case 'w' : res = isalnum((unsigned char)c); break;
234 default: return (cl == c); 234 default: return (cl == c);
235 } 235 }
236 return (islower(cl) ? res : !res); 236 return (islower((unsigned char)cl) ? res : !res);
237} 237}
238 238
239int singlematch (int c, char *p) 239int singlematch (int c, char *p)
@@ -333,7 +333,7 @@ static char *match (char *s, char *p, int level)
333 return res; 333 return res;
334 } 334 }
335 case ESC: 335 case ESC:
336 if (isdigit(*(p+1))) { /* capture */ 336 if (isdigit((unsigned char)*(p+1))) { /* capture */
337 int l = check_cap(*(p+1), level); 337 int l = check_cap(*(p+1), level);
338 if (strncmp(capture[l].init, s, capture[l].len) == 0) { 338 if (strncmp(capture[l].init, s, capture[l].len) == 0) {
339 /* return match(p+2, s+capture[l].len, level); */ 339 /* return match(p+2, s+capture[l].len, level); */
@@ -415,7 +415,7 @@ static void add_s (lua_Object newp)
415 if (lua_isstring(newp)) { 415 if (lua_isstring(newp)) {
416 char *news = lua_getstring(newp); 416 char *news = lua_getstring(newp);
417 while (*news) { 417 while (*news) {
418 if (*news != ESC || !isdigit(*++news)) 418 if (*news != ESC || !isdigit((unsigned char)*++news))
419 luaI_addchar(*news++); 419 luaI_addchar(*news++);
420 else { 420 else {
421 int l = check_cap(*news++, num_captures); 421 int l = check_cap(*news++, num_captures);