Commits

Laurens Rodriguez committed e30aa06

kiolib.c: fixes from Lua 5.2.2

Comments (0)

Files changed (2)

extra/killa/compare.pl

         $line =~ s/killa_rawtsvalue/rawtsvalue/g;
         $line =~ s/killa_sizeCclosure/sizeCclosure/g;
         $line =~ s/killa_sizeLclosure/sizeLclosure/g;
+        $line =~ s/killa_isdead/isdead/g;
+        $line =~ s/killa_changewhite/changewhite/g;
+        $line =~ s/killa_isblack/isblack/g;
+
         $line =~ s/KILLA_REFNULL/LUA_REFNIL/g;
         $line =~ s/OP_LOADNULL/OP_LOADNIL/g;
         $line =~ s/KILLA_MAXSTACK/MAXSTACK/g;

src/libraries/killa/kiolib.c

 #include "killalib.h"
 
 
+#if !defined(killa_checkmode)
+
+/*
+** Check whether 'mode' matches '[rwa]%+?b?'.
+** Change this macro to accept other modes for 'fopen' besides
+** the standard ones.
+*/
+#define killa_checkmode(mode) \
+	(*mode != '\0' && strchr("rwa", *(mode++)) != NULL &&	\
+	(*mode != '+' || ++mode) &&  /* skip if char is '+' */	\
+	(*mode != 'b' || ++mode) &&  /* skip if char is 'b' */	\
+	(*mode == '\0'))
+
+#endif
 
 /*
 ** {======================================================
   const char *filename = killaL_checkstring(L, 1);
   const char *mode = killaL_optstring(L, 2, "r");
   LStream *p = newfile(L);
-  int i = 0;
-  /* check whether 'mode' matches '[rwa]%+?b?' */
-  if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
-       (mode[i] != '+' || ++i) &&  /* skip if char is '+' */
-       (mode[i] != 'b' || ++i) &&  /* skip if char is 'b' */
-       (mode[i] == '\0')))
-    return killaL_error(L, "invalid mode " KILLA_QS
-                         " (should match " KILLA_QL("[rwa]%%+?b?") ")", mode);
+  const char *md = mode;  /* to traverse/check mode */
+  killaL_argcheck(L, killa_checkmode(md), 2, "invalid mode");
   p->f = fopen(filename, mode);
   return (p->f == NULL) ? killaL_fileresult(L, 0, filename) : 1;
 }