Parcourir la source

ANSI ctype only works for unsigned chars (or EOF)

Roberto Ierusalimschy il y a 29 ans
Parent
commit
1f4ee4a4d2
2 fichiers modifiés avec 26 ajouts et 23 suppressions
  1. 11 8
      lex.c
  2. 15 15
      strlib.c

+ 11 - 8
lex.c

@@ -1,4 +1,4 @@
-char *rcs_lex = "$Id: lex.c,v 2.39 1996/11/08 19:08:30 roberto Exp roberto $";
+char *rcs_lex = "$Id: lex.c,v 2.40 1996/11/21 14:44:04 roberto Exp roberto $";
 
 
 
 
 #include <ctype.h>
 #include <ctype.h>
@@ -85,7 +85,7 @@ static int inclinenumber (int pragma_allowed)
     char *buff = luaI_buffer(MINBUFF+1);
     char *buff = luaI_buffer(MINBUFF+1);
     int i = 0;
     int i = 0;
     next();  /* skip $ */
     next();  /* skip $ */
-    while (isalnum(current)) {
+    while (isalnum((unsigned char)current)) {
       if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
       if (i >= MINBUFF) luaI_syntaxerror("pragma too long");
       buff[i++] = current;
       buff[i++] = current;
       next();
       next();
@@ -259,7 +259,9 @@ int luaY_lex (void)
       case '_':
       case '_':
       {
       {
         TaggedString *ts;
         TaggedString *ts;
-        do { save_and_next(); } while (isalnum(current) || current == '_');
+        do {
+          save_and_next();
+        } while (isalnum((unsigned char)current) || current == '_');
         save(0);
         save(0);
         ts = lua_createstring(yytext);
         ts = lua_createstring(yytext);
         if (ts->marked > 2)
         if (ts->marked > 2)
@@ -281,7 +283,7 @@ int luaY_lex (void)
           }
           }
           else return CONC;   /* .. */
           else return CONC;   /* .. */
         }
         }
-        else if (!isdigit(current)) return '.';
+        else if (!isdigit((unsigned char)current)) return '.';
         /* current is a digit: goes through to number */
         /* current is a digit: goes through to number */
 	a=0.0;
 	a=0.0;
         goto fraction;
         goto fraction;
