diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
| commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
| tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /liolib.c | |
| parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
| download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip | |
"const" !!!
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 48 |
1 files changed, 24 insertions, 24 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.42 1999/07/22 19:35:50 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.43 1999/08/10 13:05: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 | */ |
| @@ -44,8 +44,8 @@ | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | #ifdef POPEN | 46 | #ifdef POPEN |
| 47 | FILE *popen(); | 47 | /* FILE *popen(); |
| 48 | int pclose(); | 48 | int pclose(); */ |
| 49 | #define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0) | 49 | #define CLOSEFILE(f) ((pclose(f) == -1) ? fclose(f) : 0) |
| 50 | #else | 50 | #else |
| 51 | /* no support for popen */ | 51 | /* no support for popen */ |
| @@ -88,7 +88,7 @@ static int ishandle (lua_Object f) { | |||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | static FILE *getfilebyname (char *name) { | 91 | static FILE *getfilebyname (const char *name) { |
| 92 | lua_Object f = lua_rawgetglobal(name); | 92 | lua_Object f = lua_rawgetglobal(name); |
| 93 | if (!ishandle(f)) | 93 | if (!ishandle(f)) |
| 94 | luaL_verror("global variable `%.50s' is not a file handle", name); | 94 | luaL_verror("global variable `%.50s' is not a file handle", name); |
| @@ -109,7 +109,7 @@ static FILE *getnonullfile (int arg) { | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | 111 | ||
| 112 | static FILE *getfileparam (char *name, int *arg) { | 112 | static FILE *getfileparam (const char *name, int *arg) { |
| 113 | FILE *f = getfile(*arg); | 113 | FILE *f = getfile(*arg); |
| 114 | if (f) { | 114 | if (f) { |
| 115 | (*arg)++; | 115 | (*arg)++; |
| @@ -152,13 +152,13 @@ static void io_open (void) { | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | static void setfile (FILE *f, char *name, int tag) { | 155 | static void setfile (FILE *f, const char *name, int tag) { |
| 156 | lua_pushusertag(f, tag); | 156 | lua_pushusertag(f, tag); |
| 157 | lua_setglobal(name); | 157 | lua_setglobal(name); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | 160 | ||
| 161 | static void setreturn (FILE *f, char *name) { | 161 | static void setreturn (FILE *f, const char *name) { |
| 162 | if (f == NULL) | 162 | if (f == NULL) |
| 163 | pushresult(0); | 163 | pushresult(0); |
| 164 | else { | 164 | else { |
| @@ -181,7 +181,7 @@ static void io_readfrom (void) { | |||
| 181 | else if (lua_tag(f) == gettag()) /* deprecated option */ | 181 | else if (lua_tag(f) == gettag()) /* deprecated option */ |
| 182 | current = lua_getuserdata(f); | 182 | current = lua_getuserdata(f); |
| 183 | else { | 183 | else { |
| 184 | char *s = luaL_check_string(FIRSTARG); | 184 | const char *s = luaL_check_string(FIRSTARG); |
| 185 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); | 185 | current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); |
| 186 | } | 186 | } |
| 187 | setreturn(current, FINPUT); | 187 | setreturn(current, FINPUT); |
| @@ -200,7 +200,7 @@ static void io_writeto (void) { | |||
| 200 | else if (lua_tag(f) == gettag()) /* deprecated option */ | 200 | else if (lua_tag(f) == gettag()) /* deprecated option */ |
| 201 | current = lua_getuserdata(f); | 201 | current = lua_getuserdata(f); |
| 202 | else { | 202 | else { |
| 203 | char *s = luaL_check_string(FIRSTARG); | 203 | const char *s = luaL_check_string(FIRSTARG); |
| 204 | current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); | 204 | current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w"); |
| 205 | } | 205 | } |
| 206 | setreturn(current, FOUTPUT); | 206 | setreturn(current, FOUTPUT); |
| @@ -228,7 +228,7 @@ static void io_appendto (void) { | |||
| 228 | #define NEED_OTHER (EOF-1) /* just some flag different from EOF */ | 228 | #define NEED_OTHER (EOF-1) /* just some flag different from EOF */ |
| 229 | 229 | ||
| 230 | 230 | ||
| 231 | static int read_pattern (FILE *f, char *p) { | 231 | static int read_pattern (FILE *f, const char *p) { |
| 232 | int inskip = 0; /* {skip} level */ | 232 | int inskip = 0; /* {skip} level */ |
| 233 | int c = NEED_OTHER; | 233 | int c = NEED_OTHER; |
| 234 | while (*p != '\0') { | 234 | while (*p != '\0') { |
| @@ -243,7 +243,7 @@ static int read_pattern (FILE *f, char *p) { | |||
| 243 | p++; | 243 | p++; |
| 244 | continue; | 244 | continue; |
| 245 | default: { | 245 | default: { |
| 246 | char *ep = luaI_classend(p); /* get what is next */ | 246 | const char *ep = luaI_classend(p); /* get what is next */ |
| 247 | int m; /* match result */ | 247 | int m; /* match result */ |
| 248 | if (c == NEED_OTHER) c = getc(f); | 248 | if (c == NEED_OTHER) c = getc(f); |
| 249 | m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep); | 249 | m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep); |
| @@ -317,10 +317,10 @@ static void read_file (FILE *f) { | |||
| 317 | 317 | ||
| 318 | 318 | ||
| 319 | static void io_read (void) { | 319 | static void io_read (void) { |
| 320 | static char *options[] = {"*n", "*l", "*a", ".*", "*w", NULL}; | 320 | static const char *const options[] = {"*n", "*l", "*a", ".*", "*w", NULL}; |
| 321 | int arg = FIRSTARG; | 321 | int arg = FIRSTARG; |
| 322 | FILE *f = getfileparam(FINPUT, &arg); | 322 | FILE *f = getfileparam(FINPUT, &arg); |
| 323 | char *p = luaL_opt_string(arg++, "*l"); | 323 | const char *p = luaL_opt_string(arg++, "*l"); |
| 324 | do { /* repeat for each part */ | 324 | do { /* repeat for each part */ |
| 325 | long l; | 325 | long l; |
| 326 | int success; | 326 | int success; |
| @@ -355,7 +355,7 @@ static void io_write (void) { | |||
| 355 | int arg = FIRSTARG; | 355 | int arg = FIRSTARG; |
| 356 | FILE *f = getfileparam(FOUTPUT, &arg); | 356 | FILE *f = getfileparam(FOUTPUT, &arg); |
| 357 | int status = 1; | 357 | int status = 1; |
| 358 | char *s; | 358 | const char *s; |
| 359 | long l; | 359 | long l; |
| 360 | while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL) | 360 | while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL) |
| 361 | status = status && ((long)fwrite(s, 1, l, f) == l); | 361 | status = status && ((long)fwrite(s, 1, l, f) == l); |
| @@ -364,8 +364,8 @@ static void io_write (void) { | |||
| 364 | 364 | ||
| 365 | 365 | ||
| 366 | static void io_seek (void) { | 366 | static void io_seek (void) { |
| 367 | static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 367 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
| 368 | static char *modenames[] = {"set", "cur", "end", NULL}; | 368 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 369 | FILE *f = getnonullfile(FIRSTARG); | 369 | FILE *f = getnonullfile(FIRSTARG); |
| 370 | int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames); | 370 | int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames); |
| 371 | long offset = luaL_opt_long(FIRSTARG+2, 0); | 371 | long offset = luaL_opt_long(FIRSTARG+2, 0); |
| @@ -428,7 +428,7 @@ static void io_clock (void) { | |||
| 428 | 428 | ||
| 429 | static void io_date (void) { | 429 | static void io_date (void) { |
| 430 | char b[256]; | 430 | char b[256]; |
| 431 | char *s = luaL_opt_string(1, "%c"); | 431 | const char *s = luaL_opt_string(1, "%c"); |
| 432 | struct tm *tm; | 432 | struct tm *tm; |
| 433 | time_t t; | 433 | time_t t; |
| 434 | time(&t); tm = localtime(&t); | 434 | time(&t); tm = localtime(&t); |
| @@ -440,9 +440,9 @@ static void io_date (void) { | |||
| 440 | 440 | ||
| 441 | 441 | ||
| 442 | static void setloc (void) { | 442 | static void setloc (void) { |
| 443 | static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, | 443 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, |
| 444 | LC_TIME}; | 444 | LC_NUMERIC, LC_TIME}; |
| 445 | static char *catnames[] = {"all", "collate", "ctype", "monetary", | 445 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", |
| 446 | "numeric", "time", NULL}; | 446 | "numeric", "time", NULL}; |
| 447 | int op = luaL_findstring(luaL_opt_string(2, "all"), catnames); | 447 | int op = luaL_findstring(luaL_opt_string(2, "all"), catnames); |
| 448 | luaL_arg_check(op != -1, 2, "invalid option"); | 448 | luaL_arg_check(op != -1, 2, "invalid option"); |
| @@ -485,9 +485,9 @@ static void errorfb (void) { | |||
| 485 | lua_Object func; | 485 | lua_Object func; |
| 486 | sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1))); | 486 | sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1))); |
| 487 | while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { | 487 | while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { |
| 488 | char *name; | 488 | const char *name; |
| 489 | int currentline; | 489 | int currentline; |
| 490 | char *chunkname; | 490 | const char *chunkname; |
| 491 | char buffchunk[MAXSRC]; | 491 | char buffchunk[MAXSRC]; |
| 492 | int linedefined; | 492 | int linedefined; |
| 493 | lua_funcinfo(func, &chunkname, &linedefined); | 493 | lua_funcinfo(func, &chunkname, &linedefined); |
| @@ -531,7 +531,7 @@ static void errorfb (void) { | |||
| 531 | 531 | ||
| 532 | 532 | ||
| 533 | 533 | ||
| 534 | static struct luaL_reg iolib[] = { | 534 | static const struct luaL_reg iolib[] = { |
| 535 | {"_ERRORMESSAGE", errorfb}, | 535 | {"_ERRORMESSAGE", errorfb}, |
| 536 | {"clock", io_clock}, | 536 | {"clock", io_clock}, |
| 537 | {"date", io_date}, | 537 | {"date", io_date}, |
| @@ -546,7 +546,7 @@ static struct luaL_reg iolib[] = { | |||
| 546 | }; | 546 | }; |
| 547 | 547 | ||
| 548 | 548 | ||
| 549 | static struct luaL_reg iolibtag[] = { | 549 | static const struct luaL_reg iolibtag[] = { |
| 550 | {"appendto", io_appendto}, | 550 | {"appendto", io_appendto}, |
| 551 | {"closefile", io_close}, | 551 | {"closefile", io_close}, |
| 552 | {"flush", io_flush}, | 552 | {"flush", io_flush}, |
