diff options
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 28 |
1 files changed, 17 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.36 1999/03/26 13:48:26 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.37 1999/04/05 19:47:05 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 | */ |
| @@ -221,9 +221,17 @@ static void io_appendto (void) { | |||
| 221 | ** ======================================================= | 221 | ** ======================================================= |
| 222 | */ | 222 | */ |
| 223 | 223 | ||
| 224 | |||
| 225 | /* | ||
| 226 | ** We cannot lookahead without need, because this can lock stdin. | ||
| 227 | ** This flag signals when we need to read a next char. | ||
| 228 | */ | ||
| 229 | #define NEED_OTHER (EOF-1) /* just some flag different from EOF */ | ||
| 230 | |||
| 231 | |||
| 224 | static int read_pattern (FILE *f, char *p) { | 232 | static int read_pattern (FILE *f, char *p) { |
| 225 | int inskip = 0; /* {skip} level */ | 233 | int inskip = 0; /* {skip} level */ |
| 226 | int c = getc(f); | 234 | int c = NEED_OTHER; |
| 227 | while (*p != '\0') { | 235 | while (*p != '\0') { |
| 228 | switch (*p) { | 236 | switch (*p) { |
| 229 | case '{': | 237 | case '{': |
| @@ -238,6 +246,7 @@ static int read_pattern (FILE *f, char *p) { | |||
| 238 | default: { | 246 | default: { |
| 239 | char *ep; /* get what is next */ | 247 | char *ep; /* get what is next */ |
| 240 | int m; /* match result */ | 248 | int m; /* match result */ |
| 249 | if (c == NEED_OTHER) c = getc(f); | ||
| 241 | if (c != EOF) | 250 | if (c != EOF) |
| 242 | m = luaI_singlematch(c, p, &ep); | 251 | m = luaI_singlematch(c, p, &ep); |
| 243 | else { | 252 | else { |
| @@ -246,7 +255,7 @@ static int read_pattern (FILE *f, char *p) { | |||
| 246 | } | 255 | } |
| 247 | if (m) { | 256 | if (m) { |
| 248 | if (!inskip) luaL_addchar(c); | 257 | if (!inskip) luaL_addchar(c); |
| 249 | c = getc(f); | 258 | c = NEED_OTHER; |
| 250 | } | 259 | } |
| 251 | switch (*ep) { | 260 | switch (*ep) { |
| 252 | case '*': /* repetition */ | 261 | case '*': /* repetition */ |
| @@ -256,17 +265,14 @@ static int read_pattern (FILE *f, char *p) { | |||
| 256 | p = ep+1; /* continues reading the pattern */ | 265 | p = ep+1; /* continues reading the pattern */ |
| 257 | continue; | 266 | continue; |
| 258 | default: | 267 | default: |
| 259 | if (!m) { /* pattern fails? */ | 268 | if (!m) goto break_while; /* pattern fails? */ |
| 260 | ungetc(c, f); | 269 | p = ep; /* else continues reading the pattern */ |
| 261 | return 0; | ||
| 262 | } | ||
| 263 | p = ep; /* continues reading the pattern */ | ||
| 264 | } | 270 | } |
| 265 | } | 271 | } |
| 266 | } | 272 | } |
| 267 | } | 273 | } break_while: |
| 268 | ungetc(c, f); | 274 | if (c != NEED_OTHER) ungetc(c, f); |
| 269 | return 1; | 275 | return (*p == '\0'); |
| 270 | } | 276 | } |
| 271 | 277 | ||
| 272 | 278 | ||
