home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / CMTEX330 / SOURCE / DEF.C < prev    next >
C/C++ Source or Header  |  1992-04-21  |  21KB  |  1,126 lines

  1.  
  2. /*
  3.  * %Y%:%M%:%I%:%Q%
  4.  *
  5.  * Copyright 1987,1988,1991 Pat J Monardo
  6.  *
  7.  * Redistribution of this file is permitted through
  8.  * the specifications in the file COPYING.
  9.  *
  10.  * 
  11.  */
  12.  
  13. #ifndef lint
  14. static char *sccsid = "%A%";
  15. #endif
  16.  
  17. #include "tex.h"
  18.  
  19. tok    after_token;
  20. int    mag_set;
  21. bool    long_help_seen;
  22.  
  23. #define glob    (a >= 4)
  24.  
  25. #define def(eq, type, value) \
  26.     if (glob) \
  27.         eq_gdefine(eq, type, value); \
  28.     else eq_define(eq, type, value)
  29.  
  30. #define reg_def(reg, type, value) \
  31.     if (glob) \
  32.         reg_gdefine(reg, type, value); \
  33.     else reg_define(reg, type, value)
  34.  
  35. void
  36. get_r_token ()
  37. {
  38. restart:
  39.     do get_token();
  40.     while (cur_tok == SPACE_TOKEN);
  41.     if (cur_cs == null_sym || isfrozen(cur_cs)) {
  42.         print_err("Missing control sequence inserted");
  43.         help_missing_cs();
  44.         if (cur_cs == null_sym)
  45.             back_input();
  46.         cur_tok = sym2tok(FROZEN_PROTECTION);
  47.         ins_error();
  48.         goto restart;
  49.     }
  50. }
  51.  
  52. void
  53. prefixed_command ()
  54. {
  55.     int    a = 0;
  56.  
  57.     while (cur_cmd == PREFIX) {
  58.         if (!odd(a / cur_chr))
  59.             a += cur_chr;
  60.         get_nbrx_token();
  61.         if (cur_cmd <= MAX_NON_PREFIXED_COMMAND) {
  62.             print_err("You can't use a prefix with `");
  63.             print_cmd_chr(cur_cmd, cur_chr);
  64.             print("'");
  65.             help_prefix();
  66.             back_error();
  67.             return;
  68.         }
  69.     }
  70.     if (cur_cmd != DEF && a % 4 != 0) {
  71.         print_err("You can't use `");
  72.         print_esc("long");
  73.         print("' or `");
  74.         print_esc("outer");
  75.         print("' with `");
  76.         print_cmd_chr(cur_cmd, cur_chr);
  77.         print("'");
  78.         help_pref();
  79.         error();
  80.     }
  81.     if (global_defs != 0) {
  82.         if (global_defs < 0) {
  83.             if (glob) a -= 4;
  84.         } else {
  85.             if (!glob) a += 4;
  86.         }
  87.     }
  88.     switch (cur_cmd) 
  89.     {
  90.     case SET_FONT:
  91.         reg_def(cur_font_ptr, FNT_REG, cur_chr);
  92.         break;
  93.  
  94.     case DEF: {
  95.         bool    e;
  96.         sym    s;
  97.  
  98.         if (odd(cur_chr) && !glob && global_defs >= 0)
  99.             a += 4;
  100.         e = cur_chr >= 2;
  101.         get_r_token();
  102.         s = cur_cs;
  103.         scan_toks(TRUE, e);
  104.         def(s, CALL + (a % 4), def_ref);
  105.         break;
  106.     }
  107.     case LET: {
  108.         int    n;
  109.         sym    s;
  110.         tok    t;
  111.  
  112.         n = cur_chr;
  113.         get_r_token();
  114.         s = cur_cs;
  115.         if (n == NORMAL) {
  116.             do get_token();
  117.             while (cur_cmd == SPACER);
  118.             if (cur_tok == OTHER_TOKEN + '=') {
  119.                 get_token();
  120.                 if (cur_cmd == SPACER)
  121.                     get_token();
  122.             }
  123.         } else {
  124.             get_token();
  125.             t = cur_tok;
  126.             get_token();
  127.             back_input();
  128.             cur_tok = t;
  129.             back_input();
  130.         }
  131.         if (cur_cmd >= CALL)
  132.             add_token_ref(cur_chr);
  133.         def(s, cur_cmd, cur_chr);
  134.         break;
  135.     }
  136.     case SHORTHAND_DEF: {
  137.         int    n;
  138.         sym    s;
  139.  
  140.         n = cur_chr;
  141.         get_r_token();
  142.         s = cur_cs; 
  143.         def(s, RELAX, 256);
  144.         scan_optional_equals();
  145.         switch (n)
  146.         {
  147.         case CHAR_DEF_CODE:
  148.             scan_char_num();
  149.             def(s, CHAR_GIVEN, cur_val);
  150.             break;
  151.  
  152.         case MATH_CHAR_DEF_CODE:
  153.             scan_fifteen_bit_int();
  154.             def(s, MATH_GIVEN, cur_val);
  155.             break;
  156.  
  157.         default:
  158.             scan_eight_bit_int();
  159.             switch (n) {
  160.             case MU_SKIP_DEF_CODE:
  161.                 def(s, ASSIGN_MU_GLUE, MU_GLUE_PARS + cur_val);
  162.                 break;
  163.             case SKIP_DEF_CODE:
  164.                 def(s, ASSIGN_GLUE, GLUE_PARS + cur_val);
  165.                 break;
  166.             case DIMEN_DEF_CODE:
  167.                 def(s, ASSIGN_DIMEN, DIMEN_PARS + cur_val);
  168.                 break;
  169.             case COUNT_DEF_CODE:
  170.                 def(s, ASSIGN_INT, INT_PARS + cur_val);
  171.                 break;
  172.             case TOKS_DEF_CODE:
  173.                 def(s, ASSIGN_TOKS, TOK_PARS + cur_val);
  174.                 break;
  175.             }
  176.             break;
  177.         }
  178.         break;
  179.     }
  180.     case READ_TO_CS: {
  181.         int    n;
  182.         sym    s;
  183.  
  184.         scan_int();
  185.         n = cur_val;
  186.         if (!scan_keyword("to")) {
  187.             print_err("Missing `to' inserted");
  188.             help_read_to();
  189.             error();
  190.         }
  191.         get_r_token();
  192.         s = cur_cs;
  193.         read_toks(n, s);
  194.         def(s, CALL, cur_val);
  195.         break;
  196.     }
  197.     case TOKS_REGISTER:
  198.     case ASSIGN_TOKS: {
  199.         ptr    p;
  200.         reg    r;
  201.         sym    s;
  202.  
  203.         s = cur_cs;
  204.         if (cur_cmd == TOKS_REGISTER) {
  205.             scan_eight_bit_int();
  206.             r = toks_reg[TOK_PARS + cur_val];
  207.         } else {
  208.             r = toks_reg[cur_chr];
  209.         }
  210.         scan_optional_equals();
  211.         get_nbrx_token();
  212.         if (cur_cmd != LEFT_BRACE) {
  213.             if (cur_cmd == TOKS_REGISTER) {
  214.                 scan_eight_bit_int();
  215.                 cur_cmd = ASSIGN_TOKS;
  216.                 cur_chr = TOK_PARS + cur_val;
  217.             }
  218.             if (cur_cmd == ASSIGN_TOKS) {
  219.                 p = reg_equiv(toks_reg[cur_chr]);
  220.                 if (p == null) {
  221.                     reg_def(r, TOKS_REG, null);
  222.                 } else {    
  223.                     add_token_ref(p);
  224.                     reg_def(r, TOKS_REG, p);
  225.                 }
  226.                 break;
  227.             }
  228.         }
  229.         back_input();
  230.         cur_cs = s;
  231.         scan_toks(FALSE, FALSE);
  232.         if (token_link(def_ref) == null) {
  233.             reg_def(r, TOKS_REG, null);
  234.             free_token(def_ref);
  235.         } else {
  236.             if (r == output_routine_reg) {
  237.                 p = token_link(def_ref);
  238.                 while (token_link(p) != null)
  239.                     p = token_link(p);
  240.                 p = token_link(p) = new_token();
  241.                 token(p) = RIGHT_BRACE_TOKEN + '}';
  242.                 p = new_token();
  243.                 token(p) = LEFT_BRACE_TOKEN + '{';
  244.                 token_link(p) = token_link(def_ref);
  245.                 token_link(def_ref) = p;
  246.             }
  247.             reg_def(r, TOKS_REG, def_ref);
  248.         }
  249.         break;
  250.     }
  251.     case ASSIGN_INT: {
  252.         reg        r;
  253.  
  254.         r = int_reg[cur_chr];
  255.         scan_optional_equals();
  256.         scan_int();
  257.         reg_def(r, INT_REG, cur_val); 
  258.         break;
  259.     }
  260.     case ASSIGN_DIMEN: {
  261.         reg        r;
  262.  
  263.         r = dimen_reg[cur_chr];
  264.         scan_optional_equals();
  265.         scan_normal_dimen();
  266.         reg_def(r, DIMEN_REG, cur_val); 
  267.         break;
  268.     }
  269.     case ASSIGN_GLUE: {
  270.         reg        r;
  271.  
  272.         r = skip_reg[cur_chr];
  273.         scan_optional_equals();
  274.         scan_glue(GLUE_VAL);
  275.         trap_zero_glue();
  276.         reg_def(r, SKIP_REG, cur_val); 
  277.         break;
  278.     }
  279.     case ASSIGN_MU_GLUE: {
  280.         reg        r;
  281.  
  282.         r = mu_skip_reg[cur_chr];
  283.         scan_optional_equals();
  284.         scan_glue(MU_VAL);
  285.         trap_zero_glue();
  286.         reg_def(r, MU_SKIP_REG, cur_val); 
  287.         break;
  288.     }
  289.     case DEF_CODE: {
  290.         int    m;
  291.         int    n;
  292.         int    o;
  293.         reg        r;
  294.  
  295.         m = cur_chr;
  296.         if (m == CAT_CODE) {
  297.             n = MAX_CHAR_CODE;
  298.             o = CAT_CODE_REG;
  299.         } else if (m == LC_CODE) {
  300.             n = 255;
  301.             o = LC_CODE_REG;
  302.         } else if (m == UC_CODE) {
  303.             n = 255;
  304.             o = UC_CODE_REG;
  305.         } else if (m == SF_CODE) {
  306.             n = 077777;
  307.             o = SF_CODE_REG;
  308.         } else if (m == MATH_CODE) {
  309.             n = 0100000;
  310.             o = MATH_CODE_REG;
  311.         } else if (m == DEL_CODE) {
  312.             n = 077777777;
  313.             o = DEL_CODE_REG;
  314.         } else {
  315.             confusion("confusing code");
  316.         }
  317.         scan_char_num();
  318.         switch (m) {
  319.         case CAT_CODE: r = cat_code_reg[cur_val]; break;
  320.         case UC_CODE: r = uc_code_reg[cur_val]; break;
  321.         case LC_CODE: r = lc_code_reg[cur_val]; break;
  322.         case SF_CODE: r = sf_code_reg[cur_val]; break;
  323.         case MATH_CODE: r = math_code_reg[cur_val]; break;
  324.         case DEL_CODE: r = del_code_reg[cur_val]; break;
  325.         }
  326.         scan_optional_equals();
  327.         scan_int(); 
  328.         if (cur_val < 0 && m != DEL_CODE || cur_val > n) {
  329.             print_err("Invalid code (");
  330.             print_int(cur_val);
  331.             if (m != DEL_CODE) {
  332.                 print("), should be in the range 0..");
  333.             } else {
  334.                 print("), should be at most ");
  335.             }
  336.             print_int(n);
  337.             help_code();
  338.             error();
  339.             cur_val = 0;
  340.         }
  341.         reg_def(r, o, cur_val);
  342.         break;
  343.     }
  344.     case DEF_FAMILY: {
  345.         int    i;
  346.         reg    r;
  347.  
  348.         i = cur_chr;
  349.         scan_four_bit_int();
  350.         i += cur_val;
  351.         scan_optional_equals();
  352.         scan_font_ident();
  353.         r = fnt_reg[1 + i];
  354.         reg_def(r, FNT_REG, cur_val);
  355.         break;
  356.     }
  357.     case REGISTER:
  358.     case ADVANCE:
  359.     case MULTIPLY:
  360.     case DIVIDE:
  361.         do_register_command(a);
  362.         break;
  363.  
  364.     case SET_BOX: {
  365.         int    n;
  366.  
  367.         scan_eight_bit_int();
  368.         if (glob) {
  369.             n = 256 + cur_val;
  370.         } else {
  371.             n = cur_val;
  372.         }
  373.         scan_optional_equals();
  374.         scan_box(BOX_FLAG + n);
  375.         break;
  376.     }
  377.     case SET_AUX:
  378.         alter_aux();
  379.         break;
  380.  
  381.     case SET_PREV_GRAF:
  382.         alter_prev_graf();
  383.         break;
  384.  
  385.     case SET_PAGE_DIMEN:
  386.         alter_page_so_far();
  387.         break;
  388.  
  389.     case SET_PAGE_INT:
  390.         alter_integer();
  391.         break;
  392.  
  393.     case SET_BOX_DIMEN:
  394.         alter_box_dimen();
  395.         break;
  396.  
  397.     case SET_SHAPE: {
  398.         int    i;
  399.         int    n;
  400.         ptr    p;
  401.  
  402.         scan_optional_equals();
  403.         scan_int();
  404.         n = cur_val;
  405.         if (n <= 0) {
  406.             def(par_shape_cs, SET_SHAPE, null);
  407.         } else {
  408.             p = new_node(sizeof(mcell) + n * sizeof(shape_t));
  409.             def(par_shape_cs, SET_SHAPE, p);
  410.             info(p) = n;
  411.             for (i = 1; i <= n; incr(i)) {
  412.                 scan_normal_dimen();
  413.                 par_shape_indent(i) = cur_val;
  414.                 scan_normal_dimen();
  415.                 par_shape_width(i) = cur_val;
  416.             }
  417.         }
  418.         break;
  419.     }
  420.     case HYPH_DATA:
  421.         if (cur_chr == 1) 
  422.             new_patterns();
  423.         else new_hyph_exceptions();
  424.         break;
  425.  
  426.     case ASSIGN_FONT_DIMEN: {
  427.         scal    *d;
  428.  
  429.         d = find_font_dimen(TRUE);
  430.         scan_optional_equals();
  431.         scan_normal_dimen();
  432.         if (d != (scal *) 0)
  433.             *d = cur_val;
  434.         break;
  435.     }
  436.     case ASSIGN_FONT_INT: {
  437.         int    f;
  438.         int    n;
  439.  
  440.         n = cur_chr;
  441.         scan_font_ident();
  442.         f = cur_val;
  443.         scan_optional_equals();
  444.         scan_int(); 
  445.         if (n == 0)
  446.             hyphen_char(f) = cur_val;
  447.         else skew_char(f) = cur_val;
  448.         break;
  449.     }
  450.     case DEF_FONT:
  451.         new_font(a);
  452.         break;
  453.  
  454.     case SET_INTERACTION:
  455.         new_interaction();
  456.         break;
  457.  
  458.     default:
  459.         confusion("prefix");
  460.         break;
  461.     }
  462.     if (after_token != 0) {
  463.         cur_tok = after_token;
  464.         back_input();
  465.         after_token = 0;
  466.     }
  467.  
  468. void
  469. trap_zero_glue()
  470. {
  471.     if (glue_width(cur_val) == 0
  472.     && stretch(cur_val) == 0
  473.     && shrink(cur_val) == 0) {
  474.         add_glue_ref(zero_glue);
  475.         delete_glue_ref(cur_val);
  476.         cur_val = zero_glue;
  477.     }
  478. }
  479.  
  480. void
  481. do_register_command (a)
  482.     int    a;
  483. {
  484.     int    b;
  485.     int    c;
  486.     ptr    p;
  487.     reg    r;
  488.     int    v;
  489.  
  490.     c = cur_cmd;
  491.     if (c != REGISTER) {
  492.         get_x_token();
  493.         if (cur_cmd >= ASSIGN_INT && cur_cmd <= ASSIGN_MU_GLUE) {
  494.             b = cur_cmd - ASSIGN_INT;
  495.             switch (b) {
  496.             case INT_VAL: r = int_reg[cur_chr]; break;
  497.             case DIMEN_VAL: r = dimen_reg[cur_chr]; break; 
  498.             case GLUE_VAL: r = skip_reg[cur_chr]; break; 
  499.             case MU_VAL: r = mu_skip_reg[cur_chr]; break;
  500.             }
  501.             goto found;
  502.         }
  503.         if (cur_cmd != REGISTER) {
  504.             print_err("You can't use `");
  505.             print_cmd_chr(cur_cmd, cur_chr);
  506.             print("' after ");
  507.             print_cmd_chr(c, 0);
  508.             help_register();
  509.             error();
  510.             return;
  511.         }
  512.     }
  513.  
  514.     b = cur_chr;
  515.     scan_eight_bit_int();
  516.     switch (b) {
  517.     case INT_VAL: r = int_reg[INT_PARS + cur_val]; break;
  518.     case DIMEN_VAL: r = dimen_reg[DIMEN_PARS + cur_val]; break; 
  519.     case GLUE_VAL: r = skip_reg[GLUE_PARS + cur_val]; break; 
  520.     case MU_VAL: r = mu_skip_reg[MU_GLUE_PARS + cur_val]; break;
  521.     }
  522.  
  523. found:
  524.     v = reg_equiv(r);
  525.     if (c == REGISTER)
  526.         scan_optional_equals();
  527.     else scan_keyword("by");
  528.     arith_error = FALSE;
  529.     if (c < MULTIPLY)  {
  530.         if (b < GLUE_VAL) {
  531.             if (b == INT_VAL)
  532.                 scan_int();
  533.             else scan_normal_dimen();
  534.             if (c == ADVANCE)
  535.                 cur_val += v;
  536.         } else {
  537.             scan_glue(b);
  538.             if (c == ADVANCE) {
  539.                 p = new_spec(cur_val);
  540.                 delete_glue_ref(cur_val);
  541.                 glue_width(p) += glue_width(v);
  542.                 if (stretch(p) == 0)
  543.                     stretch_order(p) = NORMAL;
  544.                 if (stretch_order(p) == stretch_order(v)) {
  545.                     stretch(p) += stretch(v);
  546.                 } else if (stretch_order(p) < stretch_order(v)
  547.                     && stretch(v)) {
  548.                     stretch(p) = stretch(v);
  549.                     stretch_order(p) = stretch_order(v);
  550.                 }
  551.                 if (shrink(p) == 0)
  552.                     shrink_order(p) = NORMAL;
  553.                 if (shrink_order(p) == shrink_order(v)) {
  554.                     shrink(p) += shrink(v);
  555.                 } else if (shrink_order(p) < shrink_order(v)
  556.                     && shrink(v)) {
  557.                     shrink(p) = shrink(v); 
  558.                     shrink_order(p) = shrink_order(v);
  559.                 }
  560.                 cur_val = p;
  561.             }
  562.         }
  563.     } else {
  564.         scan_int();
  565.         if (b < GLUE_VAL) {
  566.             if (c == MULTIPLY) {
  567.                 if (b == INT_VAL) {
  568.                     cur_val = mult_integers(v, cur_val);
  569.                 } else {
  570.                     cur_val = nx_plus_y(v, cur_val, 0);
  571.                 }
  572.             } else {
  573.                 cur_val = x_over_n(v, cur_val);
  574.             }
  575.         } else {
  576.             p = new_spec(v);
  577.             if (c == MULTIPLY) {
  578.                 glue_width(p) =
  579.                     nx_plus_y(glue_width(v), cur_val, 0);
  580.                 stretch(p) = nx_plus_y(stretch(v), cur_val, 0);
  581.                 shrink(p) = nx_plus_y(shrink(v), cur_val, 0);
  582.             } else {
  583.                 glue_width(p) =
  584.                     x_over_n(glue_width(v), cur_val);
  585.                 stretch(p) = x_over_n(stretch(v), cur_val);
  586.                 shrink(p) = x_over_n(shrink(v), cur_val);
  587.             }
  588.             cur_val = p;
  589.         }
  590.     }
  591.     if (arith_error) {
  592.         print_err("Arithmetic overflow");
  593.         help_overflow();
  594.         error();
  595.         return;
  596.     }
  597.     switch (b) {
  598.     case INT_VAL: reg_def(r, INT_REG, cur_val); break;
  599.     case DIMEN_VAL: reg_def(r, DIMEN_REG, cur_val); break;
  600.     case GLUE_VAL: trap_zero_glue(); reg_def(r, SKIP_REG, cur_val); break;
  601.     case MU_VAL: trap_zero_glue(); reg_def(r, MU_SKIP_REG, cur_val); break;
  602.     }
  603. }
  604.  
  605. void
  606. alter_aux ()
  607. {
  608.     int    c;
  609.  
  610.     if (cur_chr != abs(mode)) {
  611.         report_illegal_case();
  612.     } else {
  613.         c = cur_chr;
  614.         scan_optional_equals();
  615.         if (c == VMODE)  {
  616.             scan_normal_dimen();
  617.             prev_depth = cur_val;
  618.         } else {
  619.             scan_int();
  620.             if (cur_val <= 0 || cur_val > 32767) {
  621.                 print_err("Bad space factor");
  622.                 help_space_factor();
  623.                 int_error(cur_val);
  624.             } else {
  625.                 space_factor = cur_val;
  626.             }
  627.         }
  628.     }
  629. }
  630.  
  631. void
  632. alter_prev_graf ()
  633. {
  634.     list    *p;
  635.  
  636.     *nest_ptr = cur_list;
  637.     p = nest_ptr;
  638.     while (abs(p->mode_field) != VMODE)
  639.         decr(p);
  640.     scan_optional_equals();
  641.     scan_int();
  642.     if (cur_val < 0) {
  643.         print_err("Bad ");
  644.         print_esc("prevgraf");
  645.         help_prevgraf();
  646.         int_error(cur_val);
  647.     } else {
  648.         p->pg_field = cur_val;
  649.         cur_list = *nest_ptr;
  650.     }
  651. }
  652.  
  653. void
  654. alter_page_so_far ()
  655. {
  656.     int    c;
  657.  
  658.     c = cur_chr;
  659.     scan_optional_equals(); 
  660.     scan_normal_dimen();
  661.     page_so_far[c] = cur_val;
  662. }
  663.  
  664. void
  665. alter_integer ()
  666. {
  667.     int    c;
  668.     
  669.     c = cur_chr;
  670.     scan_optional_equals();
  671.     scan_int();
  672.     if (c == 0) {
  673.         dead_cycles = cur_val;
  674.     } else {
  675.         insert_penalties = cur_val;
  676.     }
  677. }
  678.  
  679. void
  680. alter_box_dimen ()
  681. {
  682.     int    b;
  683.     int    c;
  684.     
  685.     c = cur_chr;
  686.     scan_eight_bit_int();
  687.     b = cur_val; 
  688.     scan_optional_equals();
  689.     scan_normal_dimen();
  690.     if (box(b) != null) {
  691.         switch (c) {
  692.         case WD_CODE: box_width(box(b)) = cur_val; break;
  693.         case HT_CODE: box_height(box(b)) = cur_val; break;
  694.         case DP_CODE: box_depth(box(b)) = cur_val; break;
  695.         }
  696.     }
  697. }
  698.  
  699. void
  700. new_font (a)
  701.     int    a;
  702. {
  703.     fnt    f;
  704.     scal    s;
  705.     str    t;
  706.     int    l;
  707.     sym    u;
  708.  
  709. #define ILL_MAG "Illegal magnification has been changed to 1000"
  710.  
  711.     if (job_name == null_str)
  712.         open_log_file();
  713.     get_r_token();
  714.     u = cur_cs;
  715.     switch (length(u))
  716.     {
  717.     case 0:
  718.         t = make_str_given("FONT");
  719.         l = 0;
  720.         break;
  721.  
  722.     case 1:
  723.         if (isactive(u)) {
  724.             int old_setting = selector;
  725.             selector = NEW_STRING;
  726.             print("FONT");
  727.             print_ASCII(textbyte(u));
  728.             selector = old_setting;
  729.             l = cur_length();
  730.             t = make_str();
  731.         } else {
  732.             l = 1;
  733.             t = text(u);
  734.         }
  735.         break;
  736.  
  737.     default:
  738.         l = length(u);
  739.         t = text(u);
  740.         break;
  741.     }
  742.     def(u, SET_FONT, null_font);
  743.     scan_optional_equals();
  744.     scan_file_name();
  745.     name_in_progress = TRUE;
  746.     if (scan_keyword("at")) {
  747.         scan_normal_dimen();
  748.         s = cur_val;
  749.         if (s <= 0 || s >= 01000000000) {
  750.             print_err("Improper `at' size (");
  751.             print_scaled(s);
  752.             print("pt), replaced by 10pt");
  753.             help_font_at();
  754.             error();
  755.             s = 10 * UNITY;
  756.         }
  757.     } else if (scan_keyword("scaled")) {
  758.         scan_int();
  759.         s = -cur_val;
  760.         if (cur_val <= 0 || cur_val > 32768) {
  761.             print_err(ILL_MAG);
  762.             help_font_magnification();
  763.             int_error(cur_val);
  764.             s = -1000;
  765.         }
  766.     } else {
  767.         s = -1000;
  768.     }
  769.     name_in_progress = FALSE;
  770.     for (f = null_font + 1; f < null_font + font_ptr - font_info; f++) {
  771.         if (str_eq(font_name(f), cur_name) &&
  772.             str_eq(font_area(f), cur_area)) {
  773.             if (s > 0) {
  774.                 if (s == font_size(f))
  775.                     goto common_end;
  776.             } else if (font_size(f) ==
  777.                 xn_over_d(font_dsize(f), -s, 1000)) {
  778.                 goto common_end;
  779.             }
  780.         }
  781.     }
  782.     f = read_font_info(u, cur_name, cur_area, s);
  783.  
  784. common_end:
  785.     equiv(u) = f;
  786.     *font_id_base[f] = *u;
  787.     font_id_text(f) = t;
  788.     font_id_length(f) = l;
  789. }
  790.  
  791. void
  792. prepare_mag ()
  793. {
  794.     if (mag_set > 0 && mag != mag_set) {
  795.         print_err("Incompatible magnification (");
  796.         print_int(mag);
  797.         print(");");
  798.         print_nl(" the previous value will be retained");
  799.         help_mag();
  800.         int_error(mag_set);
  801.         reg_gdefine(int_reg[MAG_CODE], INT_REG, mag_set);
  802.     }
  803.     if (mag <= 0 || mag > 32768) {
  804.         print_err("Illegal magnification has been changed to 1000");
  805.         help_ill_mag();
  806.         int_error(mag);
  807.         reg_gdefine(int_reg[MAG_CODE], INT_REG, 1000);
  808.     }
  809.     mag_set = mag;
  810. }
  811.  
  812. void
  813. new_interaction ()
  814. {
  815.     print_ln();
  816.     interaction = cur_chr;
  817.     if (interaction == BATCH_MODE)
  818.         selector = NO_PRINT;
  819.     else selector = TERM_ONLY;
  820.     if (job_name != null_str)
  821.         selector += 2;
  822. }
  823.  
  824. void
  825. do_assignments ()
  826. {
  827.     loop {
  828.         get_nbrx_token();
  829.         if (cur_cmd <= MAX_NON_PREFIXED_COMMAND)
  830.             break;
  831.         prefixed_command();
  832.     }
  833. }
  834.  
  835. void
  836. clopen_stream ()
  837. {    
  838.     int    c;
  839.     int    n;
  840.  
  841.     c = cur_chr;
  842.     scan_four_bit_int();
  843.     n = cur_val; 
  844.     if (read_open[n] != CLOSED) {
  845.         a_close(read_file[n]);
  846.         read_open[n] = CLOSED;
  847.     }
  848.     if (c != 0) {
  849.         scan_optional_equals();
  850.         scan_file_name();
  851.         if (cur_ext == null_str) {
  852.             cur_ext = str_tex;
  853.         }
  854.         pack_cur_name();
  855.         read_file[n] = a_open_in();
  856.         if (read_file[n]) {
  857.             read_open[n] = OPENED;
  858.         }
  859.     }
  860. }
  861.  
  862. void
  863. issue_message ()
  864. {
  865.     int    c;
  866.     str    s;
  867.     int    old_setting;
  868.  
  869.     c = cur_chr;
  870.     scan_toks(FALSE, TRUE);
  871.     old_setting = selector;
  872.     selector = NEW_STRING;
  873.     token_show(def_ref);
  874.     selector = old_setting;
  875.     flush_list(def_ref);
  876.     s = make_str();
  877.     if (c == 0) {
  878.         if (term_offset + str_length(s) > MAX_PRINT_LINE - 2) {
  879.             print_ln();
  880.         } else if (term_offset > 0 || file_offset > 0) {
  881.             print(" ");
  882.         }
  883.         print(s);
  884.         update_terminal();
  885.     } else {
  886.         print_err(null_str);
  887.         print(s);
  888.         if (err_help != null) {
  889.             use_err_help = TRUE;
  890.         } else if (long_help_seen) {
  891.             help_err_msg();
  892.         } else {
  893.             if (interaction < ERROR_STOP_MODE) {
  894.                 long_help_seen = TRUE;
  895.             }
  896.             help_poirot();
  897.         }
  898.         error();
  899.         use_err_help = FALSE;
  900.     }
  901.     flush_str();
  902. }
  903.  
  904. void
  905. give_err_help ()
  906. {
  907.     token_show(err_help);
  908. }
  909.  
  910. void
  911. shift_case ()
  912. {
  913.     reg    *r;
  914.     int    c;
  915.     int    i;
  916.     ptr    p;
  917.     sym    s;
  918.     tok    t;
  919.  
  920.     r = (cur_chr == LC_CODE) ? lc_code_reg : uc_code_reg;
  921.     scan_toks(FALSE, FALSE);
  922.     for (p = token_link(def_ref); p != null; p = token_link(p)) {
  923.         t = token(p);
  924.         if (is_sym(t)) {
  925.             s = tok2sym(t);
  926.             if (!isactive(s)) {
  927.                 continue;
  928.             }
  929.             c = textbyte(s);
  930.             if (reg_equiv(r[c]) != 0) {
  931.                 i = reg_equiv(r[c]);
  932.                 token(p) = sym2tok(active_base[i]);
  933.             }
  934.         } else {
  935.             c = t % 0400;
  936.             if (reg_equiv(r[c]) != 0) {
  937.                 i = reg_equiv(r[c]);
  938.                 token(p) = (t / 0400) * 256 + i;
  939.             }
  940.         }
  941.     }
  942.     back_list(token_link(def_ref));
  943.     free_token(def_ref);
  944. }
  945.  
  946. void
  947. show_whatever ()
  948. {
  949.     ptr    t;
  950.     
  951.     switch (cur_chr)
  952.     {
  953.     case SHOW_LISTS:
  954.         begin_diagnostic();
  955.         show_activities();
  956.         break;
  957.  
  958.     case SHOW_BOX_CODE:
  959.         scan_eight_bit_int();
  960.         begin_diagnostic();
  961.         print_nl("> \\box");
  962.         print_int(cur_val);
  963.         print("=");
  964.         if (box(cur_val) == null) {
  965.             print("void");
  966.         } else {
  967.             show_box(box(cur_val));
  968.         }
  969.         break;
  970.     
  971.     case SHOW_CODE:
  972.         get_token();
  973.         print_nl("> ");
  974.         if (cur_cs != null_sym) {
  975.             sprint_cs(cur_cs);
  976.             print("=");
  977.         }
  978.         print_meaning();
  979.         goto common_end;
  980.     
  981.     default:
  982.         t = the_toks();
  983.         print_nl("> ");
  984.         token_show(t);
  985.         flush_list(t);
  986.         goto common_end;
  987.     }
  988.     end_diagnostic(TRUE);
  989.     print_err("OK");
  990.     if (selector == TERM_AND_LOG && tracing_online <= 0) {
  991.         selector = TERM_ONLY;
  992.         print(" (see the transcript file)");
  993.         selector = TERM_AND_LOG;
  994.     }
  995.  
  996. common_end:
  997.     if (interaction < ERROR_STOP_MODE) {
  998.         help0();
  999.         decr(error_cnt);
  1000.     } else if (tracing_online > 0) {
  1001.         help_show_online();
  1002.     } else {
  1003.         help_show();
  1004.     }
  1005.     error();
  1006. }
  1007.  
  1008. void
  1009. _def_init ()
  1010. {
  1011.     long_help_seen = FALSE;
  1012.     mag_set = 0;
  1013. }
  1014.  
  1015. void
  1016. _def_init_once ()
  1017. {
  1018. }
  1019.  
  1020. /*
  1021. **    Help text
  1022. */
  1023.  
  1024. help_missing_cs ()
  1025. {
  1026.     help5("Please don't say `\\def cs{...}', say `\\def\\cs{...}'.",
  1027.     "I've inserted an inaccessible control sequence so that your",
  1028.     "definition will be completed without mixing me up too badly.",
  1029.     "You can recover graciously from this error, if you're",
  1030.     "careful; see exercise 27.2 in The TeXbook.");
  1031. }
  1032.  
  1033. help_prefix ()
  1034. {
  1035.     help1("I'll pretend you didn't say \\long or \\outer or \\global.");
  1036. }
  1037.  
  1038. help_pref ()
  1039. {
  1040.     help1("I'll pretend you didn't say \\long or \\outer here.");
  1041. }
  1042.  
  1043. help_read_to ()
  1044. {
  1045.     help2("You should have said `\\read<number> to \\cs'.",
  1046.     "I'm going to look for the \\cs now.");
  1047. }
  1048.  
  1049. help_code ()
  1050. {
  1051.     help1("I'm going to use 0 instead of that illegal code value.");
  1052. }
  1053.  
  1054. help_register ()
  1055. {
  1056.     help1("I'm forgetting what you said and not changing anything.");
  1057. }
  1058.  
  1059. help_space_factor ()
  1060. {
  1061.     help1("I allow only values in the range 1..32767 here.");
  1062. }
  1063.  
  1064. help_prevgraf ()
  1065. {
  1066.     help1("I allow only nonnegative values here.");
  1067. }
  1068.  
  1069. help_overflow ()
  1070. {
  1071.     help2("I can't carry out that multiplication or division,",
  1072.     "since the result is out of range.");
  1073. }
  1074.  
  1075. help_font_at ()
  1076. {
  1077.     help2("I can only handle fonts at positive sizes that are",
  1078.     "less than 2048pt, so I've changed what you said to 10pt.");
  1079. }
  1080.  
  1081. help_font_magnification ()
  1082. {
  1083.     help1("The magnification ratio must be between 1 and 32768.");
  1084. }
  1085.  
  1086. help_mag()
  1087. {
  1088.     help2("I can handle only one magnification ratio per job. So I've",
  1089.     "reverted to the magnification you used earlier on this run.");
  1090. }
  1091.  
  1092. help_ill_mag ()
  1093. {
  1094.     help1("The magnification ratio must be between 1 and 32768.");
  1095. }
  1096.  
  1097. help_err_msg ()
  1098. {
  1099.     help1("(That was another \\errmessage.)");
  1100. }
  1101.  
  1102. help_poirot ()
  1103. {
  1104.     help4("This error message was generated by an \\errmessage",
  1105.     "command, so I can't give any explicit help.",
  1106.     "Pretend that you're Hercule Poirot: Examine all clues,",
  1107.     "and deduce the truth by order and method.");
  1108. }
  1109.  
  1110. help_show_online ()
  1111. {
  1112.     help3("This isn't an error message; I'm just \\showing something.",
  1113.     "Type `I\\show...' to show more (e.g., \\show\\cs,",
  1114.     "\\showthe\\count10, \\showbox255, \\showlists).");
  1115. }
  1116.  
  1117. help_show ()
  1118. {
  1119.     help5("This isn't an error message; I'm just \\showing something.",
  1120.     "Type `I\\show...' to show more (e.g., \\show\\cs,",
  1121.     "\\showthe\\count10, \\showbox255, \\showlists).",
  1122.     "And type `I\\tracingonline=1\\show...' to show boxes and",
  1123.     "lists on your terminal as well as in the transcript file.");
  1124. }
  1125.