| 1 |
/* dumpdata.h |
| 2 |
|
| 3 |
Copyright 2009, 2012 Taco Hoekwater <[email protected]> |
| 4 |
|
| 5 |
This file is part of LuaTeX. |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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/>. */ |
| 19 |
|
| 20 |
|
| 21 |
#ifndef DUMPDATA_H |
| 22 |
# define DUMPDATA_H |
| 23 |
|
| 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 */ |
| 27 |
|
| 28 |
extern void store_fmt_file(void); |
| 29 |
extern boolean load_fmt_file(const char *); |
| 30 |
|
| 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) |
| 36 |
|
| 37 |
extern void do_zdump(char *, int, int, FILE *); |
| 38 |
extern void do_zundump(char *, int, int, FILE *); |
| 39 |
|
| 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) |
| 57 |
|
| 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) |
| 73 |
|
| 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) |
| 77 |
|
| 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 |
| 84 |
|
| 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) |
| 94 |
|
| 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 \ |
| 101 |
{ \ |
| 102 |
int x_val; \ |
| 103 |
generic_undump (x_val); \ |
| 104 |
x = x_val; \ |
| 105 |
} \ |
| 106 |
while (0) |
| 107 |
# else |
| 108 |
# define undump_int generic_undump |
| 109 |
# endif /* not (REGFIX || WIN32) */ |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#endif |