~ubuntu-branches/ubuntu/jaunty/luatex/jaunty

« back to all changes in this revision

Viewing changes to src/texk/web2c/luatexdir/tex/linebreak.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2007-12-10 10:24:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071210102434-9w9ljypghznwb4dy
Tags: 0.20.1-1
* new upstreams, add the announcements with changes to the debian dir
* call build.sh.linux with bash, not with sh, otherwise building breaks
  (thanks to Pascal de Bruijn <pmjdebruijn@gmail.com> from Ubuntu for
  letting us know) [np]
* update libpoppler patch
* change the texdoclua patch to use the new os.tmpdir with a template of
  /tmp/luatex.XXXXXX
* bump standards version to 3.7.3, no changes necessary
* convert copyright file to utf-8

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                             (subtype((a)) != pdf_refxform_node))       \
77
77
                         /* reference to an image or XObject form */    \
78
78
                         || ((type((a)) == disc_node) &&                \
79
 
                             (vlink(pre_break(a)) == null) &&           \
80
 
                             (vlink(post_break(a)) == null) &&          \
81
 
                             (vlink(no_break(a)) == null))              \
 
79
                             (vlink_pre_break(a) == null) &&            \
 
80
                             (vlink_post_break(a) == null) &&           \
 
81
                             (vlink_no_break(a) == null))               \
82
82
                         /* an empty |disc_node| */                     \
83
83
                         || ((type((a)) == math_node) &&                \
84
84
                             (surround((a)) == 0))                      \
396
396
#define restore_active_width(a) active_width[(a)] = prev_active_width[(a)]
397
397
 
398
398
static scaled active_width[10] = {0}; /*distance from first active node to~|cur_p|*/
399
 
static scaled cur_active_width[10] = {0}; /*distance from current active node*/
400
399
static scaled background[10] = {0}; /*length of an ``empty'' line*/
401
400
static scaled break_width[10] = {0}; /*length being computed after current break*/
402
401
 
551
550
 
552
551
#define act_width active_width[1] /*length from first active node to current node*/
553
552
 
554
 
#define kern_break() {                                                        \
555
 
    if ((!is_char_node(vlink(cur_p))) && auto_breaking)                        \
556
 
      if (type(vlink(cur_p))==glue_node)                                \
557
 
        ext_try_break(0,unhyphenated_node, pdf_adjust_spacing,        \
558
 
                      par_shape_ptr, adj_demerits,                        \
559
 
                      tracing_paragraphs, pdf_protrude_chars,                \
560
 
                      line_penalty, last_line_fit,                        \
561
 
                      double_hyphen_demerits,  final_hyphen_demerits,first_p,cur_p);        \
562
 
    if (type(cur_p)!=math_node) act_width+=width(cur_p);                \
563
 
    else                        act_width+=surround(cur_p);                \
 
553
#define kern_break() {  \
 
554
    if ((!is_char_node(vlink(cur_p))) && auto_breaking)  \
 
555
      if (type(vlink(cur_p))==glue_node)  \
 
556
        ext_try_break(0,unhyphenated_node, pdf_adjust_spacing,  \
 
557
                      par_shape_ptr, adj_demerits,  \
 
558
                      tracing_paragraphs, pdf_protrude_chars,  \
 
559
                      line_penalty, last_line_fit,  \
 
560
                      double_hyphen_demerits,  final_hyphen_demerits,first_p,cur_p);  \
 
561
    if (type(cur_p)!=math_node) act_width+=width(cur_p);  \
 
562
    else                        act_width+=surround(cur_p);  \
564
563
  }
565
564
 
566
 
#define clean_up_the_memory() {                                        \
567
 
    q=vlink(active);                                                \
568
 
    while (q!=active) {                                        \
569
 
      cur_p=vlink(q);                                                \
570
 
      if (type(q)==delta_node)         free_node(q,delta_node_size);        \
571
 
      else                        free_node(q,active_node_size);        \
572
 
      q=cur_p;                                                        \
573
 
    }                                                                \
574
 
    q=passive;                                                        \
575
 
    while (q!=null) {                                                \
576
 
      cur_p=vlink(q);                                                \
577
 
      free_node(q,passive_node_size);                                \
578
 
      q=cur_p;                                                        \
579
 
    }                                                                \
 
565
#define clean_up_the_memory() {  \
 
566
    q=vlink(active);  \
 
567
    while (q!=active) {  \
 
568
      cur_p=vlink(q);  \
 
569
      if (type(q)==delta_node)         flush_node(q);  \
 
570
      else                        flush_node(q);  \
 
571
      q=cur_p;  \
 
572
    }  \
 
573
    q=passive;  \
 
574
    while (q!=null) {  \
 
575
      cur_p=vlink(q);  \
 
576
      flush_node(q);  \
 
577
      q=cur_p;  \
 
578
    }  \
580
579
  }
581
580
 
582
581
#define inf_bad 10000 /* infinitely bad value */
594
593
#define reset_disc_width(a) disc_width[(a)] = 0
595
594
 
596
595
#define add_disc_width_to_break_width(a)     break_width[(a)] += disc_width[(a)]
597
 
#define add_disc_width_to_active_width(a)    active_width[(a)] += disc_width[(a)]
598
596
#define sub_disc_width_from_active_width(a)  active_width[(a)] -= disc_width[(a)]
599
597
 
600
598
#define add_char_shrink(a,b)  a += char_shrink((b))
608
606
#define sub_kern_stretch(a,b) a -= kern_stretch((b))
609
607
 
610
608
 
611
 
#define update_width(a) cur_active_width[a] += varmem[(r+(a))].cint
612
 
 
613
 
#define set_break_width_to_background(a) break_width[(a)]=background[(a)]
614
 
 
615
 
#define convert_to_break_width(a)                                        \
616
 
  varmem[(prev_r+(a))].cint -= (cur_active_width[(a)]+break_width[(a)])
617
 
 
618
 
#define store_break_width(a)      active_width[(a)]=break_width[(a)]
619
 
 
620
 
#define new_delta_to_break_width(a)                                                        \
621
 
  varmem[(q+(a))].cint=break_width[(a)]-cur_active_width[(a)]
622
 
 
623
 
#define new_delta_from_break_width(a)                                                \
624
 
  varmem[(q+(a))].cint=cur_active_width[(a)]-break_width[(a)]
625
 
 
626
 
#define copy_to_cur_active(a) cur_active_width[(a)]=active_width[(a)]
627
 
 
628
609
/* When we insert a new active node for a break at |cur_p|, suppose this
629
610
   new node is to be placed just before active node |a|; then we essentially
630
611
   want to insert `$\delta\,|cur_p|\,\delta^\prime$' before |a|, where
652
633
   disc_width[]
653
634
   line_break_dir
654
635
*/
655
 
void 
656
 
