aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/liolib.c b/liolib.c
index b663221c..545e4d12 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.79 2000/09/11 20:29:27 roberto Exp roberto $ 2** $Id: liolib.c,v 1.80 2000/09/12 13:48:34 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -246,6 +246,8 @@ static int io_appendto (lua_State *L) {
246static int read_pattern (lua_State *L, FILE *f, const char *p) { 246static int read_pattern (lua_State *L, FILE *f, const char *p) {
247 int inskip = 0; /* {skip} level */ 247 int inskip = 0; /* {skip} level */
248 int c = NEED_OTHER; 248 int c = NEED_OTHER;
249 luaL_Buffer b;
250 luaL_buffinit(L, &b);
249 while (*p != '\0') { 251 while (*p != '\0') {
250 switch (*p) { 252 switch (*p) {
251 case '{': 253 case '{':
@@ -263,7 +265,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
263 if (c == NEED_OTHER) c = getc(f); 265 if (c == NEED_OTHER) c = getc(f);
264 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep); 266 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
265 if (m) { 267 if (m) {
266 if (!inskip) luaL_putchar(L, c); 268 if (!inskip) luaL_putchar(&b, c);
267 c = NEED_OTHER; 269 c = NEED_OTHER;
268 } 270 }
269 switch (*ep) { 271 switch (*ep) {
@@ -274,7 +276,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
274 while (m) { /* reads the same item until it fails */ 276 while (m) { /* reads the same item until it fails */
275 c = getc(f); 277 c = getc(f);
276 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep); 278 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
277 if (m && !inskip) luaL_putchar(L, c); 279 if (m && !inskip) luaL_putchar(&b, c);
278 } 280 }
279 /* go through to continue reading the pattern */ 281 /* go through to continue reading the pattern */
280 case '?': /* optional */ 282 case '?': /* optional */
@@ -288,6 +290,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
288 } 290 }
289 } break_while: 291 } break_while:
290 if (c != NEED_OTHER) ungetc(c, f); 292 if (c != NEED_OTHER) ungetc(c, f);
293 luaL_pushresult(&b); /* close buffer */
291 return (*p == '\0'); 294 return (*p == '\0');
292} 295}
293 296