diff options
| author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-01-03 11:14:13 -0200 |
|---|---|---|
| committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-01-03 11:14:13 -0200 |
| commit | e4c69cf91710337b9c80039853941d48d211fcfd (patch) | |
| tree | f64f0c7dd91ee98c075d9c5fed0e8a891afa635c /iolib.c | |
| parent | 5b8ced84b4bd5ec300d3658b2ddb48d715512732 (diff) | |
| download | lua-e4c69cf91710337b9c80039853941d48d211fcfd.tar.gz lua-e4c69cf91710337b9c80039853941d48d211fcfd.tar.bz2 lua-e4c69cf91710337b9c80039853941d48d211fcfd.zip | |
correcao de bug na construcao do formato.
Diffstat (limited to 'iolib.c')
| -rw-r--r-- | iolib.c | 21 |
1 files changed, 11 insertions, 10 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.17 1994/12/13 15:55:41 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.17 1994/12/13 15:55:41 roberto Exp $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -29,7 +29,7 @@ static FILE *in=stdin, *out=stdout; | |||
| 29 | static void io_readfrom (void) | 29 | static void io_readfrom (void) |
| 30 | { | 30 | { |
| 31 | lua_Object o = lua_getparam (1); | 31 | lua_Object o = lua_getparam (1); |
| 32 | if (o == LUA_NOOBJECT) /* restore standart input */ | 32 | if (o == NULL) /* restore standart input */ |
| 33 | { | 33 | { |
| 34 | if (in != stdin) | 34 | if (in != stdin) |
| 35 | { | 35 | { |
| @@ -74,7 +74,7 @@ static void io_readfrom (void) | |||
| 74 | static void io_writeto (void) | 74 | static void io_writeto (void) |
| 75 | { | 75 | { |
| 76 | lua_Object o = lua_getparam (1); | 76 | lua_Object o = lua_getparam (1); |
| 77 | if (o == LUA_NOOBJECT) /* restore standart output */ | 77 | if (o == NULL) /* restore standart output */ |
| 78 | { | 78 | { |
| 79 | if (out != stdout) | 79 | if (out != stdout) |
| 80 | { | 80 | { |
| @@ -120,7 +120,7 @@ static void io_writeto (void) | |||
| 120 | static void io_appendto (void) | 120 | static void io_appendto (void) |
| 121 | { | 121 | { |
| 122 | lua_Object o = lua_getparam (1); | 122 | lua_Object o = lua_getparam (1); |
| 123 | if (o == LUA_NOOBJECT) /* restore standart output */ | 123 | if (o == NULL) /* restore standart output */ |
| 124 | { | 124 | { |
| 125 | if (out != stdout) | 125 | if (out != stdout) |
| 126 | { | 126 | { |
| @@ -177,7 +177,7 @@ static void io_appendto (void) | |||
| 177 | static void io_read (void) | 177 | static void io_read (void) |
| 178 | { | 178 | { |
| 179 | lua_Object o = lua_getparam (1); | 179 | lua_Object o = lua_getparam (1); |
| 180 | if (!lua_isstring(o)) /* free format */ | 180 | if (o == NULL || !lua_isstring(o)) /* free format */ |
| 181 | { | 181 | { |
| 182 | int c; | 182 | int c; |
| 183 | char s[256]; | 183 | char s[256]; |
| @@ -383,7 +383,8 @@ static char *buildformat (char *e, lua_Object o) | |||
| 383 | m = m*10 + (*e++ - '0'); | 383 | m = m*10 + (*e++ - '0'); |
| 384 | if (*e == '.') e++; /* skip point */ | 384 | if (*e == '.') e++; /* skip point */ |
| 385 | while (isdigit(*e)) | 385 | while (isdigit(*e)) |
| 386 | n = n*10 + (*e++ - '0'); | 386 | if (n < 0) n = (*e++ - '0'); |
| 387 | else n = n*10 + (*e++ - '0'); | ||
| 387 | 388 | ||
| 388 | sprintf(f,"%%"); | 389 | sprintf(f,"%%"); |
| 389 | if (j == '<' || j == '|') sprintf(strchr(f,0),"-"); | 390 | if (j == '<' || j == '|') sprintf(strchr(f,0),"-"); |
| @@ -442,12 +443,12 @@ static void io_write (void) | |||
| 442 | { | 443 | { |
| 443 | lua_Object o1 = lua_getparam (1); | 444 | lua_Object o1 = lua_getparam (1); |
| 444 | lua_Object o2 = lua_getparam (2); | 445 | lua_Object o2 = lua_getparam (2); |
| 445 | if (o1 == LUA_NOOBJECT) /* new line */ | 446 | if (o1 == NULL) /* new line */ |
| 446 | { | 447 | { |
| 447 | fprintf (out, "\n"); | 448 | fprintf (out, "\n"); |
| 448 | lua_pushnumber(1); | 449 | lua_pushnumber(1); |
| 449 | } | 450 | } |
| 450 | else if (o2 == LUA_NOOBJECT) /* free format */ | 451 | else if (o2 == NULL) /* free format */ |
| 451 | { | 452 | { |
| 452 | int status=0; | 453 | int status=0; |
| 453 | if (lua_isnumber(o1)) | 454 | if (lua_isnumber(o1)) |
| @@ -475,7 +476,7 @@ static void io_write (void) | |||
| 475 | static void io_execute (void) | 476 | static void io_execute (void) |
| 476 | { | 477 | { |
| 477 | lua_Object o = lua_getparam (1); | 478 | lua_Object o = lua_getparam (1); |
| 478 | if (!lua_isstring (o)) | 479 | if (o == NULL || !lua_isstring (o)) |
| 479 | { | 480 | { |
| 480 | lua_error ("incorrect argument to function 'execute`"); | 481 | lua_error ("incorrect argument to function 'execute`"); |
| 481 | lua_pushnumber (0); | 482 | lua_pushnumber (0); |
| @@ -495,7 +496,7 @@ static void io_execute (void) | |||
| 495 | static void io_remove (void) | 496 | static void io_remove (void) |
| 496 | { | 497 | { |
| 497 | lua_Object o = lua_getparam (1); | 498 | lua_Object o = lua_getparam (1); |
| 498 | if (!lua_isstring (o)) | 499 | if (o == NULL || !lua_isstring (o)) |
| 499 | { | 500 | { |
| 500 | lua_error ("incorrect argument to function 'execute`"); | 501 | lua_error ("incorrect argument to function 'execute`"); |
| 501 | lua_pushnumber (0); | 502 | lua_pushnumber (0); |
