Merge tag 'upstream/2014.20140912.35100'
Upstream version 2014.20140912.35100
# gpg: Signature made Fri 12 Sep 2014 12:06:37 AM JST using RSA key ID 860CDC13
# gpg: Good signature from "Norbert Preining <preining@logic.at>"
# gpg: aka "Norbert Preining <preining@debian.org>"
# gpg: aka "Norbert Preining <norbert@preining.info>"
# gpg: aka "Norbert Preining <preining@jaist.ac.jp>"
Norbert Preining
9 years ago
0 | 2014-09-01 Akira Kakuto <kakuto@fuk.kindai.ac.jp> | |
1 | ||
2 | * vf.c: Add missing break in case X1: case X2: case X3: case X4: | |
3 | in void vf_set_char(int32_t ch, int vf_font). | |
4 | ||
0 | 5 | 2014-08-24 Shunsaku Hirata <shunsaku.hirata74@gmail.com> |
1 | 6 | |
2 | 7 | * t1_char.c: Fix a bug in type1 handling reported by Bob Tennent |
497 | 497 | break; |
498 | 498 | case X1: case X2: case X3: case X4: |
499 | 499 | dvi_x (sqxfw (ptsize, get_pkt_signed_num (&start, end, opcode-X1))); |
500 | break; | |
500 | 501 | case DOWN1: case DOWN2: case DOWN3: case DOWN4: |
501 | 502 | dvi_down (sqxfw (ptsize, get_pkt_signed_num (&start, end, opcode-DOWN1))); |
502 | 503 | break; |
8 | 8 | |
9 | 9 | ######################################################################## |
10 | 10 | # arlatex # |
11 | # Copyright (C) 2011 Scott Pakin # | |
11 | # Copyright (C) 2014 Scott Pakin # | |
12 | 12 | # # |
13 | 13 | # This program may be distributed and/or modified under the conditions # |
14 | 14 | # of the LaTeX Project Public License, either version 1.3c of this # |
26 | 26 | ######################################################################## |
27 | 27 | |
28 | 28 | use 5.006; # Fail gracefully if we're not using Perl v5.6.0. |
29 | our $VERSION = "1.02"; # Specify the version of arlatex. | |
29 | our $VERSION = "1.03"; # Specify the version of arlatex. | |
30 | 30 | use Getopt::Long; |
31 | 31 | use Pod::Usage; |
32 | 32 | use File::Basename; |
37 | 37 | my $progname = basename($0); # Name of this program |
38 | 38 | my $latexfile; # Main LaTeX document |
39 | 39 | my $outfile = "-"; # Output file (default is standard output) |
40 | my $baseoutfile = "-"; # Base name of output file | |
40 | 41 | |
41 | 42 | ###################################################################### |
42 | 43 | |
45 | 46 | { |
46 | 47 | my $filename = $_[0]; |
47 | 48 | my $basefilename = basename $filename; |
49 | next if $basefilename eq $baseoutfile; # Don't let a file overwrite itself. | |
50 | $basefilename = "\"$basefilename\"" if $basefilename =~ /\s/ && substr($basefilename, 0, 1) ne '"'; | |
48 | 51 | open (SOMEFILE, "<$filename") || die "${progname}: $! ($filename)\n"; |
49 | 52 | print OUTFILE "\\begin{filecontents*}{$basefilename}\n"; |
50 | 53 | print OUTFILE <SOMEFILE>; |
70 | 73 | $latexfile = $newlatexfile; |
71 | 74 | } |
72 | 75 | } |
76 | $baseoutfile = basename $outfile if $outfile ne "-"; | |
73 | 77 | |
74 | 78 | # Read the entire input file. |
75 | 79 | open (LATEXFILE, "<$latexfile") || die "${progname}: $! ($latexfile)\n"; |
83 | 87 | while ($entirefile[0] =~ /^\s*(\%.*)?$/) { |
84 | 88 | print OUTFILE (shift @entirefile); |
85 | 89 | } |
90 | print OUTFILE "\\IfFileExists{filecontents.sty}{\\RequirePackage{filecontents}}{}\n"; | |
86 | 91 | my @expandedARGV; |
87 | 92 | foreach my $filename (@ARGV) { |
88 | 93 | if (-f $filename) { |
6 | 6 | |
7 | 7 | ######################################################################## |
8 | 8 | # bundledoc # |
9 | # Copyright (C) 2011 Scott Pakin # | |
9 | # Copyright (C) 2014 Scott Pakin # | |
10 | 10 | # # |
11 | 11 | # This program may be distributed and/or modified under the conditions # |
12 | 12 | # of the LaTeX Project Public License, either version 1.3c of this # |
24 | 24 | ######################################################################## |
25 | 25 | |
26 | 26 | use 5.006; # Fail gracefully if we're not using Perl v5.6.0. |
27 | our $VERSION = "3.1"; # Specify the version of bundledoc. | |
27 | our $VERSION = "3.2"; # Specify the version of bundledoc. | |
28 | 28 | use File::Basename; |
29 | 29 | use File::Copy; |
30 | 30 | use File::Spec::Functions qw(abs2rel catfile devnull rel2abs rootdir updir); |
38 | 38 | ###################################################################### |
39 | 39 | |
40 | 40 | # Variables the user can override with a configuration file |
41 | # DEFAULTS: Unix + kpathsea | |
41 | # DEFAULTS: Linux + kpathsea | |
42 | 42 | my %uservariable; |
43 | $uservariable{"bundle"} = '(tar -cvf - $BDINPUTS | compress > $BDBASE.tar.Z)'; | |
43 | $uservariable{"bundle"} = '(tar -cvf - $BDINPUTS | gzip --best > $BDBASE.tar.gz)'; | |
44 | 44 | $uservariable{"find"} = 'kpsewhich -progname=latex $BDINPUTS'; |
45 | 45 | $uservariable{"sink"} = '> ' . devnull() . ' 2>&1'; |
46 | 46 | |
65 | 65 | # or abort if we can't. |
66 | 66 | sub qualifyname ($) |
67 | 67 | { |
68 | my $filename = $_[0]; | |
69 | $filename = "\"$filename\"" if $filename =~ /\s/ && substr($filename, 0, 1) ne '"'; | |
68 | 70 | my $command = $uservariable{find}; |
69 | $command =~ s/[\$\%]BDINPUTS\%?/$_[0]/g; | |
71 | $command =~ s/[\$\%]BDINPUTS\%?/$filename/g; | |
70 | 72 | $command =~ s/[\$\%]BDBASE\%?/$ENV{"BDBASE"}/g; |
71 | 73 | my $qualified = `$command` || |
72 | 74 | die "${progname}: \"$uservariable{find}\" (BDINPUTS=\"$_[0]\") failed to find $_[0]\n"; |
693 | 695 | Configuration file for MikTeX installations. MikTeX is a popular TeX |
694 | 696 | distribution for Microsoft Windows. F<miktex.cfg> assumes you have |
695 | 697 | B<zip> and uses it to produce a F<.zip> archive file. The |
696 | configuration file has B<bundledoc> use the rather nonstandard | |
697 | B<initexmf> to find LaTeX files. | |
698 | configuration file now has B<bundledoc> use B<kpsewhich> to find LaTeX | |
699 | files; older version of MikTeX required the rather nonstandard | |
700 | B<initexmf> for this purpose. | |
701 | ||
702 | =item F<texlive-unix-arlatex.cfg> | |
703 | ||
704 | This is a variant of F<texlive-unix.cfg> that uses B<arlatex> instead | |
705 | of B<gzip> to archive files. B<arlatex> is a script included in the | |
706 | B<bundledoc> distribution that generates a self-extracting F<.tex> | |
707 | file based on LaTeX's C<filecontents> environment. | |
698 | 708 | |
699 | 709 | =back |
700 | 710 | |
800 | 810 | I'd like B<bundledoc> to work on as wide a variety of TeX |
801 | 811 | distributions as possible. If your platform is significantly |
802 | 812 | different from the ones listed in L<"Testing Status"> (e.g., if you're |
803 | running MacOS) and you need to create a substantially different | |
813 | running Z<OS X>) and you need to create a substantially different | |
804 | 814 | configuration file from F<texlive-unix.cfg> and F<miktex.cfg>, please |
805 | 815 | send it to me at the address listed in L<"AUTHOR"> so I can include it |
806 | 816 | in a future version of B<bundledoc>. (I make no promises, though). |
825 | 835 | |
826 | 836 | =head1 SEE ALSO |
827 | 837 | |
828 | gzip(1), kpsewhich(1), latex(1), perl(1), zip(1), the B<snapshot> | |
829 | documentation | |
838 | arlatex(1), gzip(1), kpsewhich(1), latex(1), perl(1), zip(1), | |
839 | the B<snapshot> documentation | |
830 | 840 | |
831 | 841 | |
832 | 842 | =head1 AUTHOR |
0 | 2014-09-03 Akira Kakuto <kakuto@fuk.kindai.ac.jp> | |
1 | ||
2 | * lmplib.c, mp.w, mpmath.w, mpmathbinary.w, mpmathdecimal.w, | |
3 | mpmathdouble.w, mpost.w, mpxout.w, psout.w: Sync with the trunk. | |
4 | ||
0 | 5 | 2014-07-15 Peter Breitenlohner <peb@mppmu.mpg.de> |
1 | 6 | |
2 | 7 | * mpxout.w: Replace the deprecated spawnvp() by _spawnvp(), |
36 | 36 | #define lua_objlen lua_rawlen |
37 | 37 | #endif |
38 | 38 | |
39 | #ifndef luaL_reg | |
40 | #define luaL_reg luaL_Reg | |
41 | #endif | |
42 | ||
43 | ||
44 | #ifndef lua_objlen | |
45 | #define lua_objlen lua_rawlen | |
46 | #endif | |
47 | ||
48 | ||
39 | 49 | #include "mplib.h" |
40 | 50 | #include "mplibps.h" |
41 | 51 | #include "mplibsvg.h" |
42 | 52 | #include "mplibpng.h" |
43 | 53 | |
44 | 54 | /*@unused@*/ static const char _svn_version[] = |
45 | "$Id: lmplib.c 1962 2014-03-11 13:18:08Z taco $"; | |
55 | "$Id: lmplib.c 2036 2014-06-26 18:44:57Z luigi $"; | |
46 | 56 | |
47 | 57 | int luaopen_mplib(lua_State * L); /* forward */ |
48 | 58 | |
222 | 232 | |
223 | 233 | typedef enum { |
224 | 234 | P_ERROR_LINE, P_MAX_LINE, P_RANDOM_SEED, P_MATH_MODE, |
225 | P_INTERACTION, P_INI_VERSION, P_MEM_NAME, P_JOB_NAME, P_FIND_FILE, | |
235 | P_INTERACTION, P_INI_VERSION, P_MEM_NAME, P_JOB_NAME, P_FIND_FILE, | |
236 | P_RUN_SCRIPT, P_SCRIPT_ERROR, | |
226 | 237 | P__SENTINEL } mplib_parm_idx; |
227 | 238 | |
228 | 239 | typedef struct { |
231 | 242 | } mplib_parm_struct; |
232 | 243 | |
233 | 244 | static mplib_parm_struct mplib_parms[] = { |
234 | {"error_line", P_ERROR_LINE }, | |
235 | {"print_line", P_MAX_LINE }, | |
236 | {"random_seed", P_RANDOM_SEED }, | |
237 | {"interaction", P_INTERACTION }, | |
238 | {"job_name", P_JOB_NAME }, | |
239 | {"find_file", P_FIND_FILE }, | |
240 | {"math_mode", P_MATH_MODE }, | |
241 | {NULL, P__SENTINEL } | |
245 | {"error_line", P_ERROR_LINE }, | |
246 | {"print_line", P_MAX_LINE }, | |
247 | {"random_seed", P_RANDOM_SEED }, | |
248 | {"interaction", P_INTERACTION }, | |
249 | {"job_name", P_JOB_NAME }, | |
250 | {"find_file", P_FIND_FILE }, | |
251 | {"run_script", P_RUN_SCRIPT }, | |
252 | {"script_error", P_SCRIPT_ERROR }, | |
253 | {"math_mode", P_MATH_MODE }, | |
254 | {NULL, P__SENTINEL } | |
242 | 255 | }; |
243 | 256 | |
244 | 257 | |
245 | 258 | /* Start by defining the needed callback routines for the library */ |
259 | ||
260 | /* todo: make subtable in registry, beware, for all mp instances */ | |
246 | 261 | |
247 | 262 | static char *mplib_find_file(MP mp, const char *fname, const char *fmode, int ftype) |
248 | 263 | { |
249 | 264 | lua_State *L = (lua_State *)mp_userdata(mp); |
250 | 265 | lua_checkstack(L, 4); |
251 | lua_getfield(L, LUA_REGISTRYINDEX, "mplib_file_finder"); | |
266 | lua_getfield(L, LUA_REGISTRYINDEX, "mplib.file_finder"); | |
252 | 267 | if (lua_isfunction(L, -1)) { |
253 | 268 | char *s = NULL; |
254 | 269 | const char *x = NULL; |
282 | 297 | if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { |
283 | 298 | return 1; /* error */ |
284 | 299 | } |
285 | lua_pushstring(L, "mplib_file_finder"); | |
300 | lua_pushstring(L, "mplib.file_finder"); | |
286 | 301 | lua_pushvalue(L, -2); |
287 | 302 | lua_rawset(L, LUA_REGISTRYINDEX); |
288 | 303 | return 0; |
304 | } | |
305 | ||
306 | static void mplib_script_error(MP mp, const char *str) | |
307 | { | |
308 | lua_State *L = (lua_State *)mp_userdata(mp); | |
309 | lua_checkstack(L, 1); | |
310 | lua_getfield(L, LUA_REGISTRYINDEX, "mplib.script_error"); | |
311 | if (lua_isfunction(L, -1)) { | |
312 | lua_pushstring(L, str); | |
313 | lua_pcall(L, 1, 0, 0); /* assume the function is ok */ | |
314 | } else { | |
315 | fprintf(stdout,"Error in script: %s\n",str); | |
316 | lua_pop(L, 1); | |
317 | } | |
318 | } | |
319 | ||
320 | static int mplib_script_error_function(lua_State * L) | |
321 | { | |
322 | if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { | |
323 | return 1; /* error */ | |
324 | } | |
325 | lua_pushstring(L, "mplib.script_error"); | |
326 | lua_pushvalue(L, -2); | |
327 | lua_rawset(L, LUA_REGISTRYINDEX); | |
328 | return 0; | |
329 | } | |
330 | ||
331 | static char *mplib_run_script(MP mp, const char *str) | |
332 | { | |
333 | lua_State *L = (lua_State *)mp_userdata(mp); | |
334 | lua_checkstack(L, 1); | |
335 | lua_getfield(L, LUA_REGISTRYINDEX, "mplib.run_script"); | |
336 | if (lua_isfunction(L, -1)) { | |
337 | char *s = NULL; | |
338 | const char *x = NULL; | |
339 | lua_pushstring(L, str); | |
340 | if (lua_pcall(L, 1, 1, 0) != 0) { | |
341 | mplib_script_error(mp, lua_tostring(L, -1)); | |
342 | return NULL; | |
343 | } | |
344 | x = lua_tostring(L, -1); | |
345 | if (x != NULL) | |
346 | s = strdup(x); | |
347 | lua_pop(L, 1); /* pop the string */ | |
348 | return s; | |
349 | } else { | |
350 | lua_pop(L, 1); | |
351 | } | |
352 | return NULL; | |
353 | } | |
354 | ||
355 | static int mplib_run_script_function(lua_State * L) | |
356 | { | |
357 | if (!(lua_isfunction(L, -1) || lua_isnil(L, -1))) { | |
358 | return 1; /* error */ | |
359 | } | |
360 | lua_pushstring(L, "mplib.run_script"); | |
361 | lua_pushvalue(L, -2); | |
362 | lua_rawset(L, LUA_REGISTRYINDEX); | |
363 | return 0; | |
364 | } | |
365 | ||
366 | static int mplib_get_numeric(lua_State * L) | |
367 | { | |
368 | MP *mp = is_mp(L, 1); | |
369 | if (*mp != NULL) { | |
370 | size_t l; | |
371 | const char *s = lua_tolstring(L, 2, &l); | |
372 | if (s != NULL) { | |
373 | lua_pushnumber(L, mp_get_numeric_value(*mp,s,l)); | |
374 | return 1; | |
375 | } | |
376 | } | |
377 | lua_pushnumber(L,0); | |
378 | return 1; | |
379 | } | |
380 | ||
381 | static int mplib_get_boolean(lua_State * L) | |
382 | { | |
383 | MP *mp = is_mp(L, 1); | |
384 | if (*mp != NULL) { | |
385 | size_t l; | |
386 | const char *s = lua_tolstring(L, 2, &l); | |
387 | if (s != NULL) { | |
388 | lua_pushboolean(L, mp_get_boolean_value(*mp,s,l)); | |
389 | return 1; | |
390 | } | |
391 | } | |
392 | lua_pushboolean(L,0); | |
393 | return 1; | |
394 | } | |
395 | ||
396 | static int mplib_get_string(lua_State * L) | |
397 | { | |
398 | MP *mp = is_mp(L, 1); | |
399 | if (*mp != NULL) { | |
400 | size_t l; | |
401 | const char *s = lua_tolstring(L, 2, &l); | |
402 | if (s != NULL) { | |
403 | char *r = mp_get_string_value(*mp,s,l) ; | |
404 | if (r != NULL) { | |
405 | lua_pushstring(L, r); | |
406 | return 1; | |
407 | } | |
408 | } | |
409 | } | |
410 | lua_pushstring(L,""); | |
411 | return 1; | |
289 | 412 | } |
290 | 413 | |
291 | 414 | #define xfree(A) if ((A)!=NULL) { free((A)); A = NULL; } |
300 | 423 | options->userdata = (void *) L; |
301 | 424 | options->noninteractive = 1; /* required ! */ |
302 | 425 | options->find_file = mplib_find_file; |
426 | options->run_script = mplib_run_script; | |
427 | /* options->script_error = mplib_script_error; */ | |
303 | 428 | options->print_found_names = 1; |
304 | 429 | options->ini_version = 1; |
305 | 430 | if (lua_type(L, 1) == LUA_TTABLE) { |
338 | 463 | break; |
339 | 464 | case P_FIND_FILE: |
340 | 465 | if (mplib_find_file_function(L)) { /* error here */ |
341 | fprintf(stdout, | |
342 | "Invalid arguments to mp.new({find_file=...})\n"); | |
466 | fprintf(stdout,"Invalid arguments to mp.new { find_file = ... }\n"); | |
467 | } | |
468 | break; | |
469 | case P_RUN_SCRIPT: | |
470 | if (mplib_run_script_function(L)) { /* error here */ | |
471 | fprintf(stdout,"Invalid arguments to mp.new { run_script = ... }\n"); | |
472 | } | |
473 | break; | |
474 | case P_SCRIPT_ERROR: | |
475 | if (mplib_script_error_function(L)) { /* error here */ | |
476 | fprintf(stdout,"Invalid arguments to mp.new { script_error = ... }\n"); | |
343 | 477 | } |
344 | 478 | break; |
345 | 479 | default: |
1566 | 1700 | } |
1567 | 1701 | |
1568 | 1702 | |
1703 | ||
1569 | 1704 | static const struct luaL_reg mplib_meta[] = { |
1570 | 1705 | {"__gc", mplib_collect}, |
1571 | 1706 | {"__tostring", mplib_tostring}, |
1605 | 1740 | {"char_depth", mplib_chardepth}, |
1606 | 1741 | {"statistics", mplib_statistics}, |
1607 | 1742 | {"solve_path", mplib_solve_path}, |
1743 | {"get_numeric", mplib_get_numeric}, | |
1744 | {"get_number", mplib_get_numeric}, | |
1745 | {"get_boolean", mplib_get_boolean}, | |
1746 | {"get_string", mplib_get_string}, | |
1608 | 1747 | {NULL, NULL} /* sentinel */ |
1609 | 1748 | }; |
1610 | 1749 | |
1614 | 1753 | {"version", mplib_version}, |
1615 | 1754 | {"fields", mplib_gr_fields}, |
1616 | 1755 | {"pen_info", mplib_gr_peninfo}, |
1756 | {"get_numeric", mplib_get_numeric}, | |
1757 | {"get_number", mplib_get_numeric}, | |
1758 | {"get_boolean", mplib_get_boolean}, | |
1759 | {"get_string", mplib_get_string}, | |
1617 | 1760 | {NULL, NULL} /* sentinel */ |
1618 | 1761 | }; |
1619 | 1762 |
0 | % $Id: mp.w 2005 2014-04-09 10:02:21Z taco $ | |
0 | % $Id: mp.w 2037 2014-09-02 14:59:07Z luigi $ | |
1 | 1 | % |
2 | 2 | % This file is part of MetaPost; |
3 | 3 | % the MetaPost program is in the public domain. |
151 | 151 | # include <unistd.h> /* for access */ |
152 | 152 | #endif |
153 | 153 | #include <time.h> /* for struct tm \& co */ |
154 | #include <zlib.h> /* for ZLIB_VERSION, zlibVersion() */ | |
155 | #include <png.h> /* for PNG_LIBPNG_VER_STRING, png_libpng_ver */ | |
156 | #include <pixman.h> /* for PIXMAN_VERSION_STRING, pixman_version_string() */ | |
157 | #include <cairo.h> /* for CAIRO_VERSION_STRING, cairo_version_string() */ | |
158 | #include <gmp.h> /* for __GNU_MP_VERSION etc., gmp_version */ | |
159 | #include <mpfr.h> /* for MPFR_VERSION_STRING, mpfr_get_version() */ | |
154 | #include <zlib.h> /* for |ZLIB_VERSION|, zlibVersion() */ | |
155 | #include <png.h> /* for |PNG_LIBPNG_VER_STRING|, |png_libpng_ver| */ | |
156 | #include <pixman.h> /* for |PIXMAN_VERSION_STRING|, |pixman_version_string()| */ | |
157 | #include <cairo.h> /* for |CAIRO_VERSION_STRING|, |cairo_version_string()| */ | |
158 | #include <gmp.h> /* for |gmp_version| */ | |
159 | #include <mpfr.h> /* for |MPFR_VERSION_STRING|, |mpfr_get_version()| */ | |
160 | 160 | #include "mplib.h" |
161 | 161 | #include "mplibps.h" /* external header */ |
162 | 162 | #include "mplibsvg.h" /* external header */ |
516 | 516 | set_callback_option (write_ascii_file); |
517 | 517 | set_callback_option (write_binary_file); |
518 | 518 | set_callback_option (shipout_backend); |
519 | set_callback_option (run_script); | |
519 | 520 | if (opt->banner && *(opt->banner)) { |
520 | 521 | mp->banner = xstrdup (opt->banner); |
521 | 522 | } else { |
702 | 703 | @d decr(A) (A)=(A)-1 /* decrease a variable by unity */ |
703 | 704 | @d negate(A) (A)=-(A) /* change the sign of a variable */ |
704 | 705 | @d double(A) (A)=(A)+(A) |
705 | @d odd(A) ((A)%2==1) | |
706 | @d odd(A) (abs(A)%2==1) | |
706 | 707 | |
707 | 708 | @* The character set. |
708 | 709 | In order to make \MP\ readily portable to a wide variety of |
835 | 836 | mp_filetype_text /* first text file for readfrom and writeto primitives */ |
836 | 837 | }; |
837 | 838 | typedef char *(*mp_file_finder) (MP, const char *, const char *, int); |
839 | typedef char *(*mp_script_runner) (MP, const char *); | |
838 | 840 | typedef void *(*mp_file_opener) (MP, const char *, const char *, int); |
839 | 841 | typedef char *(*mp_file_reader) (MP, void *, size_t *); |
840 | 842 | typedef void (*mp_binfile_reader) (MP, void *, void **, size_t *); |
847 | 849 | @ @<Option variables@>= |
848 | 850 | mp_file_finder find_file; |
849 | 851 | mp_file_opener open_file; |
852 | mp_script_runner run_script; | |
850 | 853 | mp_file_reader read_ascii_file; |
851 | 854 | mp_binfile_reader read_binary_file; |
852 | 855 | mp_file_closer close_file; |
866 | 869 | return mp_strdup (fname); |
867 | 870 | } |
868 | 871 | return NULL; |
872 | } | |
873 | ||
874 | @ @c | |
875 | static char *mp_run_script (MP mp, const char *str) { | |
876 | (void) mp; | |
877 | return mp_strdup (str); | |
869 | 878 | } |
870 | 879 | |
871 | 880 | |
884 | 893 | static void mp_flush_file (MP mp, void *f); |
885 | 894 | static void mp_write_ascii_file (MP mp, void *f, const char *s); |
886 | 895 | static void mp_write_binary_file (MP mp, void *f, void *s, size_t t); |
896 | static char *mp_run_script (MP mp, const char *str); | |
887 | 897 | |
888 | 898 | @ The function to open files can now be very short. |
889 | 899 | |
3115 | 3125 | mp_exit_test, /* premature exit from a loop (\&{exitif}) */ |
3116 | 3126 | mp_relax, /* do nothing (\.{\char`\\}) */ |
3117 | 3127 | mp_scan_tokens, /* put a string into the input buffer */ |
3128 | mp_runscript, /* put a script result string into the input buffer */ | |
3118 | 3129 | mp_expand_after, /* look ahead one token */ |
3119 | 3130 | mp_defined_macro, /* a macro defined by the user */ |
3120 | 3131 | mp_save_command, /* save a list of tokens (\&{save}) */ |
4663 | 4674 | return mp_do_id_lookup (mp, mp->frozen_symbols, j, l, insert_new); |
4664 | 4675 | } |
4665 | 4676 | |
4677 | /* see mp_print_sym (mp_sym sym) */ | |
4678 | ||
4679 | double mp_get_numeric_value (MP mp, const char *s, size_t l) { | |
4680 | char *ss = mp_xstrdup(mp,s); | |
4681 | if (ss) { | |
4682 | mp_sym sym = mp_id_lookup(mp,ss,l,false); | |
4683 | if (sym != NULL) { | |
4684 | if (mp_type(sym->v.data.node) == mp_known) { | |
4685 | mp_xfree (ss); | |
4686 | return number_to_double(sym->v.data.node->data.n) ; | |
4687 | } | |
4688 | } | |
4689 | } | |
4690 | mp_xfree (ss); | |
4691 | return 0 ; | |
4692 | } | |
4693 | ||
4694 | int mp_get_boolean_value (MP mp, const char *s, size_t l) { | |
4695 | char *ss = mp_xstrdup(mp,s); | |
4696 | if (ss) { | |
4697 | mp_sym sym = mp_id_lookup(mp,ss,l,false); | |
4698 | if (sym != NULL) { | |
4699 | if (mp_type(sym->v.data.node) == mp_boolean_type) { | |
4700 | if (number_to_boolean (sym->v.data.node->data.n) == mp_true_code) { | |
4701 | mp_xfree(ss); | |
4702 | return 1 ; | |
4703 | } | |
4704 | } | |
4705 | } | |
4706 | } | |
4707 | mp_xfree (ss); | |
4708 | return 0; | |
4709 | } | |
4710 | ||
4711 | char *mp_get_string_value (MP mp, const char *s, size_t l) { | |
4712 | char *ss = mp_xstrdup(mp,s); | |
4713 | if (ss) { | |
4714 | mp_sym sym = mp_id_lookup(mp,ss,l,false); | |
4715 | if (sym != NULL) { | |
4716 | if (mp_type(sym->v.data.node) == mp_string_type) { | |
4717 | mp_xfree (ss); | |
4718 | return (char *) sym->v.data.node->data.str->str; | |
4719 | } | |
4720 | } | |
4721 | } | |
4722 | mp_xfree (ss); | |
4723 | return NULL; | |
4724 | } | |
4725 | ||
4726 | @ @<Exported function headers@>= | |
4727 | double mp_get_numeric_value(MP mp,const char *s,size_t l); | |
4728 | int mp_get_boolean_value(MP mp,const char *s,size_t l); | |
4729 | char *mp_get_string_value(MP mp,const char *s,size_t l); | |
4666 | 4730 | |
4667 | 4731 | @ We need to put \MP's ``primitive'' symbolic tokens into the hash |
4668 | 4732 | table, together with their command code (which will be the |eq_type|) |
4776 | 4840 | @:save_}{\&{save} primitive@>; |
4777 | 4841 | mp_primitive (mp, "scantokens", mp_scan_tokens, 0); |
4778 | 4842 | @:scan_tokens_}{\&{scantokens} primitive@>; |
4843 | ||
4844 | mp_primitive (mp, "runscript", mp_runscript, 0); | |
4845 | @:run_script_}{\&{runscript} primitive@>; | |
4846 | ||
4779 | 4847 | mp_primitive (mp, "shipout", mp_ship_out_command, 0); |
4780 | 4848 | @:ship_out_}{\&{shipout} primitive@>; |
4781 | 4849 | mp_primitive (mp, "skipto", mp_skip_to, 0); |
4893 | 4961 | case mp_scan_tokens: |
4894 | 4962 | mp_print (mp, "scantokens"); |
4895 | 4963 | break; |
4964 | case mp_runscript: | |
4965 | mp_print (mp, "runscript"); | |
4966 | break; | |
4896 | 4967 | case mp_semicolon: |
4897 | 4968 | mp_print_char (mp, xord (';')); |
4898 | 4969 | break; |
4994 | 5065 | @ @c |
4995 | 5066 | #if DEBUG |
4996 | 5067 | #define value_sym(A) do_get_value_sym(mp,(mp_token_node)(A)) |
4997 | //#define value_number(A) do_get_value_number(mp,(mp_token_node)(A)) | |
5068 | /* |#define value_number(A) do_get_value_number(mp,(mp_token_node)(A))| */ | |
4998 | 5069 | #define value_number(A) ((mp_token_node)(A))->data.n |
4999 | 5070 | #define value_node(A) do_get_value_node(mp,(mp_token_node)(A)) |
5000 | 5071 | #define value_str(A) do_get_value_str(mp,(mp_token_node)(A)) |
10013 | 10084 | number_clone (d1, inf_t); /* reuse d1 */ |
10014 | 10085 | number_clone (v1, n); /* v1 = n */ |
10015 | 10086 | number_add (v1, epsilon_t); /* v1 = n1+1 */ |
10016 | set_number_from_div (d1, d1, v1); /* d1 = EL_GORDO / v1 */ | |
10087 | set_number_from_div (d1, d1, v1); /* |d1 = EL_GORDO / v1| */ | |
10017 | 10088 | if (number_greater (t_tot, d1)) { |
10018 | 10089 | mp->arith_error = true; |
10019 | 10090 | check_arith(); |
15781 | 15852 | } else { |
15782 | 15853 | if (number_greaterequal (absv, coef_bound_k) && mp->watch_coefs) { |
15783 | 15854 | mp_type (qq) = independent_needing_fix; |
15855 | /* If we set this , then we can drop (mp_type(pp) == independent_needing_fix && mp->fix_needed) later */ | |
15856 | /* set_number_from_scaled (value_number (qq), indep_value(qq)); */ | |
15784 | 15857 | mp->fix_needed = true; |
15785 | 15858 | } |
15786 | 15859 | set_mp_link (r, (mp_node) s); |
15795 | 15868 | } else { |
15796 | 15869 | if (pp == NULL) |
15797 | 15870 | set_number_to_neg_inf(v); |
15798 | else if (mp_type(pp) == mp_independent) | |
15871 | else if (mp_type(pp) == mp_independent || (mp_type(pp) == independent_needing_fix && mp->fix_needed)) | |
15799 | 15872 | set_number_from_scaled(v, indep_value(pp)); |
15800 | 15873 | else |
15801 | 15874 | number_clone (v, value_number (pp)); |
15802 | 15875 | if (qq == NULL) |
15803 | 15876 | set_number_to_neg_inf(vv); |
15804 | else if (mp_type(qq) == mp_independent) | |
15877 | else if (mp_type(qq) == mp_independent || (mp_type(qq) == independent_needing_fix && mp->fix_needed)) | |
15805 | 15878 | set_number_from_scaled(vv, indep_value(qq)); |
15806 | 15879 | else |
15807 | 15880 | number_clone (vv, value_number (qq)); |
15924 | 15997 | } else { |
15925 | 15998 | if (number_greaterequal(test, coef_bound_k) && mp->watch_coefs) { |
15926 | 15999 | mp_type (qq) = independent_needing_fix; |
16000 | /* If we set this , then we can drop (mp_type(pp) == independent_needing_fix && mp->fix_needed) later */ | |
16001 | /* set_number_from_scaled (value_number (qq), indep_value(qq)); */ | |
15927 | 16002 | mp->fix_needed = true; |
15928 | 16003 | } |
15929 | 16004 | set_mp_link (r, (mp_node) s); |
15937 | 16012 | } else { |
15938 | 16013 | if (pp == NULL) |
15939 | 16014 | set_number_to_zero (v); |
15940 | else if (mp_type(pp) == mp_independent) | |
16015 | else if (mp_type(pp) == mp_independent || (mp_type(pp) == independent_needing_fix && mp->fix_needed)) | |
15941 | 16016 | set_number_from_scaled (v, indep_value(pp)); |
15942 | 16017 | else |
15943 | 16018 | number_clone (v, value_number (pp)); |
15944 | 16019 | if (qq == NULL) |
15945 | 16020 | set_number_to_zero (vv); |
15946 | else if (mp_type(qq) == mp_independent) | |
16021 | else if (mp_type(qq) == mp_independent || (mp_type(qq) == independent_needing_fix && mp->fix_needed)) | |
15947 | 16022 | set_number_from_scaled (vv, indep_value(qq)); |
15948 | 16023 | else |
15949 | 16024 | number_clone (vv, value_number (qq)); |
18823 | 18898 | n = 0; |
18824 | 18899 | set_eq_type (mp->warning_info, mp_defined_macro); |
18825 | 18900 | set_equiv_node (mp->warning_info, q); |
18826 | } else { /* var_def */ | |
18901 | } else { /* |var_def| */ | |
18827 | 18902 | p = mp_scan_declared_variable (mp); |
18828 | 18903 | mp_flush_variable (mp, equiv_node (mp_sym_sym (p)), mp_link (p), true); |
18829 | 18904 | mp->warning_info_node = mp_find_variable (mp, p); |
18975 | 19050 | Only a few command codes |<min_command| can possibly be returned by |
18976 | 19051 | |get_t_next|; in increasing order, they are |
18977 | 19052 | |if_test|, |fi_or_else|, |input|, |iteration|, |repeat_loop|, |
18978 | |exit_test|, |relax|, |scan_tokens|, |expand_after|, and |defined_macro|. | |
19053 | |exit_test|, |relax|, |scan_tokens|, |run_script|, |expand_after|, and |defined_macro|. | |
18979 | 19054 | |
18980 | 19055 | \MP\ usually gets the next token of input by saying |get_x_next|. This is |
18981 | 19056 | like |get_t_next| except that it keeps getting more tokens until |
19091 | 19166 | case mp_scan_tokens: |
19092 | 19167 | @<Put a string into the input buffer@>; |
19093 | 19168 | break; |
19169 | case mp_runscript: | |
19170 | @<Put a script result string into the input buffer@>; | |
19171 | break; | |
19094 | 19172 | case mp_defined_macro: |
19095 | 19173 | mp_macro_call (mp, cur_mod_node(), NULL, cur_sym()); |
19096 | 19174 | break; |
19247 | 19325 | } |
19248 | 19326 | } |
19249 | 19327 | |
19328 | @ @<Put a script result string into the input buffer@>= | |
19329 | { | |
19330 | mp_get_x_next (mp); | |
19331 | mp_scan_primary (mp); | |
19332 | if (mp->cur_exp.type != mp_string_type) { | |
19333 | mp_value new_expr; | |
19334 | const char *hlp[] = { | |
19335 | "I'm going to flush this expression, since", | |
19336 | "runscript should be followed by a known string.", | |
19337 | NULL }; | |
19338 | memset(&new_expr,0,sizeof(mp_value)); | |
19339 | new_number(new_expr.data.n); | |
19340 | mp_disp_err (mp, NULL); | |
19341 | mp_back_error (mp, "Not a string", hlp, true); | |
19342 | @.Not a string@>; | |
19343 | mp_get_x_next (mp); | |
19344 | mp_flush_cur_exp (mp, new_expr); | |
19345 | } else { | |
19346 | mp_back_input (mp); | |
19347 | if (cur_exp_str ()->len > 0) { | |
19348 | mp_value new_expr; | |
19349 | char *s = mp->run_script(mp,(const char*) cur_exp_str()->str) ; | |
19350 | if (s != NULL) { | |
19351 | size_t size = strlen(s); | |
19352 | memset(&new_expr,0,sizeof(mp_value)); | |
19353 | new_number(new_expr.data.n); | |
19354 | mp_begin_file_reading (mp); | |
19355 | name = is_scantok; | |
19356 | mp->last = mp->first; | |
19357 | k = mp->first + size; | |
19358 | if (k >= mp->max_buf_stack) { | |
19359 | while (k >= mp->buf_size) { | |
19360 | mp_reallocate_buffer (mp, (mp->buf_size + (mp->buf_size / 4))); | |
19361 | } | |
19362 | mp->max_buf_stack = k + 1; | |
19363 | } | |
19364 | limit = (halfword) k; | |
19365 | (void) memcpy ((mp->buffer + mp->first), s, size); | |
19366 | free(s); | |
19367 | mp->buffer[limit] = xord ('%'); | |
19368 | mp->first = (size_t) (limit + 1); | |
19369 | loc = start; | |
19370 | mp_flush_cur_exp (mp, new_expr); | |
19371 | } | |
19372 | } | |
19373 | } | |
19374 | } | |
19250 | 19375 | |
19251 | 19376 | @ @<Pretend we're reading a new one-line file@>= |
19252 | 19377 | { |
20948 | 21073 | |
20949 | 21074 | @<Allocate or ...@>= |
20950 | 21075 | mp->job_name = mp_xstrdup (mp, opt->job_name); |
20951 | /* | |
21076 | /*| | |
20952 | 21077 | if (mp->job_name != NULL) { |
20953 | 21078 | char *s = mp->job_name + strlen (mp->job_name); |
20954 | 21079 | while (s > mp->job_name) { |
20958 | 21083 | s--; |
20959 | 21084 | } |
20960 | 21085 | } |
20961 | */ | |
21086 | |*/ | |
20962 | 21087 | if (opt->noninteractive) { |
20963 | 21088 | if (mp->job_name == NULL) |
20964 | 21089 | mp->job_name = mp_xstrdup (mp, mp->mem_name); |
26932 | 27057 | set_cur_exp_node ((mp_node) qq); |
26933 | 27058 | mp->cur_exp.type = mp_type (p); |
26934 | 27059 | mp_name_type (qq) = mp_capsule; |
26935 | /* clang: never read: q = (mp_node) qq; */ | |
27060 | /* clang: never read: |q = (mp_node) qq;| */ | |
26936 | 27061 | } |
26937 | 27062 | set_dep_list (qq, dep_list ((mp_value_node) p)); |
26938 | 27063 | mp_type (qq) = mp_type (p); |
28271 | 28396 | if (mp_left_type (p) == mp_endpoint) { |
28272 | 28397 | set_number_to_zero(v); |
28273 | 28398 | } else { |
28274 | /* v = n - 1 - ((-v - 1) % n) | |
28275 | == - ((-v - 1) % n) - 1 + n */ | |
28399 | /* |v = n - 1 - ((-v - 1) % n) | |
28400 | == - ((-v - 1) % n) - 1 + n| */ | |
28276 | 28401 | number_negate (v); |
28277 | 28402 | number_add_scaled (v, -1); |
28278 | 28403 | number_modulo (v, n); |
29526 | 29651 | return s; |
29527 | 29652 | } |
29528 | 29653 | static void mp_append_string (MP mp, mp_stream * a, const char *b) { |
29529 | size_t l = strlen (b) + 1; /* don't forget the trailing '\0' */ | |
29654 | size_t l = strlen (b) + 1; /* don't forget the trailing |'\0'| */ | |
29530 | 29655 | if ((a->used + l) >= a->size) { |
29531 | 29656 | a->size += 256 + (a->size) / 5 + l; |
29532 | 29657 | a->data = xrealloc (a->data, a->size, 1); |
29802 | 29927 | return mp_strdup (metapost_version); |
29803 | 29928 | } |
29804 | 29929 | void mp_show_library_versions (void) { |
29805 | fprintf(stdout, "Compiled with mpfr %s; using %s\n", MPFR_VERSION_STRING, mpfr_get_version()); | |
29806 | fprintf(stdout, "Compiled with gmp %d.%d.%d; using %s\n", | |
29807 | __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, gmp_version); | |
29808 | 29930 | fprintf(stdout, "Compiled with cairo %s; using %s\n", CAIRO_VERSION_STRING, cairo_version_string()); |
29809 | 29931 | fprintf(stdout, "Compiled with pixman %s; using %s\n", PIXMAN_VERSION_STRING, pixman_version_string()); |
29810 | 29932 | fprintf(stdout, "Compiled with libpng %s; using %s\n", PNG_LIBPNG_VER_STRING, png_libpng_ver); |
29811 | fprintf(stdout, "Compiled with zlib %s; using %s\n\n", ZLIB_VERSION, zlibVersion()); | |
29933 | fprintf(stdout, "Compiled with zlib %s; using %s\n", ZLIB_VERSION, zlibVersion()); | |
29934 | fprintf(stdout, "Compiled with mpfr %s; using %s\n", MPFR_VERSION_STRING, mpfr_get_version()); | |
29935 | 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); | |
29812 | 29936 | } |
29813 | 29937 | |
29814 | 29938 | @ @<Exported function headers@>= |
30401 | 30525 | if (cur_sym() != NULL) |
30402 | 30526 | if (cur_sym_mod() == 0) |
30403 | 30527 | if (cur_cmd() == mp_tag_token) |
30404 | if (cur_mod() != 0) { | |
30528 | if (cur_mod() != 0 || cur_mod_node()!=NULL) { | |
30405 | 30529 | mp_disp_var (mp, cur_mod_node()); |
30406 | 30530 | goto DONE; |
30407 | 30531 | } |
32751 | 32875 | mp->header_byte[6] = (char) ((dd / 16) % 256); |
32752 | 32876 | mp->header_byte[7] = (char) ((dd % 16) * 16); |
32753 | 32877 | } |
32754 | /* mp->max_tfm_dimen = 16 * internal_value (mp_design_size) - 1 - internal_value (mp_design_size) / 010000000 */ | |
32878 | /* |mp->max_tfm_dimen = 16 * internal_value (mp_design_size) - 1 - internal_value (mp_design_size) / 010000000| */ | |
32755 | 32879 | { |
32756 | 32880 | mp_number secondpart; |
32757 | 32881 | new_number (secondpart); |
33170 | 33294 | for (k = 0; k <= 255; k++) { |
33171 | 33295 | /* These are disabled for now following a bug-report about double free |
33172 | 33296 | errors. TO BE FIXED, bug tracker id 831 */ |
33173 | /* | |
33297 | /*| | |
33174 | 33298 | mp_free_value_node (mp, mp->tfm_width[k]); |
33175 | 33299 | mp_free_value_node (mp, mp->tfm_height[k]); |
33176 | 33300 | mp_free_value_node (mp, mp->tfm_depth[k]); |
33177 | 33301 | mp_free_value_node (mp, mp->tfm_ital_corr[k]); |
33178 | */ | |
33302 | |*/ | |
33179 | 33303 | } |
33180 | 33304 | |
33181 | 33305 | xfree (mp->font_info); |
34414 | 34538 | @c |
34415 | 34539 | void mp_final_cleanup (MP mp) { |
34416 | 34540 | /* -Wunused: integer c; */ /* 0 for \&{end}, 1 for \&{dump} */ |
34417 | /* clang: never read: c = cur_mod(); */ | |
34541 | /* clang: never read: |c = cur_mod();| */ | |
34418 | 34542 | if (mp->job_name == NULL) |
34419 | 34543 | mp_open_log_file (mp); |
34420 | 34544 | while (mp->input_ptr > 0) { |
0 | % $Id: mpmath.w 1959 2014-03-11 11:19:43Z taco $ | |
0 | % $Id: mpmath.w 2037 2014-09-02 14:59:07Z luigi $ | |
1 | 1 | % |
2 | 2 | % This file is part of MetaPost; |
3 | 3 | % the MetaPost program is in the public domain. |
1680 | 1680 | @d one_eighty_deg 01320000000 /* $180\cdot2^{20}$, represents $180^\circ$ */ |
1681 | 1681 | @d three_sixty_deg 02640000000 /* $360\cdot2^{20}$, represents $360^\circ$ */ |
1682 | 1682 | |
1683 | @d odd(A) ((A)%2==1) | |
1683 | @d odd(A) (abs(A)%2==1) | |
1684 | 1684 | |
1685 | 1685 | @ Compute a multiple of the sine and cosine |
1686 | 1686 |
588 | 588 | |
589 | 589 | @ |
590 | 590 | |
591 | @d odd(A) ((A)%2==1) | |
591 | @d odd(A) (abs(A)%2==1) | |
592 | 592 | |
593 | 593 | @c |
594 | 594 | int mp_number_to_int(mp_number A) { |
758 | 758 | |
759 | 759 | @ |
760 | 760 | |
761 | @d odd(A) ((A)%2==1) | |
761 | @d odd(A) (abs(A)%2==1) | |
762 | 762 | |
763 | 763 | @c |
764 | 764 | int mp_number_to_int(mp_number A) { |
0 | % $Id: mpmathdouble.w 1959 2014-03-11 11:19:43Z taco $ | |
0 | % $Id: mpmathdouble.w 2037 2014-09-02 14:59:07Z luigi $ | |
1 | 1 | % |
2 | 2 | % This file is part of MetaPost; |
3 | 3 | % the MetaPost program is in the public domain. |
1195 | 1195 | @d one_eighty_deg (180.0*angle_multiplier) |
1196 | 1196 | @d three_sixty_deg (360.0*angle_multiplier) |
1197 | 1197 | |
1198 | @d odd(A) ((A)%2==1) | |
1198 | @d odd(A) (abs(A)%2==1) | |
1199 | 1199 | |
1200 | 1200 | @ Compute a multiple of the sine and cosine |
1201 | 1201 |
0 | % $Id: mpost.w 1955 2014-03-10 10:30:30Z taco $ | |
0 | % $Id: mpost.w 2007 2014-04-10 11:13:03Z taco $ | |
1 | 1 | % |
2 | 2 | % This file is part of MetaPost; |
3 | 3 | % the MetaPost program is in the public domain. |
1026 | 1026 | "For more information about these matters, see the file\n" |
1027 | 1027 | "COPYING.LESSER or <http://gnu.org/licenses/lgpl.html>.\n" |
1028 | 1028 | "Original author of MetaPost: John Hobby.\n" |
1029 | "Author of the CWEB MetaPost: Taco Hoekwater.\n\n" | |
1029 | "Author of the CWEB MetaPost: Taco Hoekwater.\n" | |
1030 | "Current maintainer of MetaPost: Luigi Scarso.\n\n" | |
1030 | 1031 | ); |
1031 | 1032 | mpost_xfree(s); |
1032 | 1033 | if (!dvitomp_only) { |
0 | % $Id: mpxout.w 1808 2012-12-10 08:57:11Z taco $ | |
0 | % $Id: mpxout.w 2031 2014-06-24 13:38:58Z luigi $ | |
1 | 1 | % This file is part of MetaPost; |
2 | 2 | % the MetaPost program is in the public domain. |
3 | 3 | % See the <Show version...> code in mpost.w for more info. |
0 | % $Id: psout.w 2009 2014-04-23 07:09:51Z taco $ | |
0 | % $Id: psout.w 2037 2014-09-02 14:59:07Z luigi $ | |
1 | 1 | % This file is part of MetaPost; |
2 | 2 | % the MetaPost program is in the public domain. |
3 | 3 | % See the <Show version...> code in mpost.w for more info. |
51 | 51 | @d incr(A) (A)=(A)+1 /* increase a variable by unity */ |
52 | 52 | @d decr(A) (A)=(A)-1 /* decrease a variable by unity */ |
53 | 53 | @d negate(A) (A)=-(A) /* change the sign of a variable */ |
54 | @d odd(A) ((A)%2==1) | |
54 | @d odd(A) (abs(A)%2==1) | |
55 | 55 | @d max_quarterword 0x3FFF /* largest allowable value in a |quarterword| */ |
56 | 56 | |
57 | 57 | @c |