@@ -292,7 +294,7 @@ int luaY_lex (void)
         do {
         do {
           a=10.0*a+(current-'0');
           a=10.0*a+(current-'0');
           save_and_next();
           save_and_next();
-        } while (isdigit(current));
+        } while (isdigit((unsigned char)current));
         if (current == '.') {
         if (current == '.') {
           save_and_next();
           save_and_next();
           if (current == '.')
           if (current == '.')
@@ -301,7 +303,7 @@ int luaY_lex (void)
         }
         }
       fraction:
       fraction:
 	{ double da=0.1;
 	{ double da=0.1;
-	  while (isdigit(current))
+	  while (isdigit((unsigned char)current))
 	  {
 	  {
             a+=(current-'0')*da;
             a+=(current-'0')*da;
             da/=10.0;
             da/=10.0;
@@ -315,11 +317,12 @@ int luaY_lex (void)
             save_and_next();
             save_and_next();
 	    neg=(current=='-');
 	    neg=(current=='-');
             if (current == '+' || current == '-') save_and_next();
             if (current == '+' || current == '-') save_and_next();
-            if (!isdigit(current)) { save(0); return WRONGTOKEN; }
+            if (!isdigit((unsigned char)current)) {
+              save(0); return WRONGTOKEN; }
             do {
             do {
               e=10.0*e+(current-'0');
               e=10.0*e+(current-'0');
               save_and_next();
               save_and_next();
-            } while (isdigit(current));
+            } while (isdigit((unsigned char)current));
 	    for (ea=neg?0.1:10.0; e>0; e>>=1)
 	    for (ea=neg?0.1:10.0; e>0; e>>=1)
 	    {
 	    {
 	      if (e & 1) a*=ea;
 	      if (e & 1) a*=ea;

+ 15 - 15
strlib.c

@@ -3,7 +3,7 @@
 ** String library to LUA
 ** String library to LUA
 */
 */
 
 
-char *rcs_strlib="$Id: strlib.c,v 1.32 1996/11/07 20:26:19 roberto Exp roberto $";
+char *rcs_strlib="$Id: strlib.c,v 1.33 1996/11/20 13:47:59 roberto Exp roberto $";
 
 
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -154,7 +154,7 @@ static void str_lower (void)
   char *s = lua_check_string(1, "strlower");
   char *s = lua_check_string(1, "strlower");
   luaI_addchar(0);
   luaI_addchar(0);
   while (*s)
   while (*s)
-    luaI_addchar(tolower(*s++));
+    luaI_addchar(tolower((unsigned char)*s++));
   lua_pushstring(luaI_addchar(0));
   lua_pushstring(luaI_addchar(0));
 }
 }
 
 
@@ -166,7 +166,7 @@ static void str_upper (void)
   char *s = lua_check_string(1, "strupper");
   char *s = lua_check_string(1, "strupper");
   luaI_addchar(0);
   luaI_addchar(0);
   while (*s)
   while (*s)
-    luaI_addchar(toupper(*s++));
+    luaI_addchar(toupper((unsigned char)*s++));
   lua_pushstring(luaI_addchar(0));
   lua_pushstring(luaI_addchar(0));
 }
 }
 
 
@@ -222,18 +222,18 @@ char *item_end (char *p)
 static int matchclass (int c, int cl)
 static int matchclass (int c, int cl)
 {
 {
   int res;
   int res;
-  switch (tolower(cl)) {
-    case 'a' : res = isalpha(c); break;
-    case 'c' : res = iscntrl(c); break;
-    case 'd' : res = isdigit(c); break;
-    case 'l' : res = islower(c); break;
-    case 'p' : res = ispunct(c); break;
-    case 's' : res = isspace(c); break;
-    case 'u' : res = isupper(c); break;
-    case 'w' : res = isalnum(c); break;
+  switch (tolower((unsigned char)cl)) {
+    case 'a' : res = isalpha((unsigned char)c); break;
+    case 'c' : res = iscntrl((unsigned char)c); break;
+    case 'd' : res = isdigit((unsigned char)c); break;
+    case 'l' : res = islower((unsigned char)c); break;
+    case 'p' : res = ispunct((unsigned char)c); break;
+    case 's' : res = isspace((unsigned char)c); break;
+    case 'u' : res = isupper((unsigned char)c); break;
+    case 'w' : res = isalnum((unsigned char)c); break;
     default: return (cl == c);
     default: return (cl == c);
   }
   }
-  return (islower(cl) ? res : !res);
+  return (islower((unsigned char)cl) ? res : !res);
 }
 }
 
 
 int singlematch (int c, char *p)
 int singlematch (int c, char *p)
@@ -333,7 +333,7 @@ static char *match (char *s, char *p, int level)
       return res;
       return res;
     }
     }
     case ESC:
     case ESC:
-      if (isdigit(*(p+1))) {  /* capture */
+      if (isdigit((unsigned char)*(p+1))) {  /* capture */
         int l = check_cap(*(p+1), level);
         int l = check_cap(*(p+1), level);
         if (strncmp(capture[l].init, s, capture[l].len) == 0) {
         if (strncmp(capture[l].init, s, capture[l].len) == 0) {
           /* return match(p+2, s+capture[l].len, level); */
           /* return match(p+2, s+capture[l].len, level); */
@@ -415,7 +415,7 @@ static void add_s (lua_Object newp)
   if (lua_isstring(newp)) {
   if (lua_isstring(newp)) {
     char *news = lua_getstring(newp);
     char *news = lua_getstring(newp);
     while (*news) {
     while (*news) {
-      if (*news != ESC || !isdigit(*++news))
+      if (*news != ESC || !isdigit((unsigned char)*++news))
         luaI_addchar(*news++);
         luaI_addchar(*news++);
       else {
       else {
         int l = check_cap(*news++, num_captures);
         int l = check_cap(*news++, num_captures);