Browse Source

read patterns (deprecated) use new auxlib's buffer system

Roberto Ierusalimschy 25 years ago
parent
commit
c1f725ba4a
1 changed files with 6 additions and 3 deletions
  1. 6 3
      liolib.c

+ 6 - 3
liolib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: liolib.c,v 1.79 2000/09/11 20:29:27 roberto Exp roberto $
+** $Id: liolib.c,v 1.80 2000/09/12 13:48:34 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -246,6 +246,8 @@ static int io_appendto (lua_State *L) {
 static int read_pattern (lua_State *L, FILE *f, const char *p) {
 static int read_pattern (lua_State *L, FILE *f, const char *p) {
   int inskip = 0;  /* {skip} level */
   int inskip = 0;  /* {skip} level */
   int c = NEED_OTHER;
   int c = NEED_OTHER;
+  luaL_Buffer b;
+  luaL_buffinit(L, &b);
   while (*p != '\0') {
   while (*p != '\0') {
     switch (*p) {
     switch (*p) {
       case '{':
       case '{':
@@ -263,7 +265,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
         if (c == NEED_OTHER) c = getc(f);
         if (c == NEED_OTHER) c = getc(f);
         m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
         m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
         if (m) {
         if (m) {
-          if (!inskip) luaL_putchar(L, c);
+          if (!inskip) luaL_putchar(&b, c);
           c = NEED_OTHER;
           c = NEED_OTHER;
         }
         }
         switch (*ep) {
         switch (*ep) {
@@ -274,7 +276,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
             while (m) {  /* reads the same item until it fails */
             while (m) {  /* reads the same item until it fails */
               c = getc(f);
               c = getc(f);
               m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
               m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
-              if (m && !inskip) luaL_putchar(L, c);
+              if (m && !inskip) luaL_putchar(&b, c);
             }
             }
             /* go through to continue reading the pattern */
             /* go through to continue reading the pattern */
           case '?':  /* optional */
           case '?':  /* optional */
@@ -288,6 +290,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
     }
     }
   } break_while:
   } break_while:
   if (c != NEED_OTHER) ungetc(c, f);
   if (c != NEED_OTHER) ungetc(c, f);
+  luaL_pushresult(&b);  /* close buffer */
   return (*p == '\0');
   return (*p == '\0');
 }
 }