Debian Codegraph @

texk/web2c/showstream.ch

raw
1 % $Id: showstream.ch 72043 2024-08-16 14:43:28Z ascherer $
2 % Implementation of |\showstream|.
3 % Public domain. Originally written by Marcel Kr\"uger, 2021.
4
5 Since we redirect content which is normally written to the terminal/log
6 to a write stream, print_nl will sometimes get called while selector is a write
7 stream. Therefore we adapt print_nl to handle that case properly.
8 @x
9 procedure print_nl(@!s:str_number); {prints string |s| at beginning of line}
10 begin if ((term_offset>0)and(odd(selector)))or@|
11 ((file_offset>0)and(selector>=log_only)) then print_ln;
12 print(s);
13 end;
14 @y
15 procedure print_nl(@!s:str_number); {prints string |s| at beginning of line}
16 begin if (selector<no_print)or((term_offset>0)and(odd(selector)))or@|
17 ((file_offset>0)and(selector>=log_only)) then print_ln;
18 print(s);
19 end;
20 @z
21
22 Add a integer parameter
23 @x
24 @d web2c_int_pars=web2c_int_base+5 {total number of web2c's integer parameters}
25 @#
26 @y
27 @d show_stream_code=web2c_int_base+5 {stream to output xray commands to}
28 @d web2c_int_pars=web2c_int_base+6 {total number of web2c's integer parameters}
29 @#
30 @z
31
32 @x
33 @d partoken_context==int_par(partoken_context_code)
34 @y
35 @d partoken_context==int_par(partoken_context_code)
36 @d show_stream==int_par(show_stream_code)
37 @z
38
39 @x
40 partoken_context_code:print_esc("partokencontext");
41 @y
42 partoken_context_code:print_esc("partokencontext");
43 show_stream_code:print_esc("showstream");
44 @z
45
46 @x
47 primitive("partokencontext",assign_int,int_base+partoken_context_code);@/
48 @!@:partoken_context_}{\.{\\partokencontext} primitive@>
49 @y
50 primitive("partokencontext",assign_int,int_base+partoken_context_code);@/
51 @!@:partoken_context_}{\.{\\partokencontext} primitive@>
52 primitive("showstream",assign_int,int_base+show_stream_code);@/
53 @!@:show_stream_}{\.{\\showstream} primitive@>
54 @z
55
56 Then assign a default value since it's not the normal 0.
57 @x Part of the integer section of @<Initialize table entries...@>=, the integer section
58 del_code("."):=0; {this null delimiter is used in error recovery}
59 @y
60 del_code("."):=0; {this null delimiter is used in error recovery}
61 show_stream:=-1;
62 @z
63
64 Then do the actual change: In all cases of |show_whatever| we adjust the selector
65 if |show_stream| is set. We don't need any changes
66 to |begin/end_diagnostic| since they don't do anything interesting if
67 |selector| isn't |term_and_log|.
68
69 For |show_lists_code| this is done directly in |show_whatever|:
70 @x
71 show_lists_code: begin begin_diagnostic; show_activities;
72 end;
73 @y
74 show_lists_code:
75 begin @<Adjust |selector| based on |show_stream|@>@;
76 begin_diagnostic; show_activities;
77 end;
78 @z
79
80 The ending gets skipped if we changed the selector,
81 but we have to reset the |selector| based on the current interaction setting.
82 @x
83 @<Complete a potentially long \.{\\show} command@>;
84 common_ending: if interaction<error_stop_mode then
85 begin help0; decr(error_count);
86 end
87 else if tracing_online>0 then
88 begin@t@>@;@/
89 help3("This isn't an error message; I'm just \showing something.")@/
90 ("Type `I\show...' to show more (e.g., \show\cs,")@/
91 ("\showthe\count10, \showbox255, \showlists).");
92 end
93 else begin@t@>@;@/
94 help5("This isn't an error message; I'm just \showing something.")@/
95 ("Type `I\show...' to show more (e.g., \show\cs,")@/
96 ("\showthe\count10, \showbox255, \showlists).")@/
97 ("And type `I\tracingonline=1\show...' to show boxes and")@/
98 ("lists on your terminal as well as in the transcript file.");
99 end;
100 error;
101 end;
102 @y
103 @<Complete a potentially long \.{\\show} command@>;
104 common_ending: if selector<no_print then
105 begin print_ln;
106 @<Initialize the print |selector| based on |interaction|@>;
107 if log_opened then selector:=selector+2;
108 end
109 else begin if interaction<error_stop_mode then
110 begin help0; decr(error_count);
111 end
112 else if tracing_online>0 then
113 begin@t@>@;@/
114 help3("This isn't an error message; I'm just \showing something.")@/
115 ("Type `I\show...' to show more (e.g., \show\cs,")@/
116 ("\showthe\count10, \showbox255, \showlists).");
117 end
118 else begin@t@>@;@/
119 help5("This isn't an error message; I'm just \showing something.")@/
120 ("Type `I\show...' to show more (e.g., \show\cs,")@/
121 ("\showthe\count10, \showbox255, \showlists).")@/
122 ("And type `I\tracingonline=1\show...' to show boxes and")@/
123 ("lists on your terminal as well as in the transcript file.");
124 end;
125 error;
126 end;
127 end;
128 @z
129
130 While the other cases have separate blocks
131 @x
132 @ @<Show the current meaning of a token...@>=
133 begin get_token;
134 @y
135 @ @<Show the current meaning of a token...@>=
136 begin get_token;
137 @<Adjust |selector| based on |show_stream|@>@;
138 @z
139
140 @x
141 @ @<Show the current contents of a box@>=
142 begin scan_register_num; fetch_box(p); begin_diagnostic;
143 @y
144 @ @<Show the current contents of a box@>=
145 begin scan_register_num; fetch_box(p);
146 @<Adjust |selector| based on |show_stream|@>@;
147 begin_diagnostic;
148 @z
149
150 @x
151 @ @<Show the current value of some parameter...@>=
152 begin p:=the_toks;
153 @y
154 @ @<Show the current value of some parameter...@>=
155 begin p:=the_toks;
156 @<Adjust |selector| based on |show_stream|@>@;
157 @z
158
159 @x
160 show_groups: begin begin_diagnostic; show_save_groups;
161 @y
162 show_groups: begin @<Adjust |selector| based on |show_stream|@>@;
163 begin_diagnostic; show_save_groups;
164 @z
165
166 @x
167 show_ifs: begin begin_diagnostic; print_nl(""); print_ln;
168 @y
169 show_ifs: begin @<Adjust |selector| based on |show_stream|@>@;
170 begin_diagnostic; print_nl(""); print_ln;
171 @z
172
173 @x
174 @* \[55] Index.
175 @y
176 @ @<Adjust |selector| based on |show_stream|@>=
177 if (show_stream>=0) and (show_stream<no_print) and write_open[show_stream] then
178 selector:=show_stream;
179
180 @* \[55] Index.
181 @z