1
4
5# include "luametatex.h"
6
7dump_state_info lmt_dump_state = {
8 .fingerprint = luametatex_format_fingerprint,
9 .padding = 0
10};
11
12
34
35
49
50# define MAGIC_FORMAT_NUMBER_LE_1 0x58544D4C
51# define MAGIC_FORMAT_NUMBER_LE_2 0x5845542D
52# define MAGIC_FORMAT_NUMBER_LE_3 0x544D462D
53
54static int tex_aux_report_dump_state(dumpstream f, int pos, const char *what)
55{
56 int tmp = ftell(f);
57 tex_print_format("%i %s", tmp - pos, what);
58 fflush(stdout);
59 return tmp;
60}
61
62
63
64static void tex_aux_dump_fingerprint(dumpstream f)
65{
66 dump_via_int(f, MAGIC_FORMAT_NUMBER_LE_1);
67 dump_via_int(f, MAGIC_FORMAT_NUMBER_LE_2);
68 dump_via_int(f, MAGIC_FORMAT_NUMBER_LE_3);
69 dump_via_int(f, luametatex_format_fingerprint);
70}
71
72static void tex_aux_undump_fingerprint(dumpstream f)
73{
74 int x;
75 undump_int(f, x);
76 if (x == MAGIC_FORMAT_NUMBER_LE_1) {
77 undump_int(f, x);
78 if (x == MAGIC_FORMAT_NUMBER_LE_2) {
79 undump_int(f, x);
80 if (x == MAGIC_FORMAT_NUMBER_LE_3) {
81 undump_int(f, x);
82 if (x == luametatex_format_fingerprint) {
83 return;
84 } else {
85 tex_fatal_undump_error("version id");
86 }
87 }
88 }
89 }
90 tex_fatal_undump_error("initial fingerprint");
91}
92
93static void tex_aux_dump_final_check(dumpstream f)
94{
95 dump_via_int(f, luametatex_format_fingerprint);
96}
97
98static void tex_aux_undump_final_check(dumpstream f)
99{
100 int x;
101 undump_int(f, x);
102 if (x == luametatex_format_fingerprint) {
103 return;
104 } else {
105 tex_fatal_undump_error("final fingerprint");
106 }
107}
108
109static void tex_aux_create_fmt_name(void)
110{
111 lmt_print_state.selector = new_string_selector_code;
112
113
114 tex_print_format("%s %i.%i.%i %s",lmt_fileio_state.fmt_name, year_par, month_par, day_par, lmt_fileio_state.job_name);
115 lmt_print_state.selector = terminal_and_logfile_selector_code;
116}
117
118static void tex_aux_dump_preamble(dumpstream f)
119{
120 dump_via_int(f, hash_size);
121 dump_via_int(f, hash_prime);
122 dump_via_int(f, prim_size);
123 dump_via_int(f, prim_prime);
124 dump_int(f, lmt_hash_state.hash_data.allocated);
125 dump_int(f, lmt_hash_state.hash_data.ptr);
126 dump_int(f, lmt_hash_state.hash_data.top);
127}
128
129static void tex_aux_undump_preamble(dumpstream f)
130{
131 int x;
132 undump_int(f, x);
133 if (x != hash_size) {
134 goto BAD;
135 }
136 undump_int(f, x);
137 if (x != hash_prime) {
138 goto BAD;
139 }
140 undump_int(f, x);
141 if (x != prim_size) {
142 goto BAD;
143 }
144 undump_int(f, x);
145 if (x != prim_prime) {
146 goto BAD;
147 }
148 undump_int(f, lmt_hash_state.hash_data.allocated);
149 undump_int(f, lmt_hash_state.hash_data.ptr);
150 undump_int(f, lmt_hash_state.hash_data.top);
151
154 tex_initialize_hash_mem();
155 return;
156 BAD:
157 tex_fatal_undump_error("preamble");
158}
159
160void tex_store_fmt_file(void)
161{
162 int pos = 0;
163 dumpstream f = NULL;
164
165
170
171 if (lmt_save_state.save_stack_data.ptr != 0) {
172 tex_handle_error(
173 succumb_error_type,
174 "You can't dump inside a group",
175 "'{...\\dump}' is a no-no."
176 );
177 }
178
179
182
183 tex_dispose_specification_nodes();
184
185
188
189 {
190 int callback_id = lmt_callback_defined(pre_dump_callback);
191 if (callback_id > 0) {
192 (void) lmt_run_callback(lmt_lua_state.lua_instance, callback_id, "->");
193 }
194 }
195
196
201
202 tex_aux_create_fmt_name();
203
204 f = tex_open_fmt_file(1);
205 if (! f) {
206 tex_formatted_error("system", "format file '%s' cannot be opened for writing", lmt_fileio_state.fmt_name);
207 return;
208 }
209
210 tex_print_nlp();
211 tex_print_format("Dumping format in file '%s': ", lmt_fileio_state.fmt_name);
212 fflush(stdout);
213
214 tex_compact_tokens();
215 tex_compact_string_pool();
216
217 tex_aux_dump_fingerprint(f); pos = tex_aux_report_dump_state(f, pos, "fingerprint + ");
218 lmt_dump_engine_info(f); pos = tex_aux_report_dump_state(f, pos, "engine + ");
219 tex_aux_dump_preamble(f); pos = tex_aux_report_dump_state(f, pos, "preamble + ");
220 tex_dump_constants(f); pos = tex_aux_report_dump_state(f, pos, "constants + ");
221 tex_dump_string_pool(f); pos = tex_aux_report_dump_state(f, pos, "stringpool + ");
222
223 tex_dump_node_mem(f); pos = tex_aux_report_dump_state(f, pos, "nodes + ");
224
225 tex_dump_token_mem(f); pos = tex_aux_report_dump_state(f, pos, "tokens + ");
226 tex_dump_equivalents_mem(f); pos = tex_aux_report_dump_state(f, pos, "equivalents + ");
227 tex_dump_math_codes(f); pos = tex_aux_report_dump_state(f, pos, "math codes + ");
228 tex_dump_text_codes(f); pos = tex_aux_report_dump_state(f, pos, "text codes + ");
229 tex_dump_primitives(f); pos = tex_aux_report_dump_state(f, pos, "primitives + ");
230 tex_dump_hashtable(f); pos = tex_aux_report_dump_state(f, pos, "hashtable + ");
231 tex_dump_font_data(f); pos = tex_aux_report_dump_state(f, pos, "fonts + ");
232 tex_dump_math_data(f); pos = tex_aux_report_dump_state(f, pos, "math + ");
233 tex_dump_language_data(f); pos = tex_aux_report_dump_state(f, pos, "language + ");
234 tex_dump_insert_data(f); pos = tex_aux_report_dump_state(f, pos, "insert + ");
235 lmt_dump_registers(f); pos = tex_aux_report_dump_state(f, pos, "bytecodes + ");
236 tex_aux_dump_final_check(f); pos = tex_aux_report_dump_state(f, pos, "housekeeping = ");
237
238 tex_aux_report_dump_state(f, 0, "total.");
239 tex_close_fmt_file(f);
240 tex_print_ln();
241
242}
243
244
255
256int tex_fatal_undump_error(const char *s)
257{
258 tex_emergency_message("system", "fatal format error, loading file '%s' failed with bad '%s' data, remake the format", emergency_fmt_name, s);
259 return tex_emergency_exit();
260}
261
262
263# define undumping(s)
264
265static void tex_aux_undump_fmt_data(dumpstream f)
266{
267 undumping("warmingup")
268
269 undumping("fingerprint") tex_aux_undump_fingerprint(f);
270 undumping("engineinfo") lmt_undump_engine_info(f);
271 undumping("preamble") tex_aux_undump_preamble(f);
272 undumping("constants") tex_undump_constants(f);
273 undumping("strings") tex_undump_string_pool(f);
274 undumping("nodes") tex_undump_node_mem(f);
275 undumping("tokens") tex_undump_token_mem(f);
276 undumping("equivalents") tex_undump_equivalents_mem(f);
277 undumping("mathcodes") tex_undump_math_codes(f);
278 undumping("textcodes") tex_undump_text_codes(f);
279 undumping("primitives") tex_undump_primitives(f);
280 undumping("hashtable") tex_undump_hashtable(f);
281 undumping("fonts") tex_undump_font_data(f);
282 undumping("math") tex_undump_math_data(f);
283 undumping("languages") tex_undump_language_data(f);
284 undumping("inserts") tex_undump_insert_data(f);
285 undumping("bytecodes") lmt_undump_registers(f);
286 undumping("finalcheck") tex_aux_undump_final_check(f);
287
288 undumping("done")
289
290
291
292 cur_list.prev_depth = ignore_depth_criterion_par;
293}
294
295
299
300int tex_load_fmt_file(void)
301{
302 dumpstream f = tex_open_fmt_file(0);
303 if (f) {
304 tex_aux_undump_fmt_data(f);
305 tex_close_fmt_file(f);
306 return 1;
307 } else {
308 return tex_fatal_undump_error("filehandle");
309 }
310}
311
312void tex_initialize_dump_state(void)
313{
314 if (! lmt_engine_state.dump_name) {
315 lmt_engine_state.dump_name = lmt_memory_strdup("initex");
316 }
317}
318 |