From 1b8b254a766350291f8e7e19feaf6326ebabe633 Mon Sep 17 00:00:00 2001 From: Luigi Scarso Date: Wed, 5 Sep 2018 21:30:41 +0000 Subject: sync with luatex revision 6924. git-svn-id: svn://tug.org/texlive/trunk@48591 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/mplibdir/ChangeLog | 4 + Build/source/texk/web2c/mplibdir/am/libmplib.am | 20 +- Build/source/texk/web2c/mplibdir/am/mplib.am | 6 +- Build/source/texk/web2c/mplibdir/lmplib.c | 526 +++++++++++++++--------- Build/source/texk/web2c/mplibdir/mp.w | 353 +++++++++++----- Build/source/texk/web2c/mplibdir/mpmath.w | 2 +- Build/source/texk/web2c/mplibdir/mpmathbinary.w | 13 + Build/source/texk/web2c/mplibdir/mpmathdouble.w | 2 +- 8 files changed, 604 insertions(+), 322 deletions(-) (limited to 'Build/source/texk/web2c/mplibdir') diff --git a/Build/source/texk/web2c/mplibdir/ChangeLog b/Build/source/texk/web2c/mplibdir/ChangeLog index 9f69e0665b9..e2c7244ebf0 100644 --- a/Build/source/texk/web2c/mplibdir/ChangeLog +++ b/Build/source/texk/web2c/mplibdir/ChangeLog @@ -1,3 +1,7 @@ +2018-08-27 Luigi Scarso + * separation of mpmathbinary from the the core + + 2018-02-19 Luigi Scarso * Small cleanup of the code * Bump to version 2.0rc2: the current version is 2.00 diff --git a/Build/source/texk/web2c/mplibdir/am/libmplib.am b/Build/source/texk/web2c/mplibdir/am/libmplib.am index 3d57231194f..a4be39e68b7 100644 --- a/Build/source/texk/web2c/mplibdir/am/libmplib.am +++ b/Build/source/texk/web2c/mplibdir/am/libmplib.am @@ -5,15 +5,18 @@ ## libmplib.a, used by MetaPost and luaTeX ## -EXTRA_LIBRARIES += libmplibcore.a libmplibbackends.a +EXTRA_LIBRARIES += libmplibcore.a libmplibextramath.a libmplibbackends.a -libmplibcore_a_CPPFLAGS = $(MPFR_INCLUDES) $(GMP_INCLUDES) $(LIBPNG_INCLUDES) $(ZLIB_INCLUDES) $(AM_CPPFLAGS) -I$(srcdir)/mplibdir + +libmplibcore_a_CPPFLAGS = $(LIBPNG_INCLUDES) $(ZLIB_INCLUDES) $(AM_CPPFLAGS) -I$(srcdir)/mplibdir +libmplibextramath_a_CPPFLAGS = $(MPFR_INCLUDES) $(GMP_INCLUDES) -I${top_builddir}/../../libs $(AM_CPPFLAGS) -I$(srcdir)/mplibdir libmplibbackends_a_CPPFLAGS = $(MPFR_INCLUDES) $(GMP_INCLUDES) $(CAIRO_INCLUDES) $(PIXMAN_INCLUDES) \ $(LIBPNG_INCLUDES) $(ZLIB_INCLUDES) $(AM_CPPFLAGS) -I$(srcdir)/mplibdir -## libmplib C sources core + backends -nodist_libmplibcore_a_SOURCES = tfmin.c $(mp_c_h) $(mpmath_c_h) $(mpmathbinary_c_h) $(mpmathdecimal_c_h) \ +## libmplib C sources core + extramath + backends +nodist_libmplibcore_a_SOURCES = tfmin.c $(mp_c_h) $(mpmath_c_h) $(mpmathdecimal_c_h) \ $(mpmathdouble_c_h) $(mpstrings_c_h) $(psout_c_h) +nodist_libmplibextramath_a_SOURCES = $(mpmathbinary_c_h) nodist_libmplibbackends_a_SOURCES = $(pngout_c_h) $(svgout_c_h) @@ -84,15 +87,16 @@ libmplib_web += mplibdir/mpmath.w mplibdir/mpmathbinary.w mplibdir/mpmathdecimal libmplib_web += mplibdir/mpmathdouble.w mplibdir/mpstrings.w mplibdir/tfmin.w ## core need headers backends -$(nodist_libmplibcore_a_SOURCES): $(svgout_c_h) $(pngout_c_h) +$(nodist_libmplibcore_a_SOURCES): $(mpmathbinary_c_h) $(svgout_c_h) $(pngout_c_h) -$(libmplibcore_a_OBJECTS): $(nodist_libmplibcore_a_SOURCES) $(KPATHSEA_DEPEND) $(MPFR_DEPEND) +$(libmplibcore_a_OBJECTS): $(nodist_libmplibcore_a_SOURCES) $(KPATHSEA_DEPEND) +$(libmplibextramath_a_OBJECTS): $(nodist_libmplibextramath_a_SOURCES) $(KPATHSEA_DEPEND) $(MPFR_DEPEND) $(libmplibbackends_a_OBJECTS): $(nodist_libmplibbackends_a_SOURCES) $(KPATHSEA_DEPEND) $(CAIRO_DEPEND) $(MPFR_DEPEND) EXTRA_DIST += $(libmplib_web) -DISTCLEANFILES += $(nodist_libmplibcore_a_SOURCES) $(nodist_libmplibbackends_a_SOURCES) \ - mp-tangle mpmath-tangle mpmathbinary-tangle mpmathdecimal-tangle mpmathdouble-tangle \ +DISTCLEANFILES += $(nodist_libmplibcore_a_SOURCES) $(nodist_libmplibextramath_a_SOURCES) $(nodist_libmplibbackends_a_SOURCES) \ + mp-tangle mpmath-tangle mpmathdecimal-tangle mpmathdouble-tangle \ mpstrings-tangle psout-tangle svgout-tangle pngout-tangle diff --git a/Build/source/texk/web2c/mplibdir/am/mplib.am b/Build/source/texk/web2c/mplibdir/am/mplib.am index f58658de18f..10b1fe4aa44 100644 --- a/Build/source/texk/web2c/mplibdir/am/mplib.am +++ b/Build/source/texk/web2c/mplibdir/am/mplib.am @@ -18,9 +18,7 @@ endif MP EXTRA_PROGRAMS += mpost mpost_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_INCLUDES) $(LIBPNG_INCLUDES) -I$(srcdir)/mplibdir -#mpost_LDADD = libmplib.a $(KPATHSEA_LIBS) $(MPFR_LIBS) $(GMP_LIBS) \ -# $(CAIRO_LIBS) $(PIXMAN_LIBS) $(LIBPNG_LIBS) $(ZLIB_LIBS) libmputil.a -mpost_LDADD = libmplibcore.a libmplibbackends.a $(KPATHSEA_LIBS) $(MPFR_LIBS) $(GMP_LIBS) \ +mpost_LDADD = libmplibcore.a libmplibextramath.a libmplibbackends.a $(KPATHSEA_LIBS) $(MPFR_LIBS) $(GMP_LIBS) \ $(CAIRO_LIBS) $(PIXMAN_LIBS) $(LIBPNG_LIBS) $(ZLIB_LIBS) libmputil.a @@ -60,7 +58,7 @@ mpxout-tangle: ctangle$(EXEEXT) mplibdir/mpxout.w tangle-sh mpost_web = mplibdir/mpost.w mplibdir/mpxout.w #$(mpost_OBJECTS): $(nodist_mpost_SOURCES) libmplib.a $(LIBPNG_DEPEND) -$(mpost_OBJECTS): $(nodist_mpost_SOURCES) libmplibcore.a libmplibbackends.a $(LIBPNG_DEPEND) +$(mpost_OBJECTS): $(nodist_mpost_SOURCES) libmplibcore.a libmplibextramath.a libmplibbackends.a $(LIBPNG_DEPEND) EXTRA_DIST += mplibdir/ChangeLog $(mpost_web) diff --git a/Build/source/texk/web2c/mplibdir/lmplib.c b/Build/source/texk/web2c/mplibdir/lmplib.c index d90482b887e..eb8432bb507 100644 --- a/Build/source/texk/web2c/mplibdir/lmplib.c +++ b/Build/source/texk/web2c/mplibdir/lmplib.c @@ -15,7 +15,9 @@ License for more details. You should have received a copy of the GNU Lesser General Public License along - with LuaTeX; if not, see . */ + with LuaTeX; if not, see . + +*/ #include #include @@ -23,7 +25,7 @@ #ifdef HAVE_UNISTD_H #include #endif -#include /* temporary */ +#include #ifndef pdfTeX # include @@ -41,20 +43,23 @@ #define luaL_reg luaL_Reg #endif - #ifndef lua_objlen #define lua_objlen lua_rawlen #endif - #include "mplib.h" #include "mplibps.h" #include "mplibsvg.h" #include "mplibpng.h" -int luaopen_mplib(lua_State * L); /* forward */ +int luaopen_mplib(lua_State * L); -/* metatable identifiers and tests */ +/*tex + + We need a few metatable identifiers in order to access the metatables for the + main object and result userdata. + +*/ #define MPLIB_METATABLE "MPlib.meta" #define MPLIB_FIG_METATABLE "MPlib.fig" @@ -64,25 +69,33 @@ int luaopen_mplib(lua_State * L); /* forward */ #define is_fig(L,b) (struct mp_edge_object **)luaL_checkudata(L,b,MPLIB_FIG_METATABLE) #define is_gr_object(L,b) (struct mp_graphic_object **)luaL_checkudata(L,b,MPLIB_GR_METATABLE) -/* Lua string pre-hashing */ +/*tex -#define mplib_init_S(a) do { \ - lua_pushliteral(L,#a); \ - mplib_##a##_ptr = lua_tostring(L,-1); \ - mplib_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \ - } while (0) + We pre-hash the \LUA\ strings which is much faster. The approach is similar to the one + used at the \TEX\ end. -#define mplib_push_S(a) do { \ - lua_rawgeti(L,LUA_REGISTRYINDEX,mplib_##a##_index); \ - } while (0) +*/ + +#define mplib_init_S(a) do { \ + lua_pushliteral(L,#a); \ + mplib_##a##_ptr = lua_tostring(L,-1); \ + mplib_##a##_index = luaL_ref (L,LUA_REGISTRYINDEX); \ +} while (0) + +#define mplib_push_S(a) do { \ + lua_rawgeti(L,LUA_REGISTRYINDEX,mplib_##a##_index); \ +} while (0) -#define mplib_is_S(a,i) (mplib_##a##_ptr==lua_tostring(L,i)) +#define mplib_is_S(a,i) \ + (mplib_##a##_ptr==lua_tostring(L,i)) -#define mplib_make_S(a) \ - static int mplib_##a##_index = 0; \ - static const char *mplib_##a##_ptr = NULL +#define mplib_make_S(a) \ + static int mplib_##a##_index = 0; \ + static const char *mplib_##a##_ptr = NULL -static int mplib_type_Ses[mp_special_code + 1] = { 0 }; /* [0] is not used */ +/*tex In the next array entry 0 is not used */ + +static int mplib_type_Ses[mp_special_code + 1] = { 0 }; mplib_make_S(term); mplib_make_S(error); @@ -94,6 +107,7 @@ mplib_make_S(memory); mplib_make_S(hash); mplib_make_S(params); mplib_make_S(open); +mplib_make_S(cycle); mplib_make_S(offset); mplib_make_S(dashes); @@ -153,6 +167,7 @@ static void mplib_init_Ses(lua_State * L) mplib_init_S(hash); mplib_init_S(params); mplib_init_S(open); + mplib_init_S(cycle); mplib_init_S(offset); mplib_init_S(dashes); @@ -210,11 +225,15 @@ static void mplib_init_Ses(lua_State * L) mplib_init_S(elliptical); } +/*tex + + Here are some enumeration arrays to map MPlib enums to \LUA\ strings. If needed + we can also predefine keys here, as we do with nodes. -/* Enumeration arrays to map MPlib enums to Lua strings */ +*/ static const char *math_options[] = - { "scaled", "double", "binary", "decimal", NULL }; + { "scaled", "double", "binary", "decimal", NULL }; static const char *interaction_options[] = { "unknown", "batch", "nonstop", "scroll", "errorstop", NULL }; @@ -255,18 +274,34 @@ static const char *stop_clip_fields[] = static const char *no_fields[] = { NULL }; +/*tex -/* The list of supported MPlib options (not all make sense) */ + The list of supported MPlib options (not all make sense). + +*/ typedef enum { - P_ERROR_LINE, P_MAX_LINE, P_RANDOM_SEED, P_MATH_MODE, - P_INTERACTION, P_INI_VERSION, P_MEM_NAME, P_JOB_NAME, P_FIND_FILE, - P_RUN_SCRIPT, P_MAKE_TEXT, P_SCRIPT_ERROR, P_EXTENSIONS, - P__SENTINEL } mplib_parm_idx; + P_ERROR_LINE, + P_MAX_LINE, + P_RANDOM_SEED, + P_MATH_MODE, + P_INTERACTION, + P_INI_VERSION, + P_MEM_NAME, + P_JOB_NAME, + P_FIND_FILE, + P_RUN_SCRIPT, + P_MAKE_TEXT, + P_SCRIPT_ERROR, + P_EXTENSIONS, + P__SENTINEL +} mplib_parm_idx; typedef struct { - const char *name; /* parameter name */ - mplib_parm_idx idx; /* parameter index */ + /*tex parameter name */ + const char *name; + /*tex parameter index */ + mplib_parm_idx idx; } mplib_parm_struct; static mplib_parm_struct mplib_parms[] = { @@ -284,10 +319,11 @@ static mplib_parm_struct mplib_parms[] = { {NULL, P__SENTINEL } }; +/*tex -/* Start by defining the needed callback routines for the library */ + We start by defining the needed callback routines for the library. -/* todo: make subtable in registry, beware, for all mp instances */ +*/ static char *mplib_find_file(MP mp, const char *fname, const char *fmode, int ftype) { @@ -300,7 +336,7 @@ static char *mplib_find_file(MP mp, const char *fname, const char *fmode, int ft lua_pushstring(L, fname); lua_pushstring(L, fmode); if (ftype >= mp_filetype_text) { - lua_pushnumber(L, (lua_Number)(ftype - mp_filetype_text)); + lua_pushinteger(L, (ftype - mp_filetype_text)); } else { lua_pushstring(L, mplib_filetype_names[ftype]); } @@ -311,7 +347,8 @@ static char *mplib_find_file(MP mp, const char *fname, const char *fmode, int ft x = lua_tostring(L, -1); if (x != NULL) s = strdup(x); - lua_pop(L, 1); /* pop the string */ + /*tex pop the string */ + lua_pop(L, 1); return s; } else { lua_pop(L, 1); @@ -325,7 +362,8 @@ static char *mplib_find_file(MP mp, const char *fname, const char *fmode, int ft static int mplib_find_file_function(lua_State * L) { if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { - return 1; /* error */ + /*tex An error. */ + return 1; } lua_pushstring(L, "mplib.file_finder"); lua_pushvalue(L, -2); @@ -333,6 +371,11 @@ static int mplib_find_file_function(lua_State * L) return 0; } +static void mplib_warning(const char *str) +{ + fprintf(stdout,"mplib warning: %s\n",str); +} + static void mplib_script_error(MP mp, const char *str) { lua_State *L = (lua_State *)mp_userdata(mp); @@ -340,9 +383,10 @@ static void mplib_script_error(MP mp, const char *str) lua_getfield(L, LUA_REGISTRYINDEX, "mplib.script_error"); if (lua_isfunction(L, -1)) { lua_pushstring(L, str); - lua_pcall(L, 1, 0, 0); /* assume the function is ok */ + /*tex We assume that the function is okay. */ + lua_pcall(L, 1, 0, 0); } else { - fprintf(stdout,"Error in script: %s\n",str); + mplib_warning(str); lua_pop(L, 1); } } @@ -350,7 +394,8 @@ static void mplib_script_error(MP mp, const char *str) static int mplib_script_error_function(lua_State * L) { if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { - return 1; /* error */ + /*tex An error. */ + return 1; } lua_pushstring(L, "mplib.script_error"); lua_pushvalue(L, -2); @@ -368,13 +413,14 @@ static char *mplib_run_script(MP mp, const char *str) const char *x = NULL; lua_pushstring(L, str); if (lua_pcall(L, 1, 1, 0) != 0) { - mplib_script_error(mp, lua_tostring(L, -1)); + fprintf(stdout,"mplib warning: error in script: %s\n",lua_tostring(L, -1)); return NULL; } x = lua_tostring(L, -1); if (x != NULL) s = strdup(x); - lua_pop(L, 1); /* pop the string */ + /*tex Pop the string. */ + lua_pop(L, 1); return s; } else { lua_pop(L, 1); @@ -385,7 +431,7 @@ static char *mplib_run_script(MP mp, const char *str) static int mplib_run_script_function(lua_State * L) { if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { - return 1; /* error */ + return 1; /* error */ } lua_pushstring(L, "mplib.run_script"); lua_pushvalue(L, -2); @@ -410,7 +456,8 @@ static char *mplib_make_text(MP mp, const char *str, int mode) x = lua_tostring(L, -1); if (x != NULL) s = strdup(x); - lua_pop(L, 1); /* pop the string */ + /*tex Pop the string. */ + lua_pop(L, 1); return s; } else { lua_pop(L, 1); @@ -421,7 +468,8 @@ static char *mplib_make_text(MP mp, const char *str, int mode) static int mplib_make_text_function(lua_State * L) { if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { - return 1; /* error */ + /*tex An error. */ + return 1; } lua_pushstring(L, "mplib.make_text"); lua_pushvalue(L, -2); @@ -487,7 +535,8 @@ static int mplib_new(lua_State * L) int i; struct MP_options *options = mp_options(); options->userdata = (void *) L; - options->noninteractive = 1; /* required ! */ + /*tex Required: */ + options->noninteractive = 1; options->extensions = 0 ; options->find_file = mplib_find_file; options->run_script = mplib_run_script; @@ -500,56 +549,59 @@ static int mplib_new(lua_State * L) lua_getfield(L, 1, mplib_parms[i].name); if (lua_isnil(L, -1)) { lua_pop(L, 1); - continue; /* skip unset */ + continue; } switch (mplib_parms[i].idx) { - case P_ERROR_LINE: - options->error_line = (int)lua_tointeger(L, -1); - if (options->error_line<60) options->error_line =60; - if (options->error_line>250) options->error_line = 250; - options->half_error_line = (options->error_line/2)+10; - break; - case P_MAX_LINE: - options->max_print_line = (int)lua_tointeger(L, -1); - if (options->max_print_line<60) options->max_print_line = 60; - break; - case P_RANDOM_SEED: - options->random_seed = (int)lua_tointeger(L, -1); - break; - case P_INTERACTION: - options->interaction = luaL_checkoption(L, -1, "errorstopmode", interaction_options); - break; - case P_MATH_MODE: - options->math_mode = luaL_checkoption(L, -1, "scaled", math_options); - break; - case P_JOB_NAME: - options->job_name = strdup(lua_tostring(L, -1)); - break; - case P_FIND_FILE: - if (mplib_find_file_function(L)) { /* error here */ - fprintf(stdout,"Invalid arguments to mp.new { find_file = ... }\n"); - } - break; - case P_RUN_SCRIPT: - if (mplib_run_script_function(L)) { /* error here */ - fprintf(stdout,"Invalid arguments to mp.new { run_script = ... }\n"); - } - break; - case P_MAKE_TEXT: - if (mplib_make_text_function(L)) { /* error here */ - fprintf(stdout,"Invalid arguments to mp.new { make_text = ... }\n"); - } - break; - case P_SCRIPT_ERROR: - if (mplib_script_error_function(L)) { /* error here */ - fprintf(stdout,"Invalid arguments to mp.new { script_error = ... }\n"); - } - break; - case P_EXTENSIONS: - options->extensions = (int)lua_tointeger(L, -1); - break; - default: - break; + case P_ERROR_LINE: + options->error_line = (int)lua_tointeger(L, -1); + if (options->error_line < 60) + options->error_line = 60; + if (options->error_line > 250) + options->error_line = 250; + options->half_error_line = (options->error_line/2)+10; + break; + case P_MAX_LINE: + options->max_print_line = (int)lua_tointeger(L, -1); + if (options->max_print_line < 60) + options->max_print_line = 60; + break; + case P_RANDOM_SEED: + options->random_seed = (int)lua_tointeger(L, -1); + break; + case P_INTERACTION: + options->interaction = luaL_checkoption(L, -1, "errorstopmode", interaction_options); + break; + case P_MATH_MODE: + options->math_mode = luaL_checkoption(L, -1, "scaled", math_options); + break; + case P_JOB_NAME: + options->job_name = strdup(lua_tostring(L, -1)); + break; + case P_FIND_FILE: + if (mplib_find_file_function(L)) { + mplib_warning("function expected for 'find_file'"); + } + break; + case P_RUN_SCRIPT: + if (mplib_run_script_function(L)) { + mplib_warning("function expected for 'run_script'"); + } + break; + case P_MAKE_TEXT: + if (mplib_make_text_function(L)) { + mplib_warning("function expected for 'make_text'"); + } + break; + case P_SCRIPT_ERROR: + if (mplib_script_error_function(L)) { + mplib_warning("function expected for 'script_error'"); + } + break; + case P_EXTENSIONS: + options->extensions = (int)lua_tointeger(L, -1); + break; + default: + break; } lua_pop(L, 1); } @@ -626,7 +678,7 @@ static int mplib_wrapresults(lua_State * L, mp_run_data *res, int status) res->edges = NULL; } mplib_push_S(status); - lua_pushnumber(L, (lua_Number)status); + lua_pushinteger(L, status); lua_rawset(L,-3); return 1; } @@ -716,16 +768,16 @@ static int mplib_statistics(lua_State * L) if (*mp_ptr != NULL) { lua_newtable(L); mplib_push_S(memory); - lua_pushnumber(L, (lua_Number)mp_memory_usage(*mp_ptr)); + lua_pushinteger(L, mp_memory_usage(*mp_ptr)); lua_rawset(L,-3); mplib_push_S(hash); - lua_pushnumber(L, (lua_Number)mp_hash_usage(*mp_ptr)); + lua_pushinteger(L, mp_hash_usage(*mp_ptr)); lua_rawset(L,-3); mplib_push_S(params); - lua_pushnumber(L, (lua_Number)mp_param_usage(*mp_ptr)); + lua_pushinteger(L, mp_param_usage(*mp_ptr)); lua_rawset(L,-3); mplib_push_S(open); - lua_pushnumber(L, (lua_Number)mp_open_usage(*mp_ptr)); + lua_pushinteger(L, mp_open_usage(*mp_ptr)); lua_rawset(L,-3); } else { lua_pushnil(L); @@ -733,7 +785,6 @@ static int mplib_statistics(lua_State * L) return 1; } - static int set_direction (lua_State * L, MP mp, mp_knot p) { double direction_x = 0, direction_y = 0; direction_x = (double)lua_tonumber(L,-1); @@ -821,8 +872,8 @@ static int set_right_control (lua_State * L, MP mp, mp_knot p) { return 1; } - #if 0 + #define ROUNDED_ZERO(v) (fabs((v))<0.00001 ? 0 : (v)) #define PI 3.1415926535897932384626433832795028841971 #define RADIANS(a) (mp_number_as_double(mp,(a)) / 16.0) * PI/180.0 @@ -915,6 +966,7 @@ void mp_dump_path (MP mp, mp_knot h) { printf("cycle"); printf (";\n"); } + #endif static int mplib_solve_path(lua_State * L) @@ -938,10 +990,8 @@ static int mplib_solve_path(lua_State * L) mp = *mp_ptr; cyclic = lua_toboolean(L,3); lua_pop(L,1); - - /* build up the path */ + /*tex We build up the path. */ numpoints = lua_objlen(L,2); - first = p = NULL; for (i=1;i<=numpoints;i++) { int left_set = 0, right_set = 0; @@ -951,7 +1001,6 @@ static int mplib_solve_path(lua_State * L) errormsg = "Wrong argument types"; goto BAD; } - mplib_push_S(x_coord); lua_rawget(L,-2); if (!lua_isnumber(L,-1)) { @@ -960,7 +1009,6 @@ static int mplib_solve_path(lua_State * L) } x_coord = (double)lua_tonumber(L,-1); lua_pop(L,1); - mplib_push_S(y_coord); lua_rawget(L,-2); if (!lua_isnumber(L,-1)) { @@ -969,11 +1017,14 @@ static int mplib_solve_path(lua_State * L) } y_coord = (double)lua_tonumber(L,-1); lua_pop(L,1); - q = p; if (q!=NULL) { - /* we have to save the right_tension because |mp_append_knot| trashes - it, believing that it is as yet uninitialized */ + /*tex + + We have to save the right_tension because |mp_append_knot| + trashes it, believing that it is as yet uninitialized. + + */ double saved_tension = mp_number_as_double(mp, mp_knot_right_tension(mp,p)); p = mp_append_knot(mp, p, x_coord, y_coord); if ( ! p ) { @@ -988,10 +1039,8 @@ static int mplib_solve_path(lua_State * L) goto BAD; } } - if (first == NULL) first = p; - mplib_push_S(left_curl); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1001,9 +1050,9 @@ static int mplib_solve_path(lua_State * L) } left_set = 1; } else { - lua_pop(L,1); /* a nil value */ + /*tex A |nil| value. */ + lua_pop(L,1); } - mplib_push_S(left_tension); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1018,9 +1067,9 @@ static int mplib_solve_path(lua_State * L) left_set = 1; } } else { - lua_pop(L,1); /* a nil value */ + /*tex A |nil| value. */ + lua_pop(L,1); } - mplib_push_S(left_x); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1036,7 +1085,6 @@ static int mplib_solve_path(lua_State * L) } else { lua_pop(L,1); } - mplib_push_S(right_curl); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1046,9 +1094,9 @@ static int mplib_solve_path(lua_State * L) } right_set = 1; } else { - lua_pop(L,1); /* a nil value */ + /*tex A |nil| value. */ + lua_pop(L,1); } - mplib_push_S(right_tension); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1065,7 +1113,6 @@ static int mplib_solve_path(lua_State * L) } else { lua_pop(L,1); } - mplib_push_S(right_x); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1081,7 +1128,6 @@ static int mplib_solve_path(lua_State * L) } else { lua_pop(L,1); } - mplib_push_S(direction_x); lua_rawget(L,-2); if (lua_isnumber(L,-1)) { @@ -1090,12 +1136,12 @@ static int mplib_solve_path(lua_State * L) goto BAD; } } else { - lua_pop(L,1); /* a nil value */ + /*tex A |nil| value. */ + lua_pop(L,1); } - - lua_pop(L,1); /* done with this item */ + /*tex Up the next item */ + lua_pop(L,1); } - if (cyclic) { mp_close_path_cycle (mp, p, first); } else { @@ -1104,12 +1150,12 @@ static int mplib_solve_path(lua_State * L) #if 0 mp_dump_path(mp,first); #endif - /* finished reading arguments */ + /*tex We're finished reading arguments. */ if (!mp_solve_path(mp,first)) { errormsg = "Failed to solve the path"; goto BAD; } - /* squeeze the new values back into the table */ + /*tex Squeeze the new values back into the table. */ p = first; for (i=1;i<=numpoints;i++) { lua_rawgeti(L,-1, i); @@ -1117,14 +1163,14 @@ static int mplib_solve_path(lua_State * L) mplib_push_S(left_y); lua_pushnumber(L, mp_number_as_double(mp, mp_knot_left_y(mp, p))); lua_rawset(L,-3); mplib_push_S(right_x); lua_pushnumber(L, mp_number_as_double(mp, mp_knot_right_x(mp, p))); lua_rawset(L,-3); mplib_push_S(right_y); lua_pushnumber(L, mp_number_as_double(mp, mp_knot_right_y(mp, p))); lua_rawset(L,-3); - /* is this really needed */ - mplib_push_S(left_tension); lua_pushnil(L); lua_rawset(L,-3); - mplib_push_S(right_tension); lua_pushnil(L); lua_rawset(L,-3); - mplib_push_S(left_curl); lua_pushnil(L); lua_rawset(L,-3); - mplib_push_S(right_curl); lua_pushnil(L); lua_rawset(L,-3); - mplib_push_S(direction_x); lua_pushnil(L); lua_rawset(L,-3); - mplib_push_S(direction_y); lua_pushnil(L); lua_rawset(L,-3); - /* till here */ + /*tex This is a bit overkill \unknown */ + mplib_push_S(left_tension); lua_pushnil(L); lua_rawset(L,-3); + mplib_push_S(right_tension); lua_pushnil(L); lua_rawset(L,-3); + mplib_push_S(left_curl); lua_pushnil(L); lua_rawset(L,-3); + mplib_push_S(right_curl); lua_pushnil(L); lua_rawset(L,-3); + mplib_push_S(direction_x); lua_pushnil(L); lua_rawset(L,-3); + mplib_push_S(direction_y); lua_pushnil(L); lua_rawset(L,-3); + /*tex \unknown\ till here. */ mplib_push_S(left_type); lua_pushstring(L, knot_type_enum[mp_knot_left_type(mp, p)]); lua_rawset(L, -3); mplib_push_S(right_type); lua_pushstring(L, knot_type_enum[mp_knot_right_type(mp, p)]); lua_rawset(L, -3); lua_pop(L,1); @@ -1132,7 +1178,7 @@ static int mplib_solve_path(lua_State * L) } lua_pushboolean(L, 1); return 1; -BAD: + BAD: if (p != NULL) { mp_close_path (mp, p, first); mp_free_path (mp, p); @@ -1142,7 +1188,11 @@ BAD: return 2; } -/* figure methods */ +/*tex + + The next methods are for collecting the results from |fig|. + +*/ static int mplib_fig_collect(lua_State * L) { @@ -1171,7 +1221,8 @@ static int mplib_fig_body(lua_State * L) i++; p = p->next; } - (*hh)->body = NULL; /* prevent double free */ + /*tex Prevent a double free: */ + (*hh)->body = NULL; return 1; } @@ -1233,7 +1284,6 @@ static int mplib_fig_svg(lua_State * L) return 1; } - static int mplib_fig_png(lua_State * L) { mp_run_data *res; @@ -1316,8 +1366,6 @@ static int mplib_fig_charcode(lua_State * L) return 1; } - - static int mplib_fig_bb(lua_State * L) { struct mp_edge_object **hh = is_fig(L, 1); @@ -1333,7 +1381,11 @@ static int mplib_fig_bb(lua_State * L) return 1; } -/* object methods */ +/*tex + + The methods for the figure objects plus a few helpers. + +*/ static int mplib_gr_collect(lua_State * L) { @@ -1413,7 +1465,6 @@ static double coord_range_y (mp_gr_knot h, double dz) { return (zhi - zlo <= dz ? aspect_bound : aspect_default); } - static int mplib_gr_peninfo(lua_State * L) { double x_coord, y_coord, left_x, left_y, right_x, right_y; double wx, wy; @@ -1481,6 +1532,13 @@ static int mplib_gr_peninfo(lua_State * L) { return 1; } +/*tex + + Here is a helper that reports the valid field names of the possible + objects. + +*/ + static int mplib_gr_fields(lua_State * L) { const char **fields; @@ -1526,7 +1584,6 @@ static int mplib_gr_fields(lua_State * L) return 1; } - #define mplib_push_number(L,x) lua_pushnumber(L,(lua_Number)(x)) #define MPLIB_PATH 0 @@ -1534,7 +1591,7 @@ static int mplib_gr_fields(lua_State * L) static void mplib_push_path(lua_State * L, mp_gr_knot h, int is_pen) { - mp_gr_knot p; /* for scanning the path */ + mp_gr_knot p; int i = 1; p = h; if (p != NULL) { @@ -1583,16 +1640,63 @@ static void mplib_push_path(lua_State * L, mp_gr_knot h, int is_pen) } } -/* this assumes that the top of the stack is a table - or nil already in the case +static int mplib_get_path(lua_State * L) +{ + MP *mp = is_mp(L, 1); + if (*mp != NULL) { + size_t l; + const char *s = lua_tolstring(L, 2, &l); + if (s != NULL) { + mp_knot p = mp_get_path_value(*mp,s,l) ; + if (p != NULL) { + int i = 1; + mp_knot h = p; + lua_newtable(L); + do { + lua_createtable(L, 6, 1); + mplib_push_number(L, mp_number_as_double(*mp,p->x_coord)); + lua_rawseti(L,-2,1); + mplib_push_number(L, mp_number_as_double(*mp,p->y_coord)); + lua_rawseti(L,-2,2); + mplib_push_number(L, mp_number_as_double(*mp,p->left_x)); + lua_rawseti(L,-2,3); + mplib_push_number(L, mp_number_as_double(*mp,p->left_y)); + lua_rawseti(L,-2,4); + mplib_push_number(L, mp_number_as_double(*mp,p->right_x)); + lua_rawseti(L,-2,5); + mplib_push_number(L, mp_number_as_double(*mp,p->right_y)); + lua_rawseti(L,-2,6); + lua_rawseti(L,-2, i); + i++; + if (p->data.types.right_type == mp_endpoint) { + mplib_push_S(cycle); + lua_pushboolean(L,0); + lua_rawset(L,-3); + return 1; + } + p = p->next; + } while (p != h); + mplib_push_S(cycle); + lua_pushboolean(L,1); + lua_rawset(L,-3); + return 1; + } + } + } + return 0; +} + +/*tex + + This assumes that the top of the stack is a table or nil already in the case. */ static void mplib_push_pentype(lua_State * L, mp_gr_knot h) { - mp_gr_knot p; /* for scanning the path */ + mp_gr_knot p; p = h; if (p == NULL) { - /* do nothing */ + /*tex Do nothing. */ } else if (p == p->next) { mplib_push_S(type); mplib_push_S(elliptical); @@ -1643,7 +1747,11 @@ static void mplib_push_color(lua_State * L, struct mp_graphic_object *p) } } -/* the dash scale is not exported, the field has no external value */ +/*tex + + The dash scale is not exported, the field has no external value. + +*/ static void mplib_push_dash(lua_State * L, struct mp_stroked_object *h) { @@ -1811,7 +1919,6 @@ static int mplib_gr_index(lua_State * L) struct mp_graphic_object **hh = is_gr_object(L, 1); if (*hh) { struct mp_graphic_object *h = *hh; - if (mplib_is_S(type, 2)) { lua_rawgeti(L, LUA_REGISTRYINDEX, mplib_type_Ses[h->type]); } else { @@ -1847,61 +1954,77 @@ static int mplib_gr_index(lua_State * L) } static const struct luaL_reg mplib_meta[] = { - {"__gc", mplib_collect}, - {"__tostring", mplib_tostring}, - {NULL, NULL} /* sentinel */ + { "__gc", mplib_collect }, + { "__tostring", mplib_tostring }, + /*tex sentinel */ + { NULL, NULL} }; static const struct luaL_reg mplib_fig_meta[] = { - {"__gc", mplib_fig_collect}, - {"__tostring", mplib_fig_tostring}, - {"objects", mplib_fig_body}, - {"copy_objects", mplib_fig_copy_body}, - {"filename", mplib_fig_filename}, - {"postscript", mplib_fig_postscript}, - {"png", mplib_fig_png}, - {"svg", mplib_fig_svg}, - {"boundingbox", mplib_fig_bb}, - {"width", mplib_fig_width}, - {"height", mplib_fig_height}, - {"depth", mplib_fig_depth}, - {"italcorr", mplib_fig_italcorr}, - {"charcode", mplib_fig_charcode}, - {NULL, NULL} /* sentinel */ + { "__gc", mplib_fig_collect }, + { "__tostring", mplib_fig_tostring }, + { "objects", mplib_fig_body }, + { "copy_objects", mplib_fig_copy_body }, + { "filename", mplib_fig_filename }, + { "postscript", mplib_fig_postscript }, + { "png", mplib_fig_png }, + { "svg", mplib_fig_svg }, + { "boundingbox", mplib_fig_bb }, + { "width", mplib_fig_width }, + { "height", mplib_fig_height }, + { "depth", mplib_fig_depth }, + { "italcorr", mplib_fig_italcorr }, + { "charcode", mplib_fig_charcode }, + /*tex sentinel */ + { NULL, NULL} }; static const struct luaL_reg mplib_gr_meta[] = { - {"__gc", mplib_gr_collect}, - {"__tostring", mplib_gr_tostring}, - {"__index", mplib_gr_index}, - {NULL, NULL} /* sentinel */ + { "__gc", mplib_gr_collect}, + { "__tostring", mplib_gr_tostring}, + { "__index", mplib_gr_index}, + /*tex sentinel */ + { NULL, NULL} }; static const struct luaL_reg mplib_d[] = { - {"execute", mplib_execute}, - {"finish", mplib_finish}, - {"char_width", mplib_charwidth}, - {"char_height", mplib_charheight}, - {"char_depth", mplib_chardepth}, - {"statistics", mplib_statistics}, - {"solve_path", mplib_solve_path}, - {"get_numeric", mplib_get_numeric}, - {"get_number", mplib_get_numeric}, - {"get_boolean", mplib_get_boolean}, - {"get_string", mplib_get_string}, - {NULL, NULL} /* sentinel */ + { "execute", mplib_execute }, + { "finish", mplib_finish }, + { "char_width", mplib_charwidth }, + { "char_height", mplib_charheight }, + { "char_depth", mplib_chardepth }, + { "statistics", mplib_statistics }, + { "solve_path", mplib_solve_path }, + { "get_numeric", mplib_get_numeric }, + { "get_number", mplib_get_numeric }, + { "get_boolean", mplib_get_boolean }, + { "get_string", mplib_get_string }, + { "get_path", mplib_get_path }, + /*tex sentinel */ + {NULL, NULL } }; static const struct luaL_reg mplib_m[] = { - {"new", mplib_new}, - {"version", mplib_version}, - {"fields", mplib_gr_fields}, - {"pen_info", mplib_gr_peninfo}, - {"get_numeric", mplib_get_numeric}, - {"get_number", mplib_get_numeric}, - {"get_boolean", mplib_get_boolean}, - {"get_string", mplib_get_string}, - {NULL, NULL} /* sentinel */ + { "new", mplib_new }, + { "version", mplib_version }, + { "fields", mplib_gr_fields }, + /* indirect */ + { "execute", mplib_execute }, + { "finish", mplib_finish }, + { "char_width", mplib_charwidth }, + { "char_height", mplib_charheight }, + { "char_depth", mplib_chardepth }, + { "statistics", mplib_statistics }, + { "solve_path", mplib_solve_path }, + /* helpers */ + { "pen_info", mplib_gr_peninfo }, + { "get_numeric", mplib_get_numeric }, + { "get_number", mplib_get_numeric }, + { "get_boolean", mplib_get_boolean }, + { "get_string", mplib_get_string }, + { "get_path", mplib_get_path }, + /*tex sentinel */ + { NULL, NULL} }; int luaopen_mplib(lua_State * L) @@ -1909,22 +2032,23 @@ int luaopen_mplib(lua_State * L) mplib_init_Ses(L); luaL_newmetatable(L, MPLIB_GR_METATABLE); - lua_pushvalue(L, -1); /* push metatable */ - lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - luaL_register(L, NULL, mplib_gr_meta); /* object meta methods */ + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + luaL_register(L, NULL, mplib_gr_meta); lua_pop(L, 1); luaL_newmetatable(L, MPLIB_FIG_METATABLE); - lua_pushvalue(L, -1); /* push metatable */ - lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - luaL_register(L, NULL, mplib_fig_meta); /* figure meta methods */ + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + luaL_register(L, NULL, mplib_fig_meta); lua_pop(L, 1); luaL_newmetatable(L, MPLIB_METATABLE); - lua_pushvalue(L, -1); /* push metatable */ - lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - luaL_register(L, NULL, mplib_meta); /* meta methods */ - luaL_register(L, NULL, mplib_d); /* dict methods */ - luaL_register(L, "mplib", mplib_m); /* module functions */ + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + luaL_register(L, NULL, mplib_meta); + luaL_register(L, NULL, mplib_d); + luaL_register(L, "mplib", mplib_m); + return 1; } diff --git a/Build/source/texk/web2c/mplibdir/mp.w b/Build/source/texk/web2c/mplibdir/mp.w index 2c956ea5a83..d52ad37ce8b 100644 --- a/Build/source/texk/web2c/mplibdir/mp.w +++ b/Build/source/texk/web2c/mplibdir/mp.w @@ -139,7 +139,7 @@ typedef struct MP_instance { @ @c /*\#define DEBUGENVELOPE */ -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE static int DEBUGENVELOPECOUNTER=0; #define dbg_str(A) printf("\n--[==[%03d DEBUGENVELOPE ]==] %s", DEBUGENVELOPECOUNTER++, #A) #define dbg_n(A) printf("\n--[==[%03d DEBUGENVELOPE ]==] ['%s']=%s, ", DEBUGENVELOPECOUNTER++, #A, number_tostring(A)) @@ -176,8 +176,8 @@ static int DEBUGENVELOPECOUNTER=0; #include /* for |PNG_LIBPNG_VER_STRING|, |png_libpng_ver| */ /*\#include */ /* for |PIXMAN_VERSION_STRING|, |pixman_version_string()| */ /*\#include */ /* for |CAIRO_VERSION_STRING|, |cairo_version_string()| */ -#include /* for |gmp_version| */ -#include /* for |MPFR_VERSION_STRING|, |mpfr_get_version()| */ +/*\#include */ /* for |gmp_version| */ +/*\#include */ /* for |MPFR_VERSION_STRING|, |mpfr_get_version()| */ #include "mplib.h" #include "mplibps.h" /* external header */ /*\#include "mplibsvg.h" */ /* external header */ @@ -189,7 +189,7 @@ static int DEBUGENVELOPECOUNTER=0; #include "mpmath.h" /* internal header */ #include "mpmathdouble.h" /* internal header */ #include "mpmathdecimal.h" /* internal header */ -#include "mpmathbinary.h" /* internal header */ +/*#include "mpmathbinary.h"*/ /* internal header */ #include "mpstrings.h" /* internal header */ /* BEGIN PATCH */ mp_number dx_ap; /* approximation of dx */ @@ -200,12 +200,19 @@ mp_number ueps_ap; /* epsilon for above approximations */ boolean is_dxdy, is_dxindyin; /* END PATCH */ -@ We move the {\tt cairo} and {\tt pixman} libraries outside {\tt mp.w}, +@ We move the {\tt cairo} and {\tt pixman} libraries outside {\tt mp.w}, to minimize dependencies. @c extern const char *COMPILED_CAIRO_VERSION_STRING; extern const char* cairo_version_string (void); +extern const char *COMPILED_MPFR_VERSION_STRING; +extern const char* mpfr_get_version (void); +extern void * mp_initialize_binary_math (MP mp) ; +extern int COMPILED__GNU_MP_VERSION; +extern int COMPILED__GNU_MP_VERSION_MINOR; +extern int COMPILED__GNU_MP_VERSION_PATCHLEVEL; +extern const char * const COMPILED_gmp_version; extern const char *COMPILED_PIXMAN_VERSION_STRING; extern const char* pixman_version_string (void); extern void mp_png_backend_initialize (MP mp); @@ -2628,7 +2635,7 @@ void mp_new_randoms (MP mp) { mp->j_random = 54; } -@ To consume a random fraction, the program below will say `|next_random|'. +@ To consume a random fraction, the program below will say `|next_random|'. Now each number system has its own implementation, true to the original as much as possibile. @@ -2657,7 +2664,7 @@ As said before, now each number system has its own implementation. @c /*Unused. static void mp\_unif\_rand (MP mp, mp\_number *ret, mp\_number x\_orig) { - mp\_number y; // trial value + mp\_number y; // trial value mp\_number x, abs\_x; mp\_number u; new\_fraction (y); @@ -2896,7 +2903,7 @@ void *do_alloc_node (MP mp, size_t size) { @c void mp_xfree (void *x) { - if (x != NULL) + if (x != NULL) free (x); } void *mp_xrealloc (MP mp, void *p, size_t nmem, size_t size) { @@ -3235,8 +3242,7 @@ mp_random_seed, /* initialize random number generator (\&{randomseed}) */ mp_message_command, /* communicate to user (\&{message}, \&{errmessage}) */ mp_every_job_command, /* designate a starting token (\&{everyjob}) */ mp_delimiters, /* define a pair of delimiters (\&{delimiters}) */ -mp_special_command, /* output special info (\&{special}) - or font map info (\&{fontmapfile}, \&{fontmapline}) */ +mp_special_command, /* output special info (\&{special}) or font map info (\&{fontmapfile}, \&{fontmapline}) */ mp_write_command, /* write text to a file (\&{write}) */ mp_type_name, /* declare a type (\&{numeric}, \&{pair}, etc.) */ mp_left_delimiter, /* the left delimiter of a matching pair */ @@ -3275,15 +3281,13 @@ mp_left_bracket, /* the operator `\.[' */ mp_right_bracket, /* the operator `\.]' */ mp_right_brace, /* the operator `\.{\char`\}}' */ mp_with_option, /* option for filling (\&{withpen}, \&{withweight}, etc.) */ -mp_thing_to_add, - /* variant of \&{addto} (\&{contour}, \&{doublepath}, \&{also}) */ +mp_thing_to_add, /* variant of \&{addto} (\&{contour}, \&{doublepath}, \&{also}) */ mp_of_token, /* the operator `\&{of}' */ mp_to_token, /* the operator `\&{to}' */ mp_step_token, /* the operator `\&{step}' */ mp_until_token, /* the operator `\&{until}' */ mp_within_token, /* the operator `\&{within}' */ -mp_lig_kern_token, - /* the operators `\&{kern}' and `\.{=:}' and `\.{=:\char'174}', etc. */ +mp_lig_kern_token, /* the operators `\&{kern}' and `\.{=:}' and `\.{=:\char'174}', etc. */ mp_assignment, /* the operator `\.{:=}' */ mp_skip_to, /* the operation `\&{skipto}' */ mp_bchar_label, /* the operator `\.{\char'174\char'174:}' */ @@ -4046,6 +4050,7 @@ enum mp_given_internal { mp_pausing, /* positive to display lines on the terminal before they are read */ mp_showstopping, /* positive to stop after each \&{show} command */ mp_fontmaking, /* positive if font metric output is to be produced */ + mp_texscriptmode, /* controls spacing in texmode */ mp_linejoin, /* as in \ps: 0 for mitered, 1 for round, 2 for beveled */ mp_linecap, /* as in \ps: 0 for butt, 1 for round, 2 for square */ mp_miterlimit, /* controls miter length as in \ps */ @@ -4196,6 +4201,8 @@ mp_primitive (mp, "showstopping", mp_internal_quantity, mp_showstopping); @:mp_showstopping_}{\&{showstopping} primitive@>; mp_primitive (mp, "fontmaking", mp_internal_quantity, mp_fontmaking); @:mp_fontmaking_}{\&{fontmaking} primitive@>; +mp_primitive (mp, "texscriptmode", mp_internal_quantity, mp_texscriptmode); +@:mp_texscriptmode_}{\&{texscriptmode} primitive@>; mp_primitive (mp, "linejoin", mp_internal_quantity, mp_linejoin); @:mp_linejoin_}{\&{linejoin} primitive@>; mp_primitive (mp, "linecap", mp_internal_quantity, mp_linecap); @@ -4214,8 +4221,7 @@ mp_primitive (mp, "mpprocset", mp_internal_quantity, mp_procset); @:mp_procset_}{\&{mpprocset} primitive@>; mp_primitive (mp, "troffmode", mp_internal_quantity, mp_gtroffmode); @:troffmode_}{\&{troffmode} primitive@>; -mp_primitive (mp, "defaultcolormodel", mp_internal_quantity, - mp_default_color_model); +mp_primitive (mp, "defaultcolormodel", mp_internal_quantity, mp_default_color_model); @:mp_default_color_model_}{\&{defaultcolormodel} primitive@>; mp_primitive (mp, "restoreclipcolor", mp_internal_quantity, mp_restore_clip_color); @:mp_restore_clip_color_}{\&{restoreclipcolor} primitive@>; @@ -4273,6 +4279,7 @@ set_internal_string (mp_output_format, mp_intern (mp, "eps")); set_internal_string (mp_output_format_options, mp_intern (mp, "")); set_internal_string (mp_number_system, mp_intern (mp, "scaled")); set_internal_from_number (mp_number_precision, precision_default); +set_internal_from_number (mp_texscriptmode, unity_t); #if DEBUG number_clone (internal_value (mp_tracing_titles), three_t); number_clone (internal_value (mp_tracing_equations), three_t); @@ -4320,6 +4327,7 @@ set_internal_name (mp_design_size, xstrdup ("designsize")); set_internal_name (mp_pausing, xstrdup ("pausing")); set_internal_name (mp_showstopping, xstrdup ("showstopping")); set_internal_name (mp_fontmaking, xstrdup ("fontmaking")); +set_internal_name (mp_texscriptmode, xstrdup ("texscriptmode")); set_internal_name (mp_linejoin, xstrdup ("linejoin")); set_internal_name (mp_linecap, xstrdup ("linecap")); set_internal_name (mp_miterlimit, xstrdup ("miterlimit")); @@ -4443,6 +4451,8 @@ class numbers in nonstandard extensions of \MP. @d invalid_class 20 /* bad character in the input */ @d max_class 20 /* the largest class number */ +@d semicolon_class 6 /* the ; */ + @= #define digit_class 0 /* the class number of \.{0123456789} */ int char_class[256]; /* the class numbers */ @@ -4843,10 +4853,26 @@ char *mp_get_string_value (MP mp, const char *s, size_t l) { return NULL; } +mp_knot mp_get_path_value (MP mp, const char *s, size_t l) { + char *ss = mp_xstrdup(mp,s); + if (ss) { + mp_sym sym = mp_id_lookup(mp,ss,l,false); + if (sym != NULL) { + if (mp_type(sym->v.data.node) == mp_path_type) { + mp_xfree (ss); + return (mp_knot) sym->v.data.node->data.p; + } + } + } + mp_xfree (ss); + return NULL; +} + @ @= double mp_get_numeric_value(MP mp,const char *s,size_t l); int mp_get_boolean_value(MP mp,const char *s,size_t l); char *mp_get_string_value(MP mp,const char *s,size_t l); +mp_knot mp_get_path_value(MP mp,const char *s,size_t l); @ We need to put \MP's ``primitive'' symbolic tokens into the hash table, together with their command code (which will be the |eq_type|) @@ -13270,26 +13296,26 @@ static mp_knot mp_offset_prep (MP mp, mp_knot c, mp_knot h) { c0 = c; k_needed = 0; #ifdef DEBUGENVELOPE -dbg_nl;dbg_str(--[==[BEGIN]==]);dbg_nl; -dbg_str(return {);dbg_nl; +dbg_nl;dbg_str(--[==[BEGIN]==]);dbg_nl; +dbg_str(return {);dbg_nl; dbg_n(w0->x_coord); dbg_n(w0->y_coord); #endif do { q = mp_next_knot (p); #ifdef DEBUGENVELOPE -dbg_nl;dbg_open_t;dbg_str(--[==[begin loop]==]);dbg_nl; +dbg_nl;dbg_open_t;dbg_str(--[==[begin loop]==]);dbg_nl; dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_n(p->right_x);dbg_n(p->right_y); dbg_n(q->left_x);dbg_n(q->left_y); dbg_n(q->x_coord);dbg_n(q->y_coord); dbg_n(w0->x_coord); dbg_n(w0->y_coord); -#endif +#endif @; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(end Split the cubic between |p| and |q|);dbg_open_t;dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord); dbg_n(w0->x_coord);dbg_n(w0->y_coord); @@ -13301,7 +13327,7 @@ dbg_close_t; dbg_comma;dbg_nl; #ifdef DEBUGENVELOPE dbg_n(w0->x_coord);dbg_n(w0->y_coord); dbg_str(--[==[end loop]==]);dbg_nl; dbg_close_t;dbg_comma;dbg_nl; -#endif +#endif } while (q != c); #ifdef DEBUGENVELOPE dbg_key(Fix the offset change);dbg_open_t;dbg_nl; @@ -13312,7 +13338,7 @@ dbg_str(--[==[end loop]==]);dbg_nl; dbg_close_t;dbg_comma;dbg_nl; #endif @; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_key_ival(info post,mp_knot_info(p));dbg_comma;dbg_nl; dbg_n(c->x_coord);dbg_n(c->y_coord); @@ -13412,7 +13438,7 @@ the testcase reported by Bogus\l{}aw Jackowski in tracker id 267, case 52c on Sarovar.) @= -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(Advance |p| to node |q|);dbg_nl; #endif q0 = q; @@ -13437,11 +13463,11 @@ if ((q != q0) && (q != c || c == c0)) @ @= { - #ifdef DEBUGENVELOPE + #ifdef DEBUGENVELOPE dbg_key(Remove the cubic following p);dbg_open_t;dbg_nl; dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_key_ival(pre info p,mp_knot_info(p)); dbg_close_t;dbg_comma;dbg_nl; - #endif + #endif k_needed = mp_knot_info (p) - zero_off; if (r == q) { q = p; @@ -13459,11 +13485,11 @@ if ((q != q0) && (q != c || c == c0)) mp->spec_p2 = p; r = p; mp_remove_cubic (mp, p); - #ifdef DEBUGENVELOPE + #ifdef DEBUGENVELOPE dbg_key(Remove the cubic following p);dbg_open_t;dbg_nl; dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_key_ival(post info p,mp_knot_info (p)); dbg_close_t;dbg_comma;dbg_nl; - #endif + #endif } @@ -13532,16 +13558,16 @@ We may have to split a cubic into many pieces before each piece corresponds to a unique offset. @= -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(Split the cubic between |p| and |q|);dbg_nl; dbg_key(Split the cubic);dbg_open_t;dbg_nl; dbg_key_ival(pre info p,mp_knot_info(p));dbg_comma; dbg_n(w0->x_coord);dbg_n(w0->y_coord); -#endif +#endif mp_knot_info (p) = zero_off + k_needed; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key_ival(post info p,mp_knot_info(p));dbg_close_t;dbg_comma; dbg_nl; -#endif +#endif k_needed = 0; @; @@ -13708,7 +13734,7 @@ void mp_fin_offset_prep (MP mp, mp_knot p, mp_knot w, mp_number new_number(t2); new_fraction(s); new_fraction(t); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(mp_fin_offset_prep);dbg_open_t;dbg_nl; #endif while (1) { @@ -13716,7 +13742,7 @@ dbg_key(mp_fin_offset_prep);dbg_open_t;dbg_nl; ww = mp_next_knot (w); /* a pointer to $w\k$ */ else ww = mp_prev_knot (w); /* a pointer to $w_{k-1}$ */ -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(begin iteration); dbg_open_t;dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord); @@ -13727,11 +13753,11 @@ dbg_in(rise); #endif @; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(crossing_point); #endif crossing_point (t, t0, t1, t2); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_n(t);dbg_n(t0);dbg_n(t1);dbg_n(t2); dbg_in(number_greaterequal(t, fraction_one_t)); dbg_in(turn_amt); @@ -13743,18 +13769,18 @@ dbg_close_t; dbg_comma;dbg_nl; else goto RETURN; } -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(Split the cubic at $t$ and split off another cubic if the derivative crosses back); #endif @; w = ww; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(end iteration); #endif } RETURN: -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_comment(RETURN); dbg_n(t); #endif @@ -13766,7 +13792,7 @@ dbg_n(t); free_number (t0); free_number (t1); free_number (t2); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_close_t; dbg_comma;dbg_nl; #endif } @@ -13782,7 +13808,7 @@ begins to fail. mp_number abs_du, abs_dv; new_number (abs_du); new_number (abs_dv); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(Compute test coefficients |(t0,t1,t2)| for $d(t)$ versus...);dbg_open_t;dbg_nl; #endif set_number_from_substraction(du, ww->x_coord, w->x_coord); @@ -13791,7 +13817,7 @@ dbg_key(Compute test coefficients |(t0,t1,t2)| for $d(t)$ versus...);dbg_open_t; number_abs(abs_du); number_clone(abs_dv, dv); number_abs(abs_dv); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_CUBIC; dbg_n(w->x_coord);dbg_n(w->y_coord); dbg_n(ww->x_coord);dbg_n(ww->y_coord); @@ -13838,7 +13864,7 @@ dbg_in(number_greaterequal(abs_du, abs_dv)); free_number (abs_dv); if (number_negative(t0)) set_number_to_zero(t0); /* should be positive without rounding error */ -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_n(t0);dbg_n(t1);dbg_n(t2); dbg_close_t; dbg_comma;dbg_nl; #endif @@ -13981,19 +14007,19 @@ if (number_zero(dxin) && number_zero(dyin)) { #ifdef DEBUGENVELOPE dbg_key(dxin dyin before);dbg_open_t;dbg_nl; dbg_n(dxin);dbg_n(dyin); -dbg_close_t;dbg_comma; +dbg_close_t;dbg_comma; #endif #ifdef DEBUGENVELOPE dbg_key(dxin dyin after);dbg_open_t;dbg_nl; dbg_n(dxin);dbg_n(dyin); -dbg_close_t;dbg_comma; +dbg_close_t;dbg_comma; #endif /* BEGIN PATCH */ #ifdef DEBUGENVELOPE dbg_key(dx dy dxin dyin after patch);dbg_open_t;dbg_nl; dbg_n(dx);dbg_n(dy);dbg_n(dx_ap);dbg_n(dy_ap); dbg_n(dxin);dbg_n(dyin);dbg_n(dxin_ap);dbg_n(dyin_ap); -dbg_close_t;dbg_comma; +dbg_close_t;dbg_comma; #endif /* END PATCH ****/ @@ -14012,13 +14038,13 @@ right.) This code depends on |w0| being the offset for |(dxin,dyin)|. #ifdef DEBUGENVELOPE dbg_nl; dbg_comment(Update |mp_knot_info(p)|);dbg_nl; -dbg_key(mp_get_turn_amt_dx_dy);dbg_open_t;dbg_str(--[==[call mp_get_turn_amt]==]);dbg_nl; +dbg_key(mp_get_turn_amt_dx_dy);dbg_open_t;dbg_str(--[==[call mp_get_turn_amt]==]);dbg_nl; dbg_n(w0->x_coord);dbg_n(w0->y_coord);dbg_n(dx);dbg_n(dy);dbg_in(number_nonnegative(ab_vs_cd)); dbg_n(ab_vs_cd); #endif is_dxdy=true; turn_amt = mp_get_turn_amt (mp, w0, dx, dy, number_nonnegative(ab_vs_cd)); - is_dxdy=false; + is_dxdy=false; #ifdef DEBUGENVELOPE dbg_dn(turn_amt); dbg_close_t;dbg_comma; @@ -14078,20 +14104,20 @@ integer mp_get_turn_amt (MP mp, mp_knot w, mp_number dx, mp_number dy, boolean c ab_vs_cd (t, dy, arg1, dx, arg2); #ifdef DEBUGENVELOPE dbg_sp; - dbg_open_t;dbg_str(--[==[inside mp_get_turn_amt do loop ]==]);dbg_nl; + dbg_open_t;dbg_str(--[==[inside mp_get_turn_amt do loop ]==]);dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord);dbg_n(ww->x_coord);dbg_n(ww->y_coord); dbg_n(t);dbg_n(dy);dbg_n(arg1);dbg_n(dx);dbg_n(arg2); dbg_n(t_ap);dbg_n(dy_ap);dbg_n(dx_ap);dbg_n(dyin_ap);dbg_n(dxin_ap); dbg_close_t;dbg_comma; dbg_in(number_zero(dx) && number_zero(arg1) && number_positive(dy) && number_positive(arg2) && is_dxdy); - dbg_in(is_dxdy && number_zero(dx) && number_zero(arg1) && number_negative(dy) && number_negative(arg2) && number_positive(dyin_ap)); + dbg_in(is_dxdy && number_zero(dx) && number_zero(arg1) && number_negative(dy) && number_negative(arg2) && number_positive(dyin_ap)); dbg_in(is_dxindyin && number_zero(dx) && number_zero(arg1) && number_positive(dy) && number_positive(arg2) && number_negative(dyin_ap)); dbg_in(number_zero(dy) && number_zero(arg2) && number_negative(dx) && number_negative(arg1)); dbg_in(number_zero(dx) && number_zero(arg1) && number_negative(dy) && number_positive(arg2)); dbg_in(number_zero(dy) && number_zero(arg2) && number_positive(dx) && number_negative(arg1)); dbg_nl; #endif - if (number_negative(t)) + if (number_negative(t)) break; incr (s); w = ww; @@ -14104,7 +14130,7 @@ integer mp_get_turn_amt (MP mp, mp_knot w, mp_number dx, mp_number dy, boolean c ab_vs_cd (t, dy, arg1, dx, arg2); #ifdef DEBUGENVELOPE dbg_sp; - dbg_open_t;dbg_str(--[==[outside mp_get_turn_amt do loop ]==]);dbg_nl; + dbg_open_t;dbg_str(--[==[outside mp_get_turn_amt do loop ]==]);dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord);dbg_n(ww->x_coord);dbg_n(ww->y_coord); dbg_n(t);dbg_n(dy);dbg_n(arg1);dbg_n(dx);dbg_n(arg2); dbg_n(t_ap);dbg_n(dy_ap);dbg_n(dx_ap);dbg_n(dyin_ap);dbg_n(dxin_ap); @@ -14120,7 +14146,7 @@ integer mp_get_turn_amt (MP mp, mp_knot w, mp_number dx, mp_number dy, boolean c ab_vs_cd (t, dy, arg1, dx, arg2); #ifdef DEBUGENVELOPE dbg_sp; - dbg_open_t;dbg_str(--[==[inside mp_get_turn_amt do loop for t<0 ]==]);dbg_nl; + dbg_open_t;dbg_str(--[==[inside mp_get_turn_amt do loop for t<0 ]==]);dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord);dbg_n(ww->x_coord);dbg_n(ww->y_coord); dbg_n(t);dbg_n(dy);dbg_n(arg1);dbg_n(dx);dbg_n(arg2); dbg_n(t_ap);dbg_n(dy_ap);dbg_n(dx_ap); @@ -14173,14 +14199,14 @@ with respect to $d_{k-1}$, and apply |fin_offset_prep| to each part. @= ww = mp_prev_knot (w); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(Complete the offset splitting process);dbg_open_t;dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord); dbg_n(ww->x_coord);dbg_n(ww->y_coord); dbg_close_t; dbg_comma;dbg_nl; #endif @; -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(after Compute test coeff);dbg_open_t;dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord); dbg_n(ww->x_coord);dbg_n(ww->y_coord); @@ -14189,7 +14215,7 @@ dbg_close_t; dbg_comma;dbg_nl; @; if (number_greater(t, fraction_one_t)) { -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(t > fraction_one_t);dbg_open_t;dbg_nl; dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_n(w->x_coord);dbg_n(w->y_coord); @@ -14207,7 +14233,7 @@ dbg_close_t; dbg_comma;dbg_nl; set_number_from_of_the_way(y1a, t, y0, y1); set_number_from_of_the_way(y1, t, y1, y2); set_number_from_of_the_way(y2a, t, y1a, y1); -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(t <= fraction_one_t);dbg_open_t;dbg_nl; dbg_n(p->x_coord);dbg_n(p->y_coord); dbg_n(t); @@ -14245,7 +14271,7 @@ dbg_close_t; dbg_comma;dbg_nl; mp_fin_offset_prep (mp, r, ww, x0, x1, x2, y0, y1, y2, -1, (-1 - turn_amt)); } } -#ifdef DEBUGENVELOPE +#ifdef DEBUGENVELOPE dbg_key(end Complete the offset splitting process);dbg_open_t;dbg_nl; dbg_n(w->x_coord);dbg_n(w->y_coord); dbg_n(w0->x_coord);dbg_n(w0->y_coord); @@ -14278,7 +14304,7 @@ crossing and the first crossing cannot be antiparallel. @= #ifdef DEBUGENVELOPE dbg_key(Find the first |t| where);dbg_open_t;dbg_nl; -#endif +#endif crossing_point (t, t0, t1, t2); if (turn_amt >= 0) { if (number_negative(t2)) { @@ -14316,7 +14342,7 @@ if (turn_amt >= 0) { #ifdef DEBUGENVELOPE dbg_n(t); dbg_close_t; dbg_comma;dbg_nl; -#endif +#endif @ @= @@ -19845,6 +19871,7 @@ is less than |loop_text|. @ @= if (s != NULL) { int k ; + mp_value new_expr; size_t size = strlen(s); memset(&new_expr,0,sizeof(mp_value)); new_number(new_expr.data.n); @@ -19860,7 +19887,6 @@ if (s != NULL) { } limit = (halfword) k; (void) memcpy ((mp->buffer + mp->first), s, size); - free(s); mp->buffer[limit] = xord ('%'); mp->first = (size_t) (limit + 1); loc = start; @@ -19891,26 +19917,42 @@ if (s != NULL) { } else { mp_back_input (mp); if (cur_exp_str ()->len > 0) { - mp_value new_expr; char *s = mp->run_script(mp,(const char*) cur_exp_str()->str) ; @ + free(s); } } } -@ @= +@ The |texscriptmode| parameter controls how spaces and newlines get honoured in +|btex| or |verbatimtex| ... |etex|. The default value is~1. Possible values are: +0: no newlines, 1: newlines in |verbatimtex|, 2: newlines in |verbatimtex| and +|etex|, 3: no leading and trailing strip in |verbatimtex|, 4: no leading and +trailing strip in |verbatimtex| and |btex|. That way the Lua handler can do what +it likes. An |etex| has to be followed by a space or |;| or be at the end of a +line and preceded by a space or at the beginning of a line. + +@= { - int first ; - while ((loc < limit - 4) && (mp->buffer[loc] == ' ')) { + char *txt = NULL; + char *ptr = NULL; + int slin = line; + int size = 0; + int done = 0; + int mode = round_unscaled(internal_value(mp_texscriptmode)) ; /* default: 1 */ + int verb = cur_mod() == verbatim_code; + int first; + /* we had a (mandate) trailing space */ + if (loc <= limit && mp->char_class[mp->buffer[loc]] == space_class) { incr(loc); + } else { + /* maybe issue an error message and quit */ } - first = loc ; - if (mp->buffer[loc-1] == ' ') { - decr(loc); - } - while (loc < limit - 5) { - if (mp->buffer[loc] == ' ') { - incr(loc); + /* we loop over lines */ + first = loc; + while (1) { + /* we don't need to check when we have less than 4 characters left */ + if (loc < limit - 4) { if (mp->buffer[loc] == 'e') { incr(loc); if (mp->buffer[loc] == 't') { @@ -19918,39 +19960,135 @@ if (s != NULL) { if (mp->buffer[loc] == 'e') { incr(loc) ; if (mp->buffer[loc] == 'x') { - /* start action */ - char *s, *txt ; - int size ; - mp_value new_expr; - size = loc - first + 1 - 4 ; - if (size < 0) { - size = 0 ; - } else { - while ((size > 1) && (mp->buffer[first+size-1] == ' ')) { - decr(size); - } + /* let's see if we have the right boundary */ + if (first == (loc - 3)) { + /* when we're at the start of a line no leading space is required */ + done = 1; + } else if (mp->char_class[mp->buffer[loc - 4]] == space_class) { + /* when we're beyond the start of a line a leading space is required */ + done = 2; } - txt = malloc(size+1); - if (size > 0) { - (void) memcpy (txt, mp->buffer + first, size); + if (done) { + if ((loc + 1) <= limit) { + quarterword c = mp->char_class[mp->buffer[loc + 1]] ; + if (c != letter_class) { + incr(loc) ; + /* we're past the 'x' */ + break; + } else { + /* this is no valid etex */ + done = 0; + } + } else { + /* when we're at the end of a line we're ok */ + incr(loc) ; + /* we're past the 'x' */ + break; + } } - txt[size] = '\0'; - incr(loc); - s = mp->make_text(mp,txt,(cur_mod() == verbatim_code)) ; /* we could pass the size */ - @ - /* done */ - free(txt); - break ; - } else { - // decr(loc) ; } } } } + } + /* no etex seen (yet) */ + if (loc >= limit) { + if (size) { + txt = realloc(txt, size + limit - first + 1); + } else { + txt = malloc(limit - first + 1); + } + (void) memcpy (txt + size, mp->buffer + first, limit - first); + size += limit - first + 1; + if (mode <= 0) { + txt[size - 1] = ' '; + } else if (verb) { + /* modes >= 1 permit a newline in verbatimtex */ + txt[size - 1] = '\n'; + } else if (mode >= 2) { + /* modes >= 2 permit a newline in btex */ + txt[size - 1] = '\n'; + } else { + txt[size - 1] = ' '; + } + if (move_to_next_line(mp)) { + /* we abort the scanning */ + goto FATAL_ERROR; + } + first = loc; } else { incr(loc); } } + if (done) { + /* we're past the 'x' */ + int l = loc - 5 ; // 4 + int n = l - first + 1 ; + /* we're before the 'etex' */ + if (done == 2) { + /* we had ' etex' */ + l -= 1; + n -= 1; + /* we're before the ' etex' */ + } + if (size) { + txt = realloc(txt, size + n + 1); + } else { + txt = malloc(n + 1); + } + (void) memcpy (txt + size, mp->buffer + first, n); /* 0 */ + size += n; + if (verb && mode >= 3) { + /* don't strip verbatimtex */ + txt[size] = '\0'; + ptr = txt; + } else if (mode >= 4) { + /* don't strip btex */ + txt[size] = '\0'; + ptr = txt; + } else { + /* strip trailing whitespace, we have a \0 so we're one off */ + /* while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-2]] == space_class || txt[size-2] == '\n')) { */ + while ((size > 1) && (mp->char_class[(ASCII_code) txt[size-1]] == space_class || txt[size-1] == '\n')) { + decr(size); + } + /* prune the string */ + txt[size] = '\0'; + /* strip leading whitespace */ + ptr = txt; + while ((size > 1) && (mp->char_class[(ASCII_code) ptr[0]] == space_class || ptr[0] == '\n')) { + incr(ptr); + decr(size); + } + } + /* action */ + { + char *s = mp->make_text(mp,ptr,verb) ; + @ + free(s); + } + free(txt); + /* really needed */ + mp_get_next(mp); + return; + } + /* + we don't recover because in practice the graphic will be broken anyway and + we're not really interacting in mplib .. just fix the input + */ + FATAL_ERROR: + { + /* line numbers are not always meaningfull so we can get a 0 reported */ + char msg[256]; + const char *hlp[] = { "An 'etex' is missing at this input level, nothing gets done.", NULL }; + if (slin > 0) { + mp_snprintf(msg, 256, "No matching 'etex' for '%stex'.", verb ? "verbatim" : "b"); + } else { + mp_snprintf(msg, 256, "No matching 'etex' for '%stex' in line %d.", verb ? "verbatim" : "b",slin); + } + mp_error (mp, msg, hlp, false); + free(txt); + } } @ @= @@ -19964,7 +20102,7 @@ if (s != NULL) { mp_value new_expr; const char *hlp[] = { "I'm going to flush this expression, since", - "makete should be followed by a known string.", + "maketext should be followed by a known string.", NULL }; memset(&new_expr,0,sizeof(mp_value)); new_number(new_expr.data.n); @@ -19976,9 +20114,9 @@ if (s != NULL) { } else { mp_back_input (mp); if (cur_exp_str ()->len > 0) { - mp_value new_expr; char *s = mp->make_text(mp,(const char*) cur_exp_str()->str,0) ; @ + free(s); } } } @@ -23295,7 +23433,7 @@ RESTART: q = mp_get_value_node (mp); mp_name_type (q) = mp_capsule; - if (cur_cmd() == mp_comma) { + if (cur_cmd() == mp_comma) { mp_init_color_node (mp, q); r = value_node (q); mp_stash_in (mp, y_part (r)); @@ -23321,7 +23459,7 @@ RESTART: } mp_stash_in (mp, blue_part (r)); - if (cur_cmd() == mp_comma) { + if (cur_cmd() == mp_comma) { mp_node t; /* a token */ mp_init_cmykcolor_node (mp, q); t = value_node (q); @@ -23337,13 +23475,13 @@ RESTART: set_dep_list (cyan_part(t),dep_list ((mp_value_node) red_part(r))); set_prev_dep (cyan_part(t),prev_dep ((mp_value_node) red_part(r))); set_mp_link (prev_dep (cyan_part(t)), (mp_node) cyan_part(t)); - } + } if ( ((mp_type (magenta_part (t))) != mp_independent) && ((mp_type (magenta_part (t))) != mp_known) ) { /* Copy the dep list */ set_dep_list (magenta_part(t),dep_list ((mp_value_node) green_part(r))); set_prev_dep (magenta_part(t),prev_dep ((mp_value_node) green_part(r))); set_mp_link (prev_dep (magenta_part(t)), (mp_node) magenta_part(t)); - } + } if ( ((mp_type (yellow_part (t))) != mp_independent) && ((mp_type (yellow_part (t))) != mp_known)) { /* Copy the dep list */ set_dep_list (yellow_part(t),dep_list ((mp_value_node) blue_part(r))); @@ -28985,7 +29123,7 @@ static void mp_set_up_boundingpath (MP mp, mp_node p) { unsigned char ljoin, lcap; mp_number miterlim; mp_knot q = mp_copy_path (mp, cur_exp_knot ()); /* the original path */ - mp_knot pen; + mp_knot pen; mp_knot qq; new_number(miterlim); @@ -30671,8 +30809,8 @@ void mp_show_library_versions (void) { fprintf(stdout, "Compiled with pixman %s; using %s\n",COMPILED_PIXMAN_VERSION_STRING, pixman_version_string()); fprintf(stdout, "Compiled with libpng %s; using %s\n", PNG_LIBPNG_VER_STRING, png_libpng_ver); fprintf(stdout, "Compiled with zlib %s; using %s\n", ZLIB_VERSION, zlibVersion()); - fprintf(stdout, "Compiled with mpfr %s; using %s\n", MPFR_VERSION_STRING, mpfr_get_version()); - fprintf(stdout, "Compiled with gmp %d.%d.%d; using %s\n\n", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, gmp_version); + fprintf(stdout, "Compiled with mpfr %s; using %s\n", COMPILED_MPFR_VERSION_STRING, mpfr_get_version()); + fprintf(stdout, "Compiled with gmp %d.%d.%d; using %s\n\n", COMPILED__GNU_MP_VERSION, COMPILED__GNU_MP_VERSION_MINOR, COMPILED__GNU_MP_VERSION_PATCHLEVEL, COMPILED_gmp_version); } @ @= @@ -33230,7 +33368,7 @@ We may need to cancel skips that span more than 127 lig/kern steps. @ The header could contain ASCII zeroes, so can't use |strdup|. -The index |j| can be beyond the index |header_last|, hence we +The index |j| can be beyond the index |header_last|, hence we have to sure to update the end of stream marker to reflect the actual position. @@ -34555,8 +34693,9 @@ extreme cases so it may have to be shortened on some systems. @= { - s = xmalloc (7, 1); - mp_snprintf (s, 7, ".%i", (int) c); + s = xmalloc (12, 1); + mp_snprintf (s, 12, ".%i", (int) c); + s[7]='\0'; } diff --git a/Build/source/texk/web2c/mplibdir/mpmath.w b/Build/source/texk/web2c/mplibdir/mpmath.w index 772f8042bfc..6c0ee6d00a6 100644 --- a/Build/source/texk/web2c/mplibdir/mpmath.w +++ b/Build/source/texk/web2c/mplibdir/mpmath.w @@ -1,4 +1,4 @@ -% $Id$ +% $Id: mpmath.w 2118 2017-02-15 17:49:54Z luigi $ % % This file is part of MetaPost; % the MetaPost program is in the public domain. diff --git a/Build/source/texk/web2c/mplibdir/mpmathbinary.w b/Build/source/texk/web2c/mplibdir/mpmathbinary.w index c6df9ced4c8..f3d9ed947a8 100644 --- a/Build/source/texk/web2c/mplibdir/mpmathbinary.w +++ b/Build/source/texk/web2c/mplibdir/mpmathbinary.w @@ -39,6 +39,19 @@ #include "mpmp.h" /* internal header */ #include #include + +#ifdef HAVE_CONFIG_H +#include +const char * const COMPILED_gmp_version = VERSION; +#else +const char * const COMPILED_gmp_version = "unknown"; +#endif + +const char *COMPILED_MPFR_VERSION_STRING = MPFR_VERSION_STRING; +int COMPILED__GNU_MP_VERSION = __GNU_MP_VERSION ; +int COMPILED__GNU_MP_VERSION_MINOR = __GNU_MP_VERSION_MINOR ; +int COMPILED__GNU_MP_VERSION_PATCHLEVEL = __GNU_MP_VERSION_PATCHLEVEL ; + @; #endif diff --git a/Build/source/texk/web2c/mplibdir/mpmathdouble.w b/Build/source/texk/web2c/mplibdir/mpmathdouble.w index 4834876e5c3..cb14969365f 100644 --- a/Build/source/texk/web2c/mplibdir/mpmathdouble.w +++ b/Build/source/texk/web2c/mplibdir/mpmathdouble.w @@ -1,4 +1,4 @@ -% $Id$ +% $Id: mpmathdouble.w 2118 2017-02-15 17:49:54Z luigi $ % % This file is part of MetaPost; % the MetaPost program is in the public domain. -- cgit v1.2.3