compute_break_width (int break_type, int pdf_adjust_spacing, halfword p) {
657
 
  halfword s; /*runs through nodes ahead of |cur_p|*/
658
 
  halfword v; /*points to a glue specification or a node ahead of |cur_p|*/
 
636
static void 
 
637
compute_break_width (int break_type, int pdf_adjust_spacing, halfword p
 
638
    /*, halfword s*/) {
 
639
  halfword s; /* glue and other 'whitespace' to be skipped after a break
 
640
               * used if unhyphenated, or post_break==empty */
659
641
  s=p;
660
 
  if (break_type>unhyphenated_node) {
661
 
    if (p!=null) {
662
 
      /*@<Compute the discretionary |break_width| values@>;*/
663
 
      /* When |p| is a discretionary break, the length of a line
664
 
         ``from |p| to |p|'' has to be defined properly so
665
 
         that the other calculations work out.  Suppose that the
666
 
         pre-break text at |p| has length $l_0$, the post-break
667
 
         text has length $l_1$, and the replacement text has length
668
 
         |l|. Suppose also that |q| is the node following the
669
 
         replacement text. Then length of a line from |p| to |q|
670
 
         will be computed as $\gamma+\beta(q)-\alpha(|p|)$, where
671
 
         $\beta(q)=\beta(|p|)-l_0+l$. The actual length will be
672
 
         the background plus $l_1$, so the length from |p| to
673
 
         |p| should be $\gamma+l_0+l_1-l$.  If the post-break text
674
 
         of the discretionary is empty, a break may also discard~|q|;
675
 
         in that unusual case we subtract the length of~|q| and any
676
 
         other nodes that will be discarded after the discretionary
677
 
         break.
678
 
 
679
 
         TH: I don't quite understand the above remarks.
680
 
                 
681
 
         The value of $l_0$ need not be computed, since |line_break|
682
 
         will put it into the global variable |disc_width| before
683
 
         calling |try_break|.
684
 
      */
685
 
 
686
 
      v=vlink(no_break(p)); 
687
 
      while (v!=null) {
688
 
        /* @<Subtract the width of node |v| from |break_width|@>; */
689
 
        /* Replacement texts and discretionary texts are supposed to contain
690
 
           only character nodes, kern nodes, and box or rule nodes.*/
691
 
        if (is_char_node(v)) {
692
 
          if (is_rotated(line_break_dir)) {
693
 
            break_width[1] -= (glyph_height(v)+glyph_depth(v));
694
 
          } else {
695
 
            break_width[1] -= glyph_width(v);
696
 
          }
697
 
          if ((pdf_adjust_spacing > 1) && check_expand_pars(font(v))) {
698
 
            set_prev_char_p(v);
699
 
            sub_char_stretch(break_width[8],v);
700
 
            sub_char_shrink(break_width[9],v);
701
 
          }
 
642
  if (break_type>unhyphenated_node && p!=null) {
 
643
    /*@<Compute the discretionary |break_width| values@>;*/
 
644
    /* When |p| is a discretionary break, the length of a line
 
645
       ``from |p| to |p|'' has to be defined properly so
 
646
       that the other calculations work out.  Suppose that the
 
647
       pre-break text at |p| has length $l_0$, the post-break
 
648
       text has length $l_1$, and the replacement text has length
 
649
       |l|. Suppose also that |q| is the node following the
 
650
       replacement text. Then length of a line from |p| to |q|
 
651
       will be computed as $\gamma+\beta(q)-\alpha(|p|)$, where
 
652
       $\beta(q)=\beta(|p|)-l_0+l$. The actual length will be
 
653
       the background plus $l_1$, so the length from |p| to
 
654
       |p| should be $\gamma+l_0+l_1-l$.  If the post-break text
 
655
       of the discretionary is empty, a break may also discard~|q|;
 
656
       in that unusual case we subtract the length of~|q| and any
 
657
       other nodes that will be discarded after the discretionary
 
658
       break.
 
659
 
 
660
       TH: I don't quite understand the above remarks.
 
661
               
 
662
       The value of $l_0$ need not be computed, since |line_break|
 
663
       will put it into the global variable |disc_width| before
 
664
       calling |try_break|.
 
665
    */
 
666
    /* In case of nested discretionaries, we always follow the no_break
 
667
       path, as we are talking about the breaking on _this_ position.
 
668
    */
 
669
 
 
670
    halfword v;
 
671
    for (v=vlink_no_break(p); v!=null; v=vlink(v)) {
 
672
      /* @<Subtract the width of node |v| from |break_width|@>; */
 
673
      /* Replacement texts and discretionary texts are supposed to contain
 
674
         only character nodes, kern nodes, and box or rule nodes.*/
 
675
      if (is_char_node(v)) {
 
676
        if (is_rotated(line_break_dir)) {
 
677
          break_width[1] -= (glyph_height(v)+glyph_depth(v));
702
678
        } else {
703
 
          switch (type(v)) {
704
 
          case hlist_node:
705
 
          case vlist_node:
706
 
            if (!(dir_orthogonal(dir_primary[box_dir(v)],
707
 
                                 dir_primary[line_break_dir])))
708
 
              break_width[1] -= width(v);
709
 
            else
710
 
              break_width[1] -= (depth(v)+height(v));
711
 
            break;
712
 
          case kern_node: 
713
 
            if ((pdf_adjust_spacing > 1) && (subtype(v) == normal)) {
714
 
              sub_kern_stretch(break_width[8],v);
715
 
              sub_kern_shrink(break_width[9],v);
716
 
            }
717
 
            /* fall through */
718
 
          case rule_node:
 
679
          break_width[1] -= glyph_width(v);
 
680
        }
 
681
        if ((pdf_adjust_spacing > 1) && check_expand_pars(font(v))) {
 
682
          set_prev_char_p(v);
 
683
          sub_char_stretch(break_width[8],v);
 
684
          sub_char_shrink(break_width[9],v);
 
685
        }
 
686
      } else {
 
687
        switch (type(v)) {
 
688
        case hlist_node:
 
689
        case vlist_node:
 
690
          if (!(dir_orthogonal(dir_primary[box_dir(v)],
 
691
                               dir_primary[line_break_dir])))
719
692
            break_width[1] -= width(v);
720
 
            break;
721
 
          case disc_node:
722
 
            /* well? */
723
 
            break;
724
 
          default:
725
 
            confusion(maketexstring("disc1"));
726
 
            break;
727
 
          }
728
 
        }
729
 
        v=vlink(v);
730
 
      }
731
 
      s=vlink(post_break(p));
732
 
      while (s!=null) {
733
 
        /* @<Add the width of node |s| to |break_width|@>; */
734
 
        if (is_char_node(s)) { 
735
 
          if (is_rotated(line_break_dir)) 
736
 
            break_width[1] += (glyph_height(s)+glyph_depth(s));
737
 
          else
738
 
            break_width[1] += glyph_width(s);
739
 
          if ((pdf_adjust_spacing > 1) && check_expand_pars(font(s))) {
740
 
            set_prev_char_p(s);
741
 
            add_char_stretch(break_width[8],s);
742
 
            add_char_shrink(break_width[9],s);
743
 
          }
744
 
        } else  { 
745
 
          switch (type(s)) {
746
 
          case hlist_node:
747
 
          case vlist_node: 
748
 
            if (!(dir_orthogonal(dir_primary[box_dir(s)],
749
 
                                 dir_primary[line_break_dir])))
750
 
              break_width[1] += width(s);
751
 
            else
752
 
              break_width[1] += (depth(s)+height(s));
753
 
            break;
754
 
          case kern_node:
755
 
            if ((pdf_adjust_spacing > 1) && (subtype(s) == normal)) {
756
 
              add_kern_stretch(break_width[8],s);
757
 
              add_kern_shrink(break_width[9],s);
758
 
            }
759
 
            /* fall through */
760
 
          case rule_node:
761
 
            break_width[1] += width(s);
762
 
            break;
763
 
          case disc_node:
764
 
            /* NB: now what */
765
 
            assert(vlink(s)==null);
766
 
            /* NB: temporary solution: not good, but not bad either */
767
 
            s = no_break(s);
768
 
            break;
769
 
          default:
770
 
            confusion(maketexstring("disc2"));
771
 
          }
772
 
        }
773
 
        s=vlink(s);
774
 
      };
775
 
      do_one_seven_eight(add_disc_width_to_break_width);
776
 
      if (vlink(post_break(p))==null) {
777
 
        /* nodes may be discardable after the break */
778
 
        /* fixme */
779
 
        s=vlink(p);
780
 
      }
781
 
    }
 
693
          else
 
694
            break_width[1] -= (depth(v)+height(v));
 
695
          break;
 
696
        case kern_node: 
 
697
          if ((pdf_adjust_spacing > 1) && (subtype(v) == normal)) {
 
698
            sub_kern_stretch(break_width[8],v);
 
699
            sub_kern_shrink(break_width[9],v);
 
700
          }
 
701
          /* fall through */
 
702
        case rule_node:
 
703
          break_width[1] -= width(v);
 
704
          break;
 
705
        case disc_node:
 
706
          assert(vlink(v)==null); /* discs are _always_ last */
 
707
          v = no_break(v);
 
708
          break;
 
709
        default:
 
710
          tconfusion("disc1");
 
711
          break;
 
712
        }
 
713
      }
 
714
    }
 
715
 
 
716
    for (v=vlink_post_break(p); v!=null; v=vlink(v)) {
 
717
      /* @<Add the width of node |v| to |break_width|@>; */
 
718
      if (is_char_node(v)) { 
 
719
        if (is_rotated(line_break_dir)) 
 
720
          break_width[1] += (glyph_height(v)+glyph_depth(v));
 
721
        else
 
722
          break_width[1] += glyph_width(v);
 
723
        if ((pdf_adjust_spacing > 1) && check_expand_pars(font(v))) {
 
724
          set_prev_char_p(v);
 
725
          add_char_stretch(break_width[8],v);
 
726
          add_char_shrink(break_width[9],v);
 
727
        }
 
728
      } else  { 
 
729
        switch (type(v)) {
 
730
        case hlist_node:
 
731
        case vlist_node: 
 
732
          if (!(dir_orthogonal(dir_primary[box_dir(v)],
 
733
                               dir_primary[line_break_dir])))
 
734
            break_width[1] += width(v);
 
735
          else
 
736
            break_width[1] += (depth(v)+height(v));
 
737
          break;
 
738
        case kern_node:
 
739
          if ((pdf_adjust_spacing > 1) && (subtype(v) == normal)) {
 
740
            add_kern_stretch(break_width[8],v);
 
741
            add_kern_shrink(break_width[9],v);
 
742
          }
 
743
          /* fall through */
 
744
        case rule_node:
 
745
          break_width[1] += width(v);
 
746
          break;
 
747
        case disc_node:
 
748
          assert(vlink(v)==null);
 
749
          v = no_break(v);
 
750
          break;
 
751
        default:
 
752
          tconfusion("disc2");
 
753
        }
 
754
      }
 
755
    }
 
756
 
 
757
    do_one_seven_eight(add_disc_width_to_break_width);
 
758
    if (vlink_post_break(p)==null) {
 
759
      s=vlink(p); /* no post_break: 'skip' any 'whitespace' following */
 
760
    } else {
 
761
      s=null;
 
762
    }
 
763
  } else {
 
764
    s = p; /* unhyphenated: we need to 'skip' any 'whitespace' following */
782
765
  }
783
766
  while (s!=null) {
784
767
    switch (type(s)) {
785
768
    case glue_node:
786
769
      /*@<Subtract glue from |break_width|@>;*/
787
 
      v=glue_ptr(s);
 
770
      {halfword v=glue_ptr(s);
788
771
      break_width[1] -= width(v);
789
772
      break_width[2+stretch_order(v)] -= stretch(v);
790
773
      break_width[7] -= shrink(v);
791
 
      break;
 
774
      }break;
792
775
    case penalty_node: 
793
776
      break;
794
777
    case math_node: 
807
790
  }
808
791
}
809
792
 
 
793
 
 
794
static void
 
795
print_break_node(halfword q, fitness_value fit_class,
 
796
    quarterword break_type, halfword cur_p) {
 
797
  /* @<Print a symbolic description of the new break node@> */
 
798
  tprint_nl("@@"); 
 
799
  print_int(serial(passive));
 
800
  tprint(": line "); 
 
801
  print_int(line_number(q)-1);
 
802
  print_char('.'); 
 
803
  print_int(fit_class);
 
804
  if (break_type==hyphenated_node) 
 
805
    print_char('-');
 
806
  tprint(" t="); 
 
807
  print_int(total_demerits(q));
 
808
  if (do_last_line_fit) {
 
809
    /*@<Print additional data in the new active node@>; */
 
810
    tprint(" s="); 
 
811
    print_scaled(active_short(q));
 
812
    if (cur_p==null) 
 
813
      tprint(" a=");
 
814
    else 
 
815
      tprint(" g=");
 
816
    print_scaled(active_glue(q));
 
817
  }
 
818
  tprint(" -> @@");
 
819
  if (prev_break(passive)==null) 
 
820
    print_char('0');
 
821
  else 
 
822
    print_int(serial(prev_break(passive)));
 
823
}
 
824
 
 
825
 
 
826
static void 
 
827
print_feasible_break(halfword cur_p, pointer r, halfword b, integer pi,
 
828
    integer d, boolean artificial_demerits) {
 
829
  /* @<Print a symbolic description of this feasible break@>;*/
 
830
  if (printed_node!=cur_p) {
 
831
    /* @<Print the list between |printed_node| and |cur_p|, then
 
832
       set |printed_node:=cur_p|@>;*/
 
833
    tprint_nl("");
 
834
    if (cur_p==null) {
 
835
      short_display(vlink(printed_node));
 
836
    } else {
 
837
      halfword save_link=vlink(cur_p);
 
838
      vlink(cur_p)=null; 
 
839
      tprint_nl(""); 
 
840
      short_display(vlink(printed_node));
 
841
      vlink(cur_p)=save_link;
 
842
    }
 
843
    printed_node=cur_p;
 
844
  }
 
845
  tprint_nl("@");
 
846
  if (cur_p==null) { 
 
847
    tprint_esc("par"); 
 
848
  } else if (type(cur_p)!=glue_node) {
 
849
    if      (type(cur_p)==penalty_node)  tprint_esc("penalty");
 
850
    else if (type(cur_p)==disc_node)     tprint_esc("discretionary");
 
851
    else if (type(cur_p)==kern_node)     tprint_esc("kern");
 
852
    else                                 tprint_esc("math");
 
853
  }
 
854
  tprint(" via @@");
 
855
  if (break_node(r)==null) 
 
856
    print_char('0');
 
857
  else 
 
858
    print_int(serial(break_node(r)));
 
859
  tprint(" b=");
 
860
  if (b>inf_bad)  
 
861
    print_char('*');
 
862
  else 
 
863
    print_int(b);
 
864
  tprint(" p="); 
 
865
  print_int(pi); 
 
866
  tprint(" d=");
 
867
  if (artificial_demerits) 
 
868
    print_char('*');
 
869
  else 
 
870
    print_int(d);
 
871
}
 
872
 
 
873
#define add_disc_width_to_active_width(a)   active_width[a] += disc_width[a]
 
874
#define update_width(a) cur_active_width[a] += varmem[(r+(a))].cint
 
875
 
 
876
#define set_break_width_to_background(a) break_width[a]=background[(a)]
 
877
 
 
878
#define convert_to_break_width(a)  \
 
879
  varmem[(prev_r+(a))].cint -= (cur_active_width[(a)]+break_width[(a)])
 
880
 
 
881
#define store_break_width(a)      active_width[(a)]=break_width[(a)]
 
882
 
 
883
#define new_delta_to_break_width(a)  \
 
884
  varmem[(q+(a))].cint=break_width[(a)]-cur_active_width[(a)]
 
885
 
 
886
#define new_delta_from_break_width(a)  \
 
887
  varmem[(q+(a))].cint=cur_active_width[(a)]-break_width[(a)]
 
888
 
 
889
#define copy_to_cur_active(a) cur_active_width[(a)]=active_width[(a)]
 
890
 
810
891
#define combine_two_deltas(a) varmem[(prev_r+(a))].cint += varmem[(r+(a))].cint
811
892
#define downdate_width(a) cur_active_width[(a)] -= varmem[(prev_r+(a))].cint
812
893
#define update_active(a) active_width[(a)]+=varmem[(r+(a))].cint
820
901
#define right_side 1
821
902
 
822
903
 
823
 
#define cal_margin_kern_var(a) {                                        \
824
 
character(cp) = character((a));                                                \
825
 
font(cp) = font((a));                                                        \
826
 
do_subst_font(cp, 1000);                                                \
827
 
if (font(cp) != font((a)))                                                 \
828
 
  margin_kern_stretch += left_pw((a)) - left_pw(cp);                        \
829
 
font(cp) = font((a));                                                        \
830
 
do_subst_font(cp, -1000);                                                \
831
 
if (font(cp) != font((a)))                                                \
832
 
  margin_kern_shrink += left_pw(cp) - left_pw((a));                        \
833
 
}
 
904
#define cal_margin_kern_var(a) {  \
 
905
  character(cp) = character((a));  \
 
906
  font(cp) = font((a));  \
 
907
  do_subst_font(cp, 1000);  \
 
908
  if (font(cp) != font((a)))  \
 
909
    margin_kern_stretch += left_pw((a)) - left_pw(cp);  \
 
910
  font(cp) = font((a));  \
 
911
  do_subst_font(cp, -1000);  \
 
912
  if (font(cp) != font((a)))  \
 
913
    margin_kern_shrink += left_pw(cp) - left_pw((a));  \
 
914
  }
834
915
 
835
916
static void 
836
917
ext_try_break(integer pi,
852
933
  scaled margin_kern_shrink;
853
934
  halfword lp, rp, cp;
854
935
  halfword prev_r;  /* stays a step behind |r| */
 
936
  halfword prev_prev_r; /*a step behind |prev_r|, if |type(prev_r)=delta_node|*/
855
937
  halfword old_l; /* maximum line number in current equivalence class of lines */
856
938
  boolean no_break_yet; /* have we found a feasible break at |cur_p|? */
857
 
  halfword prev_prev_r; /*a step behind |prev_r|, if |type(prev_r)=delta_node|*/
858
939
  halfword q; /*points to a new node being created*/
859
940
  halfword l; /*line number of current active node*/
860
941
  boolean node_r_stays_active; /*should node |r| remain in the active list?*/
863
944
  halfword b; /*badness of test line*/
864
945
  integer d; /*demerits of test line*/
865
946
  boolean artificial_demerits; /*has |d| been forced to zero?*/
866
 
  halfword save_link; /*temporarily holds value of |vlink(cur_p)|*/
 
947
 
867
948
  scaled shortfall; /*used in badness calculations*/
868
949
  scaled g; /*glue stretch or shrink of test line, adjustment for last line*/
 
950
  scaled cur_active_width[10] = {0}; /*distance from current active node*/
869
951
 
870
952
  line_width=0;  g=0; prev_prev_r=null;
871
953
  /*@<Make sure that |pi| is in the proper range@>;*/
880
962
  old_l=0;
881
963
  do_all_eight(copy_to_cur_active);
882
964
 
883
 
 CONTINUE: 
884
965
  while (1)  {
885
966
    r=vlink(prev_r);
886
967
    /* @<If node |r| is of type |delta_node|, update |cur_active_width|,
887
968
       set |prev_r| and |prev_prev_r|, then |goto continue|@>; */
888
969
    /* The following code uses the fact that |type(active)<>delta_node| */
889
970
    if (type(r)==delta_node) {
890
 
      do_all_eight(update_width);
 
971
      do_all_eight(update_width); /* IMPLICIT ,r */
891
972
      prev_prev_r=prev_r; 
892
973
      prev_r=r; 
893
 
      goto CONTINUE;
 
974
      continue;
894
975
    }
895
976
    /* @<If a line number class has ended, create new active nodes for
896
977
       the best feasible breaks in that class; then |return|
919
1000
        /* @<Insert a delta node to prepare for breaks at |cur_p|@>;*/
920
1001
        /* We use the fact that |type(active)<>delta_node|.*/
921
1002
        if (type(prev_r)==delta_node) {/* modify an existing delta node */
922
 
          do_all_eight(convert_to_break_width);                               
 
1003
          do_all_eight(convert_to_break_width);  /* IMPLICIT prev_r */
923
1004
        } else if (prev_r==active) { /* no delta node needed at the beginning */
924
1005
          do_all_eight(store_break_width);                                
925
1006
        } else {                                                        
926
 
          q=get_node(delta_node_size); 
 
1007
          q=new_node(delta_node,0); 
927
1008
          vlink(q)=r; 
928
 
          type(q)=delta_node;        
929
 
          subtype(q)=0; /* the |subtype| is not used */                        
930
 
          do_all_eight(new_delta_to_break_width);                        
 
1009
          do_all_eight(new_delta_to_break_width); /* IMPLICIT q */
931
1010
          vlink(prev_r)=q;  
932
1011
          prev_prev_r=prev_r; 
933
1012
          prev_r=q;                
944
1023
            /* When we create an active node, we also create the corresponding
945
1024
               passive node.
946
1025
            */
947
 
            q=get_node(passive_node_size); 
948
 
            type(q)=passive_node;
 
1026
            q=new_node(passive_node,0); 
949
1027
            vlink(q)=passive; 
950
1028
            passive=q; 
951
1029
            cur_break(q)=cur_p;
966
1044
            }
967
1045
            passive_right_box(q)=internal_right_box;
968
1046
            passive_right_box_width(q)=internal_right_box_width;
969
 
            q=get_node(active_node_size); 
 
1047
            q=new_node(break_type,fit_class); 
970
1048
            break_node(q)=passive;
971
1049
            line_number(q)=best_pl_line[fit_class]+1;
972
 
            fitness(q)=fit_class; 
973
 
            type(q)=break_type;
974
1050
            total_demerits(q)=minimal_demerits[fit_class];
975
1051
            if (do_last_line_fit) {
976
1052
              /*@<Store \(a)additional data in the new active node@>*/
982
1058
            vlink(q)=r;
983
1059
            vlink(prev_r)=q; 
984
1060
            prev_r=q;
985
 
            if (tracing_paragraphs>0) {
986
 
              /* @<Print a symbolic description of the new break node@> */
987
 
              print_nl(maketexstring("@@")); 
988
 
              print_int(serial(passive));
989
 
              print(maketexstring(": line ")); 
990
 
              print_int(line_number(q)-1);
991
 
              print_char('.'); 
992
 
              print_int(fit_class);
993
 
              if (break_type==hyphenated_node) 
994
 
                print_char('-');
995
 
              print(maketexstring(" t=")); 
996
 
              print_int(total_demerits(q));
997
 
              if (do_last_line_fit) {
998
 
                /*@<Print additional data in the new active node@>; */
999
 
                print(maketexstring(" s=")); 
1000
 
                print_scaled(active_short(q));
1001
 
                if (cur_p==null) 
1002
 
                  print(maketexstring(" a="));
1003
 
                else 
1004
 
                  print(maketexstring(" g="));
1005
 
                print_scaled(active_glue(q));
1006
 
              }
1007
 
              print(maketexstring(" -> @@"));
1008
 
              if (prev_break(passive)==null) 
1009
 
                print_char('0');
1010
 
              else 
1011
 
                print_int(serial(prev_break(passive)));
1012
 
            }
 
1061
            if (tracing_paragraphs>0) 
 
1062
              print_break_node(q,fit_class,break_type,cur_p);
1013
1063
          }
1014
1064
          minimal_demerits[fit_class]=awful_bad;
1015
1065
        }
1019
1069
           least one active node before |r|, so |type(prev_r)<>delta_node|. 
1020
1070
        */
1021
1071
        if (r!=active) {                                                
1022
 
          q=get_node(delta_node_size); 
 
1072
          q=new_node(delta_node,0); 
1023
1073
          vlink(q)=r; 
1024
 
          type(q)=delta_node;        
1025
 
          subtype(q)=0; /* the |subtype| is not used */                        
1026
 
          do_all_eight(new_delta_from_break_width);                                
 
1074
          do_all_eight(new_delta_from_break_width);  /* IMPLICIT q */
1027
1075
          vlink(prev_r)=q; 
1028
1076
          prev_prev_r=prev_r; 
1029
1077
          prev_r=q;                        
1062
1110
       then |goto continue| if a line from |r| to |cur_p| is infeasible,
1063
1111
       otherwise record a new feasible break@>; */
1064
1112
    artificial_demerits=false;
1065
 
    shortfall = line_width-cur_active_width[1]; /*we're this much too short*/
1066
 
    if (break_node(r)==null)
1067
 
      shortfall -= init_internal_left_box_width;
1068
 
    else 
1069
 
      shortfall -= passive_last_left_box_width(break_node(r));
1070
 
    shortfall -= internal_right_box_width;
 
1113
    shortfall = line_width
 
1114
      - cur_active_width[1]
 
1115
      -(( break_node(r)==null)
 
1116
        ? init_internal_left_box_width
 
1117
        : passive_last_left_box_width(break_node(r)))
 
1118
      - internal_right_box_width;
1071
1119
    if (pdf_protrude_chars > 1) {
1072
1120
      halfword l, o;
1073
1121
      l = (break_node(r) == null) ? first_p : cur_break(break_node(r));
1074
 
      assert(vlink(alink(cur_p))==cur_p);
1075
 
      o = alink(cur_p);
 
1122
      if (cur_p==null) {
 
1123
        o = null;
 
1124
      } else { /* TODO if (is_character_node(alink(cur_p))) */
 
1125
        o = alink(cur_p);
 
1126
        assert(vlink(o)==cur_p);
 
1127
      }
1076
1128
      /* let's look at the right margin first */
1077
 
      if ((cur_p != null) && (type(cur_p) == disc_node) && (vlink(pre_break(cur_p)) != null)) {
 
1129
      if ((cur_p != null) && (type(cur_p) == disc_node) && (vlink_pre_break(cur_p) != null)) {
1078
1130
        /* a |disc_node| with non-empty |pre_break|, protrude the last char of |pre_break| */
1079
 
        o = tlink(pre_break(cur_p));
 
1131
        o = tlink_pre_break(cur_p);
1080
1132
      } else { 
1081
1133
        o = find_protchar_right(l, o);
1082
1134
      }
1083
1135
      /* now the left margin */
1084
 
      if ((l != null) && (type(l) == disc_node) &&  (vlink(post_break(l)) != null)) {
 
1136
      if ((l != null) && (type(l) == disc_node) &&  (vlink_post_break(l) != null)) {
1085
1137
        /* FIXME: first 'char' could be a disc! */
1086
 
        l = vlink(post_break(l)); /* protrude the first char */
 
1138
        l = vlink_post_break(l); /* protrude the first char */
1087
1139
      } else {
1088
1140
        l = find_protchar_left(l, true);
1089
1141
      }
1096
1148
        /* @<Calculate variations of marginal kerns@>;*/
1097
1149
        lp = last_leftmost_char;
1098
1150
        rp = last_rightmost_char;
1099
 
        cp = new_char_node(0,0);
 
1151
        cp = raw_glyph_node();
1100
1152
        if (lp != null) {
1101
1153
          cal_margin_kern_var(lp);
1102
1154
        }
1103
1155
        if (rp != null) {
1104
1156
          cal_margin_kern_var(rp);
1105
1157
        }
1106
 
        ext_free_node(cp,glyph_node_size);
 
1158
        flush_node(cp);
1107
1159
      }
1108
1160
      if ((shortfall > 0) && ((total_font_stretch + margin_kern_stretch) > 0)) {
1109
1161
        if ((total_font_stretch + margin_kern_stretch) > shortfall)
1250
1302
      /* @<Prepare to deactivate node~|r|, and |goto deactivate| unless
1251
1303
         there is a reason to consider lines of text from |r| to |cur_p|@> */
1252
1304
      /* During the final pass, we dare not lose all active nodes, lest we lose
1253
 
         touch with the line breaks already found. The code shown here makes sure
1254
 
         that such a catastrophe does not happen, by permitting overfull boxes as
1255
 
         a last resort. This particular part of \TeX\ was a source of several subtle
1256
 
         bugs before the correct program logic was finally discovered; readers
1257
 
         who seek to ``improve'' \TeX\ should therefore think thrice before daring
1258
 
         to make any changes here.
 
1305
         touch with the line breaks already found. The code shown here makes
 
1306
         sure that such a catastrophe does not happen, by permitting overfull
 
1307
         boxes as a last resort. This particular part of \TeX\ was a source of
 
1308
         several subtle bugs before the correct program logic was finally
 
1309
         discovered; readers who seek to ``improve'' \TeX\ should therefore
 
1310
         think thrice before daring to make any changes here.
1259
1311
         @^overfull boxes@>
1260
1312
      */
1261
1313
      if (final_pass && (minimum_demerits==awful_bad) && 
1268
1320
    } else { 
1269
1321
      prev_r=r;
1270
1322
      if (b>threshold) 
1271
 
        goto CONTINUE;
 
1323
        continue;
1272
1324
      node_r_stays_active=true;
1273
1325
    }
1274
1326
    /* @<Record a new feasible break@>;*/
1275
1327
    /* When we get to this part of the code, the line from |r| to |cur_p| is
1276
 
       feasible, its badness is~|b|, and its fitness classification is |fit_class|.
1277
 
       We don't want to make an active node for this break yet, but we will
1278
 
       compute the total demerits and record them in the |minimal_demerits| array,
1279
 
       if such a break is the current champion among all ways to get to |cur_p|
1280
 
       in a given line-number class and fitness class.
 
1328
       feasible, its badness is~|b|, and its fitness classification is
 
1329
       |fit_class|.  We don't want to make an active node for this break yet,
 
1330
       but we will compute the total demerits and record them in the
 
1331
       |minimal_demerits| array, if such a break is the current champion among
 
1332
       all ways to get to |cur_p| in a given line-number class and fitness
 
1333
       class.
1281
1334
    */
1282
1335
    if (artificial_demerits) { 
1283
1336
      d=0;
1300
1353
      }
1301
1354
      if (abs(fit_class-fitness(r))>1) d=d+adj_demerits;
1302
1355
    }
1303
 
    if (tracing_paragraphs>0) {
1304
 
      /* @<Print a symbolic description of this feasible break@>;*/
1305
 
      if (printed_node!=cur_p) {
1306
 
        /* @<Print the list between |printed_node| and |cur_p|, then
1307
 
           set |printed_node:=cur_p|@>;*/
1308
 
        print_nl(maketexstring(""));
1309
 
        if (cur_p==null) {
1310
 
          short_display(vlink(printed_node));
1311
 
        } else {
1312
 
          save_link=vlink(cur_p);
1313
 
          vlink(cur_p)=null; 
1314
 
          print_nl(maketexstring("")); 
1315
 
          short_display(vlink(printed_node));
1316
 
          vlink(cur_p)=save_link;
1317
 
        }
1318
 
        printed_node=cur_p;
1319
 
      }
1320
 
      print_nl(maketexstring("@"));
1321
 
      if (cur_p==null) { 
1322
 
        print_esc(maketexstring("par")); 
1323
 
      } else if (type(cur_p)!=glue_node) {
1324
 
        if      (type(cur_p)==penalty_node)  print_esc(maketexstring("penalty"));
1325
 
        else if (type(cur_p)==disc_node)     print_esc(maketexstring("discretionary"));
1326
 
        else if (type(cur_p)==kern_node)     print_esc(maketexstring("kern"));
1327
 
        else                                 print_esc(maketexstring("math"));
1328
 
      }
1329
 
      print(maketexstring(" via @@"));
1330
 
      if (break_node(r)==null) 
1331
 
        print_char('0');
1332
 
      else 
1333
 
        print_int(serial(break_node(r)));
1334
 
      print(maketexstring(" b="));
1335
 
      if (b>inf_bad)  
1336
 
        print_char('*');
1337
 
      else 
1338
 
        print_int(b);
1339
 
      print(maketexstring(" p=")); 
1340
 
      print_int(pi); 
1341
 
      print(maketexstring(" d="));
1342
 
      if (artificial_demerits) 
1343
 
        print_char('*');
1344
 
      else 
1345
 
        print_int(d);
1346
 
    }
 
1356
    if (tracing_paragraphs>0)
 
1357
      print_feasible_break(cur_p, r, b, pi, d, artificial_demerits);
1347
1358
    d += total_demerits(r); /*this is the minimum total demerits
1348
1359
                              from the beginning to |cur_p| via |r| */
1349
1360
    if (d<=minimal_demerits[fit_class]) {
1362
1373
    }
1363
1374
    /* /Record a new feasible break */
1364
1375
    if (node_r_stays_active) 
1365
 
      goto CONTINUE; /*|prev_r| has been set to |r| */
 
1376
      continue; /*|prev_r| has been set to |r| */
1366
1377
  DEACTIVATE: 
1367
1378
    /* @<Deactivate node |r|@>; */
1368
 
    /* When an active node disappears, we must delete an adjacent delta node if the
1369
 
       active node was at the beginning or the end of the active list, or if it
1370
 
       was surrounded by delta nodes. We also must preserve the property that
1371
 
       |cur_active_width| represents the length of material from |vlink(prev_r)|
1372
 
       to~|cur_p|.*/
 
1379
    /* When an active node disappears, we must delete an adjacent delta node if
 
1380
       the active node was at the beginning or the end of the active list, or
 
1381
       if it was surrounded by delta nodes. We also must preserve the property
 
1382
       that |cur_active_width| represents the length of material from
 
1383
       |vlink(prev_r)| to~|cur_p|.*/
1373
1384
    
1374
1385
    vlink(prev_r)=vlink(r); 
1375
 
    free_node(r,active_node_size);
 
1386
    flush_node(r);
1376
1387
    if (prev_r==active) {
1377
 
      /*@<Update the active widths, since the first active node has been deleted@>*/
1378
 
      /* The following code uses the fact that |type(active)<>delta_node|. If the
1379
 
         active list has just become empty, we do not need to update the
 
1388
      /*@<Update the active widths, since the first active node has been
 
1389
        deleted@>*/
 
1390
      /* The following code uses the fact that |type(active)<>delta_node|.
 
1391
         If the active list has just become empty, we do not need to update the
1380
1392
         |active_width| array, since it will be initialized when an active
1381
1393
         node is next inserted.
1382
1394
      */
1383
1395
      r=vlink(active);
1384
1396
      if (type(r)==delta_node) {
1385
 
        do_all_eight(update_active);
 
1397
        do_all_eight(update_active); /* IMPLICIT r */
1386
1398
        do_all_eight(copy_to_cur_active);
1387
1399
        vlink(active)=vlink(r); 
1388
 
        free_node(r,delta_node_size);
1389
 
      };
 
1400
        flush_node(r);
 
1401
      }
1390
1402
    } else if (type(prev_r)==delta_node){
1391
1403
      r=vlink(prev_r);
1392
1404
      if (r==active) {
1393
 
        do_all_eight(downdate_width);
 
1405
        do_all_eight(downdate_width); /* IMPLICIT prev_r */
1394
1406
        vlink(prev_prev_r)=active;
1395
 
        free_node(prev_r,delta_node_size); 
 
1407
        flush_node(prev_r); 
1396
1408
        prev_r=prev_prev_r;
1397
1409
      } else if (type(r)==delta_node) {
1398
 
        do_all_eight(update_width);
1399
 
        do_all_eight(combine_two_deltas);
 
1410
        do_all_eight(update_width); /* IMPLICIT ,r */
 
1411
        do_all_eight(combine_two_deltas); /* IMPLICIT r prev_r */
1400
1412
        vlink(prev_r)=vlink(r); 
1401
 
        free_node(r,delta_node_size);
 
1413
        flush_node(r);
1402
1414
      }
1403
1415
    }   
1404
1416
  }
1442
1454
                   int broken_penalty,
1443
1455
                   halfword final_par_glue) {
1444
1456
  /* DONE,DONE1,DONE2,DONE3,DONE4,DONE5,CONTINUE;*/
1445
 
  halfword prev_p,cur_p,q,r,s; /* miscellaneous nodes of temporary interest */
 
1457
  halfword cur_p,q,r,s; /* miscellaneous nodes of temporary interest */
1446
1458
 
1447
1459
  /* Get ready to start ... */
1448
1460
  minimum_demerits=awful_bad;
1534
1546
    }
1535
1547
  }
1536
1548
  /* @<DIR: Initialize |dir_ptr| for |line_break|@> */
1537
 
  /*if dir_ptr<>null then free_node(dir_ptr,dir_node_size);*/
1538
 
  dir_ptr=null; 
1539
 
  push_dir(paragraph_dir);
 
1549
  if (dir_ptr!=null) {
 
1550
        fprintf(stdout,"-dir_node s %d\n",dir_ptr);
 
1551
        flush_node_list(dir_ptr);
 
1552
        dir_ptr=null; 
 
1553
  }
 
1554
  /*push_dir(paragraph_dir);*/ /* TODO what was the point of this? */
1540
1555
 
1541
1556
  /* @<Find optimal breakpoints@>;*/
1542
1557
  threshold=pretolerance;
1543
1558
  if (threshold>=0) {
1544
1559
    if (tracing_paragraphs>0) {
1545
1560
      begin_diagnostic(); 
1546
 
      print_nl(maketexstring("@firstpass"));
 
1561
      tprint_nl("@firstpass");
1547
1562
    }
1548
1563
    second_pass=false; 
1549
1564
    final_pass=false;
1557
1572
    
1558
1573
  while (1)  { 
1559
1574
    halfword first_p;
 
1575
    halfword nest_stack[10];
 
1576
    int nest_index = 0;
1560
1577
    if (threshold>inf_bad)
1561
1578
      threshold=inf_bad;
1562
1579
    /* Create an active breakpoint representing the beginning of the paragraph */
1563
 
    q=get_node(active_node_size);
1564
 
    type(q)=unhyphenated_node; 
1565
 
    fitness(q)=decent_fit;
 
1580
    q=new_node(unhyphenated_node,decent_fit);
1566
1581
    vlink(q)=active; 
1567
1582
    break_node(q)=null;
1568
1583
    line_number(q)=cur_list.pg_field+1; 
1576
1591
    pass_number=0;
1577
1592
    font_in_short_display=null_font;
1578
1593
    /* /Create an active breakpoint representing the beginning of the paragraph */
 
1594
    auto_breaking=true;
1579
1595
    cur_p=vlink(temp_head); 
1580
 
    auto_breaking=true;
1581
 
    prev_p=cur_p; /* glue at beginning is not a legal breakpoint */
 
1596
    assert(alink(cur_p)==temp_head);
1582
1597
    /* LOCAL: Initialize with first |local_paragraph| node */
1583
1598
    if ((type(cur_p)==whatsit_node)&&(subtype(cur_p)==local_par_node)) {
1584
1599
      internal_pen_inter=local_pen_inter(cur_p);
1626
1641
          add_char_stretch(active_width[8],cur_p);
1627
1642
          add_char_shrink(active_width[9],cur_p);
1628
1643
        }
1629
 
        prev_p=cur_p;
1630
1644
        cur_p=vlink(cur_p);
 
1645
        while (cur_p==null && nest_index>0) {
 
1646
          cur_p = nest_stack[--nest_index];
 
1647
                  /*          fprintf(stderr,"Node Pop  %d [%d]\n",nest_index,(int)cur_p); */
 
1648
        }
1631
1649
      }
1632
1650
      if (cur_p==null) { /* TODO */
1633
 
        confusion(maketexstring("linebreak_tail"));
 
1651
        tconfusion("linebreak_tail");
1634
1652
      }
1635
 
    /* Determine legal breaks: As we move through the hlist, we need to keep the |active_width|
1636
 
         array up to date, so that the badness of individual lines is readily calculated by
1637
 
         |try_break|. It is convenient to use the short name |act_width| for the component of
1638
 
         active width that represents real width as opposed to glue. */
 
1653
    /* Determine legal breaks: As we move through the hlist, we need to keep
 
1654
       the |active_width| array up to date, so that the badness of individual
 
1655
       lines is readily calculated by |try_break|. It is convenient to use the
 
1656
       short name |act_width| for the component of active width that represents
 
1657
       real width as opposed to glue. */
1639
1658
 
1640
1659
      switch (type(cur_p)) {
1641
1660
 
1679
1698
        /* @<If node |cur_p| is a legal breakpoint, call |try_break|;
1680
1699
           then update the active widths by including the glue in
1681
1700
           |glue_ptr(cur_p)|@>; */
1682
 
        /* When node |cur_p| is a glue node, we look at |prev_p| to
 
1701
        /* When node |cur_p| is a glue node, we look at the previous to
1683
1702
           see whether or not a breakpoint is legal at |cur_p|, as
1684
1703
           explained above. */
1685
1704
        if (auto_breaking) {
1686
 
          if (is_char_node(prev_p) ||
 
1705
          halfword prev_p = alink(cur_p);
 
1706
          if (prev_p!=temp_head &&
 
1707
             (is_char_node(prev_p) ||
1687
1708
              precedes_break(prev_p)|| 
1688
 
              ((type(prev_p)==kern_node)&&(subtype(prev_p)!=explicit))) {
 
1709
              ((type(prev_p)==kern_node)&&(subtype(prev_p)!=explicit)))) {
1689
1710
            ext_try_break(0,unhyphenated_node, pdf_adjust_spacing, par_shape_ptr, 
1690
1711
                          adj_demerits, tracing_paragraphs, pdf_protrude_chars,
1691
1712
                          line_penalty, last_line_fit,  double_hyphen_demerits,  
1718
1739
          int actual_penalty = hyphen_penalty;
1719
1740
          if (subtype(cur_p)==automatic_disc) 
1720
1741
            actual_penalty = ex_hyphen_penalty;
1721
 
          s=vlink(pre_break(cur_p));
 
1742
          s=vlink_pre_break(cur_p);
1722
1743
          do_one_seven_eight(reset_disc_width);
1723
1744
          if (s==null) { /* trivial pre-break */
1724
1745
            ext_try_break(actual_penalty,hyphenated_node, pdf_adjust_spacing, 
1760
1781
                  disc_width[1] += width(s);
1761
1782
                  break;
1762
1783
                case disc_node:
1763
 
                  confusion(maketexstring("pre_break_disc"));
 
1784
                  tconfusion("pre_break_disc");
 
1785
                  break;
1764
1786
                default:
1765
 
                  confusion(maketexstring("disc3"));
 
1787
                  tconfusion("disc3");
1766
1788
                } 
1767
1789
              }
1768
1790
              /* /Add the width of node |s| to |disc_width| */
1772
1794
            ext_try_break(actual_penalty,hyphenated_node, pdf_adjust_spacing, 
1773
1795
                          par_shape_ptr, adj_demerits, tracing_paragraphs, 
1774
1796
                          pdf_protrude_chars, line_penalty, last_line_fit,  
1775
 
                          double_hyphen_demerits,  final_hyphen_demerits,first_p,cur_p);
 
1797
                          double_hyphen_demerits, final_hyphen_demerits,
 
1798
                          first_p,cur_p);
1776
1799
            do_one_seven_eight(sub_disc_width_from_active_width);
1777
1800
          }
1778
 
          s=vlink(no_break(cur_p));
 
1801
#define FOO 1
 
1802
#if FOO
 
1803
#if 0
 
1804
          if (vlink(cur_p)!=null) nest_stack[nest_index++] = vlink(cur_p);
 
1805
          cur_p = no_break(cur_p);
 
1806
#else
 
1807
          s=vlink_no_break(cur_p);
1779
1808
          while (s!=null) { 
1780
1809
            /* @<Add the width of node |s| to |act_width|@>;*/
1781
1810
            if (is_char_node(s)) { 
1815
1844
                s = no_break(s);
1816
1845
                break;
1817
1846
              default: 
1818
 
                confusion(maketexstring("disc5"));
 
1847
                tconfusion("disc5");
1819
1848
              }
1820
1849
            }
1821
1850
            /* /Add the width of node |s| to |act_width|;*/
1822
1851
            s=vlink(s);
1823
1852
          }
 
1853
#endif
1824
1854
        } else { /* first pass, just take the no_break path */
1825
 
          s=vlink(no_break(cur_p));
 
1855
#else /* FOO */
 
1856
        }
 
1857
#endif /* FOO */
 
1858
#if 0
 
1859
        if (vlink_no_break(cur_p)!=null) {
 
1860
          if (vlink(cur_p)!=null) nest_stack[nest_index++] = vlink(cur_p);
 
1861
                  /*          fprintf(stderr,"Node Push %d [%d]->[%d] / [%d]\n",(nest_index-1),(int)cur_p,(int)vlink(cur_p),(int)vlink_no_break(cur_p));*/
 
1862
          cur_p = no_break(cur_p);
 
1863
        }
 
1864
#else
 
1865
          s=vlink_no_break(cur_p);
1826
1866
          while (s!=null) { 
1827
1867
            /* @<Add the width of node |s| to |act_width|@>;*/
1828
1868
            if (is_char_node(s)) { 
1860
1900
                s = no_break(s);
1861
1901
                break;
1862
1902
              default: 
1863
 
                confusion(maketexstring("disc4"));
 
1903
                tconfusion("disc4");
1864
1904
              }
1865
1905
            }
1866
1906
            /* /Add the width of node |s| to |act_width|;*/
1867
1907
            s=vlink(s);
1868
1908
          }
 
1909
#endif
 
1910
#if FOO
1869
1911
        }
 
1912
#endif /* FOO */
1870
1913
        break;
1871
1914
      case math_node: 
1872
1915
        auto_breaking=(subtype(cur_p)==after); 
1887
1930
        break;
1888
1931
      default: 
1889
1932
        fprintf(stdout, "\ntype=%d",type(cur_p));
1890
 
        confusion(maketexstring("paragraph")) ;
 
1933
        tconfusion("paragraph") ;
1891
1934
      }
