diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua')
20 files changed, 1449 insertions, 422 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c index c85a1912e49..f06445e62fe 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c @@ -21,7 +21,7 @@ #include <ptexlib.h> static const char _svn_version[] = - "$Id: lcallbacklib.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lcallbacklib.c $"; + "$Id: lcallbacklib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lcallbacklib.c $"; extern int do_run_callback(int special, char *values, va_list vl); extern int lua_traceback(lua_State * L); @@ -430,7 +430,10 @@ static int callback_register(lua_State * L) { int cb; char *s; - if (!lua_isstring(L, 1) || ((!lua_isfunction(L, 2)) && !lua_isnil(L, 2))) { + if (!lua_isstring(L, 1) || + ((!lua_isfunction(L, 2)) && + (!lua_isnil(L, 2)) && + (!(lua_isboolean(L, 2) && lua_toboolean(L,2)==0)))) { lua_pushnil(L); lua_pushstring(L, "Invalid arguments to callback.register."); return 2; @@ -447,6 +450,8 @@ static int callback_register(lua_State * L) } if (lua_isfunction(L, 2)) { callback_set[cb] = cb; + } else if (lua_isboolean(L, 2)) { + callback_set[cb] = -1; } else { callback_set[cb] = 0; } diff --git a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c index 6dd698ffe0a..266553aef45 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lfontlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lfontlib.c @@ -22,7 +22,14 @@ #include "nodes.h" static const char _svn_version[] = - "$Id: lfontlib.c 1226 2008-05-02 16:11:02Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lfontlib.c $"; + "$Id: lfontlib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lfontlib.c $"; + +#define TIMERS 0 + +#if TIMERS +# include <sys/time.h> +#endif + /* this function is in vfovf.c for the moment */ extern int make_vf_table(lua_State * L, char *name, scaled s); @@ -188,10 +195,27 @@ static int setfont(lua_State * L) static int deffont(lua_State * L) { int i; +#if TIMERS + struct timeval tva; + struct timeval tvb; + double tvdiff; +#endif luaL_checktype(L, -1, LUA_TTABLE); - i = new_font(); +#if TIMERS + gettimeofday(&tva, NULL); +#endif if (font_from_lua(L, i)) { +#if TIMERS + gettimeofday(&tvb, NULL); + tvdiff = tvb.tv_sec * 1000000.0; + tvdiff += (double) tvb.tv_usec; + tvdiff -= (tva.tv_sec * 1000000.0); + tvdiff -= (double) tva.tv_usec; + tvdiff /= 1000000; + fprintf(stdout, "font.define(%s,%i): %f seconds\n", + font_fullname(i),i, tvdiff); +#endif lua_pushnumber(L, i); return 1; } else { diff --git a/Build/source/texk/web2c/luatexdir/lua/limglib.c b/Build/source/texk/web2c/luatexdir/lua/limglib.c index 44b3a04712d..1054a03a779 100644 --- a/Build/source/texk/web2c/luatexdir/lua/limglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/limglib.c @@ -27,7 +27,7 @@ #include "../luatex-api.h" static const char _svn_version[] = - "$Id: limglib.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/limglib.c $"; + "$Id: limglib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/limglib.c $"; /**********************************************************************/ @@ -729,7 +729,7 @@ static const struct luaL_Reg imglib[] = { void vf_out_image(unsigned i) { image *a, **aa; - lua_State *L = Luas; /* ... */ + lua_State *L = Luas; /* ... */ lua_rawgeti(L, LUA_GLOBALSINDEX, i); /* image ... */ aa = (image **) luaL_checkudata(L, -1, TYPE_IMG); a = *aa; diff --git a/Build/source/texk/web2c/luatexdir/lua/liolib.c b/Build/source/texk/web2c/luatexdir/lua/liolib.c new file mode 100644 index 00000000000..5d10744c10b --- /dev/null +++ b/Build/source/texk/web2c/luatexdir/lua/liolib.c @@ -0,0 +1,667 @@ +/* +** $Id: liolib.c 2271 2009-04-12 23:42:21Z oneiros $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define liolib_c +#define LUA_LIB + +#ifndef MINGW32 +# define LUA_USE_POSIX 1 +#endif + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + +#include <ptexlib.h> + +#define IO_INPUT 1 +#define IO_OUTPUT 2 + +extern int shell_cmd_is_allowed(char **cmd, char **safecmd, char **cmdname); + +static const char *const fnames[] = { "input", "output" }; + + +static int pushresult(lua_State * L, int i, const char *filename) +{ + int en = errno; /* calls to Lua API may change this value */ + if (i) { + lua_pushboolean(L, 1); + return 1; + } else { + lua_pushnil(L); + if (filename) + lua_pushfstring(L, "%s: %s", filename, strerror(en)); + else + lua_pushfstring(L, "%s", strerror(en)); + lua_pushinteger(L, en); + return 3; + } +} + + +static void fileerror(lua_State * L, int arg, const char *filename) +{ + lua_pushfstring(L, "%s: %s", filename, strerror(errno)); + luaL_argerror(L, arg, lua_tostring(L, -1)); +} + + +#define topfile(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + + +static int io_type(lua_State * L) +{ + void *ud; + luaL_checkany(L, 1); + ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **) ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static FILE *tofile(lua_State * L) +{ + FILE **f = topfile(L); + if (*f == NULL) + luaL_error(L, "attempt to use a closed file"); + return *f; +} + + + +/* +** When creating file handles, always creates a `closed' file handle +** before opening the actual file; so, if there is a memory error, the +** file is not left opened. +*/ +static FILE **newfile(lua_State * L) +{ + FILE **pf = (FILE **) lua_newuserdata(L, sizeof(FILE *)); + *pf = NULL; /* file handle is currently `closed' */ + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); + return pf; +} + + +/* +** this function has a separated environment, which defines the +** correct __close for 'popen' files +*/ +static int io_pclose(lua_State * L) +{ + FILE **p = topfile(L); + int ok = lua_pclose(L, *p); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int io_fclose(lua_State * L) +{ + FILE **p = topfile(L); + int ok = (fclose(*p) == 0); + *p = NULL; + return pushresult(L, ok, NULL); +} + + +static int aux_close(lua_State * L) +{ + lua_getfenv(L, 1); + lua_getfield(L, -1, "__close"); + return (lua_tocfunction(L, -1)) (L); +} + + +static int io_close(lua_State * L) +{ + if (lua_isnone(L, 1)) + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); + tofile(L); /* make sure argument is a file */ + return aux_close(L); +} + + +static int io_gc(lua_State * L) +{ + FILE *f = *topfile(L); + /* ignore closed files and standard files */ + if (f != NULL && f != stdin && f != stdout && f != stderr) + aux_close(L); + return 0; +} + + +static int io_tostring(lua_State * L) +{ + FILE *f = *topfile(L); + if (f == NULL) + lua_pushstring(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", f); + return 1; +} + + +static int io_open(lua_State * L) +{ + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + +static int io_open_ro(lua_State * L) +{ + FILE **pf; + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + if ((strcmp(mode, "r") != 0) && (strcmp(mode, "rb") != 0)) + return pushresult(L, 0, filename); + pf = newfile(L); + *pf = fopen(filename, mode); + return (*pf == NULL) ? pushresult(L, 0, filename) : 1; +} + + + + + +static int io_popen(lua_State * L) +{ + int ret = 1; + char *safecmd = NULL; + char *cmdname = NULL; + int allow = 0; + char *cmd = (char *) luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + FILE **pf = newfile(L); + + if (shellenabledp <= 0) { + lua_pushnil(L); + lua_pushliteral(L, "All command execution is disabled"); + return 2; + } + /* If restrictedshell == 0, any command is allowed. */ + if (restrictedshell == 0) + allow = 1; + else + allow = shell_cmd_is_allowed(&cmd, &safecmd, &cmdname); + + if (allow == 1) { + *pf = lua_popen(L, cmd, mode); + ret = (*pf == NULL) ? pushresult(L, 0, cmd) : 1; + } else if (allow == 2) { + *pf = lua_popen(L, safecmd, mode); + ret = (*pf == NULL) ? pushresult(L, 0, safecmd) : 1; + } else if (allow == 0) { + lua_pushnil(L); + lua_pushliteral(L, "Command execution disabled via shell_escape='p'"); + ret = 2; + } else { + lua_pushnil(L); + lua_pushliteral(L, "Bad command line quoting"); + ret = 2; + } + return ret; +} + + +static int io_tmpfile(lua_State * L) +{ + FILE **pf = newfile(L); + *pf = tmpfile(); + return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile(lua_State * L, int findex) +{ + FILE *f; + lua_rawgeti(L, LUA_ENVIRONINDEX, findex); + f = *(FILE **) lua_touserdata(L, -1); + if (f == NULL) + luaL_error(L, "standard %s file is closed", fnames[findex - 1]); + return f; +} + + +static int g_iofile(lua_State * L, int f, const char *mode) +{ + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) { + FILE **pf = newfile(L); + *pf = fopen(filename, mode); + if (*pf == NULL) + fileerror(L, 1, filename); + } else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_rawseti(L, LUA_ENVIRONINDEX, f); + } + /* return current value */ + lua_rawgeti(L, LUA_ENVIRONINDEX, f); + return 1; +} + + +static int io_input(lua_State * L) +{ + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output(lua_State * L) +{ + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline(lua_State * L); + + +static void aux_lines(lua_State * L, int idx, int toclose) +{ + lua_pushvalue(L, idx); + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_pushcclosure(L, io_readline, 2); +} + + +static int f_lines(lua_State * L) +{ + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 1, 0); + return 1; +} + + +static int io_lines(lua_State * L) +{ + if (lua_isnoneornil(L, 1)) { /* no arguments? */ + /* will iterate over default input */ + lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); + return f_lines(L); + } else { + const char *filename = luaL_checkstring(L, 1); + FILE **pf = newfile(L); + *pf = fopen(filename, "r"); + if (*pf == NULL) + fileerror(L, 1, filename); + aux_lines(L, lua_gettop(L), 1); + return 1; + } +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +static int read_number(lua_State * L, FILE * f) +{ + lua_Number d; + if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + lua_pushnumber(L, d); + return 1; + } else + return 0; /* read fails */ +} + + +static int test_eof(lua_State * L, FILE * f) +{ + int c = getc(f); + ungetc(c, f); + lua_pushlstring(L, NULL, 0); + return (c != EOF); +} + +#if 0 +static int read_line(lua_State * L, FILE * f) +{ + luaL_Buffer b; + luaL_buffinit(L, &b); + for (;;) { + size_t l; + char *p = luaL_prepbuffer(&b); + if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ + luaL_pushresult(&b); /* close buffer */ + return (lua_strlen(L, -1) > 0); /* check whether read something */ + } + l = strlen(p); + if (l == 0 || p[l - 1] != '\n') + luaL_addsize(&b, l); + else { + luaL_addsize(&b, l - 1); /* do not include `eol' */ + luaL_pushresult(&b); /* close buffer */ + return 1; /* read at least an `eol' */ + } + } +} +#endif + +/* this new version does not care wether the file has + line endings using an 'alien' convention */ + +static int new_read_line(lua_State * L, FILE * f) +{ + luaL_Buffer buf; + int c, d; + luaL_buffinit(L, &buf); + while (1) { + c = fgetc(f); + if (c == EOF) { + luaL_pushresult(&buf); /* close buffer */ + return (lua_strlen(L, -1) > 0); /* check whether read something */ + }; + if (c == '\n') { + break; + } else if (c == '\r') { + d = fgetc(f); + if (d != EOF && d != '\n') + ungetc(d, f); + break; + } else { + luaL_addchar(&buf, c); + } + } + luaL_pushresult(&buf); /* close buffer */ + return 1; +} + + +static int read_chars(lua_State * L, FILE * f, size_t n) +{ + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + luaL_Buffer b; + luaL_buffinit(L, &b); + rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ + do { + char *p = luaL_prepbuffer(&b); + if (rlen > n) + rlen = n; /* cannot read more than asked */ + nr = fread(p, sizeof(char), rlen, f); + luaL_addsize(&b, nr); + n -= nr; /* still have to read `n' chars */ + } while (n > 0 && nr == rlen); /* until end of count or eof */ + luaL_pushresult(&b); /* close buffer */ + return (n == 0 || lua_strlen(L, -1) > 0); +} + +static int read_all(lua_State * L, FILE * f) +{ + /* attempt to speed up reading whole files */ + size_t rlen; /* how much to read */ + size_t nr; /* number of chars actually read */ + size_t old; /* old file location */ + char *p; + old = ftell(f); + if (old > 0 && (fseek(f, 0, SEEK_END) >= 0) && ((rlen = ftell(f)) > 0) && rlen < 1000 * 1000 * 100) { /* 100 MB */ + fseek(f, old, SEEK_SET); + p = malloc(rlen); + if (p != NULL) { + nr = fread(p, sizeof(char), rlen, f); + lua_pushlstring(L, p, nr); + free(p); + return 1; + } + } + if (old > 0) + fseek(f, old, SEEK_SET); + return read_chars(L, f, ~((size_t) 0)); +} + + +static int g_read(lua_State * L, FILE * f, int first) +{ + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = new_read_line(L, f); + n = first + 1; /* to return 1 result */ + } else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t) lua_tointeger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } else { + const char *p = lua_tostring(L, n); + luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); + switch (p[1]) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = new_read_line(L, f); + break; + case 'a': /* file */ + read_all(L, f); + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return pushresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + +static int io_read(lua_State * L) +{ + return g_read(L, getiofile(L, IO_INPUT), 1); +} + +static int f_read(lua_State * L) +{ + return g_read(L, tofile(L), 2); +} + +static int io_readline(lua_State * L) +{ + FILE *f = *(FILE **) lua_touserdata(L, lua_upvalueindex(1)); + int sucess; + if (f == NULL) /* file is already closed? */ + luaL_error(L, "file is already closed"); + sucess = new_read_line(L, f); + if (ferror(f)) + return luaL_error(L, "%s", strerror(errno)); + if (sucess) + return 1; + else { /* EOF */ + if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write(lua_State * L, FILE * f, int arg) +{ + int nargs = lua_gettop(L) - 1; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + status = status && + fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; + } else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + return pushresult(L, status, NULL); +} + + +static int io_write(lua_State * L) +{ + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write(lua_State * L) +{ + return g_write(L, tofile(L), 2); +} + + +static int f_seek(lua_State * L) +{ + static const int mode[] = { SEEK_SET, SEEK_CUR, SEEK_END }; + static const char *const modenames[] = { "set", "cur", "end", NULL }; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + long offset = luaL_optlong(L, 3, 0); + op = fseek(f, offset, mode[op]); + if (op) + return pushresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, ftell(f)); + return 1; + } +} + + +static int f_setvbuf(lua_State * L) +{ + static const int mode[] = { _IONBF, _IOFBF, _IOLBF }; + static const char *const modenames[] = { "no", "full", "line", NULL }; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], sz); + return pushresult(L, res == 0, NULL); +} + + + +static int io_flush(lua_State * L) +{ + return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush(lua_State * L) +{ + return pushresult(L, fflush(tofile(L)) == 0, NULL); +} + + +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"open_ro", io_open_ro}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +static const luaL_Reg flib[] = { + {"close", io_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", io_gc}, + {"__tostring", io_tostring}, + {NULL, NULL} +}; + + +static void createmeta(lua_State * L) +{ + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_register(L, NULL, flib); /* file methods */ +} + + +static void createstdfile(lua_State * L, FILE * f, int k, const char *fname) +{ + *newfile(L) = f; + if (k > 0) { + lua_pushvalue(L, -1); + lua_rawseti(L, LUA_ENVIRONINDEX, k); + } + lua_setfield(L, -2, fname); +} + + +LUALIB_API int luaopen_io(lua_State * L) +{ + createmeta(L); + /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ + lua_createtable(L, 2, 1); + lua_replace(L, LUA_ENVIRONINDEX); + /* open library */ + luaL_register(L, LUA_IOLIBNAME, iolib); + /* create (and set) default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, 0, "stderr"); + /* create environment for 'popen' */ + lua_getfield(L, -1, "popen"); + lua_createtable(L, 0, 1); + lua_pushcfunction(L, io_pclose); + lua_setfield(L, -2, "__close"); + lua_setfenv(L, -2); + lua_pop(L, 1); /* pop 'popen' */ + /* set default close function */ + lua_pushcfunction(L, io_fclose); + lua_setfield(L, LUA_ENVIRONINDEX, "__close"); + return 1; +} diff --git a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c index 23bd37e2f5f..37a5d96cddd 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lkpselib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lkpselib.c @@ -25,7 +25,7 @@ #include <kpathsea/readable.h> static const char _svn_version[] = - "$Id: lkpselib.c 2093 2009-03-23 11:44:13Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lkpselib.c $"; + "$Id: lkpselib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lkpselib.c $"; static const int filetypes[] = { kpse_gf_format, @@ -197,7 +197,7 @@ static int lua_kpathsea_find_file(lua_State * L) int i; int ftype = kpse_tex_format; int mexist = 0; - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); char *st = (char *) luaL_checkstring(L, 2); i = lua_gettop(L); while (i > 2) { @@ -240,10 +240,10 @@ static int show_path(lua_State * L) static int lua_kpathsea_show_path(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); int op = luaL_checkoption(L, -1, "tex", filetypenames); int user_format = filetypes[op]; - if (!(*kp)->format_info[user_format].type) /* needed if arg was numeric */ + if (!(*kp)->format_info[user_format].type) /* needed if arg was numeric */ kpathsea_init_format(*kp, user_format); lua_pushstring(L, (*kp)->format_info[user_format].path); return 1; @@ -259,7 +259,7 @@ static int expand_path(lua_State * L) static int lua_kpathsea_expand_path(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *st = luaL_checkstring(L, 2); lua_pushstring(L, kpathsea_path_expand(*kp, st)); return 1; @@ -275,7 +275,7 @@ static int expand_braces(lua_State * L) static int lua_kpathsea_expand_braces(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *st = luaL_checkstring(L, 2); lua_pushstring(L, kpathsea_brace_expand(*kp, st)); return 1; @@ -292,7 +292,7 @@ static int expand_var(lua_State * L) static int lua_kpathsea_expand_var(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *st = luaL_checkstring(L, 2); lua_pushstring(L, kpathsea_var_expand(*kp, st)); return 1; @@ -309,7 +309,7 @@ static int var_value(lua_State * L) static int lua_kpathsea_var_value(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *st = luaL_checkstring(L, 2); lua_pushstring(L, kpathsea_var_value(*kp, st)); return 1; @@ -358,12 +358,12 @@ static int init_prog(lua_State * L) static int lua_kpathsea_init_prog(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *prefix = luaL_checkstring(L, 2); unsigned dpi = luaL_checkinteger(L, 3); const char *mode = luaL_checkstring(L, 4); const char *fallback = luaL_optstring(L, 5, NULL); - kpathsea_init_prog(*kp,prefix, dpi, mode, fallback); + kpathsea_init_prog(*kp, prefix, dpi, mode, fallback); return 0; } @@ -377,16 +377,16 @@ static int readable_file(lua_State * L) static int lua_kpathsea_readable_file(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); const char *name = luaL_checkstring(L, 2); - lua_pushstring(L, (char *) kpathsea_readable_file(*kp,name)); + lua_pushstring(L, (char *) kpathsea_readable_file(*kp, name)); return 1; } static int lua_kpathsea_finish(lua_State * L) { - kpathsea *kp = (kpathsea *)luaL_checkudata(L, 1, KPATHSEA_METATABLE); + kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE); kpathsea_finish(*kp); return 0; } @@ -395,41 +395,41 @@ static int lua_kpathsea_new(lua_State * L) { kpathsea kpse = NULL; kpathsea *kp = NULL; - char *argv = (char *)luaL_checkstring(L,1); - char *liar = (char *)luaL_optstring(L,2,argv); + char *argv = (char *) luaL_checkstring(L, 1); + char *liar = (char *) luaL_optstring(L, 2, argv); kpse = kpathsea_new(); kpathsea_set_program_name(kpse, argv, liar); - kp = (kpathsea *)lua_newuserdata(L, sizeof(kpathsea *)); + kp = (kpathsea *) lua_newuserdata(L, sizeof(kpathsea *)); *kp = kpse; luaL_getmetatable(L, KPATHSEA_METATABLE); - lua_setmetatable(L, -2); + lua_setmetatable(L, -2); return 1; } static const struct luaL_reg kpselib_m[] = { - {"__gc", lua_kpathsea_finish }, - {"init_prog", lua_kpathsea_init_prog }, - {"readable_file", lua_kpathsea_readable_file }, - {"find_file", lua_kpathsea_find_file }, - {"expand_path", lua_kpathsea_expand_path }, - {"expand_var", lua_kpathsea_expand_var }, - {"expand_braces", lua_kpathsea_expand_braces }, - {"var_value", lua_kpathsea_var_value }, - {"show_path", lua_kpathsea_show_path }, + {"__gc", lua_kpathsea_finish}, + {"init_prog", lua_kpathsea_init_prog}, + {"readable_file", lua_kpathsea_readable_file}, + {"find_file", lua_kpathsea_find_file}, + {"expand_path", lua_kpathsea_expand_path}, + {"expand_var", lua_kpathsea_expand_var}, + {"expand_braces", lua_kpathsea_expand_braces}, + {"var_value", lua_kpathsea_var_value}, + {"show_path", lua_kpathsea_show_path}, {NULL, NULL} /* sentinel */ }; static const struct luaL_reg kpselib_l[] = { - {"new", lua_kpathsea_new }, - {"set_program_name", set_program_name }, - {"init_prog", init_prog }, - {"readable_file", readable_file }, - {"find_file", find_file }, - {"expand_path", expand_path }, - {"expand_var", expand_var }, - {"expand_braces", expand_braces }, - {"var_value", var_value }, - {"show_path", show_path }, + {"new", lua_kpathsea_new}, + {"set_program_name", set_program_name}, + {"init_prog", init_prog}, + {"readable_file", readable_file}, + {"find_file", find_file}, + {"expand_path", expand_path}, + {"expand_var", expand_var}, + {"expand_braces", expand_braces}, + {"var_value", var_value}, + {"show_path", show_path}, {NULL, NULL} /* sentinel */ }; @@ -437,7 +437,7 @@ int luaopen_kpse(lua_State * L) { luaL_newmetatable(L, KPATHSEA_METATABLE); lua_pushvalue(L, -1); - lua_setfield(L, -2,"__index"); + lua_setfield(L, -2, "__index"); luaL_register(L, NULL, kpselib_m); luaL_register(L, "kpse", kpselib_l); return 1; diff --git a/Build/source/texk/web2c/luatexdir/lua/llanglib.c b/Build/source/texk/web2c/luatexdir/lua/llanglib.c index 6aa634525b5..6ca78933d3a 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llanglib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llanglib.c @@ -23,7 +23,7 @@ #include "nodes.h" static const char _svn_version[] = - "$Id: llanglib.c 1594 2008-11-28 13:32:48Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/llanglib.c $"; + "$Id: llanglib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/llanglib.c $"; #define LANG_METATABLE "luatex.lang" diff --git a/Build/source/texk/web2c/luatexdir/lua/llualib.c b/Build/source/texk/web2c/luatexdir/lua/llualib.c index 7efff052754..cfd3b783ed6 100644 --- a/Build/source/texk/web2c/luatexdir/lua/llualib.c +++ b/Build/source/texk/web2c/luatexdir/lua/llualib.c @@ -21,7 +21,7 @@ #include <ptexlib.h> static const char _svn_version[] = - "$Id: llualib.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/llualib.c $"; + "$Id: llualib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/llualib.c $"; #define LOAD_BUF_SIZE 256 #define UINT_MAX32 0xFFFFFFFF @@ -35,17 +35,16 @@ typedef struct { static bytecode *lua_bytecode_registers = NULL; -int luabytecode_max = -1; +integer luabytecode_max = -1; unsigned int luabytecode_bytes = 0; -char *luanames[65536] = {NULL}; +char *luanames[65536] = { NULL }; extern char *luanames[]; -char * -get_lua_name (int i) +char *get_lua_name(int i) { - if (i<0 || i>65535) + if (i < 0 || i > 65535) return NULL; return luanames[i]; } @@ -53,7 +52,7 @@ get_lua_name (int i) void dump_luac_registers(void) { integer x; - int k, n; + integer k, n; bytecode b; dump_int(luabytecode_max); if (lua_bytecode_registers != NULL) { @@ -74,12 +73,12 @@ void dump_luac_registers(void) } for (k = 0; k < 65536; k++) { char *a = luanames[k]; - if (a!=NULL) { - x = strlen(a)+1; - dump_int(x); + if (a != NULL) { + x = strlen(a) + 1; + dump_int(x); dump_things(*a, x); } else { - x = 0; + x = 0; dump_int(x); } } @@ -88,7 +87,7 @@ void dump_luac_registers(void) void undump_luac_registers(void) { integer x; - int k, n; + integer k, n; unsigned int i; bytecode b; undump_int(luabytecode_max); @@ -107,7 +106,8 @@ void undump_luac_registers(void) undump_int(n); for (i = 0; i < (unsigned) n; i++) { undump_int(k); - undump_int(b.size); + undump_int(x); + b.size = x; b.buf = xmalloc(b.size); luabytecode_bytes += b.size; memset(b.buf, 0, b.size); @@ -162,7 +162,7 @@ static int bytecode_register_shadow_get(lua_State * L, int k) int writer(lua_State * L, const void *b, size_t size, void *B) { bytecode *buf = (bytecode *) B; - (void)L; /* for -Wunused */ + (void) L; /* for -Wunused */ if ((int) (buf->size + size) > buf->alloc) { buf->buf = xrealloc(buf->buf, buf->alloc + size + LOAD_BUF_SIZE); buf->alloc = buf->alloc + size + LOAD_BUF_SIZE; @@ -176,7 +176,7 @@ int writer(lua_State * L, const void *b, size_t size, void *B) const char *reader(lua_State * L, void *ud, size_t * size) { bytecode *buf = (bytecode *) ud; - (void)L; /* for -Wunused */ + (void) L; /* for -Wunused */ if (buf->done == buf->size) { *size = 0; buf->done = 0; @@ -269,9 +269,9 @@ int set_luaname(lua_State * L) { int k; char *s; - if (lua_gettop(L)==3) { + if (lua_gettop(L) == 3) { k = (int) luaL_checkinteger(L, 2); - if (k>65535 || k<0) { + if (k > 65535 || k < 0) { /* error */ } else { if (luanames[k] != NULL) { @@ -279,8 +279,8 @@ int set_luaname(lua_State * L) luanames[k] = NULL; } if (lua_isstring(L, 3)) { - s = (char *) lua_tostring(L,3); - if (s!=NULL) + s = (char *) lua_tostring(L, 3); + if (s != NULL) luanames[k] = xstrdup(s); } } @@ -292,13 +292,13 @@ int get_luaname(lua_State * L) { int k; k = (int) luaL_checkinteger(L, 2); - if (k>65535 || k<0) { + if (k > 65535 || k < 0) { /* error */ lua_pushnil(L); } else { - if (luanames[k]!=NULL) + if (luanames[k] != NULL) lua_pushstring(L, luanames[k]); - else + else lua_pushnil(L); } return 1; diff --git a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c index 0bbbc021987..65f39ca21b3 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lnodelib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lnodelib.c @@ -25,7 +25,7 @@ #include "commands.h" static const char _svn_version[] = - "$Id: lnodelib.c 2027 2009-03-14 18:47:32Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lnodelib.c $"; + "$Id: lnodelib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lnodelib.c $"; #define init_luaS_index(a) do { \ lua_pushliteral(L,#a); \ @@ -450,7 +450,7 @@ static int lua_nodelib_append(lua_State * L) j = lua_gettop(L); for (i = 1; i <= j; i++) { n = check_isnode(L, i); - m = copy_node_list(*n); + m = *n; new_tail_append(m); while (vlink(m) != null) { m = vlink(m); @@ -786,8 +786,8 @@ static int lua_nodelib_has_attribute(lua_State * L) n = check_isnode(L, 1); if (n != NULL) { i = lua_tointeger(L, 2); - val = luaL_optinteger(L, 3, -1); - if ((val = has_attribute(*n, i, val)) >= 0) { + val = luaL_optinteger(L, 3, UNUSED_ATTRIBUTE); + if ((val = has_attribute(*n, i, val)) > UNUSED_ATTRIBUTE) { lua_pushnumber(L, val); return 1; } @@ -804,7 +804,7 @@ static int lua_nodelib_set_attribute(lua_State * L) i = lua_tointeger(L, 2); val = lua_tointeger(L, 3); n = check_isnode(L, 1); - if (val < 0) { + if (val == UNUSED_ATTRIBUTE) { (void) unset_attribute(*n, i, val); } else { set_attribute(*n, i, val); @@ -823,10 +823,10 @@ static int lua_nodelib_unset_attribute(lua_State * L) int i, val, ret; if (lua_gettop(L) <= 3) { i = luaL_checknumber(L, 2); - val = luaL_optnumber(L, 3, -1); + val = luaL_optnumber(L, 3, UNUSED_ATTRIBUTE); n = check_isnode(L, 1); ret = unset_attribute(*n, i, val); - if (ret >= 0) { + if (ret > UNUSED_ATTRIBUTE) { lua_pushnumber(L, ret); } else { lua_pushnil(L); @@ -1093,7 +1093,11 @@ static void lua_nodelib_getfield_whatsit(lua_State * L, int n, int field) lua_pushnumber(L, pdf_literal_mode(n)); break; case 5: - tokenlist_to_luastring(L, pdf_literal_data(n)); + if (pdf_literal_type(n)==lua_refid_literal) { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(n)); + } else { + tokenlist_to_luastring(L, pdf_literal_data(n)); + } break; default: lua_pushnil(L); @@ -1680,17 +1684,7 @@ static int lua_nodelib_getfield(lua_State * L) lua_pushnil(L); } break; - case ord_noad: - case op_noad: - case bin_noad: - case rel_noad: - case open_noad: - case close_noad: - case punct_noad: - case inner_noad: - case under_noad: - case over_noad: - case vcenter_noad: + case simple_noad: switch (field) { case 2: lua_pushnumber(L, subtype(n)); @@ -2169,8 +2163,14 @@ static int lua_nodelib_setfield_whatsit(lua_State * L, int n, int field) pdf_literal_mode(n) = lua_tointeger(L, 3); break; case 5: - pdf_literal_data(n) = nodelib_gettoks(L, 3); - break; + if (ini_version) { + pdf_literal_data(n) = nodelib_gettoks(L, 3); + } else { + lua_pushvalue(L,3); + pdf_literal_data(n) = luaL_ref(L,LUA_REGISTRYINDEX); + pdf_literal_type(n) = lua_refid_literal; + } + break; default: return nodelib_cantset(L, field, n); } @@ -2786,17 +2786,7 @@ static int lua_nodelib_setfield(lua_State * L) return nodelib_cantset(L, field, n); } break; - case ord_noad: - case op_noad: - case bin_noad: - case rel_noad: - case open_noad: - case close_noad: - case punct_noad: - case inner_noad: - case under_noad: - case over_noad: - case vcenter_noad: + case simple_noad: switch (field) { case 2: subtype(n) = lua_tointeger(L, 3); diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c index 5f5da8dd6f5..eebb4e8e49e 100644 --- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c @@ -25,14 +25,16 @@ #include <time.h> static const char _svn_version[] = - "$Id: loslibext.c 1594 2008-11-28 13:32:48Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/loslibext.c $"; + "$Id: loslibext.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/loslibext.c $"; #if defined(_WIN32) || defined(WIN32) || defined(__NT__) -#define MKDIR(a,b) mkdir(a) +# define MKDIR(a,b) mkdir(a) #else -#define MKDIR(a,b) mkdir(a,b) +# define MKDIR(a,b) mkdir(a,b) #endif +extern int shell_cmd_is_allowed(char **cmd, char **safecmd, char **cmdname); + /* An attempt to figure out the basic platform, does not care about niceties like version numbers yet, and ignores platforms where luatex is unlikely to @@ -351,7 +353,9 @@ static char **do_flatten_command(lua_State * L, char **runcmd) static int os_exec(lua_State * L) { - char *maincmd, *runcmd; + int allow = 0; + char *maincmd = NULL, *runcmd = NULL; + char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; if (lua_gettop(L) != 1) { @@ -359,6 +363,11 @@ static int os_exec(lua_State * L) lua_pushliteral(L, "invalid arguments passed"); return 2; } + if (shellenabledp <= 0) { + lua_pushnil(L); + lua_pushliteral(L, "All command execution disabled."); + return 2; + } if (lua_type(L, 1) == LUA_TSTRING) { maincmd = (char *) lua_tostring(L, 1); cmdline = do_split_command(maincmd); @@ -366,33 +375,65 @@ static int os_exec(lua_State * L) } else if (lua_type(L, 1) == LUA_TTABLE) { cmdline = do_flatten_command(L, &runcmd); } - if (cmdline != NULL) { + /* If restrictedshell == 0, any command is allowed. */ + /* this is a little different from \write18/ os.execute processing + * because it does not test for commands with fixed arguments, + * but I am not so eager to attempt to fix that. Just document + * that os.exec() checks only the command name. + */ + if (restrictedshell == 0) + allow = 1; + else + allow = shell_cmd_is_allowed(&runcmd, &safecmd, &cmdname); + + if (allow > 0 && cmdline != NULL && runcmd != NULL) { #if defined(WIN32) && DONT_REALLY_EXIT - exec_command(runcmd, cmdline, environ); + if (allow == 2) + exec_command(safecmd, cmdline, environ); + else + exec_command(runcmd, cmdline, environ); #else - if (exec_command(runcmd, cmdline, environ) == -1) { - lua_pushnil(L); - lua_pushfstring(L, "%s: %s", runcmd, strerror(errno)); - lua_pushnumber(L, errno); - return 3; + { + int r; + if (allow == 2) + r = exec_command(safecmd, cmdline, environ); + else + r = exec_command(runcmd, cmdline, environ); + if (r == -1) { + lua_pushnil(L); + lua_pushfstring(L, "%s: %s", runcmd, strerror(errno)); + lua_pushnumber(L, errno); + return 3; + } } #endif } + if (safecmd) + free(safecmd); + if (cmdname) + free(cmdname); + if (allow == 0) { + lua_pushnil(L); + lua_pushliteral(L, "Command execution disabled via shell_escape='p'"); + return 2; + } lua_pushnil(L); lua_pushliteral(L, "invalid command line passed"); return 2; } #define do_error_return(A,B) do { \ - lua_pushnil(L); \ - lua_pushfstring(L,"%s: %s",runcmd,(A)); \ - lua_pushnumber(L, B); \ - return 3; \ - } while (0) + lua_pushnil(L); \ + lua_pushfstring(L,"%s: %s",runcmd,(A)); \ + lua_pushnumber(L, B); \ + return 3; \ + } while (0) static int os_spawn(lua_State * L) { - char *maincmd, *runcmd; + int allow = 0; + char *maincmd = NULL, *runcmd = NULL; + char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; int i; @@ -401,6 +442,11 @@ static int os_spawn(lua_State * L) lua_pushliteral(L, "invalid arguments passed"); return 2; } + if (shellenabledp <= 0) { + lua_pushnil(L); + lua_pushliteral(L, "All command execution disabled."); + return 2; + } if (lua_type(L, 1) == LUA_TSTRING) { maincmd = (char *) lua_tostring(L, 1); cmdline = do_split_command(maincmd); @@ -408,8 +454,25 @@ static int os_spawn(lua_State * L) } else if (lua_type(L, 1) == LUA_TTABLE) { cmdline = do_flatten_command(L, &runcmd); } - if (cmdline != NULL) { - i = spawn_command(runcmd, cmdline, environ); + /* If restrictedshell == 0, any command is allowed. */ + /* this is a little different from \write18/ os.execute processing + * because it does not test for commands with fixed arguments, + * but I am not so eager to attempt to fix that. Just document + * that os.exec() checks only the command name. + */ + if (restrictedshell == 0) + allow = 1; + else + allow = shell_cmd_is_allowed(&runcmd, &safecmd, &cmdname); + if (allow > 0 && cmdline != NULL && runcmd != NULL) { + if (allow == 2) + i = spawn_command(safecmd, cmdline, environ); + else + i = spawn_command(runcmd, cmdline, environ); + if (safecmd) + free(safecmd); + if (cmdname) + free(cmdname); if (i == 0) { lua_pushnumber(L, i); return 1; @@ -437,6 +500,15 @@ static int os_spawn(lua_State * L) return 1; } } + if (safecmd) + free(safecmd); + if (cmdname) + free(cmdname); + if (allow == 0) { + lua_pushnil(L); + lua_pushliteral(L, "Command execution disabled via shell_escape='p'"); + return 2; + } lua_pushnil(L); lua_pushliteral(L, "invalid command line passed"); return 2; @@ -808,6 +880,46 @@ static int os_tmpdir(lua_State * L) } +static int os_execute(lua_State * L) +{ + int allow = 0; + int ret = 1; + char *safecmd = NULL; + char *cmdname = NULL; + char *cmd = (char *) luaL_optstring(L, 1, NULL); + + if (shellenabledp <= 0) { + lua_pushnil(L); + lua_pushstring(L, "All command execution disabled."); + return 2; + } + /* If restrictedshell == 0, any command is allowed. */ + if (restrictedshell == 0) + allow = 1; + else + allow = shell_cmd_is_allowed(&cmd, &safecmd, &cmdname); + + if (allow == 1) { + lua_pushinteger(L, system(cmd)); + } else if (allow == 2) { + lua_pushinteger(L, system(safecmd)); + } else { + lua_pushnil(L); + ret = 2; + if (allow == 0) + lua_pushstring(L, + "Command execution disabled via shell_escape='p'"); + else /* allow == -1 */ + lua_pushstring(L, "Quoting error in system command line."); + } + if (safecmd) + free(safecmd); + if (cmdname) + free(cmdname); + return ret; +} + + void open_oslibext(lua_State * L, int safer_option) { @@ -816,40 +928,32 @@ void open_oslibext(lua_State * L, int safer_option) lua_getglobal(L, "os"); lua_pushcfunction(L, ex_sleep); lua_setfield(L, -2, "sleep"); - lua_getglobal(L, "os"); lua_pushliteral(L, OS_PLATTYPE); lua_setfield(L, -2, "type"); - lua_getglobal(L, "os"); lua_pushliteral(L, OS_PLATNAME); lua_setfield(L, -2, "name"); - lua_getglobal(L, "os"); lua_pushcfunction(L, ex_uname); lua_setfield(L, -2, "uname"); #if (! defined (WIN32)) && (! defined (__SUNOS__)) - lua_getglobal(L, "os"); lua_pushcfunction(L, os_times); lua_setfield(L, -2, "times"); #endif #if ! defined (__SUNOS__) - lua_getglobal(L, "os"); lua_pushcfunction(L, os_gettimeofday); lua_setfield(L, -2, "gettimeofday"); #endif + if (!safer_option) { - lua_getglobal(L, "os"); lua_pushcfunction(L, os_setenv); lua_setfield(L, -2, "setenv"); - lua_getglobal(L, "os"); lua_pushcfunction(L, os_exec); lua_setfield(L, -2, "exec"); - lua_getglobal(L, "os"); lua_pushcfunction(L, os_spawn); lua_setfield(L, -2, "spawn"); - lua_getglobal(L, "os"); + lua_pushcfunction(L, os_execute); + lua_setfield(L, -2, "execute"); lua_pushcfunction(L, os_tmpdir); lua_setfield(L, -2, "tmpdir"); - } - - + lua_pop(L, 1); /* pop the table */ } diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c index 6c1558e47a6..da9f4328a04 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lpdflib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lpdflib.c @@ -21,7 +21,7 @@ #include <ptexlib.h> static const char _svn_version[] = - "$Id: lpdflib.c 2072 2009-03-21 08:50:20Z hhenkel $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lpdflib.c $"; + "$Id: lpdflib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lpdflib.c $"; static int findcurv(lua_State * L) { @@ -39,15 +39,13 @@ static int findcurh(lua_State * L) return 1; } -typedef enum { set_origin, direct_page, direct_always } pdf_lit_mode; - int luapdfprint(lua_State * L) { int n; unsigned i; size_t len; const char *outputstr, *st; - pdf_lit_mode literal_mode; + ctm_transform_modes literal_mode; n = lua_gettop(L); if (!lua_isstring(L, -1)) { lua_pushstring(L, "no string to print"); diff --git a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c index 586ded0db4f..d98cfadfcb4 100644 --- a/Build/source/texk/web2c/luatexdir/lua/lstatslib.c +++ b/Build/source/texk/web2c/luatexdir/lua/lstatslib.c @@ -22,7 +22,7 @@ static const char _svn_version[] = - "$Id: lstatslib.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/lstatslib.c $"; + "$Id: lstatslib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/lstatslib.c $"; typedef struct statistic { const char *name; @@ -57,10 +57,14 @@ char *getlasterror(void) return makecstring(last_error); } +char *luatexrevision(void) +{ + return makecstring(get_luatexrevision()); +} extern int luabytecode_max; extern int luabytecode_bytes; -static int luastate_max = 1; /* fixed value */ +static int luastate_max = 1; /* fixed value */ extern int luastate_bytes; extern int callback_count; extern int saved_callback_count; @@ -75,6 +79,9 @@ static struct statistic stats[] = { {"log_name", 's', &texmf_log_name}, /* weird */ {"banner", 'S', &getbanner}, {"pdftex_banner", 's', &pdftex_banner}, + {"luatex_version", 'G', &get_luatexversion}, + {"luatex_revision", 'S', &luatexrevision}, + {"ini_version", 'b', &ini_version}, /* * mem stat */ @@ -182,7 +189,10 @@ static int do_getstat(lua_State * L, int i) lua_pushboolean(L, g()); break; case 'n': - lua_nodelib_push_fast(L, *(halfword *) (stats[i].value)); + if (*(halfword *) (stats[i].value)!=0) + lua_nodelib_push_fast(L, *(halfword *) (stats[i].value)); + else + lua_pushnil(L); break; case 'b': lua_pushboolean(L, *(integer *) (stats[i].value)); diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c index c07d3cac696..28d6a1e1a22 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexiolib.c @@ -21,7 +21,7 @@ #include <ptexlib.h> static const char _svn_version[] = - "$Id: ltexiolib.c 2027 2009-03-14 18:47:32Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/ltexiolib.c $"; + "$Id: ltexiolib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltexiolib.c $"; typedef void (*texio_printer) (strnumber s); diff --git a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c index a847d89f12e..e7384a40ec2 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltexlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltexlib.c @@ -24,7 +24,7 @@ #include "tokens.h" static const char _svn_version[] = - "$Id: ltexlib.c 2079 2009-03-22 10:15:03Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/ltexlib.c $"; + "$Id: ltexlib.c 2282 2009-04-14 11:00:47Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltexlib.c $"; extern halfword *check_isnode(lua_State * L, int ud); extern void lua_nodelib_push_fast(lua_State * L, halfword n); @@ -53,8 +53,7 @@ static int spindle_size = 0; static spindle *spindles = NULL; static int spindle_index = 0; -static void -luac_store (lua_State *L, int i, int partial, integer cattable) +static void luac_store(lua_State * L, int i, int partial, integer cattable) { char *st, *sttemp; size_t tsize; @@ -82,8 +81,7 @@ luac_store (lua_State *L, int i, int partial, integer cattable) } -static int -do_luacprint(lua_State * L, int partial, int deftable) +static int do_luacprint(lua_State * L, int partial, int deftable) { int i, n; integer cattable = (integer) deftable; @@ -96,11 +94,11 @@ do_luacprint(lua_State * L, int partial, int deftable) } } if (lua_type(L, startstrings) == LUA_TTABLE) { - for (i = 1; ; i++) { - lua_rawgeti(L,startstrings, i); + for (i = 1;; i++) { + lua_rawgeti(L, startstrings, i); if (lua_isstring(L, -1)) { luac_store(L, -1, partial, cattable); - lua_pop(L,1); + lua_pop(L, 1); } else { break; } @@ -111,7 +109,7 @@ do_luacprint(lua_State * L, int partial, int deftable) lua_pushstring(L, "no string to print"); lua_error(L); } - luac_store(L,i, partial, cattable); + luac_store(L, i, partial, cattable); } } return 0; @@ -229,10 +227,10 @@ void luacstring_close(int n) #define depth_offset 2 #define height_offset 3 -#define check_index_range(j) \ - if (j > 65535) { \ - lua_pushstring(L, "incorrect index value"); \ - lua_error(L); } +#define check_index_range(j,s) \ + if (j<0 || j > 65535) { \ + lua_pushfstring(L, "incorrect index value %d for tex.%s()", (int)j, s); \ + lua_error(L); } int dimen_to_number(lua_State * L, char *s) @@ -271,12 +269,37 @@ int dimen_to_number(lua_State * L, char *s) return j; } -int setdimen(lua_State * L) + +integer +get_item_index (lua_State *L, int i, integer base) { - int i, j; - size_t k; + size_t kk; + integer k; int cur_cs; char *s; + if (lua_type(L, i) == LUA_TSTRING) { + s = (char *) lua_tolstring(L, i , &kk); + cur_cs = string_lookup(s, kk); + if (cur_cs==static_undefined_control_sequence || + is_undefined_cs(cur_cs)) { + k = -1; /* guarandeed invalid */ + } else { + k = (zget_equiv(cur_cs) - base); + } + } else { + k = (integer) luaL_checkinteger(L, i ); + } + return k; +} + + +static int vsetdimen(lua_State * L, int is_global) +{ + int i, j, err; + integer k; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); j = 0; /* find the value */ @@ -288,92 +311,79 @@ int setdimen(lua_State * L) lua_error(L); } else j = (int) lua_tonumber(L, i); - /* find the index */ - if (lua_type(L, i - 1) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i - 1, &k); - cur_cs = string_lookup(s, k); - k = zget_equiv(cur_cs) - get_scaled_base(); - } else { - k = (int) luaL_checkinteger(L, i - 1); - } - check_index_range(k); - if (set_tex_dimen_register(k, j)) { + k = get_item_index(L, (i-1), get_scaled_base()); + check_index_range(k, "setdimen"); + err = set_tex_dimen_register(k, j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { lua_pushstring(L, "incorrect value"); lua_error(L); } return 0; } -int getdimen(lua_State * L) +static int setdimen(lua_State * L) { - int i, j; - size_t k; - int cur_cs; - char *s; - i = lua_gettop(L); - if (lua_type(L, i) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i, &k); - cur_cs = string_lookup(s, k); - if (is_undefined_cs(cur_cs)) { - lua_pushnil(L); - return 1; - } - k = zget_equiv(cur_cs) - get_scaled_base(); - } else { - k = (int) luaL_checkinteger(L, i); - } - check_index_range(k); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetdimen (L, isglobal); +} + +static int getdimen(lua_State * L) +{ + int j; + integer k; + k = get_item_index(L, lua_gettop(L), get_scaled_base()); + check_index_range(k, "getdimen"); j = get_tex_dimen_register(k); lua_pushnumber(L, j); return 1; } - -int setskip(lua_State * L) +static int vsetskip(lua_State * L, int is_global) { - int i; + int i, err; halfword *j; - size_t k; - int cur_cs; - char *s; + integer k; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); j = check_isnode(L, i); /* the value */ - - if (lua_type(L, i - 1) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i - 1, &k); - cur_cs = string_lookup(s, k); - k = zget_equiv(cur_cs) - get_scaled_base(); - } else { - k = (int) luaL_checkinteger(L, i - 1); - } - check_index_range(k); /* the index */ - if (set_tex_skip_register(k, *j)) { + k = get_item_index(L, (i-1), get_skip_base()); + check_index_range(k, "setskip"); /* the index */ + err = set_tex_skip_register(k, *j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { lua_pushstring(L, "incorrect value"); lua_error(L); } return 0; } +static int setskip(lua_State * L) +{ + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetskip (L, isglobal); +} + int getskip(lua_State * L) { - int i; halfword j; - size_t k; - int cur_cs; - char *s; - i = lua_gettop(L); - if (lua_type(L, i) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i, &k); - cur_cs = string_lookup(s, k); - if (is_undefined_cs(cur_cs)) { - lua_pushnil(L); - return 1; - } - k = zget_equiv(cur_cs) - get_scaled_base(); - } else { - k = (int) luaL_checkinteger(L, i); - } - check_index_range(k); + integer k; + k = get_item_index(L, lua_gettop(L), get_skip_base()); + check_index_range(k, "getskip"); j = get_tex_skip_register(k); lua_nodelib_push_fast(L, j); return 1; @@ -381,125 +391,114 @@ int getskip(lua_State * L) -int setcount(lua_State * L) +static int vsetcount(lua_State * L, int is_global) { - int i, j; - size_t k; - int cur_cs; - char *s; + int i, j, err; + integer k; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); j = (int) luaL_checkinteger(L, i); - if (lua_type(L, i - 1) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i - 1, &k); - cur_cs = string_lookup(s, k); - k = zget_equiv(cur_cs) - get_count_base(); - } else { - k = (int) luaL_checkinteger(L, i - 1); - } - check_index_range(k); - if (set_tex_count_register(k, j)) { + k = get_item_index(L, (i-1), get_count_base()); + check_index_range(k, "setcount"); + err = set_tex_count_register(k, j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { lua_pushstring(L, "incorrect value"); lua_error(L); } return 0; } -int getcount(lua_State * L) +static int setcount(lua_State * L) { - int i, j; - size_t k; - int cur_cs; - char *s; - i = lua_gettop(L); - if (lua_type(L, i) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i, &k); - cur_cs = string_lookup(s, k); - if (is_undefined_cs(cur_cs)) { - lua_pushnil(L); - return 1; - } - k = zget_equiv(cur_cs) - get_count_base(); - } else { - k = (int) luaL_checkinteger(L, i); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; } - check_index_range(k); + return vsetcount (L, isglobal); +} + +static int getcount(lua_State * L) +{ + int j; + integer k; + k = get_item_index(L, lua_gettop(L), get_count_base()); + check_index_range(k,"getcount"); j = get_tex_count_register(k); lua_pushnumber(L, j); return 1; } -int setattribute(lua_State * L) +static int vsetattribute(lua_State * L, int is_global) { - int i, j; - size_t k; - int cur_cs; - char *s; + int i, j, err; + integer k; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); j = (int) luaL_checkinteger(L, i); - if (lua_type(L, i - 1) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i - 1, &k); - cur_cs = string_lookup(s, k); - k = zget_equiv(cur_cs) - get_attribute_base(); - } else { - k = (int) luaL_checkinteger(L, i - 1); - } - check_index_range(k); - if (set_tex_attribute_register(k, j)) { + k = get_item_index(L, (i-1), get_attribute_base()); + check_index_range(k,"setattribute"); + err = set_tex_attribute_register(k, j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { lua_pushstring(L, "incorrect value"); lua_error(L); } return 0; } -int getattribute(lua_State * L) +static int setattribute(lua_State * L) { - int i, j; - size_t k; - int cur_cs; - char *s; - i = lua_gettop(L); - if (lua_type(L, i) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i, &k); - cur_cs = string_lookup(s, k); - if (is_undefined_cs(cur_cs)) { - lua_pushnil(L); - return 1; - } - k = zget_equiv(cur_cs) - get_attribute_base(); - } else { - k = (int) luaL_checkinteger(L, i); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; } - check_index_range(k); + return vsetattribute (L, isglobal); +} + +static int getattribute(lua_State * L) +{ + int j; + integer k; + k = get_item_index(L, lua_gettop(L), get_attribute_base()); + check_index_range(k,"getattribute"); j = get_tex_attribute_register(k); lua_pushnumber(L, j); return 1; } -int settoks(lua_State * L) +int vsettoks(lua_State * L, int is_global) { - int i, j; - size_t k, len; - int cur_cs; - char *s, *st; + int i, j, err; + size_t len; + integer k; + char *st; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); if (!lua_isstring(L, i)) { lua_pushstring(L, "unsupported value type"); lua_error(L); } st = (char *) lua_tolstring(L, i, &len); - - if (lua_type(L, i - 1) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i - 1, &k); - cur_cs = string_lookup(s, k); - k = zget_equiv(cur_cs) - get_toks_base(); - } else { - k = (int) luaL_checkinteger(L, i - 1); - } - check_index_range(k); + k = get_item_index (L, (i-1), get_toks_base()); + check_index_range(k,"settoks"); j = maketexlstring(st, len); - - if (zset_tex_toks_register(k, j)) { + err = zset_tex_toks_register(k, j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { flush_str(j); lua_pushstring(L, "incorrect value"); lua_error(L); @@ -507,27 +506,24 @@ int settoks(lua_State * L) return 0; } -int gettoks(lua_State * L) +static int settoks (lua_State * L) { - int i; - size_t k; - strnumber t; - int cur_cs; - char *s; - i = lua_gettop(L); - if (lua_type(L, i) == LUA_TSTRING) { - s = (char *) lua_tolstring(L, i, &k); - cur_cs = string_lookup(s, k); - if (is_undefined_cs(cur_cs)) { - lua_pushnil(L); - return 1; - } - k = zget_equiv(cur_cs) - get_toks_base(); - } else { - k = (int) luaL_checkinteger(L, i); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; } + return vsettoks (L, isglobal); +} - check_index_range(k); +static int gettoks(lua_State * L) +{ + integer k; + strnumber t; + k = get_item_index (L, lua_gettop(L), get_toks_base()); + check_index_range(k,"gettoks"); t = get_tex_toks_register(k); lua_pushstring(L, makecstring(t)); flush_str(t); @@ -554,21 +550,24 @@ static int get_box_id(lua_State * L, int i) return j; } -int getbox(lua_State * L) +static int getbox(lua_State * L) { int k, t; k = get_box_id(L, -1); - check_index_range(k); + check_index_range(k,"getbox"); t = get_tex_box_register(k); nodelist_to_lua(L, t); return 1; } -int setbox(lua_State * L) +static int vsetbox(lua_State * L, int is_global) { - int i, j, k; + int i, j, k, err; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; k = get_box_id(L, -2); - check_index_range(k); + check_index_range(k,"setbox"); i = get_tex_box_register(k); if (lua_isboolean(L, -1)) { j = lua_toboolean(L, -1); @@ -579,13 +578,27 @@ int setbox(lua_State * L) } else { j = nodelist_from_lua(L); } - if (set_tex_box_register(k, j)) { + err = set_tex_box_register(k, j); + int_par(param_global_defs_code) = save_global_defs; + if (err) { lua_pushstring(L, "incorrect value"); lua_error(L); } return 0; } +static int setbox(lua_State * L) +{ + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetbox (L, isglobal); +} + static int getboxdim(lua_State * L, int whichdim) { int i, j; @@ -624,9 +637,12 @@ int getboxdp(lua_State * L) return getboxdim(L, depth_offset); } -static int setboxdim(lua_State * L, int whichdim) +static int vsetboxdim(lua_State * L, int whichdim, int is_global) { int i, j, k, err; + integer save_global_defs = int_par(param_global_defs_code); + if (is_global) + int_par(param_global_defs_code) = 1; i = lua_gettop(L); if (!lua_isnumber(L, i)) { j = dimen_to_number(L, (char *) lua_tostring(L, i)); @@ -650,6 +666,7 @@ static int setboxdim(lua_State * L, int whichdim) case depth_offset: err = set_tex_box_depth(k, j); } + int_par(param_global_defs_code) = save_global_defs; if (err) { lua_pushstring(L, "not a box"); lua_error(L); @@ -657,19 +674,40 @@ static int setboxdim(lua_State * L, int whichdim) return 0; } -int setboxwd(lua_State * L) +static int setboxwd(lua_State * L) { - return setboxdim(L, width_offset); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetboxdim(L, width_offset, isglobal); } -int setboxht(lua_State * L) +static int setboxht(lua_State * L) { - return setboxdim(L, height_offset); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetboxdim(L, height_offset, isglobal); } -int setboxdp(lua_State * L) +static int setboxdp(lua_State * L) { - return setboxdim(L, depth_offset); + int isglobal = 0; + int n = lua_gettop(L); + if (n==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } + return vsetboxdim(L, depth_offset, isglobal); } int settex(lua_State * L) @@ -678,33 +716,41 @@ int settex(lua_State * L) int i, j, texstr; size_t k; int cur_cs, cur_cmd; + int isglobal = 0; j = 0; i = lua_gettop(L); if (lua_isstring(L, (i - 1))) { st = (char *) lua_tolstring(L, (i - 1), &k); texstr = maketexlstring(st, k); if (is_primitive(texstr)) { + if (i==3 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + isglobal = 1; + } cur_cs = string_lookup(st, k); flush_str(texstr); cur_cmd = zget_eq_type(cur_cs); if (is_int_assign(cur_cmd)) { if (lua_isnumber(L, i)) { - assign_internal_value(0, zget_equiv(cur_cs), + assign_internal_value((isglobal?4:0), zget_equiv(cur_cs), lua_tonumber(L, i)); } else { lua_pushstring(L, "unsupported value type"); lua_error(L); } } else if (is_dim_assign(cur_cmd)) { - if (!lua_isnumber(L, i)) + if (!lua_isnumber(L, i)) { if (lua_isstring(L, i)) { j = dimen_to_number(L, (char *) lua_tostring(L, i)); } else { lua_pushstring(L, "unsupported value type"); lua_error(L); - } else - j = (int) lua_tonumber(L, i); - assign_internal_value(0, zget_equiv(cur_cs), j); + } + } else { + j = (int) lua_tonumber(L, i); + } + assign_internal_value((isglobal?4:0), zget_equiv(cur_cs), j); } else { lua_pushstring(L, "unsupported tex internal assignment"); lua_error(L); @@ -888,6 +934,40 @@ int do_lastitem(lua_State * L, int cur_code) return retval; } +static int tex_setmathparm (lua_State *L) +{ + int i, j; + scaled k; + int n; + int l = cur_level; + n = lua_gettop(L); + + if ((n == 3) || (n == 4)) { + if (n==4 && lua_isstring(L,1)) { + char *s = (char *)lua_tostring(L,1); + if (strcmp(s,"global")==0) + l = 1; + } + i = luaL_checkoption(L, (n-2), NULL, math_param_names); + j = luaL_checkoption(L, (n-1), NULL, math_style_names); + k = (scaled)lua_tonumber(L, n); + def_math_param (i,j,k, l); + } + return 0; +} + +static int tex_getmathparm (lua_State *L) +{ + int i, j; + scaled k; + if ((lua_gettop(L) == 2)) { + i = luaL_checkoption(L, 1, NULL, math_param_names); + j = luaL_checkoption(L, 2, NULL, math_style_names); + k = get_math_param (i,j); + lua_pushnumber(L, k); + } + return 1; +} static int getfontname(lua_State * L) { @@ -1310,45 +1390,48 @@ static int tex_enableprimitives(lua_State * L) size_t l; int i; char *pre = (char *) luaL_checklstring(L, 1, &l); - if (lua_istable(L,2)) { + if (lua_istable(L, 2)) { int nncs = no_new_control_sequence; no_new_control_sequence = true; i = 1; while (1) { - lua_rawgeti(L,2,i); - if (lua_isstring(L,3)) { - char *prim = (char *) lua_tostring(L,3); + lua_rawgeti(L, 2, i); + if (lua_isstring(L, 3)) { + char *prim = (char *) lua_tostring(L, 3); str_number s = maketexstring(prim); halfword prim_val = prim_lookup(s); if (prim_val != undefined_primitive) { char *newprim; + integer val; size_t newl; halfword cur_cmd = get_prim_eq_type(prim_val); halfword cur_chr = get_prim_equiv(prim_val); - if (strncmp(pre,prim,l)!=0) { /* not a prefix */ - newl = strlen(prim)+l; - newprim = (char *) xmalloc (newl+1); - strcpy(newprim,pre); - strcat(newprim+l,prim); + if (strncmp(pre, prim, l) != 0) { /* not a prefix */ + newl = strlen(prim) + l; + newprim = (char *) xmalloc(newl + 1); + strcpy(newprim, pre); + strcat(newprim + l, prim); } else { newl = strlen(prim); - newprim = (char *) xmalloc (newl+1); - strcpy(newprim,prim); + newprim = (char *) xmalloc(newl + 1); + strcpy(newprim, prim); } - if (string_lookup(newprim, newl) == static_undefined_control_sequence ) { + val = string_lookup(newprim, newl); + if (val == static_undefined_control_sequence || + zget_eq_type(val) == undefined_cs_cmd) { primitive_def(newprim, newl, cur_cmd, cur_chr); } - free (newprim); + free(newprim); } flush_str(s); } else { - lua_pop(L,1); + lua_pop(L, 1); break; } - lua_pop(L,1); + lua_pop(L, 1); i++; } - lua_pop(L,1); /* the table */ + lua_pop(L, 1); /* the table */ no_new_control_sequence = nncs; } else { lua_pushstring(L, "Expected an array of names as second argument"); @@ -1359,11 +1442,12 @@ static int tex_enableprimitives(lua_State * L) } - static const struct luaL_reg texlib[] = { {"write", luacwrite}, {"print", luacprint}, {"sprint", luacsprint}, + {"set", settex}, + {"get", gettex}, {"setdimen", setdimen}, {"getdimen", getdimen}, {"setskip", setskip}, @@ -1401,22 +1485,26 @@ static const struct luaL_reg texlib[] = { {"primitives", tex_primitives}, {"extraprimitives", tex_extraprimitives}, {"enableprimitives", tex_enableprimitives}, + {"setmath", tex_setmathparm}, + {"getmath", tex_getmathparm}, {NULL, NULL} /* sentinel */ }; int luaopen_tex(lua_State * L) { luaL_register(L, "tex", texlib); - make_table(L, "attribute", "getattribute", "setattribute"); - make_table(L, "skip", "getskip", "setskip"); - make_table(L, "dimen", "getdimen", "setdimen"); - make_table(L, "count", "getcount", "setcount"); - make_table(L, "toks", "gettoks", "settoks"); - make_table(L, "box", "getbox", "setbox"); - make_table(L, "lists", "getlist", "setlist"); - make_table(L, "wd", "getboxwd", "setboxwd"); - make_table(L, "ht", "getboxht", "setboxht"); - make_table(L, "dp", "getboxdp", "setboxdp"); + /* *INDENT-OFF* */ + make_table(L, "attribute", "getattribute", "setattribute"); + make_table(L, "skip", "getskip", "setskip"); + make_table(L, "dimen", "getdimen", "setdimen"); + make_table(L, "count", "getcount", "setcount"); + make_table(L, "toks", "gettoks", "settoks"); + make_table(L, "box", "getbox", "setbox"); + make_table(L, "wd", "getboxwd", "setboxwd"); + make_table(L, "ht", "getboxht", "setboxht"); + make_table(L, "dp", "getboxdp", "setboxdp"); + make_table(L, "lists", "getlist", "setlist"); + /* *INDENT-ON* */ /* make the meta entries */ /* fetch it back */ luaL_newmetatable(L, "tex_meta"); diff --git a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c index b81c61f4023..06d1f72359f 100644 --- a/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c +++ b/Build/source/texk/web2c/luatexdir/lua/ltokenlib.c @@ -22,7 +22,7 @@ #include "tokens.h" static const char _svn_version[] = - "$Id: ltokenlib.c 2015 2009-03-13 19:06:34Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/ltokenlib.c $"; + "$Id: ltokenlib.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/ltokenlib.c $"; extern int get_command_id(char *); diff --git a/Build/source/texk/web2c/luatexdir/lua/luainit.c b/Build/source/texk/web2c/luatexdir/lua/luainit.c index f89607530ac..5aecc526921 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luainit.c +++ b/Build/source/texk/web2c/luatexdir/lua/luainit.c @@ -25,7 +25,7 @@ #include <luatexdir/luatexextra.h> static const char _svn_version[] = - "$Id: luainit.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/luainit.c $"; + "$Id: luainit.c 2288 2009-04-14 22:56:09Z hhenkel $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luainit.c $"; /* TH: TODO * @@ -43,6 +43,9 @@ static const char _svn_version[] = * SELFAUTOLOC SELFAUTODIR SELFAUTOPARENT progname * */ +extern void mk_shellcmdlist(char *v); +extern int shell_cmd_is_allowed(char **cmd, char **safecmd, char **cmdname); +extern void init_shell_escape(void); extern string normalize_quotes(const_string name, const_string mesg); @@ -172,6 +175,11 @@ static struct option long_options[] {"output-format", 1, 0, 0}, {"shell-escape", 0, &shellenabledp, 1}, {"no-shell-escape", 0, &shellenabledp, -1}, +{"shell-escape", 0, &shellenabledp, 1}, +{"no-shell-escape", 0, &shellenabledp, -1}, +{"enable-write18", 0, &shellenabledp, 1}, +{"disable-write18", 0, &shellenabledp, -1}, +{"shell-restricted", 0, 0, 0}, {"debug-format", 0, &debug_format_file, 1}, {"file-line-error-style", 0, &filelineerrorstylep, 1}, {"no-file-line-error-style", 0, &filelineerrorstylep, -1}, @@ -243,6 +251,10 @@ static void parse_options(int argc, char **argv) output_comment[255] = 0; } + } else if (ARGUMENT_IS("shell-restricted")) { + shellenabledp = 1; + restrictedshell = 1; + } else if (ARGUMENT_IS("output-format")) { pdf_output_option = 1; if (strcmp(optarg, "dvi") == 0) { @@ -314,7 +326,7 @@ static void parse_options(int argc, char **argv) "lua by Roberto Ierusalimschy, Waldemar Celes,\n" " Luiz Henrique de Figueiredo\n" "metapost by John Hobby, Taco Hoekwater and friends.\n" - "xpdf by Derek Noonberg (partial)\n" + "xpdf by Derek Noonburg (partial)\n" "fontforge by George Williams (partial)\n\n" "Some extensions to lua and additional lua libraries are used, as well as\n" "libraries for graphic inclusion. More details can be found in the source.\n" @@ -444,6 +456,7 @@ void init_kpse(void) kpse_src_compile); kpse_set_program_name(argv[0], user_progname); + init_shell_escape(); /* set up 'restrictedshell' */ program_name_set = 1; } @@ -504,6 +517,8 @@ void lua_initialize(int ac, char **av) /* parse commandline */ parse_options(ac, av); + if (lua_only) + shellenabledp = true; /* make sure that the locale is 'sane' (for lua) */ putenv("LC_CTYPE=C"); @@ -515,7 +530,7 @@ void lua_initialize(int ac, char **av) luainterpreter(); - prepare_cmdline(Luas, argv, argc, lua_offset); /* collect arguments */ + prepare_cmdline(Luas, argv, argc, lua_offset); /* collect arguments */ if (startup_filename != NULL) { given_file = xstrdup(startup_filename); @@ -577,7 +592,28 @@ void lua_initialize(int ac, char **av) haltonerrorp = false; get_lua_boolean("texconfig", "halt_on_error", &haltonerrorp); + /* restrictedshell */ + char *v1 = NULL; + get_lua_string("texconfig", "shell_escape", &v1); + if (v1) { + if (*v1 == 't' || *v1 == 'y' || *v1 == '1') { + shellenabledp = 1; + } else if (*v1 == 'p') { + shellenabledp = 1; + restrictedshell = 1; + } + } + /* If shell escapes are restricted, get allowed cmds from cnf. */ + if (shellenabledp && restrictedshell == 1) { + v1 = NULL; + get_lua_string("texconfig", "shell_escape_commands", &v1); + if (v1) { + mk_shellcmdlist(v1); + } + } + fix_dumpname(); + } else { if (luainit) { if (given_file) { @@ -596,3 +632,39 @@ void lua_initialize(int ac, char **av) } } } + +void +check_texconfig_init (void) { + if (Luas!=NULL) { + lua_getglobal(Luas, "texconfig"); + if (lua_istable(Luas, -1)) { + lua_getfield(Luas, -1, "init"); + if (lua_isfunction(Luas, -1)) { + int i = lua_pcall(Luas, 0, 0, 0); + if (i != 0) { + /* Can't be more precise here, called before TeX initialization */ + fprintf(stderr, "This went wrong: %s\n", lua_tostring(Luas, -1)); + error(); + } + } + } + } +} + +void write_svnversion(char *v) +{ + char *a_head, *n; + char *a = strdup(v); + int l = strlen("$Id: luatex.web "); + if (a != NULL) { + a_head = a; + if (strlen(a)>l) + a+=l; + n = a; + while (*n!='\0' && *n!=' ') + n++; + *n = '\0'; + fprintf(stdout, " luatex.web v%s", a); + free (a_head); + } +} diff --git a/Build/source/texk/web2c/luatexdir/lua/luanode.c b/Build/source/texk/web2c/luatexdir/lua/luanode.c index 0be6547446f..49d46b258f6 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luanode.c +++ b/Build/source/texk/web2c/luatexdir/lua/luanode.c @@ -22,7 +22,7 @@ #include "nodes.h" static const char _svn_version[] = - "$Id: luanode.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/luanode.c $"; + "$Id: luanode.c 2284 2009-04-14 12:58:45Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luanode.c $"; #undef link /* defined by cpascal.h */ #define info(a) fixmem[(a)].hhlh @@ -61,7 +61,10 @@ void lua_node_filter_s(int filterid, char *extrainfo) { lua_State *L = Luas; int s_top = lua_gettop(L); - if (!get_callback(L, callback_defined(filterid))) { + int callback_id = callback_defined(filterid); + if (callback_id<=0) + return; + if (!get_callback(L, callback_id)) { lua_settop(L, s_top); return; } @@ -85,7 +88,7 @@ lua_node_filter(int filterid, int xextrainfo, halfword head_node, lua_State *L = Luas; char *extrainfo = group_code_names[xextrainfo]; int callback_id = callback_defined(filterid); - if (head_node == null || vlink(head_node) == null || callback_id == 0) + if (head_node == null || vlink(head_node) == null || callback_id <= 0) return; if (!get_callback(L, callback_id)) { lua_pop(L, 2); @@ -131,7 +134,7 @@ lua_linebreak_callback(int is_broken, halfword head_node, halfword * new_head) int ret = 0; /* failure */ lua_State *L = Luas; int callback_id = callback_defined(linebreak_filter_callback); - if (head_node == null || vlink(head_node) == null || callback_id == 0) + if (head_node == null || vlink(head_node) == null || callback_id <= 0) return ret; if (!get_callback(L, callback_id)) { lua_pop(L, 2); @@ -164,7 +167,7 @@ lua_hpack_filter(halfword head_node, scaled size, int pack_type, int extrainfo) halfword ret; lua_State *L = Luas; int callback_id = callback_defined(hpack_filter_callback); - if (head_node == null || callback_id == 0) + if (head_node == null || callback_id <= 0) return head_node; if (!get_callback(L, callback_id)) { lua_pop(L, 2); @@ -210,7 +213,7 @@ lua_vpack_filter(halfword head_node, scaled size, int pack_type, scaled maxd, } else { callback_id = callback_defined(vpack_filter_callback); } - if (callback_id == 0) { + if (callback_id <= 0) { return head_node; } if (!get_callback(L, callback_id)) { @@ -263,3 +266,69 @@ int visible_last_node_type(int n) return -1; /* this is not right, probably dir nodes! */ return last_known_node + 1; } + +void +lua_pdf_literal (int i) +{ + char *s = NULL; + size_t l = 0; + lua_rawgeti(Luas, LUA_REGISTRYINDEX, i); + s = (char *)lua_tolstring(Luas,-1,&l); + while (l--) { + pdf_room(1); + pdf_buf[pdf_ptr++] = *s++; + } + pdf_buf[pdf_ptr++] = 10; /* pdf_print_nl */ + lua_pop(Luas,1); +} + +void +copy_pdf_literal (pointer r, pointer p) +{ + pdf_literal_type(r) = pdf_literal_type(p); + pdf_literal_mode(r) = pdf_literal_mode(p); + if (pdf_literal_type(p)==normal) { + pdf_literal_data(r) = pdf_literal_data(p); + add_token_ref(pdf_literal_data(p)); + } else { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(p)); + pdf_literal_data(r) = luaL_ref(Luas, LUA_REGISTRYINDEX); + } +} + + +void +free_pdf_literal (pointer p) +{ + if (pdf_literal_type(p)==normal) { + delete_token_ref(pdf_literal_data(p)); + } else { + luaL_unref(Luas, LUA_REGISTRYINDEX, pdf_literal_data(p)); + } +} + +void +show_pdf_literal (pointer p) +{ + tprint_esc("pdfliteral"); + switch (pdf_literal_mode(p)) { + case set_origin: + break; + case direct_page: + tprint(" page"); + break; + case direct_always: + tprint(" direct"); + break; + default: + tconfusion("literal2"); + break; + } + if (pdf_literal_type(p)==normal) { + print_mark(pdf_literal_data(p)); + } else { + lua_rawgeti(Luas, LUA_REGISTRYINDEX, pdf_literal_data(p)); + tprint((char *)lua_tostring(Luas,-1)); + lua_pop(Luas,1); + } +} diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.c b/Build/source/texk/web2c/luatexdir/lua/luastuff.c index 49298ea2fc5..a8ac317b5f1 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luastuff.c +++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.c @@ -21,7 +21,7 @@ #include <ptexlib.h> static const char _svn_version[] = - "$Id: luastuff.c 2064 2009-03-20 13:13:14Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/luastuff.c $"; + "$Id: luastuff.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luastuff.c $"; lua_State *Luas = NULL; @@ -71,7 +71,7 @@ const char *getS(lua_State * L, void *ud, size_t * size) void *my_luaalloc(void *ud, void *ptr, size_t osize, size_t nsize) { void *ret = NULL; - (void)ud; /* for -Wunused */ + (void) ud; /* for -Wunused */ if (nsize == 0) free(ptr); else @@ -88,6 +88,34 @@ static int my_luapanic(lua_State * L) return 0; } +static const luaL_Reg lualibs[] = { + {"", luaopen_base}, + {"package", luaopen_package}, + {"table", luaopen_table}, + {"io", luaopen_io}, + {"os", luaopen_os}, + {"string", luaopen_string}, + {"math", luaopen_math}, + {"debug", luaopen_debug}, + {"unicode", luaopen_unicode}, + {"zip", luaopen_zip}, + {"lpeg", luaopen_lpeg}, + {"md5", luaopen_md5}, + {"lfs", luaopen_lfs}, + {"profiler", luaopen_profiler}, + {NULL, NULL} +}; + + +static void do_openlibs(lua_State * L) +{ + const luaL_Reg *lib = lualibs; + for (; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } +} void luainterpreter(void) { @@ -99,7 +127,7 @@ void luainterpreter(void) } lua_atpanic(L, &my_luapanic); - luaL_openlibs(L); + do_openlibs(L); /* does all the 'simple' libraries */ open_oslibext(L, safer_option); @@ -108,16 +136,6 @@ void luainterpreter(void) lua_setfield(L, -2, "cpath"); lua_pop(L, 1); /* pop the table */ - /*luaopen_unicode(L); */ - lua_pushcfunction(L, luaopen_unicode); - lua_pushstring(L, "unicode"); - lua_call(L, 1, 0); - - /*luaopen_zip(L); */ - lua_pushcfunction(L, luaopen_zip); - lua_pushstring(L, "zip"); - lua_call(L, 1, 0); - /* luasockets */ /* socket and mime are a bit tricky to open because * they use a load-time dependency that has to be @@ -145,53 +163,33 @@ void luainterpreter(void) luatex_socketlua_open(L); /* preload the pure lua modules */ } - - /*luaopen_lpeg(L); */ - lua_pushcfunction(L, luaopen_lpeg); - lua_pushstring(L, "lpeg"); - lua_call(L, 1, 0); - - /*luaopen_md5(L); */ - lua_pushcfunction(L, luaopen_md5); - lua_pushstring(L, "md5"); - lua_call(L, 1, 0); - - /*luaopen_lfs(L); */ - lua_pushcfunction(L, luaopen_lfs); - lua_pushstring(L, "lfs"); - lua_call(L, 1, 0); - /* zlib. slightly odd calling convention */ luaopen_zlib(L); lua_setglobal(L, "zlib"); luaopen_gzip(L); - /* fontforge */ - luaopen_ff(L); - /* profiler, from kepler */ - luaopen_profiler(L); + /* our own libraries */ + luaopen_ff(L); luaopen_pdf(L); luaopen_tex(L); luaopen_token(L); luaopen_node(L); luaopen_texio(L); luaopen_kpse(L); - luaopen_callback(L); - lua_createtable(L, 0, 0); - lua_setglobal(L, "texconfig"); - luaopen_lua(L, startup_filename); luaopen_stats(L); luaopen_font(L); luaopen_lang(L); + luaopen_mplib(L); /* luaopen_img(L); */ lua_pushcfunction(L, luaopen_img); lua_pushstring(L, "img"); lua_call(L, 1, 0); - luaopen_mplib(L); + lua_createtable(L, 0, 0); + lua_setglobal(L, "texconfig"); if (safer_option) { /* disable some stuff if --safer */ @@ -295,27 +293,27 @@ void luacall(int p, int nameptr) if (ls.size > 0) { if (nameptr > 0) { lua_id = tokenlist_to_cstring(nameptr, 1, &l); - } else if (nameptr<0) { - char *tmp = get_lua_name((nameptr+65536)); - if (tmp!=NULL) + } else if (nameptr < 0) { + char *tmp = get_lua_name((nameptr + 65536)); + if (tmp != NULL) lua_id = xstrdup(tmp); else lua_id = xstrdup("\\latelua "); } else { lua_id = xmalloc(20); - snprintf((char *) lua_id, 20, "\\latelua ") ; + snprintf((char *) lua_id, 20, "\\latelua "); } i = lua_load(Luas, getS, &ls, lua_id); if (i != 0) { Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1)); } else { - int base = lua_gettop(Luas); /* function index */ + int base = lua_gettop(Luas); /* function index */ lua_checkstack(Luas, 1); - lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ - lua_insert(Luas, base); /* put it under chunk */ + lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ + lua_insert(Luas, base); /* put it under chunk */ i = lua_pcall(Luas, 0, 0, base); - lua_remove(Luas, base); /* remove traceback function */ + lua_remove(Luas, base); /* remove traceback function */ if (i != 0) { lua_gc(Luas, LUA_GCCOLLECT, 0); Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1)); @@ -332,7 +330,7 @@ void luatokencall(int p, int nameptr) int i, l; char *s = NULL; char *lua_id; - assert (Luas); + assert(Luas); l = 0; lua_active++; s = tokenlist_to_cstring(p, 1, &l); @@ -341,9 +339,9 @@ void luatokencall(int p, int nameptr) if (ls.size > 0) { if (nameptr > 0) { lua_id = tokenlist_to_cstring(nameptr, 1, &l); - } else if (nameptr<0) { - char *tmp = get_lua_name((nameptr+65536)); - if (tmp!=NULL) + } else if (nameptr < 0) { + char *tmp = get_lua_name((nameptr + 65536)); + if (tmp != NULL) lua_id = xstrdup(tmp); else lua_id = xstrdup("\\directlua "); @@ -355,12 +353,12 @@ void luatokencall(int p, int nameptr) if (i != 0) { Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1)); } else { - int base = lua_gettop(Luas); /* function index */ + int base = lua_gettop(Luas); /* function index */ lua_checkstack(Luas, 1); - lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ - lua_insert(Luas, base); /* put it under chunk */ + lua_pushcfunction(Luas, lua_traceback); /* push traceback function */ + lua_insert(Luas, base); /* put it under chunk */ i = lua_pcall(Luas, 0, 0, base); - lua_remove(Luas, base); /* remove traceback function */ + lua_remove(Luas, base); /* remove traceback function */ if (i != 0) { lua_gc(Luas, LUA_GCCOLLECT, 0); Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1)); diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex.c b/Build/source/texk/web2c/luatexdir/lua/luatex.c index 24b928fba45..41987c681cc 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatex.c +++ b/Build/source/texk/web2c/luatexdir/lua/luatex.c @@ -22,7 +22,7 @@ #include <zlib.h> static const char _svn_version[] = - "$Id: luatex.c 2028 2009-03-14 18:50:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/luatex.c $"; + "$Id: luatex.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luatex.c $"; /* do this aleph stuff here, for now */ diff --git a/Build/source/texk/web2c/luatexdir/lua/luatoken.c b/Build/source/texk/web2c/luatexdir/lua/luatoken.c index 4182d94e6fe..c77b2a5f049 100644 --- a/Build/source/texk/web2c/luatexdir/lua/luatoken.c +++ b/Build/source/texk/web2c/luatexdir/lua/luatoken.c @@ -24,7 +24,7 @@ #include "commands.h" static const char _svn_version[] = - "$Id: luatoken.c 2079 2009-03-22 10:15:03Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/luatoken.c $"; + "$Id: luatoken.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luatoken.c $"; command_item command_names[] = { {"relax", relax_cmd, NULL}, @@ -94,6 +94,8 @@ command_item command_names[] = { {"ex_space", ex_space_cmd, NULL}, {"no_boundary", no_boundary_cmd, NULL}, {"radical", radical_cmd, NULL}, + {"super_sub_script", super_sub_script_cmd, NULL}, + {"math_shift_cs", math_shift_cs_cmd, NULL}, {"end_cs_name", end_cs_name_cmd, NULL}, {"char_ghost", char_ghost_cmd, NULL}, {"assign_local_box", assign_local_box_cmd, NULL}, diff --git a/Build/source/texk/web2c/luatexdir/lua/texluac.c b/Build/source/texk/web2c/luatexdir/lua/texluac.c index d4295aba6ae..bac9559741f 100644 --- a/Build/source/texk/web2c/luatexdir/lua/texluac.c +++ b/Build/source/texk/web2c/luatexdir/lua/texluac.c @@ -46,7 +46,7 @@ #include <../lua51/lundump.h> static const char _svn_version[] = - "$Id: texluac.c 1226 2008-05-02 16:11:02Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/src/texk/web2c/luatexdir/lua/texluac.c $"; + "$Id: texluac.c 2271 2009-04-12 23:42:21Z oneiros $ $URL: http://scm.foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/texluac.c $"; #define PROGNAME "texluac" /* default program name */ #define OUTPUT PROGNAME ".out" /* default output file */ |