beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / tex / dumpdata.h
blob933dcfa1f0d901d4d49505f3eeea4e8dadd0915e
1 /* dumpdata.h
3 Copyright 2009, 2012 Taco Hoekwater <taco@luatex.org>
5 This file is part of LuaTeX.
7 LuaTeX is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
12 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License along
18 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21 #ifndef DUMPDATA_H
22 # define DUMPDATA_H
24 extern str_number format_ident;
25 extern str_number format_name; /* principal file name */
26 extern FILE *fmt_file; /* for input or output of format information */
28 extern void store_fmt_file(void);
29 extern boolean load_fmt_file(const char *);
31 /* (Un)dumping. These are called from the change file. */
32 # define dump_things(base, len) \
33 do_zdump ((char *) &(base), sizeof (base), (int) (len), DUMP_FILE)
34 # define undump_things(base, len) \
35 do_zundump ((char *) &(base), sizeof (base), (int) (len), DUMP_FILE)
37 extern void do_zdump(char *, int, int, FILE *);
38 extern void do_zundump(char *, int, int, FILE *);
40 /* Like do_undump, but check each value against LOW and HIGH. The
41 slowdown isn't significant, and this improves the chances of
42 detecting incompatible format files. In fact, Knuth himself noted
43 this problem with Web2c some years ago, so it seems worth fixing. We
44 can't make this a subroutine because then we lose the type of BASE. */
45 # define undump_checked_things(low, high, base, len) \
46 do { \
47 unsigned i; \
48 undump_things (base, len); \
49 for (i = 0; i < (len); i++) { \
50 if ((&(base))[i] < (low) || (&(base))[i] > (high)) { \
51 FATAL5 ("Item %u (=%ld) of .fmt array at %lx <%ld or >%ld", \
52 i, (unsigned long) (&(base))[i], (unsigned long) &(base), \
53 (unsigned long) low, (unsigned long) high); \
54 } \
55 } \
56 } while (0)
58 /* Like undump_checked_things, but only check the upper value. We use
59 this when the base type is unsigned, and thus all the values will be
60 greater than zero by definition. */
61 # define undump_upper_check_things(high, base, len) \
62 do { \
63 unsigned i; \
64 undump_things (base, len); \
65 for (i = 0; i < (len); i++) { \
66 if ((&(base))[i] > (high)) { \
67 FATAL4 ("Item %u (=%ld) of .fmt array at %lx >%ld", \
68 i, (unsigned long) (&(base))[i], (unsigned long) &(base), \
69 (unsigned long) high); \
70 } \
71 } \
72 } while (0)
74 /* Use the above for all the other dumping and undumping. */
75 # define generic_dump(x) dump_things (x, 1)
76 # define generic_undump(x) undump_things (x, 1)
78 # define dump_wd generic_dump
79 # define dump_hh generic_dump
80 # define dump_qqqq generic_dump
81 # define undump_wd generic_undump
82 # define undump_hh generic_undump
83 # define undump_qqqq generic_undump
85 /* `dump_int' is called with constant integers, so we put them into a
86 variable first. */
87 # define dump_int(x) \
88 do \
89 { \
90 int x_val = (x); \
91 generic_dump (x_val); \
92 } \
93 while (0)
95 /* web2c/regfix puts variables in the format file loading into
96 registers. Some compilers aren't willing to take addresses of such
97 variables. So we must kludge. */
98 # if defined(REGFIX) || defined(WIN32)
99 # define undump_int(x) \
100 do \
102 int x_val; \
103 generic_undump (x_val); \
104 x = x_val; \
106 while (0)
107 # else
108 # define undump_int generic_undump
109 # endif /* not (REGFIX || WIN32) */
114 #endif