diff options
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.13 1997/12/26 18:38:16 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.14 1998/01/07 16:26:48 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 | */ |
@@ -184,7 +184,7 @@ static void io_read (void) | |||
184 | { | 184 | { |
185 | int arg = FIRSTARG; | 185 | int arg = FIRSTARG; |
186 | FILE *f = getfileparam(FINPUT, &arg); | 186 | FILE *f = getfileparam(FINPUT, &arg); |
187 | char *buff; | 187 | int l; |
188 | char *p = luaL_opt_string(arg, "[^\n]*{\n}"); | 188 | char *p = luaL_opt_string(arg, "[^\n]*{\n}"); |
189 | int inskip = 0; /* to control {skips} */ | 189 | int inskip = 0; /* to control {skips} */ |
190 | int c = NEED_OTHER; | 190 | int c = NEED_OTHER; |
@@ -204,10 +204,16 @@ static void io_read (void) | |||
204 | char *ep; /* get what is next */ | 204 | char *ep; /* get what is next */ |
205 | int m; /* match result */ | 205 | int m; /* match result */ |
206 | if (c == NEED_OTHER) c = getc(f); | 206 | if (c == NEED_OTHER) c = getc(f); |
207 | m = luaI_singlematch((c == EOF) ? 0 : (char)c, p, &ep); | 207 | if (c == EOF) { |
208 | if (m) { | 208 | luaI_singlematch(0, p, &ep); /* to set "ep" */ |
209 | if (inskip == 0) luaL_addchar(c); | 209 | m = 0; |
210 | c = NEED_OTHER; | 210 | } |
211 | else { | ||
212 | m = luaI_singlematch((char)c, p, &ep); | ||
213 | if (m) { | ||
214 | if (inskip == 0) luaL_addchar(c); | ||
215 | c = NEED_OTHER; | ||
216 | } | ||
211 | } | 217 | } |
212 | switch (*ep) { | 218 | switch (*ep) { |
213 | case '*': /* repetition */ | 219 | case '*': /* repetition */ |
@@ -225,10 +231,9 @@ static void io_read (void) | |||
225 | } break_while: | 231 | } break_while: |
226 | if (c >= 0) /* not EOF nor NEED_OTHER? */ | 232 | if (c >= 0) /* not EOF nor NEED_OTHER? */ |
227 | ungetc(c, f); | 233 | ungetc(c, f); |
228 | luaL_addchar(0); | 234 | l = luaL_getsize(); |
229 | buff = luaL_buffer(); | 235 | if (l > 0 || *p == 0) /* read something or did not fail? */ |
230 | if (*buff != 0 || *p == 0) /* read something or did not fail? */ | 236 | lua_pushlstr(luaL_buffer(), l); |
231 | lua_pushstring(buff); | ||
232 | } | 237 | } |
233 | 238 | ||
234 | 239 | ||
@@ -238,8 +243,9 @@ static void io_write (void) | |||
238 | FILE *f = getfileparam(FOUTPUT, &arg); | 243 | FILE *f = getfileparam(FOUTPUT, &arg); |
239 | int status = 1; | 244 | int status = 1; |
240 | char *s; | 245 | char *s; |
241 | while ((s = luaL_opt_string(arg++, NULL)) != NULL) | 246 | long l; |
242 | status = status && (fputs(s, f) != EOF); | 247 | while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL) |
248 | status = status && (fwrite(s, 1, l, f) == l); | ||
243 | pushresult(status); | 249 | pushresult(status); |
244 | } | 250 | } |
245 | 251 | ||