diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
commit | ef62b340e0a6b7b18931000dcbb19c4703bfe0e8 (patch) | |
tree | d9d995116a8a686b798d1b625b06ead26f28ba58 /liolib.c | |
parent | 5c2dd7a9e0a5b871a71ba66c4683cd88fe4f5aa4 (diff) | |
download | lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.gz lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.bz2 lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.zip |
code cleaner for 16 bits.
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.62 2000/04/24 21:05:11 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.63 2000/05/09 14:50:16 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 | */ |
@@ -322,19 +322,23 @@ static void read_word (lua_State *L, FILE *f) { | |||
322 | static int read_line (lua_State *L, FILE *f) { | 322 | static int read_line (lua_State *L, FILE *f) { |
323 | int n; | 323 | int n; |
324 | char *b; | 324 | char *b; |
325 | do { | 325 | for (;;) { |
326 | b = luaL_openspace(L, HUNK_LINE); | 326 | b = luaL_openspace(L, HUNK_LINE); |
327 | if (!fgets(b, HUNK_LINE, f)) return 0; /* read fails */ | 327 | if (!fgets(b, HUNK_LINE, f)) return 0; /* read fails */ |
328 | n = strlen(b); | 328 | n = strlen(b); |
329 | luaL_addsize(L, n); | 329 | if (b[n-1] != '\n') |
330 | } while (b[n-1] != '\n'); | 330 | luaL_addsize(L, n); |
331 | luaL_addsize(L, -1); /* remove '\n' */ | 331 | else { |
332 | luaL_addsize(L, n-1); /* do not add the `\n' */ | ||
333 | break; | ||
334 | } | ||
335 | } | ||
332 | return 1; | 336 | return 1; |
333 | } | 337 | } |
334 | 338 | ||
335 | 339 | ||
336 | static void read_file (lua_State *L, FILE *f) { | 340 | static void read_file (lua_State *L, FILE *f) { |
337 | int n; | 341 | size_t n; |
338 | do { | 342 | do { |
339 | char *b = luaL_openspace(L, HUNK_FILE); | 343 | char *b = luaL_openspace(L, HUNK_FILE); |
340 | n = fread(b, sizeof(char), HUNK_FILE, f); | 344 | n = fread(b, sizeof(char), HUNK_FILE, f); |
@@ -343,9 +347,9 @@ static void read_file (lua_State *L, FILE *f) { | |||
343 | } | 347 | } |
344 | 348 | ||
345 | 349 | ||
346 | static int read_chars (lua_State *L, FILE *f, int n) { | 350 | static int read_chars (lua_State *L, FILE *f, size_t n) { |
347 | char *b = luaL_openspace(L, n); | 351 | char *b = luaL_openspace(L, n); |
348 | int n1 = fread(b, sizeof(char), n, f); | 352 | size_t n1 = fread(b, sizeof(char), n, f); |
349 | luaL_addsize(L, n1); | 353 | luaL_addsize(L, n1); |
350 | return (n == n1); | 354 | return (n == n1); |
351 | } | 355 | } |
@@ -357,11 +361,11 @@ static void io_read (lua_State *L) { | |||
357 | FILE *f = getfileparam(L, ctrl, &arg, INFILE); | 361 | FILE *f = getfileparam(L, ctrl, &arg, INFILE); |
358 | lua_Object op = lua_getparam(L, arg); | 362 | lua_Object op = lua_getparam(L, arg); |
359 | do { /* repeat for each part */ | 363 | do { /* repeat for each part */ |
360 | long l; | 364 | size_t l; |
361 | int success; | 365 | int success; |
362 | luaL_resetbuffer(L); | 366 | luaL_resetbuffer(L); |
363 | if (lua_isnumber(L, op)) | 367 | if (lua_isnumber(L, op)) |
364 | success = read_chars(L, f, (int)lua_getnumber(L, op)); | 368 | success = read_chars(L, f, (size_t)lua_getnumber(L, op)); |
365 | else { | 369 | else { |
366 | const char *p = luaL_opt_string(L, arg, "*l"); | 370 | const char *p = luaL_opt_string(L, arg, "*l"); |
367 | if (p[0] != '*') | 371 | if (p[0] != '*') |
@@ -409,9 +413,9 @@ static void io_write (lua_State *L) { | |||
409 | status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; | 413 | status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; |
410 | } | 414 | } |
411 | else { | 415 | else { |
412 | long l; | 416 | size_t l; |
413 | const char *s = luaL_check_lstr(L, arg, &l); | 417 | const char *s = luaL_check_lstr(L, arg, &l); |
414 | status = status && ((long)fwrite(s, sizeof(char), l, f) == l); | 418 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
415 | } | 419 | } |
416 | arg++; | 420 | arg++; |
417 | } | 421 | } |