1892
 
      prev_p=cur_p; 
1893
1935
      cur_p=vlink(cur_p); 
 
1936
      while (cur_p==null && nest_index>0) {
 
1937
        cur_p = nest_stack[--nest_index];
 
1938
                /*        fprintf(stderr,"Node Pop  %d [%d]\n",nest_index,(int)cur_p);*/
 
1939
      }
1894
1940
    }
1895
1941
    if (cur_p==null) {
1896
1942
      /* Try the final line break at the end of the paragraph,
1968
2014
 
1969
2015
    if (!second_pass)  { 
1970
2016
      if (tracing_paragraphs>0) 
1971
 
        print_nl(maketexstring("@secondpass"));
 
2017
        tprint_nl("@secondpass");
1972
2018
      threshold=tolerance; 
1973
2019
      second_pass=true; 
1974
2020
      final_pass=(emergency_stretch<=0);
1975
2021
    }  else {  /* if at first you do not succeed, \dots */
1976
2022
      if (tracing_paragraphs>0)
1977
 
        print_nl(maketexstring("@emergencypass"));
 
2023
        tprint_nl("@emergencypass");
1978
2024
      background[2] += emergency_stretch; 
1979
2025
      final_pass=true;
1980
2026
    }
2037
2083
  /* /Break the paragraph at the chosen... */
2038
2084
  /* Clean up the memory by removing the break nodes; */
2039
2085
  clean_up_the_memory();
2040
 
  /* /Clean up the memory by removing the break nodes; */
 
2086
  /*
 
2087
        flush_node_list(dir_ptr);
 
2088
        dir_ptr=null;
 
2089
  */
2041
2090
}
2042
2091
 
2043
2092