CXX peace: src/troff/input.cpp
[s-roff.git] / tmac / trace.tmac
blobfd36201ebc59b8478c52c4395ec132e76f17aa27
1 .\"@ trace.tmac.
2 .\"@ Load this before a macro package that you want to trace.
3 .\"
4 .\" Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
5 .\"
6 .\" Copyright (C) 1989 - 1992, 2000, 2002 - 2004, 2006 - 2008
7 .\"   Free Software Foundation, Inc.
8 .\"      Written by James Clark (jjc@jclark.com)
9 .\"
10 .\" This is free software; you can redistribute it and/or modify it under
11 .\" the terms of the GNU General Public License as published by the Free
12 .\" Software Foundation; either version 2, or (at your option) any later
13 .\" version.
14 .\"
15 .\" This is distributed in the hope that it will be useful, but WITHOUT ANY
16 .\" WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 .\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18 .\" for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public License along
21 .\" with groff; see the file COPYING.  If not, write to the Free Software
22 .\" Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
23 .\"
26 .\" Tracing within groff means replacing the original macros or requests
27 .\" with special versions which act as wrappers to emit tracing information.
28 .\" A natural consequence of creating such wrappers is that arguments must
29 .\" be expanded once more.  In most cases it doesn't matter, however,
30 .\" sometimes it makes a difference.
31 .\"
32 .\" To limit side effects, only macros are traced by default, together
33 .\" with some requests like `.return' which don't take (user) arguments.
34 .\" If you want more tracing, especially of number and string register
35 .\" assignments, add the `-r trace-full=1' command line option.
38 .\" Regarding the usage of `.do': All lines of macros which should
39 .\" work in compatibility mode must be protected if they contain
40 .\" GNU troff extensions and are defined with `.de'.  Example: `.ds',
41 .\" but not `.ds1', since the latter can't be called in compatibility
42 .\" mode.
45 .do if d !!!sp \
46 .  nx
48 .nr _C \n(.C
49 .cp 0
51 .ds !!!sp " \"
53 .de !!c
57 .eo
59 .rn return !!return
61 .de1 return
62 .  tm1 "\*[!!!sp]*** return
63 .  !!return twice
66 .ec
68 .ie r trace-full \{\
69 .  eo
71 .  rn nr !!nr
73 .  de nr
74 .    do ecs
75 .    ec
76 .    do !!nr \$*
77 .    do tm1 "\*[!!!sp]*** .nr \$* (-> \n[\$1])
78 .    do ecr
79 .  .
81 .  rn ds !!ds
82 .  rn ds1 !!ds1
83 .  rn as !!as
84 .  rn as1 !!as1
86 .  de ds
87 .    do ecs
88 .    ec
89 .    do tm1 "\*[!!!sp]*** .ds \$^
90 .    do !!ds \$^\"
91 .    do ecr
92 .  .
94 .  de1 ds1
95 .    ecs
96 .    ec
97 .    tm1 "\*[!!!sp]*** .ds1 \$^
98 .    !!ds1 \$^\"
99 .    ecr
100 .  .
102 .  de as
103 .    do ecs
104 .    ec
105 .    do tm1 "\*[!!!sp]*** .as \$^
106 .    do !!as \$^\"
107 .    do ecr
108 .  .
110 .  de1 as1
111 .    ecs
112 .    ec
113 .    tm1 "\*[!!!sp]*** .as1 \$^
114 .    !!as1 \$^\"
115 .    ecr
116 .  .
118 .  rn substring !!substring
120 .  de1 substring
121 .    ecs
122 .    ec
123 .    !!substring \$*
124 .    tm1 "\*[!!!sp]*** .substring \$* (-> `\*[\$1]')
125 .    ecr
126 .  .
128 .  rn so !!so
130 .  de so
131 .    do ecs
132 .    ec
133 .    do tm1 "\*[!!!sp]*** .so \$* {
134 .    do !!as !!!sp " \"
135 .    do ecr
136 .    do !!so \$*
137 .    do ecs
138 .    ec
139 .    do !!substring !!!sp 1
140 .    do tm1 "\*[!!!sp]*** }
141 .    do ecr
142 .  .
144 .  !!c We must use `.de' for the redefinition of .mso to avoid
145 .  !!c side effects; for example, it might be called with
146 .  !!c `.do mso ...'.
148 .  rn mso !!mso
150 .  de mso
151 .    do ecs
152 .    ec
153 .    do tm1 "\*[!!!sp]*** .mso \$* {
154 .    do !!as !!!sp " \"
155 .    do ecr
156 .    do !!mso \$*
157 .    do ecs
158 .    ec
159 .    do !!substring !!!sp 1
160 .    do tm1 "\*[!!!sp]*** }
161 .    do ecr
162 .  .
164 .  ec
166 .el \{\
167 .  als !!ds ds
168 .  als !!as as
169 .  als !!substring substring
175 .rn als !!als
177 .de1 als
178 .  ecs
179 .  ec
180 .  !!als \$*
181 .  if d !!\$2 \
182 .    !!als !!\$1 !!\$2
183 .  tm1 "\*[!!!sp]*** .als \$*
184 .  ecr
187 .rn rm !!rm
189 .de1 rm
190 .  ecs
191 .  ec
192 .  !!rm \$*
193 .  if d !!\$1 \
194 .    !!rm !!\$1
195 .  tm1 "\*[!!!sp]*** .rm \$*
196 .  ecr
199 .rn rn !!rn
201 .de rn
202 .  do ecs
203 .  ec
204 .  do !!rn \$*
205 .  do if d !!\$1 \
206 .    !!rn !!\$1 !!\$2
207 .  do tm1 "\*[!!!sp]*** .rn \$*
208 .  do ecr
211 .!!c Now the central tracing macros.  The redefined `de' macros
212 .!!c create wrapper macros `foo' which emit tracing messages
213 .!!c before and after the call to the traced macro `!!foo'.
214 .!!c
215 .!!c Note that we define `!!foo' in advance so that an alias to
216 .!!c `!!!!foo' is possible.  The latter occurs if `foo' is
217 .!!c called as \\[foo].
218 .!!c
219 .!!c The call to `dei' must be the last instruction in the macro
220 .!!c (since it continues the definition of the macro to trace).
222 .!!rn de !!de
223 .!!rn de1 !!de1
225 .!!de de
226 .  do ecs
227 .  ec
228 .  do !!de \$1
229 .    do ie \\n[.br] .do !!ds !!!br .\"
230 .    el             .do !!ds !!!br '\"
231 .    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** de trace enter: \\*[!!!br]\\$0 \\$@
232 .    el            .do tm1 "\\*[!!!sp]*** de trace enter \$1: \\*[!!!br]\\$0 \\$@
233 .    do !!as !!!sp " \"
235 .    do nop \\*[!!\\$0]\\
237 .    do !!substring !!!sp 1
238 .    do ie \\n[.br] .do !!ds !!!br .\"
239 .    el             .do !!ds !!!br '\"
240 .    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
241 .    el            .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
244 .  do tm1 "\*[!!!sp]*** .de \$*
246 .  do !!ds !!d1 !!\$1\"
247 .  do !!ds !!d2 \$2\"
248 .  do ecr
249 .  do dei !!d1 !!d2
252 .!!de1 de1
253 .  ecs
254 .  ec
255 .  !!de1 \$1
256 .    ie \\n[.br] .!!ds !!!br .\"
257 .    el          .!!ds !!!br '\"
258 .    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** de1 trace enter: \\*[!!!br]\\$0 \\$@
259 .    el            .tm1 "\\*[!!!sp]*** de1 trace enter \$1: \\*[!!!br]\\$0 \\$@
260 .    !!as !!!sp " \"
262 .    nop \\*[!!\\$0]\\
264 .    !!substring !!!sp 1
265 .    ie \\n[.br] .!!ds !!!br .\"
266 .    el          .!!ds !!!br '\"
267 .    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
268 .    el            .tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
271 .  tm1 "\*[!!!sp]*** .de1 \$*
273 .  !!ds !!d1 !!\$1\"
274 .  !!ds !!d2 \$2\"
275 .  ecr
276 .  dei1 !!d1 !!d2
279 .!!rn am !!am
280 .!!rn am1 !!am1
282 .!!de am
283 .  do ecs
284 .  ec
285 .  do !!de \$1
286 .    do ie \\n[.br] .do !!ds !!!br .\"
287 .    el             .do !!ds !!!br '\"
288 .    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** am trace enter: \\*[!!!br]\\$0 \\$@
289 .    el            .do tm1 "\\*[!!!sp]*** am trace enter \$1: \\*[!!!br]\\$0 \\$@
290 .    do !!as !!!sp " \"
292 .    do nop \\*[!!\\$0]\\
294 .    do !!substring !!!sp 1
295 .    do ie \\n[.br] .do !!ds !!!br .\"
296 .    el             .do !!ds !!!br '\"
297 .    ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
298 .    el            .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
301 .  do tm1 "\*[!!!sp]*** .am \$*
303 .  do !!ds !!a1 !!\$1\"
304 .  do !!ds !!a2 \$2\"
305 .  do ecr
306 .  do ami !!a1 !!a2
309 .!!de1 am1
310 .  ecs
311 .  ec
312 .  !!de1 \$1
313 .    ie \\n[.br] .!!ds !!!br .\"
314 .    el          .!!ds !!!br '\"
315 .    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** am1 trace enter: \\*[!!!br]\\$0 \\$@
316 .    el            .tm1 "\\*[!!!sp]*** am1 trace enter \$1: \\*[!!!br]\\$0 \\$@
317 .    !!as !!!sp " \"
319 .    nop \\*[!!\\$0]\\
321 .    !!substring !!!sp 1
322 .    ie \\n[.br] .!!ds !!!br .\"
323 .    el          .!!ds !!!br '\"
324 .    ie "\$1"\\$0" .tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
325 .    el            .tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
328 .  tm1 "\*[!!!sp]*** .am1 \$*
330 .  !!ds !!a1 !!\$1\"
331 .  !!ds !!a2 \$2\"
332 .  ecr
333 .  ami1 !!a1 !!a2
339 .cp \n(_C
341 .\" s-ts-mode