diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-09 11:47:32 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-09 11:47:32 -0200 |
| commit | d6232a0b2e53d6bd374c762a4f47e7a8799de5d2 (patch) | |
| tree | ec882867b57b126f4f53fae5bd599768a2635408 /lobject.c | |
| parent | ae63a0e692fdc64a2bbafcb6ff10ecbdf3946f88 (diff) | |
| download | lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.gz lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.tar.bz2 lua-d6232a0b2e53d6bd374c762a4f47e7a8799de5d2.zip | |
better treatment for source names
Diffstat (limited to 'lobject.c')
| -rw-r--r-- | lobject.c | 38 |
1 files changed, 23 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.51 2000/10/03 14:03:21 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.52 2000/10/05 12:14:08 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -87,23 +87,31 @@ void luaO_verror (lua_State *L, const char *fmt, ...) { | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | 89 | ||
| 90 | #define EXTRALEN sizeof("string \"...\"0") | 90 | #define EXTRALEN sizeof(" string \"s...\" ") |
| 91 | 91 | ||
| 92 | void luaO_chunkid (char *out, const char *source, int len) { | 92 | void luaO_chunkid (char *out, const char *source, int bufflen) { |
| 93 | if (*source == '(') { | 93 | if (*source == '=') |
| 94 | strncpy(out, source+1, len-1); /* remove first char */ | 94 | sprintf(out, "%.*s", bufflen, source+1); /* remove first char */ |
| 95 | out[len-1] = '\0'; /* make sure `out' has an end */ | ||
| 96 | out[strlen(out)-1] = '\0'; /* remove last char */ | ||
| 97 | } | ||
| 98 | else { | 95 | else { |
| 99 | len -= EXTRALEN; | 96 | bufflen -= EXTRALEN; |
| 100 | if (*source == '@') | 97 | if (*source == '@') { |
| 101 | sprintf(out, "file `%.*s'", len, source+1); | 98 | int l; |
| 99 | source++; /* skip the `@' */ | ||
| 100 | l = strlen(source); | ||
| 101 | if (l>bufflen) { | ||
| 102 | source += (l-bufflen); /* get last part of file name */ | ||
| 103 | sprintf(out, "file `...%s'", source); | ||
| 104 | } | ||
| 105 | else | ||
| 106 | sprintf(out, "file `%s'", source); | ||
| 107 | } | ||
| 102 | else { | 108 | else { |
| 103 | const char *b = strchr(source , '\n'); /* stop at first new line */ | 109 | int len = strcspn(source, "\n"); /* stop at first newline */ |
| 104 | int lim = (b && (b-source)<len) ? b-source : len; | 110 | if (len > bufflen) len = bufflen; |
| 105 | sprintf(out, "string \"%.*s\"", lim, source); | 111 | if (source[len] != '\0') /* must truncate? */ |
| 106 | strcpy(out+lim+(EXTRALEN-sizeof("...\"0")), "...\""); | 112 | sprintf(out, "string \"%.*s...\"", len, source); |
| 113 | else | ||
| 114 | sprintf(out, "string \"%s\"", source); | ||
| 107 | } | 115 | } |
| 108 | } | 116 | } |
| 109 | } | 117 | } |
