Back to index

tetex-bin  3.0
out_routines.c
Go to the documentation of this file.
00001 /* out_routines.c: Low-level routines for outputting OPL and OVP files.
00002 
00003 This file is part of Omega,
00004 which is based on the web2c distribution of TeX,
00005 
00006 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
00007 
00008 Omega is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 Omega is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Omega; if not, write to the Free Software Foundation, Inc.,
00020 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 
00022 */
00023 
00024 #include "cpascal.h"
00025 #include "list_routines.h"
00026 #include "manifests.h"
00027 #include "omfonts.h"
00028 #include "out_routines.h"
00029 #include "error_routines.h"
00030 #include "header_routines.h"
00031 #include "char_routines.h"
00032 
00033 /* Character measures */
00034 
00035 string character_measures[] =
00036      { "CHARWD",      "CHARHT",         "CHARDP",        "CHARIC",
00037        "SECWD",       "SECHT",          "SECDP",         "SECIC",
00038        "PRIMTOPAXIS", "PRIMTOPAXISBIS", "PRIMBOTAXIS",   "PRIMBOTAXISBIS",
00039        "PRIMMIDHOR",  "PRIMMIDVERT",    "PRIMBASESLANT", NULL,
00040        "SECTOPAXIS",  "SECTOPAXISBIS",  "SECBOTAXIS",    "SECBOTAXISBIS",
00041        "SECMIDHOR",   "SECMIDVERT",     "SECBASESLANT",  NULL};
00042 
00043 void
00044 out_character_measure(unsigned measure)
00045 {
00046     if ((measure < C_MIN) || (measure > C_MAX) ||
00047         (character_measures[measure]==NULL)) {
00048        internal_error_1("out_character_measure (measure=%d)", measure);
00049     }
00050     out(character_measures[measure]);
00051 }
00052 
00053 /* Extensible pieces */
00054 
00055 string extensible_pieces[] =
00056      { "TOP", "MID", "BOT", "REP", NULL };
00057 
00058 void
00059 out_extensible_piece(unsigned piece)
00060 {
00061     if ((piece < E_MIN) || (piece > E_MAX)) {
00062        internal_error_1("out_extensible_piece (piece=%d)", piece);
00063     }
00064     out(extensible_pieces[piece]);
00065 }
00066 
00067 /* Ligature commands */
00068 
00069 string ligature_commands[] =
00070      { "LIG", "LIG/", "/LIG", "/LIG/", NULL,
00071        "LIG/>", "/LIG>", "/LIG/>", NULL, NULL,
00072        NULL, "/LIG/>>", NULL };
00073 
00074 void
00075 out_ligature_command(unsigned command)
00076 {
00077     if ((command < L_MIN) || (command > L_MAX) ||
00078         (ligature_commands[command]==NULL)) {
00079        internal_error_1("out_ligature_command (command=%d)", command);
00080     }
00081     out(ligature_commands[command]);
00082 }
00083 
00084 /* Xerox faces */
00085 
00086 string xerox_faces[] =
00087     { "MRR", "MIR", "BRR", "BIR", "LRR", "LIR",
00088       "MRC", "MIC", "BRC", "BIC", "LRC", "LIC",
00089       "MRE", "MIE", "BRE", "BIE", "LRE", "LIE", NULL };
00090 
00091 void
00092 print_xerox_face(int face)
00093 {
00094     if ((face < F_MIN) || (face > F_MAX)) {
00095        internal_error_1("print_xerox_face (face=%d)", face);
00096     }
00097     out("F "); out(xerox_faces[face]);
00098 }
00099 
00100 /* Named parameters */
00101 
00102 string named_parameters[] =
00103     { NULL,      "SLANT",      "SPACE",  "STRETCH", "SHRINK",    "XHEIGHT",
00104       "QUAD",    "EXTRASPACE", NULL };
00105 
00106 void
00107 out_named_parameter(unsigned parameter)
00108 {
00109     if ((parameter < P_MIN) || (parameter > P_MAX)) {
00110        internal_error_1("out_named_parameter (parameter = %d)", parameter);
00111     }
00112     out(named_parameters[parameter]);
00113 }
00114 
00115 /* Named math symbol parameters */
00116 
00117 string named_mathsy_parameters[] =
00118     { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00119       "NUM1",   "NUM2",    "NUM3",      "DENOM1",
00120       "DENOM2",  "SUP1",       "SUP2",   "SUP3",    "SUB1",      "SUB2",
00121       "SUPDROP", "SUBDROP",    "DELIM1", "DELIM2",  "AXISHEIGHT", NULL };
00122 
00123 void
00124 out_named_mathsy_parameter(unsigned parameter)
00125 {
00126     if ((parameter < P_MATHSY_MIN) || (parameter > P_MATHSY_MAX) ||
00127         (named_mathsy_parameters[parameter]==NULL)) {
00128        internal_error_1("out_named_mathsy_parameter (parameter=%d)",parameter);
00129     }
00130     out(named_mathsy_parameters[parameter]);
00131 }
00132 
00133 /* Named math extension parameters */
00134 
00135 string named_mathex_parameters[] =
00136     { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00137       "DEFAULTRULETHICKNESS", "BIGOPSPACING1",
00138       "BIGOPSPACING2",        "BIGOPSPACING3",
00139       "BIGOPSPACING4",        "BIGOPSPACING5", NULL };
00140 
00141 void
00142 out_named_mathex_parameter(unsigned parameter)
00143 {
00144     if ((parameter < P_MATHEX_MIN) || (parameter > P_MATHEX_MAX) ||
00145         (named_mathex_parameters[parameter]==NULL)) {
00146        internal_error_1("out_named_mathex_parameter (parameter=%d)",parameter);
00147     }
00148     out(named_mathex_parameters[parameter]);
00149 }
00150 
00151 /* Typesetting directions */
00152 
00153 string type_directions[] =
00154      { "FONTDIR", "NATURALFONTDIR", NULL };
00155 
00156 string actual_directions[] =
00157      { "TL", "LT", "TR", "RT", "LB", "BL", "BR", "RB", NULL };
00158 
00159 void
00160 out_type_direction(unsigned direction)
00161 {
00162     if ((direction < DIR_MIN) || (direction > DIR_MAX)) {
00163        internal_error_1("out_type_direction (direction=%d)", direction);
00164     }
00165     out(type_directions[direction/8]); out(" ");
00166     out(actual_directions[direction%8]);
00167 }
00168 
00169 /* Kinds of accents */
00170 
00171 string accent_kinds[] =
00172      { NULL, "TOPACCENT", "MIDACCENT", "BOTACCENT", NULL };
00173 
00174 void
00175 out_accent_kind(unsigned kind)
00176 {
00177     if ((kind < ACC_TOP) || (kind > ACC_BOT)) {
00178        internal_error_1("out_accent_kind (kind=%d)", kind);
00179     }
00180     out(accent_kinds[kind]);
00181 }
00182 
00183 /* Move directions */
00184 
00185 string move_directions[] =
00186      { "MOVERIGHT", "MOVELEFT", "MOVEUP", "MOVEDOWN", NULL };
00187 
00188 void
00189 out_move_direction(unsigned direction)
00190 {
00191     if ((direction < M_MIN) || (direction > M_MAX)) {
00192        internal_error_1("out_move_direction (direction=%d)", direction);
00193     }
00194     out(move_directions[direction]);
00195 }
00196 
00197 /* Rule measures */
00198 
00199 string rule_measures[] =
00200      { "RULEWD", "RULEHT", "RULEDP", NULL };
00201 
00202 void
00203 out_rule_measure(unsigned measure)
00204 {
00205     if ((measure < RULE_MIN) || (measure > RULE_MAX)) {
00206        internal_error_1("out_rule_measure (measure=%d)", measure);
00207     }
00208     out(rule_measures[measure]);
00209 }
00210 
00211 /* Glue shrink or stretch */
00212 
00213 string glue_shrink_stretch[] =
00214      { "GLUESHRINK", "GLUESTRETCH", NULL };
00215 
00216 void
00217 out_shrink_stretch(unsigned shrink_stretch)
00218 {
00219     if ((shrink_stretch < GLUE_MIN) || (shrink_stretch > GLUE_MAX)) {
00220        internal_error_1("out_shrink_stretch (shrink_stretch=%d)",
00221                          shrink_stretch);
00222     }
00223     out(glue_shrink_stretch[shrink_stretch]);
00224 }
00225 
00226 /* Glue orders */
00227 
00228 string glue_orders[] =
00229      { "UNIT", "FI", "FIL", "FILL", "FILLL", NULL };
00230 
00231 void
00232 out_glue_order(unsigned order)
00233 {
00234     if ((order < O_MIN) || (order > O_MAX)) {
00235        internal_error_1("out_glue_order (order=%d)", order);
00236     }
00237     out(glue_orders[order]);
00238 }
00239 
00240 /* Glue kinds */
00241 
00242 string glue_kinds[] =
00243      { "NORMAL", "ALEADERS", "CLEADERS", "ALEADERS", "XLEADERS", NULL };
00244 
00245 void
00246 out_glue_kind(unsigned kind)
00247 {
00248     if ((kind < K_MIN) || (kind > K_MAX)) {
00249        internal_error_1("out_glue_kind (kind=%d)", kind);
00250     }
00251     out(glue_kinds[kind]);
00252 }
00253 
00254 unsigned parenthesis_level=0;
00255 unsigned digits[12];
00256 
00257 /* Basic routines used by everyone */
00258 
00259 void
00260 out_ln(void)
00261 {
00262     unsigned i;
00263     out("\n");
00264     for (i = 0; i < parenthesis_level; i++) out("   ");
00265 }
00266 
00267 void
00268 left(void)
00269 {
00270     parenthesis_level++; out("(");
00271 }
00272 
00273 void
00274 right(void)
00275 {
00276     if (parenthesis_level==0) internal_error_0("right");
00277     parenthesis_level--; out(")"); out_ln();
00278 }
00279 
00280 void
00281 out_char(unsigned val)
00282 {
00283         if (char_format==CHAR_CODE_NUM) out_num(val);
00284         else if (font_type!=FT_VANILLA) out_num(val);
00285         else if (((val>='0') && (val<='9')) ||
00286                  ((val>='A') && (val<='Z')) ||
00287                  ((val>='a') && (val<='z')))
00288            fprintf(file_output, "C %c", val);
00289         else out_num(val);
00290 }
00291 
00292 void
00293 out_num(unsigned val)
00294 {
00295         if (num_format==NUM_CODE_OCTAL) out_int(val, 8);
00296         else out_int(val, 16);
00297 }
00298 
00299 void
00300 out_int(unsigned val, unsigned base)
00301 {
00302        register unsigned j=0, acc=val;
00303        if (val < 0) internal_error_1("out_int (val=%d)", val);
00304        if (base==16)      out("H ");
00305        else if (base==10) out("D ");
00306        else if (base==8)  out("O ");
00307        else internal_error_1("out_int (base=%d)", base);
00308        do {
00309               digits[j] = acc % base;
00310               j++;
00311               acc = acc / base;
00312        } while (acc > 0);
00313 /*
00314         if ((base==16) && (ec>=0x100)) {
00315             while (j<4) { digits[j] = 0; j++; }
00316         }
00317 */
00318        out_digits(j);
00319 }
00320 
00321 void
00322 out_as_fix(fix fval)
00323 {
00324        register fix x=0;
00325 
00326        if (fval<0) {
00327               x = 0xff000000;
00328               fval = fval + 0x1000000;
00329        }
00330        x = x | (fval & 0xff);
00331        fval = fval % 0x100;
00332        x = x | ((fval & 0xff) << 8);
00333        fval = fval % 0x100;
00334        x = x | ((fval & 0xff) << 16);
00335         out_fix(x);
00336 }
00337 
00338 void
00339 out_fix(fix fval)
00340 {
00341        register int a = (fval & 0xfff00000) >> 20, f = fval & 0xfffff, j=0;
00342        register int delta;
00343 
00344        out("R ");
00345        if (a>0x7ff) {
00346               out("-"); a = 0x1000 - a;
00347               if (f>0) {
00348                      f = 0x100000 - f; a--;
00349               }
00350        }
00351        do {
00352               digits[j] = a % 10;
00353               j++;
00354               a = a / 10;
00355        } while (a > 0);
00356        out_digits(j);
00357        out(".");
00358        f = 10*f + 5; delta = 10;
00359        do {
00360               if (delta>0x100000) f = f + 0x80000 - (delta / 2);
00361               fprintf(file_output, "%c", (f / 0x100000) + '0');
00362               f = 10 * (f % 0x100000); delta = delta*10;
00363        } while (f>delta);
00364 }
00365 
00366 void
00367 out_digits(unsigned counter)
00368 {
00369        register unsigned j=counter, c;
00370        while (j>0) {
00371               c = digits[--j];
00372               if (c<10) fprintf(file_output, "%c", c+'0');
00373               else fprintf(file_output, "%c", c+'A'-10);
00374        }
00375 }
00376 
00377 void
00378 out(string sval)
00379 {
00380        fprintf(file_output, sval);
00381 }