texlive[60992] Build/source/texk/web2c: new cross-engine primitive

commits+karl at tug.org commits+karl at tug.org
Sun Nov 7 23:51:08 CET 2021


Revision: 60992
          http://tug.org/svn/texlive?view=revision&revision=60992
Author:   karl
Date:     2021-11-07 23:51:07 +0100 (Sun, 07 Nov 2021)
Log Message:
-----------
new cross-engine primitive \showstream, from Marcel

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/ChangeLog
    trunk/Build/source/texk/web2c/Makefile.in
    trunk/Build/source/texk/web2c/NEWS
    trunk/Build/source/texk/web2c/enctexdir/enctex-pdftex.ch
    trunk/Build/source/texk/web2c/eptexdir/am/eptex.am
    trunk/Build/source/texk/web2c/euptexdir/am/euptex.am
    trunk/Build/source/texk/web2c/luatexdir/tex/commands.c
    trunk/Build/source/texk/web2c/luatexdir/tex/equivalents.h
    trunk/Build/source/texk/web2c/luatexdir/tex/mainbody.c
    trunk/Build/source/texk/web2c/luatexdir/tex/maincontrol.c
    trunk/Build/source/texk/web2c/pdftexdir/am/pdftex.am
    trunk/Build/source/texk/web2c/xetexdir/am/xetex.am

Added Paths:
-----------
    trunk/Build/source/texk/web2c/showstream.ch

Modified: trunk/Build/source/texk/web2c/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/ChangeLog	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/ChangeLog	2021-11-07 22:51:07 UTC (rev 60992)
@@ -1,3 +1,22 @@
+2021-11-07  Marcel Kr\"uger  <tex at 2krueger.de>
+
+	* showstream.ch: new primitive \showstream.
+	* NEWS: mention this.
+
+	* eptexdir/am/eptex.am (eptex_web_srcs),
+	* euptexdir/am/euptex.am (euptex_web_srcs),
+	* pdftexdir/am/pdftex.am (pdftex_ch_srcs),
+	* xetexdir/am/xetex.am (xetex_ch_srcs): include showstream.ch.
+
+	* enctexdir/enctex-pdftex.ch: rearrange constants.
+	
+	* luatexdir/tex/commands.c (initialize_etex_commands): primitive_etex.
+	* luatexdir/tex/equivalents.h (show_stream_code, show_stream_par):
+	new #define.
+	(math_option_code): increment.
+	* luatexdir/tex/mainbody.c (main_initialize): show_stream_par=-1.
+	* luatexdir/tex/maincontrol.c (show_whatever): implement \showstream.
+
 2021-11-03  Karl Berry  <karl at freefriends.org>
 
 	* am/texmf.am (install-mf-links) [WIN32]: install via libtool,

Modified: trunk/Build/source/texk/web2c/Makefile.in
===================================================================
--- trunk/Build/source/texk/web2c/Makefile.in	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/Makefile.in	2021-11-07 22:51:07 UTC (rev 60992)
@@ -4434,6 +4434,7 @@
 	tex.ch \
 	tracingstacklevels.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	etexdir/tex.ech
 
@@ -4546,6 +4547,7 @@
 	tex.ch \
 	tracingstacklevels.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	etexdir/tex.ech
 
@@ -4665,6 +4667,7 @@
 	tracingstacklevels.ch \
 	partoken-102.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	enctexdir/enctex1.ch \
 	enctexdir/enctex-pdftex.ch \
@@ -5359,6 +5362,7 @@
 	tracingstacklevels.ch \
 	partoken-102.ch \
 	partoken.ch \
+	showstream.ch \
 	$(xetex_ch_synctex) \
 	xetexdir/xetex.ch \
 	$(xetex_post_ch_synctex) \

Modified: trunk/Build/source/texk/web2c/NEWS
===================================================================
--- trunk/Build/source/texk/web2c/NEWS	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/NEWS	2021-11-07 22:51:07 UTC (rev 60992)
@@ -1,12 +1,13 @@
 This file records noteworthy changes.  (Public domain.)
 
-* for all engines except original TeX:
+* for all engines except original (e)TeX:
+- new primitive \showstream to redirect \show output to a file.
 - new primitives \partokenname and \partokencontext allow overriding the
   name of the internally-emitted \par token at blank lines, the end of
   vboxes, etc.
 
 

