commit d6232a0b2e53d6bd374c762a4f47e7a8799de5d2
parent ae63a0e692fdc64a2bbafcb6ff10ecbdf3946f88
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 9 Oct 2000 11:47:10 -0200
better treatment for source names
Diffstat:
4 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/ldebug.c b/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 1.45 2000/10/05 13:00:17 roberto Exp roberto $
+** $Id: ldebug.c,v 1.46 2000/10/06 12:45:25 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -193,7 +193,7 @@ static void lua_funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
lua_error(L, "value for `lua_getinfo' is not a function");
}
if (cl->isC) {
- ar->source = "(C)";
+ ar->source = "=C";
ar->linedefined = -1;
ar->what = "C";
}
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.103 2000/10/05 13:00:17 roberto Exp roberto $
+** $Id: ldo.c,v 1.104 2000/10/06 12:45:25 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -260,14 +260,16 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
static int parse_file (lua_State *L, const char *filename) {
ZIO z;
- char source[MAXFILENAME];
int status;
int bin; /* flag for file mode */
int c; /* look ahead char */
FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
if (f == NULL) return LUA_ERRFILE; /* unable to open file */
- if (filename == NULL) filename = "(stdin)";
- sprintf(source, "@%.*s", (int)sizeof(source)-2, filename);
+ lua_pushstring(L, "@");
+ lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
+ lua_concat(L, 2);
+ filename = lua_tostring(L, -1); /* filename = '@'..filename */
+ lua_pop(L, 1); /* OK: there is no GC during parser */
c = fgetc(f);
ungetc(c, f);
bin = (c == ID_CHUNK);
@@ -275,7 +277,7 @@ static int parse_file (lua_State *L, const char *filename) {
f = freopen(filename, "rb", f); /* set binary mode */
if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */
}
- luaZ_Fopen(&z, f, source);
+ luaZ_Fopen(&z, f, filename);
status = protectedparser(L, &z, bin);
if (f != stdin)
fclose(f);
diff --git a/llimits.h b/llimits.h
@@ -1,5 +1,5 @@
/*
-** $Id: llimits.h,v 1.16 2000/10/03 14:03:21 roberto Exp roberto $
+** $Id: llimits.h,v 1.17 2000/10/06 19:28:38 roberto Exp roberto $
** Limits, basic types, and some other "installation-dependent" definitions
** See Copyright Notice in lua.h
*/
@@ -104,7 +104,7 @@ typedef unsigned long Instruction;
/*
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
-** so they must fit in BITS_INT-1 bits (-1 for signal)
+** so they must fit in BITS_INT-1 bits (-1 for sign)
*/
#if SIZE_U < BITS_INT-1
#define MAXARG_U ((1<<SIZE_U)-1)
@@ -196,10 +196,4 @@ typedef unsigned long Instruction;
#endif
-/* maximum part of a file name kept for error messages */
-#ifndef MAXFILENAME
-#define MAXFILENAME 260
-#endif
-
-
#endif
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 1.51 2000/10/03 14:03:21 roberto Exp roberto $
+** $Id: lobject.c,v 1.52 2000/10/05 12:14:08 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -87,23 +87,31 @@ void luaO_verror (lua_State *L, const char *fmt, ...) {
}
-#define EXTRALEN sizeof("string \"...\"0")
+#define EXTRALEN sizeof(" string \"s...\" ")
-void luaO_chunkid (char *out, const char *source, int len) {
- if (*source == '(') {
- strncpy(out, source+1, len-1); /* remove first char */
- out[len-1] = '\0'; /* make sure `out' has an end */
- out[strlen(out)-1] = '\0'; /* remove last char */
- }
+void luaO_chunkid (char *out, const char *source, int bufflen) {
+ if (*source == '=')
+ sprintf(out, "%.*s", bufflen, source+1); /* remove first char */
else {
- len -= EXTRALEN;
- if (*source == '@')
- sprintf(out, "file `%.*s'", len, source+1);
+ bufflen -= EXTRALEN;
+ if (*source == '@') {
+ int l;
+ source++; /* skip the `@' */
+ l = strlen(source);
+ if (l>bufflen) {
+ source += (l-bufflen); /* get last part of file name */
+ sprintf(out, "file `...%s'", source);
+ }
+ else
+ sprintf(out, "file `%s'", source);
+ }
else {
- const char *b = strchr(source , '\n'); /* stop at first new line */
- int lim = (b && (b-source)<len) ? b-source : len;
- sprintf(out, "string \"%.*s\"", lim, source);
- strcpy(out+lim+(EXTRALEN-sizeof("...\"0")), "...\"");
+ int len = strcspn(source, "\n"); /* stop at first newline */
+ if (len > bufflen) len = bufflen;
+ if (source[len] != '\0') /* must truncate? */
+ sprintf(out, "string \"%.*s...\"", len, source);
+ else
+ sprintf(out, "string \"%s\"", source);
}
}
}