diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-04-25 17:11:23 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-04-25 17:11:23 -0300 |
commit | cde6ab178200cc4bb79c287ecf40a7508953933a (patch) | |
tree | da60fbfe1882c5c53e6b49c6e1d0075027086bc0 | |
parent | 44521b21e542831a95de0c63271cd38d1cd4d394 (diff) | |
download | lua-cde6ab178200cc4bb79c287ecf40a7508953933a.tar.gz lua-cde6ab178200cc4bb79c287ecf40a7508953933a.tar.bz2 lua-cde6ab178200cc4bb79c287ecf40a7508953933a.zip |
Correcao de erro na funcao read quando a variavel que
especifica o formato nao era uma string e correcao do
erro para ler strings entre aspas nula no formato livre.
-rw-r--r-- | iolib.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_iolib="$Id: iolib.c,v 1.2 1993/12/30 14:52:18 roberto Exp celes $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.3 1994/03/28 15:14:02 celes Exp celes $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -179,7 +179,7 @@ static void io_appendto (void) | |||
179 | static void io_read (void) | 179 | static void io_read (void) |
180 | { | 180 | { |
181 | lua_Object o = lua_getparam (1); | 181 | lua_Object o = lua_getparam (1); |
182 | if (o == NULL) /* free format */ | 182 | if (o == NULL || !lua_isstring(o)) /* free format */ |
183 | { | 183 | { |
184 | int c; | 184 | int c; |
185 | char s[256]; | 185 | char s[256]; |
@@ -187,19 +187,31 @@ static void io_read (void) | |||
187 | ; | 187 | ; |
188 | if (c == '\"') | 188 | if (c == '\"') |
189 | { | 189 | { |
190 | if (fscanf (in, "%[^\"]\"", s) != 1) | 190 | int c, n=0; |
191 | while((c = fgetc(in)) != '\"') | ||
191 | { | 192 | { |
192 | lua_pushnil (); | 193 | if (c == EOF) |
193 | return; | 194 | { |
195 | lua_pushnil (); | ||
196 | return; | ||
197 | } | ||
198 | s[n++] = c; | ||
194 | } | 199 | } |
200 | s[n] = 0; | ||
195 | } | 201 | } |
196 | else if (c == '\'') | 202 | else if (c == '\'') |
197 | { | 203 | { |
198 | if (fscanf (in, "%[^\']\'", s) != 1) | 204 | int c, n=0; |
205 | while((c = fgetc(in)) != '\'') | ||
199 | { | 206 | { |
200 | lua_pushnil (); | 207 | if (c == EOF) |
201 | return; | 208 | { |
209 | lua_pushnil (); | ||
210 | return; | ||
211 | } | ||
212 | s[n++] = c; | ||
202 | } | 213 | } |
214 | s[n] = 0; | ||
203 | } | 215 | } |
204 | else | 216 | else |
205 | { | 217 | { |