home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Tex / Tex29 / StTeXsrc.zoo / src / def.c < prev    next >
C/C++ Source or Header  |  1988-03-13  |  24KB  |  1,015 lines

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