home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / CMTEX330 / SOURCE / BOX.C < prev    next >
C/C++ Source or Header  |  1992-02-19  |  15KB  |  975 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. int    depth_threshold;
  20. int    breadth_max;
  21. fnt    font_in_short_display;
  22.  
  23. ptr
  24. new_null_box ()
  25. {
  26.     ptr    p;
  27.  
  28.     p = new_node(BOX_NODE_SIZE);
  29.     type(p) = HLIST_NODE;
  30.     subtype(p) = MIN_QUARTERWORD;
  31.     box_width(p) = 0;
  32.     box_depth(p) = 0;
  33.     box_height(p) = 0;
  34.     shift_amount(p) = 0;
  35.     list_ptr(p) = null;
  36.     glue_sign(p) = NORMAL;
  37.     glue_order(p) = NORMAL;
  38.     glue_set(p) = 0.0;
  39.  
  40.     return p;
  41. }
  42.  
  43. ptr
  44. new_rule ()
  45. {
  46.     ptr    p;
  47.  
  48.     p = new_node(RULE_NODE_SIZE);
  49.     type(p) = RULE_NODE;
  50.     subtype(p) = 0;
  51.     rule_width(p) = NULL_FLAG;
  52.     rule_depth(p) = NULL_FLAG;
  53.     rule_height(p) = NULL_FLAG;
  54.  
  55.     return p;
  56. }
  57.  
  58. ptr
  59. new_ligature (f, c, q)
  60.     int    f;
  61.     int    c;
  62.     ptr    q;
  63. {
  64.     ptr     p;
  65.  
  66.     p = new_node(SMALL_NODE_SIZE);
  67.     type(p) = LIGATURE_NODE;
  68.     subtype(p) = 0;
  69.     font(lig_char(p)) = f;
  70.     character(lig_char(p)) = c;
  71.     lig_ptr(p) = q;
  72.  
  73.     return p;
  74. }
  75.  
  76. ptr
  77. new_lig_item (c)
  78.     int    c;
  79. {
  80.     ptr    p;
  81.  
  82.     p = new_node(SMALL_NODE_SIZE);
  83.     type(p) = LIGATURE_NODE;
  84.     subtype(p) = c;
  85.     lig_ptr(p) = null;
  86.  
  87.     return p;
  88. }
  89.  
  90. ptr
  91. make_char_from_lig (p) 
  92.     ptr    p;
  93. {
  94.     static mcell m;
  95.     mcopy(&m, lig_char(p));
  96.     link((ptr)&m) = link(p);
  97.     return ((ptr)&m);
  98. }
  99.  
  100. ptr
  101. new_disc ()
  102. {
  103.     ptr    p;
  104.  
  105.     p = new_node(SMALL_NODE_SIZE);
  106.     type(p) = DISC_NODE;
  107.     replace_count(p) = 0;
  108.     pre_break(p) = null;
  109.     post_break(p) = null;
  110.  
  111.     return p;
  112. }
  113.  
  114. ptr
  115. new_math (w, s)
  116.     scal    w;
  117.     int    s;
  118. {
  119.     ptr    p;
  120.  
  121.     p = new_node(SMALL_NODE_SIZE);
  122.     type(p) = MATH_NODE;
  123.     subtype(p) = s;
  124.     math_width(p) = w;
  125.  
  126.     return p;
  127. }
  128.  
  129. ptr
  130. new_spec (p)
  131.     ptr    p;
  132. {
  133.     ptr    q;
  134.  
  135.     q = new_node(GLUE_SPEC_SIZE);
  136.     stretch_order(q) = stretch_order(p);
  137.     shrink_order(q) = shrink_order(p);
  138.     glue_ref_count(q) = 0;
  139.     glue_width(q) = glue_width(p);
  140.     stretch(q) = stretch(p);
  141.     shrink(q) = shrink(p);
  142.  
  143.     return q;
  144. }
  145.  
  146. ptr
  147. new_param_glue (n)
  148.     int    n;
  149. {
  150.     ptr    p;
  151.     ptr    q;
  152.  
  153.     p = new_node(SMALL_NODE_SIZE);
  154.     type(p) = GLUE_NODE;
  155.     subtype(p) = n + 1;
  156.     leader_ptr(p) = null;
  157.     q = glue_par(n);
  158.     glue_ptr(p) = q;
  159.     incr(glue_ref_count(q));
  160.  
  161.     return p;
  162. }
  163.  
  164. ptr
  165. new_glue (q)
  166.     ptr    q;
  167. {
  168.     ptr    p;
  169.  
  170.     p = new_node(SMALL_NODE_SIZE);
  171.     type(p) = GLUE_NODE;
  172.     subtype(p) = NORMAL;
  173.     leader_ptr(p) = null;
  174.     glue_ptr(p) = q;
  175.     incr(glue_ref_count(q));
  176.  
  177.     return p;
  178. }
  179.  
  180. ptr
  181. new_skip_param (n)
  182.     int    n;
  183. {
  184.     ptr    p;
  185.     ptr    q;
  186.  
  187.     q = new_spec(glue_par(n));
  188.     p = new_glue(q);
  189.     glue_ref_count(q) = 0;
  190.     subtype(p) = n + 1;
  191.  
  192.     return p;
  193. }
  194.  
  195. ptr
  196. new_kern (w)
  197.     scal    w;
  198. {
  199.     ptr    p;
  200.  
  201.     p = new_node(SMALL_NODE_SIZE);
  202.     type(p) = KERN_NODE;
  203.     subtype(p) = NORMAL;
  204.     kern_width(p) = w;
  205.  
  206.     return p;
  207. }
  208.  
  209. ptr
  210. new_penalty (i)
  211.     int    i;
  212. {
  213.     ptr    p;
  214.  
  215.     p = new_node(SMALL_NODE_SIZE);
  216.     type(p) = PENALTY_NODE;
  217.     subtype(p) = 0;
  218.     penalty(p) = i;
  219.  
  220.     return p;
  221. }
  222.  
  223. void
  224. print_font_and_char (p)
  225.     ptr    p;
  226. {
  227.     if (font(p) < FONT_BASE || font(p) > FONT_MAX) {
  228.         print("* ");
  229.     } else {
  230.         print_cs(font_id(font(p)));
  231.     }
  232.     print_ASCII(character(p));
  233. }
  234.  
  235. void
  236. print_mark (p)
  237.     ptr    p;
  238. {
  239.     print("{");
  240.     show_token_list(token_link(p), null, MAX_PRINT_LINE - 10);
  241.     print("}");
  242. }
  243.  
  244. void
  245. print_rule_dimen (d)
  246.     scal    d;
  247. {
  248.     if (is_running(d)) {
  249.         print("*");
  250.     } else {
  251.         print_scaled(d);
  252.     }
  253. }
  254.  
  255. void
  256. print_glue (d, o, s)
  257.     scal    d;
  258.     int    o;
  259.     str    s;
  260. {
  261.     print_scaled(d);
  262.     if (o < NORMAL || o > FILLL) {
  263.         print("foul");
  264.     } else if (o > NORMAL) {
  265.         print("fil");
  266.         while  (o >  FIL) {
  267.             print("l");
  268.             decr(o);
  269.         }
  270.     } else if (s) {
  271.         print(s);
  272.     }
  273. }
  274.  
  275. void
  276. print_spec (p, s)
  277.     ptr    p;
  278.     str    s;
  279. {
  280.     print_scaled(glue_width(p));
  281.     print(s);
  282.     if (stretch(p) != 0) {
  283.         print(" plus ");
  284.         print_glue(stretch(p), stretch_order(p), s);
  285.     }
  286.     if (shrink(p) != 0) {
  287.         print(" minus ");
  288.         print_glue(shrink(p), shrink_order(p), s);
  289.     }
  290. }
  291.  
  292. void
  293. short_display (p)
  294.     ptr    p;
  295. {
  296.     int    n;
  297.  
  298.     for (; p != null; p = link(p)) {
  299.         if (is_char_node(p)) {
  300.             if (font(p) != font_in_short_display) {
  301.                 if (font(p) < FONT_BASE || font(p) > FONT_MAX) {
  302.                     print("* ");
  303.                 } else {
  304.                     print_cs(font_id(font(p)));
  305.                 }
  306.                 font_in_short_display = font(p);
  307.             }
  308.             print_ASCII(character(p));
  309.         } else {
  310.             switch (type(p))
  311.             {
  312.             case HLIST_NODE:
  313.             case VLIST_NODE: 
  314.             case INS_NODE:
  315.             case WHATSIT_NODE:
  316.             case MARK_NODE:
  317.             case ADJUST_NODE:
  318.             case UNSET_NODE:
  319.                 print("[]");
  320.                 break;
  321.  
  322.             case RULE_NODE:
  323.                 print("|");
  324.                 break;
  325.  
  326.             case GLUE_NODE:
  327.                 if (glue_ptr(p) != zero_glue) {
  328.                     print(" ");
  329.                 }
  330.                 break;
  331.  
  332.             case MATH_NODE:
  333.                 print("$");
  334.                 break;
  335.  
  336.             case LIGATURE_NODE:
  337.                 short_display(lig_ptr(p));
  338.                 break;
  339.  
  340.             case DISC_NODE:
  341.                 short_display(pre_break(p));
  342.                 short_display(post_break(p));
  343.                 n = replace_count(p);
  344.                 while (n > 0) {
  345.                     if (link(p) != null) {
  346.                         p = link(p);
  347.                     }
  348.                     decr(n);
  349.                 }
  350.                 break;
  351.  
  352.             default:
  353.                 break;
  354.             }
  355.         }
  356.     }
  357. }
  358.  
  359. void
  360. show_box (p)
  361.     ptr    p;
  362. {
  363.     depth_threshold = show_box_depth;
  364.     breadth_max = show_box_breadth;
  365.     if (breadth_max <= 0) {
  366.         breadth_max = 5;
  367.     }
  368.     flush_str();
  369.     if (cur_str_ptr + depth_threshold >= cur_str_end) {
  370.         depth_threshold = cur_str_end - cur_str_ptr - 1;
  371.     }
  372.     show_node_list(p);
  373. }
  374.  
  375. void
  376. show_glue_set (p)
  377.     ptr    p;
  378. {
  379.     if (glue_set(p) != 0 && glue_sign(p) != NORMAL) {
  380.         print(", glue set ");
  381.         if (glue_sign(p) == SHRINKING) {
  382.             print("- ");
  383.         }
  384.         if (abs(glue_set(p)) > 20000.0) {
  385.             if (glue_set(p) > 0) {
  386.                 print(">");
  387.             } else {
  388.                 print("< -");
  389.             }
  390.             print_glue(20000 * UNITY, glue_order(p), null_str);
  391.         } else {
  392.             print_glue(round(glue_set(p) * UNITY),
  393.                 glue_order(p), null_str);
  394.         }
  395.     }
  396. }
  397.  
  398. void
  399. show_box1 (p)
  400.     ptr    p;
  401. {
  402.     if (type(p) == HLIST_NODE) {
  403.         print_esc("h");
  404.     } else if (type(p) == VLIST_NODE) {
  405.         print_esc("v");
  406.     } else {
  407.         print_esc("unset");
  408.     }
  409.     print("box(");
  410.     print_scaled(box_height(p));
  411.     print("+")    ;
  412.     print_scaled(box_depth(p));
  413.     print(")x")    ;
  414.     print_scaled(box_width(p));
  415.     if (type(p) == UNSET_NODE) {
  416.         if (unset_span_count(p) != MIN_QUARTERWORD) {
  417.             print(" (");
  418.             print_int(unset_span_count(p)+1);
  419.             print(" columns)");
  420.         }
  421.         if (unset_stretch(p) != 0) {
  422.             print(", stretch ");
  423.             print_glue(unset_stretch(p), glue_order(p), null_str);
  424.         }
  425.         if (unset_shrink(p) != 0) {
  426.             print(", shrink ");
  427.             print_glue(unset_shrink(p), glue_sign(p), null_str);
  428.         }
  429.     } else {
  430.         show_glue_set(p);
  431.         if (shift_amount(p) != 0) {
  432.             print(", shifted ");
  433.             print_scaled(shift_amount(p));
  434.         }
  435.     }
  436.     node_list_display(list_ptr(p));
  437. }
  438.  
  439. void
  440. show_rule (p)
  441.     ptr    p;
  442. {
  443.     print_esc("rule(");
  444.     print_rule_dimen(rule_height(p));
  445.     print("+");
  446.     print_rule_dimen(rule_depth(p));
  447.     print(")x");
  448.     print_rule_dimen(rule_width(p));
  449. }
  450.  
  451. void
  452. show_insertion (p)
  453.     ptr    p;
  454. {
  455.     print_esc("insert");
  456.     print_int(subtype(p));
  457.     print(", natural size ");
  458.     print_scaled(ins_height(p));
  459.     print("; split(");
  460.     print_spec(split_top_ptr(p), null_str);
  461.     print(",");
  462.     print_scaled(ins_depth(p));
  463.     print("); float cost ");
  464.     print_int(float_cost(p));
  465.     node_list_display(ins_ptr(p));
  466. }
  467.  
  468. void
  469. show_leaders (p)
  470.     ptr    p;
  471. {
  472.     print_esc(null_str);
  473.     if (subtype(p) == C_LEADERS) {
  474.         print("c");
  475.     } else if (subtype(p) == X_LEADERS) {
  476.         print("x");
  477.     }
  478.     print("leaders ");
  479.     print_spec(glue_ptr(p), null_str);
  480.     node_list_display(leader_ptr(p));
  481. }
  482.  
  483. void
  484. show_glue_type (n)
  485.     int    n;
  486. {
  487.     print("(");
  488.     if (n < COND_MATH_GLUE) {
  489.         if (n <= GLUE_PARS) {
  490.             print_skip_param(n - 1);
  491.         } else {
  492.             print_mu_skip_param(n - 1 - GLUE_PARS);
  493.         }
  494.     } else if (n == COND_MATH_GLUE) {
  495.         print_esc("nonscript");
  496.     } else {
  497.         print_esc("mskip");
  498.     }
  499.     print(")");
  500. }
  501.  
  502. void
  503. show_glue (p)
  504.     ptr    p;
  505. {
  506.     if (subtype(p) >= A_LEADERS) {
  507.         show_leaders(p);
  508.     } else {
  509.         print_esc("glue");
  510.         if (subtype(p) != NORMAL) {
  511.             show_glue_type(subtype(p));
  512.         }
  513.         if (subtype(p) != COND_MATH_GLUE) {
  514.             print(" ");
  515.             if (subtype(p) < COND_MATH_GLUE) {
  516.                 print_spec(glue_ptr(p), null_str);
  517.             } else {
  518.                 print_spec(glue_ptr(p), "mu");
  519.             }
  520.         }
  521.     }
  522. }
  523.  
  524. void
  525. show_kern (p)
  526.     ptr    p;
  527. {
  528.     if (subtype(p) != MU_GLUE) {
  529.         print_esc("kern");
  530.         if (subtype(p) != NORMAL) {
  531.             print(" ");
  532.         }
  533.         print_scaled(kern_width(p));
  534.         if (subtype(p) == ACC_KERN) {
  535.             print(" (for accent)");
  536.         }
  537.     } else {
  538.         print_esc("mkern");
  539.         print_scaled(kern_width(p));
  540.         print("mu");
  541.     }
  542. }
  543.  
  544. void
  545. show_math (p)
  546.     ptr    p;
  547. {
  548.     print_esc("math");
  549.     if (subtype(p) == BEFORE) {
  550.         print("on");
  551.     } else {
  552.         print("off");
  553.     }
  554.     if (math_width(p) != 0) {
  555.         print(", surrounded ");
  556.         print_scaled(math_width(p));
  557.     }
  558. }
  559.     
  560. void
  561. show_ligature (p)
  562.     ptr    p;
  563. {
  564.     print_font_and_char(lig_char(p));
  565.     print(" (ligature ");
  566.     if (subtype(p) > 1) {
  567.         print("|");
  568.     }
  569.     font_in_short_display = font(lig_char(p));
  570.     short_display(lig_ptr(p));
  571.     if (odd(subtype(p))) {
  572.         print("|");
  573.     }
  574.     print(")");
  575. }
  576.  
  577. void
  578. show_discretionary (p)
  579.     ptr    p;
  580. {
  581.     print_esc("discretionary");
  582.     if (replace_count(p) > 0) {
  583.         print(" replacing ");
  584.         print_int(replace_count(p));
  585.     }
  586.     node_list_display(pre_break(p));
  587.     append_char('|');
  588.     show_node_list(post_break(p));
  589.     flush_char();
  590. }
  591.  
  592. void
  593. show_penalty (p)
  594.     ptr    p;
  595. {
  596.     print_esc("penalty ");
  597.     print_int(penalty(p));
  598. }
  599.  
  600. void
  601. show_mark (p)
  602.     ptr    p;
  603. {
  604.     print_esc("mark");
  605.     print_mark(mark_ptr(p));
  606. }
  607.  
  608. void
  609. show_adjust (p)
  610.     ptr    p;
  611. {
  612.     print_esc("vadjust");
  613.     node_list_display(adjust_ptr(p));
  614. }
  615.  
  616. void
  617. show_node_list (p)
  618.     ptr     p;
  619. {
  620.     int    n;
  621.  
  622.     if (cur_length() > depth_threshold) {
  623.         if (p > null) {
  624.             print(" []");
  625.         }
  626.         return;
  627.     }
  628.     n = 0;
  629.     while (p > null) {
  630.         print_ln();
  631.         print_str();
  632.         incr(n);
  633.         if (n > breadth_max) {
  634.             print("etc.");
  635.             return;
  636.         }
  637.         if (is_char_node(p)) {
  638.             print_font_and_char(p);
  639.         } else {
  640.             switch (type(p))
  641.             {
  642.             case HLIST_NODE:
  643.             case VLIST_NODE:
  644.             case UNSET_NODE:
  645.                 show_box1(p);
  646.                 break;
  647.  
  648.             case RULE_NODE:
  649.                 show_rule(p);
  650.                 break;
  651.             
  652.             case INS_NODE:
  653.                 show_insertion(p);
  654.                 break;
  655.             
  656.             case WHATSIT_NODE:
  657.                 show_whatsit(p);
  658.                 break;
  659.             
  660.             case GLUE_NODE:
  661.                 show_glue(p);
  662.                 break;
  663.             
  664.             case KERN_NODE:
  665.                 show_kern(p);
  666.                 break;
  667.             
  668.             case MATH_NODE:
  669.                 show_math(p);
  670.                 break;
  671.             
  672.             case LIGATURE_NODE:
  673.                 show_ligature(p);
  674.                 break;
  675.  
  676.             case PENALTY_NODE:
  677.                 show_penalty(p);
  678.                 break;
  679.         
  680.             case DISC_NODE:
  681.                 show_discretionary(p);
  682.                 break;
  683.             
  684.             case MARK_NODE:
  685.                 show_mark(p);
  686.                 break;
  687.             
  688.             case ADJUST_NODE:
  689.                 show_adjust(p);
  690.                 break;
  691.             
  692.             case STYLE_NODE:
  693.                 print_style(subtype(p));
  694.                 break;
  695.             
  696.             case CHOICE_NODE:
  697.                 show_choice_node(p);
  698.                 break;
  699.  
  700.             case INNER_NOAD:
  701.             case ORD_NOAD:
  702.             case OP_NOAD:
  703.             case BIN_NOAD:
  704.             case REL_NOAD:
  705.             case OPEN_NOAD:
  706.             case CLOSE_NOAD:
  707.             case PUNCT_NOAD:
  708.             case RADICAL_NOAD:
  709.             case OVER_NOAD:
  710.             case UNDER_NOAD:
  711.             case VCENTER_NOAD:
  712.             case ACCENT_NOAD:
  713.             case LEFT_NOAD:
  714.             case RIGHT_NOAD:
  715.                 show_normal_noad(p);
  716.                 break;
  717.             
  718.             case FRACTION_NOAD:
  719.                 show_fraction_noad(p);
  720.                 break;
  721.  
  722.             default:
  723.                 print("Unknown node type!");
  724.                 break;
  725.             }
  726.         }
  727.         p = link(p);
  728.     }
  729. }
  730.  
  731. void
  732. delete_glue_ref (p)
  733.     ptr    p;
  734. {
  735.     if (glue_ref_count(p) == 0) {
  736.         free_node(p, GLUE_SPEC_SIZE);
  737.     } else {
  738.         decr(glue_ref_count(p));
  739.     }
  740. }
  741.  
  742. void
  743. flush_node_list (p)
  744.     ptr    p;
  745. {
  746.     ptr    q;
  747.  
  748.     while (p != null) {
  749.         q = link(p);
  750.         if (is_char_node(p)) {
  751.             free_avail(p);
  752.         } else {
  753.             switch (type(p))
  754.             {
  755.             case HLIST_NODE:
  756.             case VLIST_NODE:
  757.             case UNSET_NODE:
  758.                 flush_node_list(list_ptr(p));
  759.                 free_node(p, BOX_NODE_SIZE);
  760.                 goto done;
  761.                     
  762.             case RULE_NODE:
  763.                 free_node(p, RULE_NODE_SIZE);
  764.                 goto done;
  765.  
  766.             case INS_NODE:
  767.                 flush_node_list(ins_ptr(p));
  768.                 delete_glue_ref(split_top_ptr(p));
  769.                 free_node(p, INS_NODE_SIZE);
  770.                 goto done;
  771.  
  772.             case WHATSIT_NODE:
  773.                 free_whatsit(p);
  774.                 goto done;
  775.             
  776.             case GLUE_NODE:
  777.                 fast_delete_glue_ref(glue_ptr(p));
  778.                 if (leader_ptr(p) != null) {
  779.                     flush_node_list(leader_ptr(p));
  780.                 }
  781.                 break;
  782.  
  783.             case KERN_NODE:
  784.             case MATH_NODE:
  785.             case PENALTY_NODE:
  786.                 break;
  787.  
  788.             case LIGATURE_NODE:
  789.                 flush_node_list(lig_ptr(p));
  790.                 break;
  791.  
  792.             case MARK_NODE:
  793.                 delete_token_ref(mark_ptr(p));
  794.                 break;
  795.             
  796.             case DISC_NODE:
  797.                 flush_node_list(pre_break(p));
  798.                 flush_node_list(post_break(p));
  799.                 break;
  800.  
  801.             case ADJUST_NODE:
  802.                 flush_node_list(adjust_ptr(p));
  803.                 break;
  804.  
  805.             case STYLE_NODE:
  806.                 free_node(p, STYLE_NODE_SIZE);
  807.                 goto done;
  808.  
  809.             case CHOICE_NODE:
  810.                 flush_node_list(display_mlist(p));
  811.                 flush_node_list(text_mlist(p));
  812.                 flush_node_list(script_mlist(p));
  813.                 flush_node_list(script_script_mlist(p));
  814.                 free_node(p, STYLE_NODE_SIZE);
  815.                 goto done;
  816.  
  817.             case ORD_NOAD:
  818.             case OP_NOAD:
  819.             case BIN_NOAD:
  820.             case REL_NOAD:
  821.             case OPEN_NOAD:
  822.             case CLOSE_NOAD:
  823.             case PUNCT_NOAD:
  824.             case INNER_NOAD:
  825.             case RADICAL_NOAD:
  826.             case OVER_NOAD:
  827.             case UNDER_NOAD:
  828.             case VCENTER_NOAD:
  829.             case ACCENT_NOAD:
  830.                 if (math_type(nucleus(p)) >= SUB_BOX) {
  831.                     flush_node_list(math_link(nucleus(p)));
  832.                 }
  833.                 if (math_type(supscr(p)) >= SUB_BOX) {
  834.                     flush_node_list(math_link(supscr(p)));
  835.                 }
  836.                 if (math_type(subscr(p)) >= SUB_BOX) {
  837.                     flush_node_list(math_link(subscr(p)));
  838.                 }
  839.                 if (type(p) == RADICAL_NOAD) {
  840.                     free_node(p, RADICAL_NOAD_SIZE);
  841.                 } else if (type(p) == ACCENT_NOAD) {
  842.                     free_node(p, ACCENT_NOAD_SIZE);
  843.                 } else {
  844.                     free_node(p, NOAD_SIZE);
  845.                 }
  846.                 goto done;
  847.             
  848.             case LEFT_NOAD:
  849.             case RIGHT_NOAD:
  850.                 free_node(p, NOAD_SIZE);
  851.                 goto done;
  852.             
  853.             case FRACTION_NOAD:
  854.                 flush_node_list(math_link(numerator(p)));
  855.                 flush_node_list(math_link(denominator(p)));
  856.                 free_node(p, FRACTION_NOAD_SIZE);
  857.                 goto done;
  858.  
  859.             default:
  860.                 confusion("flushing");
  861.                 break;
  862.             }
  863.             free_node(p, SMALL_NODE_SIZE);
  864.         done:
  865.             ;    
  866.         }
  867.         p = q;
  868.     }
  869. }
  870.  
  871. ptr
  872. copy_node_list (p)
  873.     ptr    p;
  874. {
  875.     ptr    h;
  876.     ptr    q;
  877.     ptr    r;
  878.  
  879.     h = q = new_avail();
  880.     while (p != null) {
  881.         if (is_char_node(p)) {
  882.             r = new_avail();
  883.             font(r) = font(p);
  884.             character(r) = character(p);
  885.         } else {
  886.             switch (type(p))
  887.             {
  888.             case HLIST_NODE:
  889.             case VLIST_NODE:
  890.             case UNSET_NODE:
  891.                 r = new_node(BOX_NODE_SIZE);
  892.                 memcpy((void *)r, (void *)p, BOX_NODE_SIZE);
  893.                 list_ptr(r) = copy_node_list(list_ptr(p));
  894.                 break;
  895.             
  896.             case RULE_NODE:
  897.                 r = new_node(RULE_NODE_SIZE);
  898.                 memcpy((void *)r, (void *)p, RULE_NODE_SIZE);
  899.                 break;
  900.  
  901.             case INS_NODE:
  902.                 r = new_node(INS_NODE_SIZE);
  903.                 memcpy((void *)r, (void *)p, INS_NODE_SIZE);
  904.                 add_glue_ref(split_top_ptr(p));
  905.                 ins_ptr(r) = copy_node_list(ins_ptr(p));
  906.                 break;
  907.  
  908.             case WHATSIT_NODE:
  909.                 r = copy_whatsit(p);
  910.                 break;
  911.             
  912.             case GLUE_NODE:
  913.                 r = new_node(SMALL_NODE_SIZE);
  914.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  915.                 add_glue_ref(glue_ptr(p));
  916.                 glue_ptr(r) = glue_ptr(p);
  917.                 leader_ptr(r) = copy_node_list(leader_ptr(p));
  918.                 break;
  919.             
  920.             case KERN_NODE:
  921.             case MATH_NODE:
  922.             case PENALTY_NODE:
  923.                 r = new_node(SMALL_NODE_SIZE);
  924.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  925.                 break;
  926.             
  927.             case LIGATURE_NODE:
  928.                 r = new_node(SMALL_NODE_SIZE);
  929.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  930.                 lig_ptr(r) = copy_node_list(lig_ptr(p));
  931.                 break;
  932.                 
  933.             case DISC_NODE:
  934.                 r = new_node(SMALL_NODE_SIZE);
  935.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  936.                 pre_break(r) = copy_node_list(pre_break(p));
  937.                 post_break(r) = copy_node_list(post_break(p));
  938.                 break;
  939.  
  940.             case MARK_NODE:
  941.                 r = new_node(SMALL_NODE_SIZE);
  942.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  943.                 add_token_ref(mark_ptr(p));
  944.                 break;
  945.  
  946.             case ADJUST_NODE:
  947.                 r = new_node(SMALL_NODE_SIZE);
  948.                 memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
  949.                 adjust_ptr(r) = copy_node_list(adjust_ptr(p));
  950.                 break;
  951.             
  952.             default:
  953.                 confusion("copying");
  954.                 break;
  955.             }
  956.         }
  957.         q = link(q) = r;
  958.         p = link(p);
  959.     }
  960.     link(q) = null;
  961.     q = link(h);
  962.     free_avail(h);
  963.     return q;
  964. }
  965.  
  966. void
  967. _box_init ()
  968. {
  969. }
  970.  
  971. void
  972. _box_init_once ()
  973. {
  974. }
  975.