$OpenBSD: patch-texk_web2c_xetexdir_xetex-new_ch,v 1.1.1.1 2007/07/17 21:53:33 jasper Exp $
--- texk/web2c/xetexdir/xetex-new.ch.orig	Wed Jan  3 16:25:04 2007
+++ texk/web2c/xetexdir/xetex-new.ch	Fri Jun 22 10:51:56 2007
@@ -56,7 +56,7 @@
 
 @d XeTeX_version=0
 @d XeTeX_revision==".996"
-@d XeTeX_version_string=='-0.996' {current \XeTeX\ version}
+@d XeTeX_version_string=='-0.996-patch1' {current \XeTeX\ version}
 @z
 
 @x
@@ -706,29 +706,28 @@ if max_quarterword-min_quarterword<@"FFFF then bad:=19
 
 To support ``native'' fonts, we build |native_word_nodes|, which are variable size whatsits.
 These have the same |width|, |depth|, and |height| fields as a |box_node|, at offsets 1-3,
-and then a word containing a size field for the node, a font number, and a length.
-Then there is a field containing two halfwords, a glyph count and a C pointer to a glyph info array;
-these are set by |set_native_metrics|. Copying and freeing of these nodes needs to take account of this!
+and then a word containing a size field for the node, a font number, a length, and a glyph count.
+Then there is a field containing a C pointer to a glyph info array;
+this and the glyph count are set by |set_native_metrics|.
+Copying and freeing of these nodes needs to take account of this!
 This is followed by |length| bytes, for the actual characters of the string.
 (Yes, we count in bytes, even though what we store there is UTF-16.)
 
 So |native_node_size|, which does not include any space for the actual text, is 6.}
 
-@d deleted_native_node=41 {native words that have been superseded by their successors}
-
 @d native_node_size=6 {size of a native_word node (plus the actual chars) -- see also xetex.h}