-2021 (for TeX Live 2021, 23 March 2021)
+2021 (for TeX Live 2021, 23 March (e)2021)
 * Knuth 2021 tune-up, with fixes to all of his *.web files. Overview:
 https://tug.org/TUGboat/42-1/tb130knuth-tuneup21.pdf
 New TeX version is 3.141592653, MF 2.71828182.

Modified: trunk/Build/source/texk/web2c/enctexdir/enctex-pdftex.ch
===================================================================
--- trunk/Build/source/texk/web2c/enctexdir/enctex-pdftex.ch	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/enctexdir/enctex-pdftex.ch	2021-11-07 22:51:07 UTC (rev 60992)
@@ -1,16 +1,16 @@
 % $Id$
 % enctex1.ch is applied first.
 % Then this change is applied for pdfTeX et al.,
-% assuming that tracingstacklevels.ch plus partoken.ch has been included,
+% assuming that tracingstacklevels.ch, partoken.ch, and showstream.ch has been included,
 % as specified in the *.am files.
 
 % encTeX: \mubytein \mubyteout \mubytelog and \specialout
 @x [17.236] l.4954
- at d web2c_int_pars=web2c_int_base+5 {total number of web2c's integer parameters}
+ at d web2c_int_pars=web2c_int_base+6 {total number of web2c's integer parameters}
 @y
- at d mubyte_in_code=web2c_int_base+5{if positive then reading mubytes is active}
- at d mubyte_out_code=web2c_int_base+6{if positive then printing mubytes is active}
- at d mubyte_log_code=web2c_int_base+7{if positive then print mubytes to log and terminal}
- at d spec_out_code=web2c_int_base+8 {if positive then print specials by mubytes}
- at d web2c_int_pars=web2c_int_base+9 {total number of web2c's integer parameters}
+ at d mubyte_in_code=web2c_int_base+6{if positive then reading mubytes is active}
+ at d mubyte_out_code=web2c_int_base+7{if positive then printing mubytes is active}
+ at d mubyte_log_code=web2c_int_base+8{if positive then print mubytes to log and terminal}
+ at d spec_out_code=web2c_int_base+9 {if positive then print specials by mubytes}
+ at d web2c_int_pars=web2c_int_base+10 {total number of web2c's integer parameters}
 @z

Modified: trunk/Build/source/texk/web2c/eptexdir/am/eptex.am
===================================================================
--- trunk/Build/source/texk/web2c/eptexdir/am/eptex.am	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/eptexdir/am/eptex.am	2021-11-07 22:51:07 UTC (rev 60992)
@@ -56,6 +56,7 @@
 	tex.ch \
 	tracingstacklevels.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	etexdir/tex.ech
 

Modified: trunk/Build/source/texk/web2c/euptexdir/am/euptex.am
===================================================================
--- trunk/Build/source/texk/web2c/euptexdir/am/euptex.am	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/euptexdir/am/euptex.am	2021-11-07 22:51:07 UTC (rev 60992)
@@ -52,6 +52,7 @@
 	tex.ch \
 	tracingstacklevels.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	etexdir/tex.ech
 

Modified: trunk/Build/source/texk/web2c/luatexdir/tex/commands.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/tex/commands.c	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/luatexdir/tex/commands.c	2021-11-07 22:51:07 UTC (rev 60992)
@@ -818,6 +818,15 @@
     primitive_luatex("shapemode", assign_int_cmd, int_base + shape_mode_code, int_base);
     primitive_luatex("hyphenationbounds", assign_int_cmd, int_base + hyphenation_bounds_code, int_base);
 
+    /*tex
+
+        The \.{\\showstream} parameter allows to redirect the output of xray_cmd
+        commands to any write stream.
+
+    */
+
+    primitive_tex("showstream", assign_int_cmd, int_base + show_stream_code, int_base);
+
     primitive_etex("showgroups", xray_cmd, show_groups, 0);
 
     /*tex

Modified: trunk/Build/source/texk/web2c/luatexdir/tex/equivalents.h
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/tex/equivalents.h	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/luatexdir/tex/equivalents.h	2021-11-07 22:51:07 UTC (rev 60992)
@@ -312,8 +312,10 @@
 #  define math_defaults_mode_code 119                                   /* > 0 : latex preferences */
 #  define discretionary_ligature_mode_code 120
 
-#  define math_option_code 121
+#  define show_stream_code 121
 
+#  define math_option_code 122
+
 #  define mathoption_int_base_code (math_option_code+1)                 /* one reserve */
 #  define mathoption_int_last_code (mathoption_int_base_code+8)
 
@@ -816,6 +818,8 @@
 #define math_defaults_mode_par             int_par(math_defaults_mode_code)
 #define discretionary_ligature_mode_par    int_par(discretionary_ligature_mode_code)
 
+#define show_stream_par                    int_par(show_stream_code)
+
 /* */
 
 #define math_use_current_family_code 7

Modified: trunk/Build/source/texk/web2c/luatexdir/tex/mainbody.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/tex/mainbody.c	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/luatexdir/tex/mainbody.c	2021-11-07 22:51:07 UTC (rev 60992)
@@ -441,6 +441,7 @@
         memset(eqtb, 0, sizeof(memory_word) * (unsigned) (eqtb_top + 1));
         init_string_pool_array((unsigned) max_strings);
         reset_cur_string();
+        show_stream_par = -1;
     }
     /*tex
         Check the ``constant'' values...

Modified: trunk/Build/source/texk/web2c/luatexdir/tex/maincontrol.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/tex/maincontrol.c	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/luatexdir/tex/maincontrol.c	2021-11-07 22:51:07 UTC (rev 60992)
@@ -3968,6 +3968,10 @@
     int m;      /* upper bound on |fi_or_else| codes */
     int l;      /* line where that conditional began */
     int n;      /* level of \.{\\if...\\fi} nesting */
+    int saved_selector; /* previous selector. Must be distinct from the global err_old_setting. */
+    saved_selector = selector;
+    if (file_can_be_written(show_stream_par))
+        selector = show_stream_par;
     switch (cur_chr) {
     case show_lists:
         begin_diagnostic();
@@ -4062,6 +4066,10 @@
         }
     }
   COMMON_ENDING:
+    if (valid_write_file(selector)) {
+        selector = saved_selector;
+        return;
+    }
     if (interaction < error_stop_mode) {
         help0();
         decr(error_count);

Modified: trunk/Build/source/texk/web2c/pdftexdir/am/pdftex.am
===================================================================
--- trunk/Build/source/texk/web2c/pdftexdir/am/pdftex.am	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/pdftexdir/am/pdftex.am	2021-11-07 22:51:07 UTC (rev 60992)
@@ -73,6 +73,7 @@
 	tracingstacklevels.ch \
 	partoken-102.ch \
 	partoken.ch \
+	showstream.ch \
 	zlib-fmt.ch \
 	enctexdir/enctex1.ch \
 	enctexdir/enctex-pdftex.ch \

Added: trunk/Build/source/texk/web2c/showstream.ch
===================================================================
--- trunk/Build/source/texk/web2c/showstream.ch	                        (rev 0)
+++ trunk/Build/source/texk/web2c/showstream.ch	2021-11-07 22:51:07 UTC (rev 60992)
@@ -0,0 +1,135 @@
+Since we redirect content which is normally written to the terminal/log
+to a write stream, print_nl will sometimes get called while selector is a write
+stream. Therefore we adapt print_nl to handle that case properly.
+ at x
+procedure print_nl(@!s:str_number); {prints string |s| at beginning of line}
+begin if ((term_offset>0)and(odd(selector)))or@|
+  ((file_offset>0)and(selector>=log_only)) then print_ln;
+print(s);
+end;
+ at y
+procedure print_nl(@!s:str_number); {prints string |s| at beginning of line}
+begin if (selector<log_only)or((term_offset>0)and(odd(selector)))or@|
+  ((file_offset>0)and(selector>=log_only)) then print_ln;
+print(s);
+end;
+ at z
+
+Add a integer parameter
+ at x
+ at d web2c_int_pars=web2c_int_base+5 {total number of web2c's integer parameters}
+@#
+ at y
+ at d show_stream_code=web2c_int_base+5 {stream to output xray commands to}
+ at d web2c_int_pars=web2c_int_base+6 {total number of web2c's integer parameters}
+@#
+ at z
+
+ at x
+ at d partoken_context==int_par(partoken_context_code)
+ at y
+ at d partoken_context==int_par(partoken_context_code)
+ at d show_stream==int_par(show_stream_code)
+ at z
+
+ at x
+partoken_context_code:print_esc("partokencontext");
+ at y
+partoken_context_code:print_esc("partokencontext");
+show_stream_code:print_esc("showstream");
+ at z
+
+ at x
+  primitive("partokencontext",assign_int,int_base+partoken_context_code);@/
+@!@:partoken_context_}{\.{\\partokencontext} primitive@>
+ at y
+  primitive("partokencontext",assign_int,int_base+partoken_context_code);@/
+@!@:partoken_context_}{\.{\\partokencontext} primitive@>
+primitive("showstream",assign_int,int_base+show_stream_code);@/
+@!@:show_stream_}{\.{\\showstream} primitive@>
+ at z
+
+Then assign a default value since it's not the normal 0.
+ at x Part of the integer section of @<Initialize table entries...@>=, the integer section
+del_code("."):=0; {this null delimiter is used in error recovery}
+ at y
+del_code("."):=0; {this null delimiter is used in error recovery}
+show_stream:=-1;
+ at z
+
+Then do the actual change: In |show_whatever| we save the old selector
+and then replace it based on |show_stream|. We don't need any changes
+to |begin/end_diagnostic| since they don't do anything interesting if
+|selector| isn't |term_and_log|.
+ at x
+procedure show_whatever;
+label common_ending;
+var p:pointer; {tail of a token list to show}
+@!t:small_number; {type of conditional being shown}
+@!m:normal..or_code; {upper bound on |fi_or_else| codes}
+@!l:integer; {line where that conditional began}
+@!n:integer; {level of \.{\\if...\\fi} nesting}
+begin case cur_chr of
+ at y
+procedure show_whatever;
+label common_ending;
+var p:pointer; {tail of a token list to show}
+@!t:small_number; {type of conditional being shown}
+@!m:normal..or_code; {upper bound on |fi_or_else| codes}
+@!l:integer; {line where that conditional began}
+@!n:integer; {level of \.{\\if...\\fi} nesting}
+@!saved_selector:0..max_selector; {previous selector, separate from the global |old_setting|}
+begin saved_selector:=selector;
+if (show_stream>=0) and (show_stream<no_print) and write_open[show_stream] then
+  selector:=show_stream;
+case cur_chr of
+ at z
+
+The ending gets skipped if we changed the selector,
+but we have to restore |selector|.
+ at x
+@<Complete a potentially long \.{\\show} command@>;
+common_ending: if interaction<error_stop_mode then
+  begin help0; decr(error_count);
+  end
+else if tracing_online>0 then
+  begin at t@>@;@/
+  help3("This isn't an error message; I'm just \showing something.")@/
+  ("Type `I\show...' to show more (e.g., \show\cs,")@/
+  ("\showthe\count10, \showbox255, \showlists).");
+  end
+else  begin at t@>@;@/
+  help5("This isn't an error message; I'm just \showing something.")@/
+  ("Type `I\show...' to show more (e.g., \show\cs,")@/
+  ("\showthe\count10, \showbox255, \showlists).")@/
+  ("And type `I\tracingonline=1\show...' to show boxes and")@/
+  ("lists on your terminal as well as in the transcript file.");
+  end;
+error;
+end;
+ at y
+@<Complete a potentially long \.{\\show} command@>;
+common_ending: if selector<no_print then
+  begin print_ln;
+  selector:=saved_selector
+  end
+else begin if interaction<error_stop_mode then
+    begin help0; decr(error_count);
+    end
+  else if tracing_online>0 then
+    begin at t@>@;@/
+    help3("This isn't an error message; I'm just \showing something.")@/
+    ("Type `I\show...' to show more (e.g., \show\cs,")@/
+    ("\showthe\count10, \showbox255, \showlists).");
+    end
+  else  begin at t@>@;@/
+    help5("This isn't an error message; I'm just \showing something.")@/
+    ("Type `I\show...' to show more (e.g., \show\cs,")@/
+    ("\showthe\count10, \showbox255, \showlists).")@/
+    ("And type `I\tracingonline=1\show...' to show boxes and")@/
+    ("lists on your terminal as well as in the transcript file.");
+    end;
+  error;
+  end;
+end;
+ at z


Property changes on: trunk/Build/source/texk/web2c/showstream.ch
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Build/source/texk/web2c/xetexdir/am/xetex.am
===================================================================
--- trunk/Build/source/texk/web2c/xetexdir/am/xetex.am	2021-11-07 21:42:57 UTC (rev 60991)
+++ trunk/Build/source/texk/web2c/xetexdir/am/xetex.am	2021-11-07 22:51:07 UTC (rev 60992)
@@ -116,6 +116,7 @@
 	tracingstacklevels.ch \
 	partoken-102.ch \
 	partoken.ch \
+	showstream.ch \
 	$(xetex_ch_synctex) \
 	xetexdir/xetex.ch \
 	$(xetex_post_ch_synctex) \



More information about the tex-live-commits mailing list.