| 1 |
/* out_routines.c: Low-level routines for outputting OPL and OVP files. |
| 2 |
|
| 3 |
This file is part of Omega, |
| 4 |
which is based on the web2c distribution of TeX, |
| 5 |
|
| 6 |
Copyright 1994--2018 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 "list_routines.h" |
| 26 |
#include "manifests.h" |
| 27 |
#include "omfonts.h" |
| 28 |
#include "out_routines.h" |
| 29 |
#include "error_routines.h" |
| 30 |
#include "header_routines.h" |
| 31 |
#include "char_routines.h" |
| 32 |
|
| 33 |
/* Character measures */ |
| 34 |
|
| 35 |
const_string character_measures[] = |
| 36 |
{ "CHARWD", "CHARHT", "CHARDP", "CHARIC", |
| 37 |
"SECWD", "SECHT", "SECDP", "SECIC", |
| 38 |
"PRIMTOPAXIS", "PRIMTOPAXISBIS", "PRIMBOTAXIS", "PRIMBOTAXISBIS", |
| 39 |
"PRIMMIDHOR", "PRIMMIDVERT", "PRIMBASESLANT", NULL, |
| 40 |
"SECTOPAXIS", "SECTOPAXISBIS", "SECBOTAXIS", "SECBOTAXISBIS", |
| 41 |
"SECMIDHOR", "SECMIDVERT", "SECBASESLANT", NULL}; |
| 42 |
|
| 43 |
void |
| 44 |
out_character_measure(unsigned measure) |
| 45 |
{ |
| 46 |
if ((measure < C_MIN) || (measure > C_MAX) || |
| 47 |
(character_measures[measure]==NULL)) { |
| 48 |
internal_error_1("out_character_measure (measure=%d)", measure); |
| 49 |
} |
| 50 |
out(character_measures[measure]); |
| 51 |
} |
| 52 |
|
| 53 |
/* Extensible pieces */ |
| 54 |
|
| 55 |
const_string extensible_pieces[] = |
| 56 |
{ "TOP", "MID", "BOT", "REP", NULL }; |
| 57 |
|
| 58 |
void |
| 59 |
out_extensible_piece(unsigned piece) |
| 60 |
{ |
| 61 |
if ((piece < E_MIN) || (piece > E_MAX)) { |
| 62 |
internal_error_1("out_extensible_piece (piece=%d)", piece); |
| 63 |
} |
| 64 |
out(extensible_pieces[piece]); |
| 65 |
} |
| 66 |
|
| 67 |
/* Ligature commands */ |
| 68 |
|
| 69 |
const_string ligature_commands[] = |
| 70 |
{ "LIG", "LIG/", "/LIG", "/LIG/", NULL, |
| 71 |
"LIG/>", "/LIG>", "/LIG/>", NULL, NULL, |
| 72 |
NULL, "/LIG/>>", NULL }; |
| 73 |
|
| 74 |
void |
| 75 |
out_ligature_command(unsigned command) |
| 76 |
{ |
| 77 |
if ((command < L_MIN) || (command > L_MAX) || |
| 78 |
(ligature_commands[command]==NULL)) { |
| 79 |
internal_error_1("out_ligature_command (command=%d)", command); |
| 80 |
} |
| 81 |
out(ligature_commands[command]); |
| 82 |
} |
| 83 |
|
| 84 |
/* Xerox faces */ |
| 85 |
|
| 86 |
const_string xerox_faces[] = |
| 87 |
{ "MRR", "MIR", "BRR", "BIR", "LRR", "LIR", |
| 88 |
"MRC", "MIC", "BRC", "BIC", "LRC", "LIC", |
| 89 |
"MRE", "MIE", "BRE", "BIE", "LRE", "LIE", NULL }; |
| 90 |
|
| 91 |
void |
| 92 |
print_xerox_face(int face) |
| 93 |
{ |
| 94 |
if ((face < F_MIN) || (face > F_MAX)) { |
| 95 |
internal_error_1("print_xerox_face (face=%d)", face); |
| 96 |
} |
| 97 |
out("F "); out(xerox_faces[face]); |
| 98 |
} |
| 99 |
|
| 100 |
/* Named parameters */ |
| 101 |
|
| 102 |
const_string named_parameters[] = |
| 103 |
{ NULL, "SLANT", "SPACE", "STRETCH", "SHRINK", "XHEIGHT", |
| 104 |
"QUAD", "EXTRASPACE", NULL }; |
| 105 |
|
| 106 |
void |
| 107 |
out_named_parameter(unsigned parameter) |
| 108 |
{ |
| 109 |
if ((parameter < P_MIN) || (parameter > P_MAX)) { |
| 110 |
internal_error_1("out_named_parameter (parameter = %d)", parameter); |
| 111 |
} |
| 112 |
out(named_parameters[parameter]); |
| 113 |
} |
| 114 |
|
| 115 |
/* Named math symbol parameters */ |
| 116 |
|
| 117 |
const_string named_mathsy_parameters[] = |
| 118 |
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 119 |
"NUM1", "NUM2", "NUM3", "DENOM1", |
| 120 |
"DENOM2", "SUP1", "SUP2", "SUP3", "SUB1", "SUB2", |
| 121 |
"SUPDROP", "SUBDROP", "DELIM1", "DELIM2", "AXISHEIGHT", NULL }; |
| 122 |
|
| 123 |
void |
| 124 |
out_named_mathsy_parameter(unsigned parameter) |
| 125 |
{ |
| 126 |
if ((parameter < P_MATHSY_MIN) || (parameter > P_MATHSY_MAX) || |
| 127 |
(named_mathsy_parameters[parameter]==NULL)) { |
| 128 |
internal_error_1("out_named_mathsy_parameter (parameter=%d)",parameter); |
| 129 |
} |
| 130 |
out(named_mathsy_parameters[parameter]); |
| 131 |
} |
| 132 |
|
| 133 |
/* Named math extension parameters */ |
| 134 |
|
| 135 |
const_string named_mathex_parameters[] = |
| 136 |
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 137 |
"DEFAULTRULETHICKNESS", "BIGOPSPACING1", |
| 138 |
"BIGOPSPACING2", "BIGOPSPACING3", |
| 139 |
"BIGOPSPACING4", "BIGOPSPACING5", NULL }; |
| 140 |
|
| 141 |
void |
| 142 |
out_named_mathex_parameter(unsigned parameter) |
| 143 |
{ |
| 144 |
if ((parameter < P_MATHEX_MIN) || (parameter > P_MATHEX_MAX) || |
| 145 |
(named_mathex_parameters[parameter]==NULL)) { |
| 146 |
internal_error_1("out_named_mathex_parameter (parameter=%d)",parameter); |
| 147 |
} |
| 148 |
out(named_mathex_parameters[parameter]); |
| 149 |
} |
| 150 |
|
| 151 |
/* Typesetting directions */ |
| 152 |
|
| 153 |
const_string type_directions[] = |
| 154 |
{ "FONTDIR", "NATURALFONTDIR", NULL }; |
| 155 |
|
| 156 |
const_string actual_directions[] = |
| 157 |
{ "TL", "LT", "TR", "RT", "LB", "BL", "BR", "RB", NULL }; |
| 158 |
|
| 159 |
void |
| 160 |
out_type_direction(unsigned direction) |
| 161 |
{ |
| 162 |
if ((direction < DIR_MIN) || (direction > DIR_MAX)) { |
| 163 |
internal_error_1("out_type_direction (direction=%d)", direction); |
| 164 |
} |
| 165 |
out(type_directions[direction/8]); out(" "); |
| 166 |
out(actual_directions[direction%8]); |
| 167 |
} |
| 168 |
|
| 169 |
/* Kinds of accents */ |
| 170 |
|
| 171 |
const_string accent_kinds[] = |
| 172 |
{ NULL, "TOPACCENT", "MIDACCENT", "BOTACCENT", NULL }; |
| 173 |
|
| 174 |
void |
| 175 |
out_accent_kind(unsigned kind) |
| 176 |
{ |
| 177 |
if ((kind < ACC_TOP) || (kind > ACC_BOT)) { |
| 178 |
internal_error_1("out_accent_kind (kind=%d)", kind); |
| 179 |
} |
| 180 |
out(accent_kinds[kind]); |
| 181 |
} |
| 182 |
|
| 183 |
/* Move directions */ |
| 184 |
|
| 185 |
const_string move_directions[] = |
| 186 |
{ "MOVERIGHT", "MOVELEFT", "MOVEUP", "MOVEDOWN", NULL }; |
| 187 |
|
| 188 |
void |
| 189 |
out_move_direction(unsigned direction) |
| 190 |
{ |
| 191 |
if ((direction < M_MIN) || (direction > M_MAX)) { |
| 192 |
internal_error_1("out_move_direction (direction=%d)", direction); |
| 193 |
} |
| 194 |
out(move_directions[direction]); |
| 195 |
} |
| 196 |
|
| 197 |
/* Rule measures */ |
| 198 |
|
| 199 |
const_string rule_measures[] = |
| 200 |
{ "RULEWD", "RULEHT", "RULEDP", NULL }; |
| 201 |
|
| 202 |
void |
| 203 |
out_rule_measure(unsigned measure) |
| 204 |
{ |
| 205 |
if ((measure < RULE_MIN) || (measure > RULE_MAX)) { |
| 206 |
internal_error_1("out_rule_measure (measure=%d)", measure); |
| 207 |
} |
| 208 |
out(rule_measures[measure]); |
| 209 |
} |
| 210 |
|
| 211 |
/* Glue shrink or stretch */ |
| 212 |
|
| 213 |
const_string glue_shrink_stretch[] = |
| 214 |
{ "GLUESHRINK", "GLUESTRETCH", NULL }; |
| 215 |
|
| 216 |
void |
| 217 |
out_shrink_stretch(unsigned shrink_stretch) |
| 218 |
{ |
| 219 |
if ((shrink_stretch < GLUE_MIN) || (shrink_stretch > GLUE_MAX)) { |
| 220 |
internal_error_1("out_shrink_stretch (shrink_stretch=%d)", |
| 221 |
shrink_stretch); |
| 222 |
} |
| 223 |
out(glue_shrink_stretch[shrink_stretch]); |
| 224 |
} |
| 225 |
|
| 226 |
/* Glue orders */ |
| 227 |
|
| 228 |
const_string glue_orders[] = |
| 229 |
{ "UNIT", "FI", "FIL", "FILL", "FILLL", NULL }; |
| 230 |
|
| 231 |
void |
| 232 |
out_glue_order(unsigned order) |
| 233 |
{ |
| 234 |
if ((order < O_MIN) || (order > O_MAX)) { |
| 235 |
internal_error_1("out_glue_order (order=%d)", order); |
| 236 |
} |
| 237 |
out(glue_orders[order]); |
| 238 |
} |
| 239 |
|
| 240 |
/* Glue kinds */ |
| 241 |
|
| 242 |
const_string glue_kinds[] = |
| 243 |
{ "NORMAL", "ALEADERS", "CLEADERS", "ALEADERS", "XLEADERS", NULL }; |
| 244 |
|
| 245 |
void |
| 246 |
out_glue_kind(unsigned kind) |
| 247 |
{ |
| 248 |
if ((kind < K_MIN) || (kind > K_MAX)) { |
| 249 |
internal_error_1("out_glue_kind (kind=%d)", kind); |
| 250 |
} |
| 251 |
out(glue_kinds[kind]); |
| 252 |
} |
| 253 |
|
| 254 |
unsigned parenthesis_level=0; |
| 255 |
unsigned digits[12]; |
| 256 |
|
| 257 |
/* Basic routines used by everyone */ |
| 258 |
|
| 259 |
void |
| 260 |
out_ln(void) |
| 261 |
{ |
| 262 |
unsigned i; |
| 263 |
out("\n"); |
| 264 |
for (i = 0; i < parenthesis_level; i++) out(" "); |
| 265 |
} |
| 266 |
|
| 267 |
void |
| 268 |
left(void) |
| 269 |
{ |
| 270 |
parenthesis_level++; out("("); |
| 271 |
} |
| 272 |
|
| 273 |
void |
| 274 |
right(void) |
| 275 |
{ |
| 276 |
if (parenthesis_level==0) internal_error_0("right"); |
| 277 |
parenthesis_level--; out(")"); out_ln(); |
| 278 |
} |
| 279 |
|
| 280 |
void |
| 281 |
out_char(unsigned val) |
| 282 |
{ |
| 283 |
if (char_format==CHAR_CODE_NUM) out_num(val); |
| 284 |
else if (font_type!=FT_VANILLA) out_num(val); |
| 285 |
else if (((val>='0') && (val<='9')) || |
| 286 |
((val>='A') && (val<='Z')) || |
| 287 |
((val>='a') && (val<='z'))) |
| 288 |
fprintf(file_output, "C %c", val); |
| 289 |
else out_num(val); |
| 290 |
} |
| 291 |
|
| 292 |
void |
| 293 |
out_num(unsigned val) |
| 294 |
{ |
| 295 |
if (num_format==NUM_CODE_OCTAL) out_int(val, 8); |
| 296 |
else out_int(val, 16); |
| 297 |
} |
| 298 |
|
| 299 |
static void out_digits(unsigned); |
| 300 |
|
| 301 |
void |
| 302 |
out_int(unsigned val, unsigned base) |
| 303 |
{ |
| 304 |
register unsigned j=0, acc=val; |
| 305 |
if (val < 0) internal_error_1("out_int (val=%d)", val); |
| 306 |
if (base==16) out("H "); |
| 307 |
else if (base==10) out("D "); |
| 308 |
else if (base==8) out("O "); |
| 309 |
else internal_error_1("out_int (base=%d)", base); |
| 310 |
do { |
| 311 |
digits[j] = acc % base; |
| 312 |
j++; |
| 313 |
acc = acc / base; |
| 314 |
} while (acc > 0); |
| 315 |
/* |
| 316 |
if ((base==16) && (ec>=0x100)) { |
| 317 |
while (j<4) { digits[j] = 0; j++; } |
| 318 |
} |
| 319 |
*/ |
| 320 |
out_digits(j); |
| 321 |
} |
| 322 |
|
| 323 |
void |
| 324 |
out_fix(fix fval) |
| 325 |
{ |
| 326 |
register int a = (fval & 0xfff00000) >> 20, f = fval & 0xfffff, j=0; |
| 327 |
register int delta; |
| 328 |
|
| 329 |
out("R "); |
| 330 |
if (a>0x7ff) { |
| 331 |
out("-"); a = 0x1000 - a; |
| 332 |
if (f>0) { |
| 333 |
f = 0x100000 - f; a--; |
| 334 |
} |
| 335 |
} |
| 336 |
do { |
| 337 |
digits[j] = a % 10; |
| 338 |
j++; |
| 339 |
a = a / 10; |
| 340 |
} while (a > 0); |
| 341 |
out_digits(j); |
| 342 |
out("."); |
| 343 |
f = 10*f + 5; delta = 10; |
| 344 |
do { |
| 345 |
if (delta>0x100000) f = f + 0x80000 - (delta / 2); |
| 346 |
fprintf(file_output, "%c", (f / 0x100000) + '0'); |
| 347 |
f = 10 * (f % 0x100000); delta = delta*10; |
| 348 |
} while (f>delta); |
| 349 |
} |
| 350 |
|
| 351 |
void |
| 352 |
out_hex(unsigned char c) |
| 353 |
{ |
| 354 |
fprintf(file_output, "%02X", c); |
| 355 |
} |
| 356 |
|
| 357 |
static void |
| 358 |
out_digits(unsigned counter) |
| 359 |
{ |
| 360 |
register unsigned j=counter, c; |
| 361 |
while (j>0) { |
| 362 |
c = digits[--j]; |
| 363 |
if (c<10) fprintf(file_output, "%c", c+'0'); |
| 364 |
else fprintf(file_output, "%c", c+'A'-10); |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
void |
| 369 |
out(const_string sval) |
| 370 |
{ |
| 371 |
fprintf(file_output, "%s", sval); |
| 372 |
} |