home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / CMTEX330 / SOURCE / EVAL.C < prev    next >
C/C++ Source or Header  |  1992-02-19  |  18KB  |  1,024 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. #define NEST_SIZE    40
  20. #define NEST_INC    20
  21.  
  22. list    cur_list;
  23. int    nlists;
  24. list    *nest;
  25. list    *nest_end;
  26. list    *nest_ptr;
  27. list    *max_nest_stack;
  28. int    shown_mode;
  29.  
  30. static fnt    main_f;
  31. static qcell    main_i;
  32. static qcell    main_j;
  33. static qcell    *main_k;
  34. static ptr    main_p;
  35. static int    main_s;
  36. static ptr    main_t;
  37.  
  38. int    cur_l;
  39. int    cur_r;
  40. ptr    cur_q;
  41. ptr    lig_stack;
  42. int    bchar;
  43. int    false_bchar;
  44. bool    lft_hit;
  45. bool    rt_hit;
  46. bool    ligature_present;
  47. bool    cancel_boundary;
  48. bool    ins_disc;
  49.  
  50. void
  51. push_nest ()
  52. {
  53.     if (nest_ptr > max_nest_stack) {
  54.         max_nest_stack = nest_ptr;
  55.         if (nest_ptr == nest_end && !realloc_nest()) {
  56.             overflow("semantic nest size", nlists);
  57.         }
  58.     }
  59.     *nest_ptr++ = cur_list;
  60.     tail = head = new_avail();
  61.     prev_graf = 0;
  62.     mode_line = line;
  63. }
  64.  
  65. void
  66. pop_nest ()
  67. {
  68.     free_avail(head);
  69.     cur_list = *--nest_ptr;
  70. }
  71.  
  72. bool
  73. realloc_nest ()
  74. {
  75.     list *tmp;
  76.  
  77.     nlists += NEST_INC;
  78.     tmp = (list *)realloc(nest, nlists * sizeof(list));
  79.     if (tmp == (list *) 0) {
  80.         overflow("nest", nlists);
  81.     }
  82.     nest = tmp;
  83.     nest_end = nest + nlists - 1;
  84.     nest_ptr = nest + nlists - NEST_INC;
  85.     return TRUE;
  86. }
  87.  
  88. void
  89. print_mode (m)
  90.     int    m;
  91. {
  92.     if (m > 0) {
  93.         switch (m / (MAX_COMMAND + 1)) {
  94.         case 0: print("vertical"); break;
  95.         case 1: print("horizontal"); break;
  96.         case 2: print("display math"); break;
  97.         }
  98.     } else if (m == 0) {
  99.         print("no");
  100.     } else {    
  101.         switch (-m / (MAX_COMMAND + 1)) {
  102.         case 0: print("internal vertical"); break;
  103.         case 1: print("restricted horizontal"); break;
  104.         case 2: print("math"); break;
  105.         }
  106.     }
  107.     print(" mode");
  108. }
  109.  
  110. #define vmode(CMD) \
  111.     case VMODE + CMD
  112.  
  113. #define hmode(CMD) \
  114.     case HMODE + CMD
  115.  
  116. #define non_math(CMD) \
  117.     case VMODE + CMD: \
  118.     case HMODE + CMD
  119.  
  120. #define mmode(CMD) \
  121.     case MMODE + CMD
  122.  
  123. #define any_mode(CMD) \
  124.     case VMODE + CMD: \
  125.     case HMODE + CMD: \
  126.     case MMODE + CMD
  127.  
  128. void
  129. main_control ()
  130. {
  131.     if (every_job != null)
  132.         begin_token_list(every_job, EVERY_JOB_TEXT);
  133.  
  134. big_switch:
  135.     get_x_token();
  136.  
  137. reswitch:
  138.     if (interrupted && OK_to_interrupt) {
  139.         back_input();
  140.         pause_for_instructions();
  141.         goto big_switch;
  142.     }
  143.  
  144.     if (tracing_commands > 0)
  145.         show_cur_cmd_chr();
  146.     
  147.     switch (abs(mode) + cur_cmd)
  148.     {
  149.     hmode(LETTER):
  150.     hmode(OTHER_CHAR):
  151.     hmode(CHAR_GIVEN):
  152.         goto main_loop;
  153.     
  154.     hmode(CHAR_NUM):
  155.         scan_char_num();
  156.         cur_chr = cur_val;
  157.         goto main_loop;
  158.  
  159.     hmode(NO_BOUNDARY):
  160.         get_x_token();
  161.         if (cur_cmd == LETTER || cur_cmd == OTHER_CHAR
  162.         || cur_cmd == CHAR_GIVEN || cur_cmd == CHAR_NUM) {
  163.             cancel_boundary = TRUE;
  164.         }
  165.         goto reswitch;
  166.  
  167.     hmode(SPACER):
  168.         if (space_factor == 1000) {
  169.             goto append_normal_space;
  170.         } else {
  171.             app_space();
  172.         }
  173.         break;
  174.     
  175.     hmode(EX_SPACE):
  176.     mmode(EX_SPACE):
  177.         goto append_normal_space;
  178.     
  179.     any_mode(RELAX):
  180.     vmode(SPACER):
  181.     mmode(SPACER):
  182.     mmode(NO_BOUNDARY):
  183.         break;
  184.     
  185.     any_mode(IGNORE_SPACES):
  186.         get_nbx_token();
  187.         goto reswitch;
  188.  
  189.     vmode(STOP):
  190.         if (its_all_over())
  191.             return;
  192.         break;
  193.  
  194.     any_mode(LAST_ITEM):
  195.     any_mode(MAC_PARAM):
  196.     non_math(EQ_NO):
  197.     vmode(VMOVE):
  198.     hmode(HMOVE):
  199.     mmode(HMOVE):
  200.     vmode(VADJUST):
  201.     vmode(ITAL_CORR):
  202.         report_illegal_case();
  203.         break;
  204.  
  205.     non_math(SUP_MARK):
  206.     non_math(SUB_MARK):
  207.     non_math(MATH_CHAR_NUM):
  208.     non_math(MATH_GIVEN):
  209.     non_math(MATH_COMP):
  210.     non_math(DELIM_NUM):
  211.     non_math(LEFT_RIGHT):
  212.     non_math(ABOVE):
  213.     non_math(RADICAL):
  214.     non_math(MATH_STYLE):
  215.     non_math(MATH_CHOICE):
  216.     non_math(VCENTER):
  217.     non_math(NON_SCRIPT):
  218.     non_math(MKERN):
  219.     non_math(LIMIT_SWITCH):
  220.     non_math(MSKIP):
  221.     non_math(MATH_ACCENT):
  222.     mmode(ENDV):
  223.     mmode(PAR_END):
  224.     mmode(STOP):
  225.     mmode(VSKIP):
  226.     mmode(UN_VBOX):
  227.     mmode(VALIGN):
  228.     mmode(HRULE):
  229.         insert_dollar_sign();
  230.         break;
  231.     
  232.     vmode(HRULE):
  233.     hmode(VRULE):
  234.     mmode(VRULE):
  235.         tail_append(scan_rule_spec());
  236.         if (abs(mode) == VMODE)
  237.             prev_depth = IGNORE_DEPTH;
  238.         else if (abs(mode) == HMODE)
  239.             space_factor = 1000;
  240.         break;
  241.     
  242.     vmode(VSKIP):
  243.     hmode(HSKIP):
  244.     mmode(HSKIP):
  245.     mmode(MSKIP):
  246.         append_glue();
  247.         break;
  248.     
  249.     any_mode(KERN):
  250.     mmode(MKERN):
  251.         append_kern();
  252.         break;
  253.     
  254.     non_math(LEFT_BRACE):
  255.         new_save_level(SIMPLE_GROUP);
  256.         break;
  257.  
  258.     any_mode(BEGIN_GROUP):
  259.         new_save_level(SEMI_SIMPLE_GROUP);
  260.         break;
  261.  
  262.     any_mode(END_GROUP):
  263.         if (cur_group == SEMI_SIMPLE_GROUP) {
  264.             unsave();
  265.         } else {
  266.             off_save();
  267.         }
  268.         break;
  269.     
  270.     any_mode(RIGHT_BRACE):
  271.         handle_right_brace();
  272.         break;
  273.  
  274.     vmode(HMOVE):
  275.     hmode(VMOVE):
  276.     mmode(VMOVE): {
  277.         int    t;
  278.  
  279.         t = cur_chr;
  280.         scan_normal_dimen();
  281.         if (t == 0) {
  282.             scan_box(cur_val);
  283.         } else {
  284.             scan_box(-cur_val);
  285.         }
  286.         break;
  287.     }
  288.     any_mode(LEADER_SHIP):
  289.         scan_box(LEADER_FLAG + cur_chr - A_LEADERS);
  290.         break;
  291.     
  292.     any_mode(MAKE_BOX):
  293.         begin_box(0);
  294.         break;
  295.  
  296.     vmode(START_PAR):
  297.         new_graf(cur_chr > 0);
  298.         break;
  299.     
  300.     vmode(LETTER):
  301.     vmode(OTHER_CHAR):
  302.     vmode(CHAR_NUM):
  303.     vmode(CHAR_GIVEN):
  304.     vmode(MATH_SHIFT):
  305.     vmode(UN_HBOX):
  306.     vmode(VRULE):
  307.     vmode(ACCENT):
  308.     vmode(DISCRETIONARY):
  309.     vmode(HSKIP):
  310.     vmode(VALIGN):
  311.     vmode(EX_SPACE):
  312.     vmode(NO_BOUNDARY):
  313.         back_input();
  314.         new_graf(TRUE);
  315.         break;
  316.     
  317.     hmode(START_PAR):
  318.     mmode(START_PAR):
  319.         indent_in_hmode();
  320.         break;
  321.     
  322.     vmode(PAR_END):
  323.         normal_paragraph();
  324.         if (mode > 0)
  325.             build_page();
  326.         break;
  327.  
  328.     hmode(PAR_END):
  329.         if (align_state < 0)
  330.             off_save();
  331.         end_graf();
  332.         if (mode == VMODE)    
  333.             build_page();
  334.         break;
  335.     
  336.     hmode(STOP):
  337.     hmode(VSKIP):
  338.     hmode(HRULE):
  339.     hmode(UN_VBOX):
  340.     hmode(HALIGN):
  341.         head_for_vmode();
  342.         break;
  343.     
  344.     any_mode(INSERT):
  345.     hmode(VADJUST):
  346.     mmode(VADJUST):
  347.         begin_insert_or_adjust();
  348.         break;
  349.     
  350.     any_mode(MARK):
  351.         make_mark();
  352.         break;
  353.     
  354.     any_mode(BREAK_PENALTY):
  355.         append_penalty();
  356.         break;
  357.     
  358.     any_mode(REMOVE_ITEM):
  359.         delete_last();
  360.         break;
  361.     
  362.     vmode(UN_VBOX):
  363.     hmode(UN_HBOX):
  364.     mmode(UN_HBOX):
  365.         unpackage();
  366.         break;
  367.     
  368.     hmode(ITAL_CORR):
  369.         append_italic_correction();
  370.         break;
  371.     
  372.     mmode(ITAL_CORR):
  373.         tail_append(new_kern(0));
  374.         break;
  375.  
  376.     hmode(DISCRETIONARY):
  377.     mmode(DISCRETIONARY):
  378.         append_discretionary();
  379.         break;
  380.     
  381.     hmode(ACCENT):
  382.         make_accent();
  383.         break;
  384.     
  385.     any_mode(CAR_RET):
  386.     any_mode(TAB_MARK):
  387.         align_error();
  388.         break;
  389.  
  390.     any_mode(NO_ALIGN):
  391.         no_align_error();
  392.         break;
  393.     
  394.     any_mode(OMIT):
  395.         omit_error();
  396.         break;
  397.  
  398.     vmode(HALIGN):
  399.     hmode(VALIGN):
  400.         init_align();
  401.         break;
  402.     
  403.     mmode(HALIGN):
  404.         if (privileged()) {
  405.             if (cur_group == MATH_SHIFT_GROUP) {
  406.                 init_align();
  407.             } else {
  408.                 off_save();
  409.             }
  410.         }
  411.         break;
  412.  
  413.     vmode(ENDV):
  414.     hmode(ENDV):
  415.         do_endv();
  416.         break;
  417.     
  418.     any_mode(END_CS_NAME):
  419.         cs_error();
  420.         break;
  421.  
  422.     hmode(MATH_SHIFT):
  423.         init_math();
  424.         break;
  425.     
  426.     mmode(EQ_NO):
  427.         if (privileged()) {
  428.             if (cur_group == MATH_SHIFT_GROUP) {
  429.                 start_eq_no();
  430.             } else {
  431.                 off_save();
  432.             }
  433.         }
  434.         break;
  435.     
  436.     mmode(LEFT_BRACE):
  437.         tail_append(new_noad());
  438.         back_input();
  439.         scan_math(nucleus(tail));
  440.         break;
  441.  
  442.     mmode(LETTER):
  443.     mmode(OTHER_CHAR):
  444.     mmode(CHAR_GIVEN):
  445.         if (cur_chr < 256)
  446.             set_math_char(math_code(cur_chr));
  447.         else set_math_char(cur_chr);
  448.         break;
  449.     
  450.     mmode(CHAR_NUM):
  451.         scan_char_num();
  452.         cur_chr = cur_val;
  453.         if (cur_chr < 256)
  454.             set_math_char(math_code(cur_chr));
  455.         else set_math_char(cur_chr);
  456.         break;
  457.     
  458.     mmode(MATH_CHAR_NUM):
  459.         scan_fifteen_bit_int();
  460.         set_math_char(cur_val);
  461.         break;
  462.     
  463.     mmode(MATH_GIVEN):
  464.         set_math_char(cur_chr);
  465.         break;
  466.  
  467.     mmode(DELIM_NUM):
  468.         scan_twenty_seven_bit_int();
  469.         set_math_char(cur_val / 010000);
  470.         break;
  471.     
  472.     mmode(MATH_COMP):
  473.         tail_append(new_noad());
  474.         type(tail) = cur_chr;
  475.         scan_math(nucleus(tail));
  476.         break;
  477.     
  478.     mmode(LIMIT_SWITCH):
  479.         math_limit_switch();
  480.         break;
  481.  
  482.     mmode(RADICAL):
  483.         math_radical();
  484.         break;
  485.  
  486.     mmode(ACCENT):
  487.     mmode(MATH_ACCENT):
  488.         math_ac();
  489.         break;
  490.  
  491.     mmode(VCENTER):
  492.         scan_spec(VCENTER_GROUP, FALSE);
  493.         normal_paragraph();
  494.         push_nest();
  495.         mode = -VMODE;
  496.         prev_depth = IGNORE_DEPTH;
  497.         if (every_vbox != null)
  498.             begin_token_list(every_vbox, EVERY_VBOX_TEXT);
  499.         break;
  500.     
  501.     mmode(MATH_STYLE):
  502.         tail_append(new_style(cur_chr));
  503.         break;
  504.     
  505.     mmode(NON_SCRIPT):
  506.         tail_append(new_glue(zero_glue));
  507.         subtype(tail) = COND_MATH_GLUE;
  508.         break;
  509.     
  510.     mmode(MATH_CHOICE):
  511.         append_choices();
  512.         break;
  513.  
  514.     mmode(SUB_MARK):
  515.     mmode(SUP_MARK):
  516.         sub_sup();
  517.         break;
  518.     
  519.     mmode(ABOVE):
  520.         math_fraction();
  521.         break;
  522.     
  523.     mmode(LEFT_RIGHT):
  524.         math_left_right();
  525.         break;
  526.  
  527.     mmode(MATH_SHIFT):
  528.         if (cur_group == MATH_SHIFT_GROUP) {
  529.             after_math();
  530.         } else {
  531.             off_save();
  532.         }
  533.         break;
  534.  
  535.     any_mode(AFTER_ASSIGNMENT):
  536.         get_token();
  537.         after_token = cur_tok;
  538.         break;
  539.     
  540.     any_mode(AFTER_GROUP):
  541.         get_token();
  542.         save_for_after(cur_tok);
  543.         break;
  544.  
  545.     any_mode(IN_STREAM):
  546.         clopen_stream();
  547.         break;
  548.  
  549.     any_mode(MESSAGE):
  550.         issue_message();
  551.         break;
  552.     
  553.     any_mode(CASE_SHIFT):
  554.         shift_case();
  555.         break;
  556.     
  557.     any_mode(XRAY):
  558.         show_whatever();
  559.         break;
  560.     
  561.     any_mode(EXTENSION):
  562.         do_extension();
  563.         break;
  564.     
  565.     default:
  566.         prefixed_command();
  567.         break;
  568.     }
  569.     goto big_switch;
  570.  
  571. #define adjust_space_factor() \
  572. { \
  573.     main_s = sf_code(cur_chr); \
  574.     if (main_s == 1000) { \
  575.         space_factor = 1000; \
  576.     } else if (main_s < 1000) { \
  577.         if (main_s > 0) { \
  578.             space_factor = main_s; \
  579.         } \
  580.     } else if (space_factor < 1000) { \
  581.         space_factor = 1000; \
  582.     } else { \
  583.         space_factor = main_s; \
  584.     } \
  585. }
  586.         
  587. main_loop:
  588.     adjust_space_factor();
  589.     main_f = cur_font;
  590.     bchar = font_bchar(main_f);
  591.     false_bchar = font_false_bchar(main_f);
  592.     if (mode > 0 && language != clang)
  593.         fix_language();
  594.     fast_new_avail(lig_stack);
  595.     font(lig_stack) = main_f;
  596.     character(lig_stack) = cur_l = cur_chr;
  597.     cur_q = tail;
  598.     if (cancel_boundary) {
  599.         cancel_boundary = FALSE;
  600.         main_k = NON_ADDRESS;
  601.     } else {
  602.         main_k = bchar_label(main_f);
  603.     }
  604.     if (main_k == NON_ADDRESS)
  605.         goto main_loop_move_2;
  606.     cur_r = cur_l;
  607.     cur_l = NON_CHAR;
  608.     goto main_lig_loop_1;
  609.  
  610. #define pack_lig(RT_HIT) \
  611. { \
  612.     main_p = new_ligature(main_f, cur_l, link(cur_q)); \
  613.     if (lft_hit) { \
  614.         subtype(main_p) = 2; \
  615.         lft_hit = FALSE; \
  616.     } \
  617.     if (RT_HIT && lig_stack == null) { \
  618.         incr(subtype(main_p)); \
  619.         rt_hit = FALSE; \
  620.     } \
  621.     tail = link(cur_q) = main_p; \
  622.     ligature_present = FALSE; \
  623. }
  624.  
  625. #define wrapup(RT_HIT) \
  626. { \
  627.     if (cur_l < NON_CHAR) { \
  628.         if (character(tail) == hyphen_char(main_f) \
  629.         && link(cur_q) != null) \
  630.             ins_disc = TRUE; \
  631.         if (ligature_present) \
  632.             pack_lig(RT_HIT); \
  633.         if (ins_disc) { \
  634.             ins_disc = FALSE; \
  635.             if (mode > 0) \
  636.                 tail_append(new_disc()); \
  637.         } \
  638.     } \
  639. }
  640.  
  641. main_loop_wrapup:
  642.     wrapup(rt_hit);
  643.  
  644. main_loop_move:
  645.     if (lig_stack == null)
  646.         goto reswitch;
  647.     cur_q = tail;
  648.     cur_l = cur_r;
  649.  
  650. main_loop_move_1:
  651.     if (!is_char_node(lig_stack))
  652.         goto main_loop_move_lig;
  653.  
  654. main_loop_move_2:
  655.     if (cur_chr < font_bc(main_f) || cur_chr > font_ec(main_f)) {
  656.         char_warning(main_f, cur_chr);
  657.         free_avail(lig_stack);
  658.         goto big_switch;
  659.     }
  660.     main_i = char_info(main_f, cur_l);
  661.     if (!char_exists(main_i)) {
  662.         char_warning(main_f, cur_chr);
  663.         free_avail(lig_stack);
  664.         goto big_switch;
  665.     }
  666.     tail_append(lig_stack);
  667.  
  668. main_loop_lookahead:
  669.     get_next();
  670.     if (cur_cmd == LETTER
  671.     || cur_cmd == OTHER_CHAR
  672.     || cur_cmd == CHAR_GIVEN) {
  673.         goto main_loop_lookahead_1;
  674.     }
  675.     x_token();
  676.     if (cur_cmd == LETTER
  677.     || cur_cmd == OTHER_CHAR
  678.     || cur_cmd == CHAR_GIVEN) {
  679.         goto main_loop_lookahead_1;
  680.     }
  681.     if (cur_cmd == CHAR_NUM) {
  682.         scan_char_num();
  683.         cur_chr = cur_val;
  684.         goto main_loop_lookahead_1;
  685.     }
  686.     if (cur_cmd == NO_BOUNDARY) {
  687.         bchar = NON_CHAR;
  688.     }
  689.     cur_r = bchar;
  690.     lig_stack = null;
  691.     goto main_lig_loop;
  692.  
  693. main_loop_lookahead_1:
  694.     adjust_space_factor();
  695.     fast_new_avail(lig_stack);
  696.     font(lig_stack) = main_f;
  697.     character(lig_stack) = cur_r = cur_chr;
  698.     if (cur_r == false_bchar) {
  699.         cur_r = NON_CHAR;
  700.     }
  701.  
  702. main_lig_loop:
  703.     if (char_tag(main_i) != LIG_TAG) {
  704.         goto main_loop_wrapup;
  705.     }
  706.     main_k = lig_kern_start(main_f, main_i);
  707.     main_j = *main_k;
  708.     if (skip_byte(main_j) <= STOP_FLAG) {
  709.         goto main_lig_loop_2;
  710.     }
  711.     main_k = lig_kern_restart(main_f, main_j);
  712.  
  713. main_lig_loop_1:
  714.     main_j = *main_k;
  715.  
  716. main_lig_loop_2:
  717.     if (next_char(main_j) == cur_r
  718.     && skip_byte(main_j) <= STOP_FLAG) {
  719.         if (op_byte(main_j) >= KERN_FLAG) {
  720.             wrapup(rt_hit);
  721.             tail_append(new_kern(char_kern(main_f, main_j)));
  722.             goto main_loop_move;
  723.         }
  724.         if (cur_l == NON_CHAR) {
  725.             lft_hit = TRUE;
  726.         } else if (lig_stack == null) {
  727.             rt_hit = TRUE;
  728.         }
  729.         check_interrupt();
  730.         switch (op_byte(main_j))
  731.         {
  732.         case 1: case 5:
  733.             cur_l = rem_byte(main_j);
  734.             main_i = char_info(main_f, cur_l);
  735.             ligature_present = TRUE;
  736.             break;
  737.             
  738.         case 2: case 6:
  739.             cur_r = rem_byte(main_j);
  740.             if (lig_stack == null) {
  741.                 lig_stack = new_lig_item(cur_r);
  742.                 bchar = NON_CHAR;
  743.             } else if (is_char_node(lig_stack)) {
  744.                 main_p = lig_stack;
  745.                 lig_stack = new_lig_item(cur_r);
  746.                 lig_ptr(lig_stack) = main_p;
  747.             } else {
  748.                 character(lig_stack) = cur_r;
  749.             }
  750.             break;
  751.  
  752.         case 3:
  753.             cur_r = rem_byte(main_j);
  754.             main_p = lig_stack;
  755.             lig_stack = new_lig_item(cur_r);
  756.             link(lig_stack) = main_p;
  757.             break;
  758.  
  759.         case 7: case 11:
  760.             wrapup(FALSE);
  761.             cur_q = tail;
  762.             cur_l = rem_byte(main_j);
  763.             main_i = char_info(main_f, cur_l);
  764.             ligature_present = TRUE;
  765.             break;
  766.  
  767.         default:
  768.             cur_l = rem_byte(main_j);
  769.             ligature_present = TRUE;
  770.             if (lig_stack == null) {
  771.                 goto main_loop_wrapup;
  772.             } else {
  773.                 goto main_loop_move_1;
  774.             }
  775.         }
  776.         if (op_byte(main_j) > 4 && op_byte(main_j) != 7)
  777.             goto main_loop_wrapup;
  778.         if (cur_l < NON_CHAR)
  779.             goto main_lig_loop;
  780.         main_k = bchar_label(main_f);
  781.         goto main_lig_loop_1;
  782.     }
  783.     if (skip_byte(main_j) == 0) {
  784.         incr(main_k);
  785.     } else {
  786.         if (skip_byte(main_j) >= STOP_FLAG)
  787.             goto main_loop_wrapup;
  788.         main_k += skip_byte(main_j) + 1;
  789.     }
  790.     goto main_lig_loop_1;
  791.  
  792. main_loop_move_lig:
  793.     main_p = lig_ptr(lig_stack);
  794.     if (main_p != null) {
  795.         tail_append(main_p);
  796.     }
  797.     main_t = lig_stack;
  798.     lig_stack = link(main_t);
  799.     free_node(main_t, SMALL_NODE_SIZE);
  800.     main_i = char_info(main_f, cur_l);
  801.     ligature_present = TRUE;
  802.     if (lig_stack == null) {
  803.         if (main_p != null) {
  804.             goto main_loop_lookahead;
  805.         } else {
  806.             cur_r = bchar;
  807.         }
  808.     } else {
  809.         cur_r = character(lig_stack);
  810.     }
  811.     goto main_lig_loop;
  812.  
  813. append_normal_space:
  814.     if (space_skip == zero_glue) {
  815.         main_p = font_glue(cur_font);
  816.         if (main_p == null)
  817.             main_p = find_font_glue(cur_font);
  818.         main_t = new_glue(main_p);
  819.     } else {
  820.         main_t = new_param_glue(SPACE_SKIP_CODE);
  821.     }
  822.     tail_append(main_t);
  823.     goto big_switch;
  824. }
  825.  
  826. void
  827. app_space ()
  828. {
  829.     ptr    p, q;
  830.  
  831.     if (space_factor >= 2000 && xspace_skip != zero_glue) {
  832.         q = new_param_glue(XSPACE_SKIP_CODE);
  833.     } else {
  834.         if (space_skip != zero_glue) {
  835.             p = space_skip;
  836.         } else {
  837.             p = find_font_glue(cur_font);
  838.         }
  839.         p = new_spec(p);
  840.         if (space_factor >= 2000)
  841.             glue_width(p) += extra_space(cur_font);
  842.         stretch(p) = xn_over_d(stretch(p), space_factor, 1000);
  843.         shrink(p) = xn_over_d(shrink(p), 1000L, space_factor);
  844.         q = new_glue(p);
  845.         glue_ref_count(p) = 0;
  846.     }
  847.     tail_append(q);
  848. }
  849.  
  850. void
  851. insert_dollar_sign ()
  852. {
  853.     back_input();
  854.     cur_tok = MATH_SHIFT_TOKEN + '$';
  855.     print_err("Missing $ inserted");
  856.     help_dollar();
  857.     ins_error();
  858. }
  859.  
  860. void
  861. you_cant ()
  862. {
  863.     print_err("You can't use `");
  864.     print_cmd_chr(cur_cmd, cur_chr);
  865.     print("' in ");
  866.     print_mode(mode);
  867. }
  868.  
  869. void
  870. report_illegal_case ()
  871. {
  872.     you_cant();
  873.     help_illegal_case();
  874.     error();
  875. }
  876.  
  877. bool
  878. privileged ()
  879. {
  880.     if (mode > 0)
  881.         return TRUE;
  882.     report_illegal_case();
  883.     return FALSE;
  884. }
  885.  
  886. bool
  887. its_all_over ()
  888. {
  889.     if (privileged()) {
  890.         if (page_head == page_tail
  891.         && head == tail
  892.         && dead_cycles == 0) {
  893.             return TRUE;
  894.         }
  895.         back_input();
  896.         tail_append(new_null_box());
  897.         box_width(tail) = hsize;
  898.         tail_append(new_glue(fill_glue));
  899.         tail_append(new_penalty(-010000000000));
  900.         build_page();
  901.     }
  902.     return FALSE;
  903. }
  904.  
  905. void
  906. show_activities ()
  907. {
  908.     int    a;
  909.     int    m;
  910.     list    *p;
  911.  
  912.     *nest_ptr = cur_list;
  913.     print_nl(null_str);
  914.     print_ln();
  915.     for (p = nest_ptr; p >= nest; decr(p)) {
  916.         m = p->mode_field;
  917.         a = p->aux_field;
  918.         print_nl("### ");
  919.         print_mode(m);
  920.         print(" entered at line ");
  921.         print_int(abs(p->ml_field));
  922.         if (m == HMODE) {
  923.             if (p->lhm_field != 2 || p->rhm_field != 3) {
  924.                 print(" (hyphenmin ");
  925.                 print_int(p->lhm_field);
  926.                 print(",");
  927.                 print_int(p->rhm_field);
  928.                 print(")");
  929.             }
  930.         }
  931.         if (p->ml_field < 0) {
  932.             print(" (\\output routine)");
  933.         }
  934.         if (p == nest) {
  935.             show_cur_page();
  936.             if (link(contrib_head) != null)
  937.                 print_nl("### recent contributions:");
  938.         }
  939.         show_box(link(p->head_field));
  940.         switch (abs(m) / (MAX_COMMAND + 1))
  941.         {
  942.         case 0:
  943.             print_nl("prevdepth ");
  944.             if (a <= IGNORE_DEPTH) {
  945.                 print("ignored");
  946.             } else {
  947.                 print_scaled(a);
  948.             }
  949.             if (p->pg_field != 0) {
  950.                 print(", prevgraf ");
  951.                 print_int(p->pg_field);
  952.                 print(" line");
  953.                 if (p->pg_field != 1) {
  954.                     print("s");
  955.                 }
  956.             }
  957.             break;
  958.  
  959.         case 1:
  960.             print_nl("spacefactor ");
  961.             print_int(a);
  962.             if (m > 0 && p->clang_field > 0) {
  963.                 print(", current language ");
  964.                 print_int(p->clang_field);
  965.             }
  966.             break;
  967.  
  968.         case 2:
  969.             if (a != null) {
  970.                 print_nl("this will be denominator of:");
  971.                 show_box(a);
  972.             }
  973.             break;
  974.         }
  975.     }
  976. }
  977.  
  978. void
  979. _eval_init ()
  980. {
  981.     head = tail = contrib_head;
  982.     mode = VMODE;
  983.     prev_depth = IGNORE_DEPTH;
  984.     mode_line = 0;
  985.     prev_graf = 0;
  986.     shown_mode = 0;
  987.     lhmin = 0;
  988.     rhmin = 0;
  989.     ligature_present = FALSE;
  990.     cancel_boundary = FALSE;
  991.     ins_disc = FALSE;
  992.     lft_hit = FALSE;
  993.     rt_hit = FALSE;
  994.     max_nest_stack = nest_ptr = nest;
  995. }
  996.  
  997. void
  998. _eval_init_once ()
  999. {
  1000.     nlists = NEST_SIZE;
  1001.     nest = (list *)malloc(nlists * sizeof(list));
  1002.     if (nest == (list *) 0)
  1003.         overflow("nest", nlists);
  1004.     nest_end = nest + nlists - 1;
  1005. }
  1006.  
  1007. /*
  1008. ** Help text
  1009. */
  1010.  
  1011. help_dollar ()
  1012. {
  1013.     help2("I've inserted a begin-math/end-math symbol since I think",
  1014.     "you left one out. Proceed, with fingers crossed.");
  1015. }
  1016.  
  1017. help_illegal_case ()
  1018. {
  1019.     help4("Sorry, but I'm not programmed to handle this case;",
  1020.     "I'll just pretend that you didn't ask for it.",
  1021.     "If you're in the wrong mode, you might be able to",
  1022.     "return to the right one by typing `I}' or `I$' or `I\\par'.");
  1023. }
  1024.