1 /* extra_routines.c: Tables for glues, rules, penalties, etc.
2
3 This file is part of Omega,
4 which is based on the web2c distribution of TeX,
5
6 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
7
8 Omega is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 Omega is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Omega; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21
22 */
23
24 #include "cpascal.h"
25 #include "manifests.h"
26 #include "list_routines.h"
27 #include "extra_routines.h"
28 #include "header_routines.h"
29 #include "error_routines.h"
30
31 #define MAX_EXTRA_TABLES 16
32 #define MAX_TABLE_ENTRIES 256
33
34 unsigned *ivalue_tables[MAX_EXTRA_TABLES];
35 unsigned *penalty_tables[MAX_EXTRA_TABLES];
36 fix *fvalue_tables[MAX_EXTRA_TABLES];
37 fix *mvalue_tables[MAX_EXTRA_TABLES];
38 rule *rule_tables[MAX_EXTRA_TABLES];
39 glue *glue_tables[MAX_EXTRA_TABLES];
40
41 unsigned max_ivalue_entry[MAX_EXTRA_TABLES];
42 unsigned max_penalty_entry[MAX_EXTRA_TABLES];
43 unsigned max_fvalue_entry[MAX_EXTRA_TABLES];
44 unsigned max_mvalue_entry[MAX_EXTRA_TABLES];
45 unsigned max_rule_entry[MAX_EXTRA_TABLES];
46 unsigned max_glue_entry[MAX_EXTRA_TABLES];
47
48 unsigned no_ivalue_tables = 0;
49 unsigned no_penalty_tables = 0;
50 unsigned no_fvalue_tables = 0;
51 unsigned no_mvalue_tables = 0;
52 unsigned no_rule_tables = 0;
53 unsigned no_glue_tables = 0;
54
55 unsigned *cur_ivalue_table;
56 unsigned *cur_penalty_table;
57 fix *cur_mvalue_table;
58 fix *cur_fvalue_table;
59 rule *cur_rule_table;
60 glue *cur_glue_table;
61
62 unsigned cur_ivalue_table_index;
63 unsigned cur_penalty_table_index;
64 unsigned cur_mvalue_table_index;
65 unsigned cur_fvalue_table_index;
66 unsigned cur_rule_table_index;
67 unsigned cur_glue_table_index;
68
69 unsigned *cur_ivalue_entry;
70 unsigned *cur_penalty_entry;
71 fix *cur_mvalue_entry;
72 fix *cur_fvalue_entry;
73 rule *cur_rule_entry;
74 glue *cur_glue_entry;
75
76 unsigned nki=0;
77 unsigned nwi=0;
78 unsigned nkp=0;
79 unsigned nwp=0;
80 unsigned nkm=0;
81 unsigned nwm=0;
82 unsigned nkf=0;
83 unsigned nwf=0;
84 unsigned nkr=0;
85 unsigned nwr=0;
86 unsigned nkg=0;
87 unsigned nwg=0;
88
89 void
compute_ofm_extra_stuff(void)90 compute_ofm_extra_stuff(void)
91 {
92 unsigned i;
93
94 /* discard trailing empty tables */
95 for (i=0; i<no_ivalue_tables; i++)
96 if (max_ivalue_entry[i] > 0) {
97 nki = i + 1;
98 nwi += max_ivalue_entry[i];
99 }
100 for (i=0; i<no_penalty_tables; i++)
101 if (max_penalty_entry[i] > 0) {
102 nkp = i + 1;
103 nwp += max_penalty_entry[i];
104 }
105 for (i=0; i<no_mvalue_tables; i++)
106 if (max_mvalue_entry[i] > 0) {
107 nkm = i + 1;
108 nwm += max_mvalue_entry[i];
109 }
110 for (i=0; i<no_fvalue_tables; i++)
111 if (max_fvalue_entry[i] > 0) {
112 nkf = i + 1;
113 nwf += max_fvalue_entry[i];
114 }
115 for (i=0; i<no_rule_tables; i++)
116 if (max_rule_entry[i] > 0) {
117 nkr = i + 1;
118 nwr += 3 * max_rule_entry[i];
119 }
120 for (i=0; i<no_glue_tables; i++)
121 if (max_glue_entry[i] > 0) {
122 nkg = i + 1;
123 nwg += 4 * max_glue_entry[i];
124 }
125 if (ofm_level < OFM_LEVEL1) {
126 if (no_ivalue_tables > 0) {
127 warning_2("Ignoring %d words in %d IVALUE tables", nwi, nki);
128 nki = nwi = 0;
129 }
130 if (no_penalty_tables > 0) {
131 warning_2("Ignoring %d words in %d PENALTY tables", nwp, nkp);
132 nkp = nwp = 0;
133 }
134 if (no_mvalue_tables > 0) {
135 warning_2("Ignoring %d words in %d MVALUE tables", nwm, nkm);
136 nkm = nwm = 0;
137 }
138 if (no_fvalue_tables > 0) {
139 warning_2("Ignoring %d words in %d FVALUE tables", nwf, nkf);
140 nkf = nwf = 0;
141 }
142 if (no_rule_tables > 0) {
143 warning_2("Ignoring %d words in %d RULE tables", nwr, nkr);
144 nkr = nwr = 0;
145 }
146 if (no_glue_tables > 0) {
147 warning_2("Ignoring %d words in %d GLUE tables", nwg, nkg);
148 nkg = nwg = 0;
149 }
150 }
151 }
152
153 void
output_ofm_extra_stuff(void)154 output_ofm_extra_stuff(void)
155 {
156 if (ofm_level >= OFM_LEVEL1) {
157 if (nki+nkp+nkm+nkf+nkr+nkg > 0) {
158 fatal_error_0("OFM level 1 not currently supported");
159 }
160 }
161 }
162
163 #if 0
164 /* Not used */
165 static void
166 init_all_tables(void)
167 {
168 unsigned i=0;
169
170 for (i=0; i<MAX_EXTRA_TABLES; i++) {
171 ivalue_tables[i] = NULL;
172 penalty_tables[i] = NULL;
173 fvalue_tables[i] = NULL;
174 mvalue_tables[i] = NULL;
175 rule_tables[i] = NULL;
176 glue_tables[i] = NULL;
177 }
178 }
179 #endif
180
181 void
init_font_ivalue(unsigned tab)182 init_font_ivalue(unsigned tab)
183 {
184 if (tab>=MAX_EXTRA_TABLES)
185 internal_error_1("init_font_ivalue (tab=%d)", tab);
186 if (ivalue_tables[tab] != NULL) {
187 warning_1("IVALUE table (D %d) previously defined; "
188 "old value ignored", tab);
189 free(ivalue_tables[tab]);
190 }
191 ivalue_tables[tab] =
192 (unsigned *) xcalloc(MAX_TABLE_ENTRIES, sizeof(unsigned));
193 if (tab >= no_ivalue_tables)
194 no_ivalue_tables = tab + 1;
195 cur_ivalue_table_index = tab;
196 cur_ivalue_table = ivalue_tables[tab];
197 max_ivalue_entry[tab] = 0;
198 }
199
200 void
init_font_penalty(unsigned tab)201 init_font_penalty(unsigned tab)
202 {
203 if (tab>=MAX_EXTRA_TABLES)
204 internal_error_1("init_font_penalty (tab=%d)", tab);
205 if (penalty_tables[tab] != NULL) {
206 warning_1("PENALTY table (D %d) previously defined; "
207 "old value ignored", tab);
208 free(penalty_tables[tab]);
209 }
210 penalty_tables[tab] =
211 (unsigned *) xcalloc(MAX_TABLE_ENTRIES, sizeof(unsigned));
212 cur_penalty_table_index = tab;
213 cur_penalty_table = penalty_tables[tab];
214 if (tab >= no_penalty_tables)
215 no_penalty_tables = tab + 1;
216 max_penalty_entry[tab] = 0;
217 }
218
219 void
init_font_mvalue(unsigned tab)220 init_font_mvalue(unsigned tab)
221 {
222 if (tab>=MAX_EXTRA_TABLES)
223 internal_error_1("init_font_mvalue (tab=%d)", tab);
224 if (mvalue_tables[tab] != NULL) {
225 warning_1("MVALUE table (D %d) previously defined; "
226 "old value ignored", tab);
227 free(mvalue_tables[tab]);
228 }
229 mvalue_tables[tab] =
230 (fix *) xcalloc(MAX_TABLE_ENTRIES, sizeof(fix));
231 if (tab >= no_mvalue_tables)
232 no_mvalue_tables = tab + 1;
233 cur_mvalue_table_index = tab;
234 cur_mvalue_table = mvalue_tables[tab];
235 max_mvalue_entry[tab] = 0;
236 }
237
238 void
init_font_fvalue(unsigned tab)239 init_font_fvalue(unsigned tab)
240 {
241 if (tab>=MAX_EXTRA_TABLES)
242 internal_error_1("init_font_fvalue (tab=%d)", tab);
243 if (fvalue_tables[tab] != NULL) {
244 warning_1("FVALUE table (D %d) previously defined; "
245 "old value ignored", tab);
246 free(fvalue_tables[tab]);
247 }
248 fvalue_tables[tab] =
249 (fix *) xcalloc(MAX_TABLE_ENTRIES, sizeof(fix));
250 if (tab >= no_fvalue_tables)
251 no_fvalue_tables = tab + 1;
252 cur_fvalue_table_index = tab;
253 cur_fvalue_table = fvalue_tables[tab];
254 max_fvalue_entry[tab] = 0;
255 }
256
257 void
init_font_rule(unsigned tab)258 init_font_rule(unsigned tab)
259 {
260 if (tab>=MAX_EXTRA_TABLES)
261 internal_error_1("init_font_rule (tab=%d)", tab);
262 if (rule_tables[tab] != NULL) {
263 warning_1("RULE table (D %d) previously defined; "
264 "old value ignored", tab);
265 free(rule_tables[tab]);
266 }
267 rule_tables[tab] =
268 (rule *) xcalloc(MAX_TABLE_ENTRIES, sizeof(rule));
269 if (tab >= no_rule_tables)
270 no_rule_tables = tab + 1;
271 cur_rule_table_index = tab;
272 cur_rule_table = rule_tables[tab];
273 max_rule_entry[tab] = 0;
274 }
275
276 void
init_font_glue(unsigned tab)277 init_font_glue(unsigned tab)
278 {
279 if (tab>=MAX_EXTRA_TABLES)
280 internal_error_1("init_font_glue (tab=%d)", tab);
281 if (glue_tables[tab] != NULL) {
282 warning_1("GLUE table (D %d) previously defined; "
283 "old value ignored", tab);
284 free(glue_tables[tab]);
285 }
286 glue_tables[tab] =
287 (glue *) xcalloc(MAX_TABLE_ENTRIES, sizeof(glue));
288 if (tab >= no_glue_tables)
289 no_glue_tables = tab + 1;
290 cur_glue_table_index = tab;
291 cur_glue_table = glue_tables[tab];
292 max_glue_entry[tab] = 0;
293 }
294
295
296 void
init_font_ivalue_entry(unsigned index)297 init_font_ivalue_entry(unsigned index)
298 {
299 if (index>=MAX_TABLE_ENTRIES)
300 internal_error_1("init_font_ivalue_entry (index=%d)", index);
301 cur_ivalue_entry = &cur_ivalue_table[index];
302 if (max_ivalue_entry[cur_ivalue_table_index] <= index)
303 max_ivalue_entry[cur_ivalue_table_index] = index + 1;
304 }
305
306 void
init_font_penalty_entry(unsigned index)307 init_font_penalty_entry(unsigned index)
308 {
309 if (index>=MAX_TABLE_ENTRIES)
310 internal_error_1("init_font_penalty_entry (index=%d)", index);
311 cur_penalty_entry = &cur_penalty_table[index];
312 if (max_penalty_entry[cur_penalty_table_index] <= index)
313 max_penalty_entry[cur_penalty_table_index] = index + 1;
314 }
315
316 void
init_font_mvalue_entry(unsigned index)317 init_font_mvalue_entry(unsigned index)
318 {
319 if (index>=MAX_TABLE_ENTRIES)
320 internal_error_1("init_font_mvalue_entry (index=%d)", index);
321 cur_mvalue_entry = &cur_mvalue_table[index];
322 if (max_mvalue_entry[cur_mvalue_table_index] <= index)
323 max_mvalue_entry[cur_mvalue_table_index] = index + 1;
324 }
325
326 void
init_font_fvalue_entry(unsigned index)327 init_font_fvalue_entry(unsigned index)
328 {
329 if (index>=MAX_TABLE_ENTRIES)
330 internal_error_1("init_font_fvalue_entry (index=%d)", index);
331 cur_fvalue_entry = &cur_fvalue_table[index];
332 if (max_fvalue_entry[cur_fvalue_table_index] <= index)
333 max_fvalue_entry[cur_fvalue_table_index] = index + 1;
334 }
335
336 void
init_font_rule_entry(unsigned index)337 init_font_rule_entry(unsigned index)
338 {
339 if (index>=MAX_TABLE_ENTRIES)
340 internal_error_1("init_font_rule_entry (index=%d)", index);
341 cur_rule_entry = &cur_rule_table[index];
342 if (max_rule_entry[cur_rule_table_index] <= index)
343 max_rule_entry[cur_rule_table_index] = index + 1;
344 }
345
346 void
init_font_glue_entry(unsigned index)347 init_font_glue_entry(unsigned index)
348 {
349 if (index>=MAX_TABLE_ENTRIES)
350 internal_error_1("init_font_glue_entry (index=%d)", index);
351 cur_glue_entry = &cur_glue_table[index];
352 if (max_glue_entry[cur_glue_table_index] <= index)
353 max_glue_entry[cur_glue_table_index] = index + 1;
354 }
355
356
357 void
set_font_ivalue_definition(unsigned val)358 set_font_ivalue_definition(unsigned val)
359 {
360 *cur_ivalue_entry = val;
361 }
362
363 void
set_font_penalty_definition(unsigned val)364 set_font_penalty_definition(unsigned val)
365 {
366 *cur_penalty_entry = val;
367 }
368
369 void
set_font_mvalue_definition(fix fval)370 set_font_mvalue_definition(fix fval)
371 {
372 *cur_mvalue_entry = fval;
373 }
374
375 void
set_font_fvalue_definition(fix fval)376 set_font_fvalue_definition(fix fval)
377 {
378 *cur_fvalue_entry = fval;
379 }
380
381 void
set_font_rule_measure(unsigned measure,fix fval)382 set_font_rule_measure(unsigned measure, fix fval)
383 {
384 switch (measure) {
385 case RULE_WD: {
386 cur_rule_entry->rule_wd = fval; break;
387 }
388 case RULE_HT: {
389 cur_rule_entry->rule_ht = fval; break;
390 }
391 case RULE_DP: {
392 cur_rule_entry->rule_dp = fval; break;
393 }
394 default: {
395 internal_error_1("set_font_rule_measure (measure=%d)", measure);
396 }
397 }
398 }
399
400
401 void
set_font_glue_width(fix width)402 set_font_glue_width(fix width)
403 {
404 cur_glue_entry->glue_width = width;
405 }
406
407 void
set_font_glue_shrink_stretch(unsigned shrink_stretch,fix width,unsigned order)408 set_font_glue_shrink_stretch(unsigned shrink_stretch,
409 fix width, unsigned order)
410 {
411 switch (shrink_stretch) {
412 case GLUE_SHRINK: {
413 cur_glue_entry->glue_shrink = width;
414 cur_glue_entry->glue_shrink_order = order; break;
415 }
416 case GLUE_STRETCH: {
417 cur_glue_entry->glue_stretch = width;
418 cur_glue_entry->glue_stretch_order = order; break;
419 }
420 default: {
421 internal_error_1("set_font_rule_measure (shrink_stretch=%d)",
422 shrink_stretch);
423 }
424 }
425 }
426
427 void
set_font_glue_type(unsigned type)428 set_font_glue_type(unsigned type)
429 {
430 cur_glue_entry->glue_type = type;
431 }
432
433 void
set_font_glue_character(unsigned c)434 set_font_glue_character(unsigned c)
435 {
436 cur_glue_entry->glue_arg_type = GLUEARG_CHAR;
437 cur_glue_entry->glue_arg1 = c;
438 }
439
440 void
set_font_glue_rule(unsigned rule_table,unsigned rule_index)441 set_font_glue_rule(unsigned rule_table, unsigned rule_index)
442 {
443 cur_glue_entry->glue_arg_type = GLUEARG_RULE;
444 cur_glue_entry->glue_arg1 = rule_table;
445 cur_glue_entry->glue_arg2 = rule_index;
446 }
447
448 void
set_character_ivalue(unsigned table,unsigned index)449 set_character_ivalue(unsigned table, unsigned index)
450 {
451 fatal_error_0("CHARIVALUE not currently supported");
452 }
453
454 void
set_character_penalty(unsigned table,unsigned index)455 set_character_penalty(unsigned table, unsigned index)
456 {
457 fatal_error_0("CHARPENALTY not currently supported");
458 }
459
460 void
set_character_mvalue(unsigned table,unsigned index)461 set_character_mvalue(unsigned table, unsigned index)
462 {
463 fatal_error_0("CHARMVALUE not currently supported");
464 }
465
466 void
set_character_fvalue(unsigned table,unsigned index)467 set_character_fvalue(unsigned table, unsigned index)
468 {
469 fatal_error_0("CHARFVALUE not currently supported");
470 }
471
472 void
set_character_rule(unsigned table,unsigned index)473 set_character_rule(unsigned table, unsigned index)
474 {
475 fatal_error_0("CHARRULE not currently supported");
476 }
477
478 void
set_character_glue(unsigned table,unsigned index)479 set_character_glue(unsigned table, unsigned index)
480 {
481 fatal_error_0("CHARGLUE not currently supported");
482 }
483