-@d native_size(#)==mem[#+4].hh.b0
-@d native_font(#)==mem[#+4].hh.b1
-@d native_length(#)==mem[#+4].hh.rh
-@d native_glyph_count(#)==mem[#+5].hh.lh
-@d native_glyph_info_ptr(#)==mem[#+5].hh.rh
+@d native_size(#)==mem[#+4].qqqq.b0
+@d native_font(#)==mem[#+4].qqqq.b1
+@d native_length(#)==mem[#+4].qqqq.b2
+@d native_glyph_count(#)==mem[#+4].qqqq.b3
+@d native_glyph_info_ptr(#)==mem[#+5].ptr
 @d native_glyph_info_size=10 { number of bytes of info per glyph: 16-bit glyph ID, 32-bit x and y coords }
 
 @d free_native_glyph_info(#) ==
   begin
-    if native_glyph_info_ptr(#) <> 0 then begin
-      libc_free(cast_to_ptr(native_glyph_info_ptr(#)));
-      native_glyph_info_ptr(#) := 0;
+    if native_glyph_info_ptr(#) <> null_ptr then begin
+      libc_free(native_glyph_info_ptr(#));
+      native_glyph_info_ptr(#) := null_ptr;
       native_glyph_count(#) := 0;
     end
   end
@@ -736,10 +735,10 @@ So |native_node_size|, which does not include any spac
 @p procedure copy_native_glyph_info(src:pointer; dest:pointer);
 var glyph_count:integer;
 begin
-  if native_glyph_info_ptr(src) <> 0 then begin
+  if native_glyph_info_ptr(src) <> null_ptr then begin
     glyph_count := native_glyph_count(src);
-    native_glyph_info_ptr(dest) := cast_to_integer(xmalloc_array(char, glyph_count * native_glyph_info_size));
-    memcpy(cast_to_ptr(native_glyph_info_ptr(dest)), cast_to_ptr(native_glyph_info_ptr(src)), glyph_count * native_glyph_info_size);
+    native_glyph_info_ptr(dest) := xmalloc_array(char, glyph_count * native_glyph_info_size);
+    memcpy(native_glyph_info_ptr(dest), native_glyph_info_ptr(src), glyph_count * native_glyph_info_size);
     native_glyph_count(dest) := glyph_count;
   end
 end;
@@ -2936,8 +2935,7 @@ done:
 end
 
 @ @<Advance |q| past ignorable nodes@>=
-while (q <> null) and (not is_char_node(q))
-  and ( (type(q) = disc_node) or ((type(q) = whatsit_node) and (subtype(q) = deleted_native_node)) ) do
+while (q <> null) and (not is_char_node(q)) and (type(q) = disc_node) do
     q := link(q)
 
 @ We ought to give special care to the efficiency of one part of |hlist_out|,
@@ -3293,7 +3291,6 @@ label done,done1,done2,done3,done4,done5,done6,continu
     or (subtype(v)=pic_node)
     or (subtype(v)=pdf_node)
     then break_width[1]:=break_width[1]-width(v)
-	else if subtype(v)=deleted_native_node then do_nothing
 	else confusion("disc1a");
   othercases confusion("disc1")
 @z
@@ -3307,7 +3304,6 @@ label done,done1,done2,done3,done4,done5,done6,continu
     or (subtype(s)=pic_node)
     or (subtype(s)=pdf_node)
     then break_width[1]:=break_width[1]+width(s)
-	else if subtype(s)=deleted_native_node then do_nothing
 	else confusion("disc2a");
   othercases confusion("disc2")
 @z
@@ -3327,7 +3323,6 @@ label done,done1,done2,done3,done4,done5,done6,continu
     or (subtype(s)=pic_node)
     or (subtype(s)=pdf_node)
     then disc_width:=disc_width+width(s)
-	else if subtype(s)=deleted_native_node then do_nothing
 	else confusion("disc3a");
   othercases confusion("disc3")
 @z
@@ -3341,7 +3336,6 @@ label done,done1,done2,done3,done4,done5,done6,continu
     or (subtype(s)=pic_node)
     or (subtype(s)=pdf_node)
     then act_width:=act_width+width(s)
-	else if subtype(s)=deleted_native_node then do_nothing
 	else confusion("disc4a");
   othercases confusion("disc4")
 @z
@@ -3784,7 +3778,7 @@ hmode+char_num: begin scan_usv_num; cur_chr:=cur_val; 
 @!main_p:pointer; {temporary register for list manipulation}
 @y
 @!main_p:pointer; {temporary register for list manipulation}
-@!main_pp:pointer; {another temporary register for list manipulation}
+@!main_pp,@!main_ppp:pointer; {more temporary registers for list manipulation}
 @!main_h:pointer; {temp for hyphen offset in native-font text}
 @!is_hyph:boolean; {whether the last char seen is the font's hyphenchar}
 @z
@@ -3859,11 +3853,22 @@ collect_native:
 
 	if mode=hmode then begin
 
+		main_ppp := head;
+		if main_ppp<>main_pp then
+			while (link(main_ppp)<>main_pp) do
+				main_ppp:=link(main_ppp);	{ find node preceding tail }
+
 		temp_ptr := str_start_macro(str_ptr);
 		repeat
 			if main_h = 0 then main_h := main_k;
 
-			if (not is_char_node(main_pp)) and (type(main_pp)=whatsit_node) and (subtype(main_pp)=native_word_node) and (native_font(main_pp)=main_f) then begin
+			if (not is_char_node(main_pp))
+				and (type(main_pp)=whatsit_node)
+				and (subtype(main_pp)=native_word_node)
+				and (native_font(main_pp)=main_f)
+				and (main_ppp<>main_pp)
+				and type(main_ppp)<>disc_node
+			then begin
 
 				{ make a new temp string that contains the concatenated text of |tail| + the current word/fragment }
 				main_k := main_h + native_length(main_pp);
@@ -3888,9 +3893,13 @@ collect_native:
 				do incr(main_h);	{ look for next hyphen or end of text }
 				if (main_h < main_k) then incr(main_h);
 
-				{ flag the previous node as no longer valid }
-				free_native_glyph_info(main_pp);
-				subtype(main_pp) := deleted_native_node;
+				{ remove the preceding node from the list }
+				link(main_ppp) := link(main_pp);
+				link(main_pp) := null;
+				flush_node_list(main_pp);
+				main_pp := tail;
+				while (link(main_ppp)<>main_pp) do
+					main_ppp:=link(main_ppp);
 
 			end else begin
 
@@ -3929,9 +3938,14 @@ collect_native:
 				set_native_char(tail, main_p + native_length(main_pp), str_pool[str_start_macro(str_ptr) + main_p]);
 			set_native_metrics(tail, XeTeX_use_glyph_metrics);
 
-			{ flag the previous node as no longer valid }
-			free_native_glyph_info(main_pp);
-			subtype(main_pp) := deleted_native_node;
+			{ remove the preceding node from the list }
+			main_p := head;
+			if main_p<>main_pp then
+				while link(main_p)<>main_pp do
+					main_p := link(main_p);
+			link(main_p) := link(main_pp);
+			link(main_pp) := null;
+			flush_node_list(main_pp);
 		end else begin
 			{ package the current string into a |native_word| whatsit }
 			link(main_pp) := new_native_word_node(main_f, main_k);
@@ -3997,7 +4011,6 @@ begin if tail<>head then
 @y
     if type(p)<>kern_node then if type(p)<>ligature_node then
 	if (type(p)<>whatsit_node) or ((subtype(p)<>native_word_node)
-									 and (subtype(p)<>deleted_native_node)
 									 and (subtype(p)<>glyph_node)) then
       begin print_err("Improper discretionary list");
 @z
@@ -4802,8 +4815,10 @@ native_word_node:begin
 	print_char(" ");
 	print_native_word(p);
   end;
+@{
 deleted_native_node:
 	print("[DELETED]");
+@}
 glyph_node:begin
     print_esc(font_id_text(native_font(p)));
     print(" glyph#");
@@ -4837,12 +4852,9 @@ native_word_node: begin words:=native_size(p);
   r:=get_node(words);
   while words > 0 do
     begin decr(words); mem[r+words]:=mem[p+words]; end;
-  native_glyph_info_ptr(r):=0; native_glyph_count(r):=0;
+  native_glyph_info_ptr(r):=null_ptr; native_glyph_count(r):=0;
   copy_native_glyph_info(p, r);
   end;
-deleted_native_node: begin words:=native_size(p);
-  r:=get_node(words);
-  end;
 glyph_node: begin r:=get_node(glyph_node_size);
   words:=glyph_node_size;
   end;
@@ -4858,7 +4870,6 @@ othercases confusion("ext2")
 othercases confusion("ext3")
 @y
 native_word_node: begin free_native_glyph_info(p); free_node(p,native_size(p)); end;
-deleted_native_node: free_node(p,native_size(p));
 glyph_node: free_node(p,glyph_node_size);
 pic_node,pdf_node: free_node(p,total_pic_node_size(p));
 pdf_save_pos_node:
@@ -5106,7 +5117,7 @@ begin
 			dvi_two(native_glyph(p));
 			cur_h := cur_h + width(p);
 		end else begin
-			if native_glyph_info_ptr(p) <> 0 then begin
+			if native_glyph_info_ptr(p) <> null_ptr then begin
 				len := make_xdv_glyph_array_data(p);
 				for k := 0 to len-1 do
 					dvi_out(xdv_buffer_byte(k));
@@ -5231,7 +5242,7 @@ end;
 @x
 language_node:do_nothing;
 @y
-language_node,deleted_native_node:do_nothing;
+language_node:do_nothing;
 @z
 
 @x
@@ -6012,6 +6023,11 @@ whatsit_node:
     goto next_p;
 
 @ Here we compute the effective width of a glue node as in |hlist_out|.
+
+@<Cases of |reverse|...@>=
+glue_node: begin round_glue;
+  @<Handle a glue node for mixed...@>;
+  end;
 @z
 
 @x
@@ -6106,7 +6122,7 @@ begin
 	native_length(q) := n;
 
 	native_glyph_count(q) := 0;
-	native_glyph_info_ptr(q) := 0;
+	native_glyph_info_ptr(q) := null_ptr;
 
 	new_native_word_node := q;
 end;
@@ -6163,7 +6179,7 @@ begin
 		
 		native_size(p) := native_node_size + 1;
 		native_glyph_count(p) := 0;
-		native_glyph_info_ptr(p) := 0;
+		native_glyph_info_ptr(p) := null_ptr;
 		native_font(p) := f;
 
 		if c > @"FFFF then begin
