%:skip
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF  
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
% NONINFRINGEMENT. IN NO EVENT SHALL SIL INTERNATIONAL BE LIABLE FOR  
% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
%
% Except as contained in this notice, the name of SIL International  
% shall not be used in advertising or otherwise to promote the sale,  
% use or other dealings in this Software without prior written  
% authorization from SIL International.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%+tracing-codes
%:
% There is nothing special that says the tracing code has to be a single character.
% It is also better to have more identifiers than less to allow for more targetted tracing.
% Trace identifiers allocated in ptx macros:
%
% | Identifier | Trace
% |------------|------
% | a | all traces
% | A | Attributes 
% | b | balancing (info for external page break analysis)
% | B | underfull pages
% | C | cutouts
% | c | Chapters 
% | ch | Active characters
% | cov | covers
% | d | diglot construction
% | dP | diglot Page use
% | D | Diglot gory details
% | De | Diglot repetative commands (each@col)
% | Df | Diglot footnote separation
% | Dh | Diglot availht extra details
% | Ds | Diglot stylesheet
% | dm | Diglot module
% | dmp | Diglot module: polyglot
% | e | Extended(sidebar)
% | eg | Sidebar gridding 
% | eb | Extended borders
% | ebi | Border style inheritance
% | eh | sidebar-headings
% | et | textborders
% | f | footnotes (output)
% | fp | footnote reparagraphing
% | F | fonts
% | Fe | font effects
% | g | figures
% | G | Shipping pages
% | gI | figure inserts - tracking saving / restoring of inserts
% | h | headings
% | hv | hanging verses
% | H | Headers, marks, etc
% | i | inserts (tracking the value of holdinginserts)
% | I | ifchecks
% | j | paragraph adjustments
% | m | milestones
% | mx | milestones: expand content
% | M | markers
% | ma | mark accounting
% | n | notes creation/save/restore
% | nS | note saving / restoring
% | o | output routines / rebalancing
% | oh | other(not stylesheet) hooks
% | orn | ornaments
% | p | page output
% | pt | Page tabs
% | P | Piclists
% | per | periph handling
% | s | stylesheet
% | sa | stylesheet additional debugging
% | sb | stylesheet boxed character styles
% | spv | stylesheet parameter lookups that return void
% | ss | style start/stop
% | sP | Stylesheet everypar/chapter 
% | sc | Stylesheet category
% | sC | Stylesheet Cache
% | sh | Stylesheet-related hooks
% | sk| Style stacK  and option stack operations
% | sko |  Style stack option-list building
% | S | side-dependent swapping 
% | t | Tables and table of contents
% | T | Triggers
% | u | 'Unprintable' pages (e.g. triggered images  don't fit)
% | V | verse numbers
% | v | marginal verses
% | x | Processes run at exit
%-tracing-codes

%+tracing
% Now modified so that multiple \tracing{} commands can be issued.
\newcount\TRACEcount %Numbered tracing for is useful for diglot. May be for something else too.
\def\y@s{y}
\def\tracing#1{\x@\xdef\csname tr@cemode-#1\endcsname{\y@s}\let\trace=\tr@cer}%
\def\untracing#1{\x@\xdef\csname tr@cemode-#1\endcsname{}}%
\def\notr@cer#1#2{\relax}%
\def\tr@cer#1#2{%
    \x@\ifx\csname tr@cemode-#1\endcsname\y@s \let\TRnext=\tr@ceout
    \else
      \x@\ifx\csname tr@cemode-a\endcsname\y@s \let\TRnext=\tr@ceout
      \else
        \let\TRnext=\notr@ceout
      \fi
    \fi
    \TRnext{#1}{#2}}%
\def\tr@ceout#1#2{%
    \immediate\write-1{#1> #2}}%
\def\traceNum#1#2{\global\advance\TRACEcount by 1\trace{#1}{+\the\TRACEcount: #2}}
\def\notr@ceout#1#2{\relax}%
\let\trace=\notr@cer
\def\IfTr@ce#1#2{\x@\ifx\csname tr@cemode-#1\endcsname\y@s #2\fi}
%-tracing

%+tracing-support
\def\pagetracing{0}
\def\tc@mmands{commands,pages,output,macros,paragraphs,ifs,restores}
\def\s@vens@ttrace#1{\x@\xdef\csname tracing-#1\endcsname{\csname #1\endcsname}\csname #1\endcsname=1}
\def\r@storetrace#1{\csname #1\endcsname=\csname tracing-#1\endcsname}
\def\alltrace#1{\ifnum#1>0\let\wh@t=\s@vens@ttrace\else\let\wh@t=\r@storetrace\fi\x@\pr@cessSp@cific \tc@mmands,\E}

\def\traceifset#1{\trace{I}{Ifset: #1=\the\currentiflevel}\x@\xdef\csname checkif@#1\endcsname{\the\currentiflevel}}
\def\traceifcheck#1{\xdef\tr@ceiflevel{\the\currentiflevel}\trace{I}{Ifcheck: #1 \tr@ceiflevel==\csname checkif@#1\endcsname}\x@\ifnum\csname checkif@#1\endcsname=\tr@ceiflevel\else
    \message{IF CHECK #1 Failed. Entered at \csname checkif@#1\endcsname \space != exit at \tr@ceiflevel}\fi}
% verbose tracing on/off macros to help with fault isolation
\def\ztmon{\tracingassigns=1 \tracingmacros=1}
\def\ztmoff{\tracingassigns=0 \tracingmacros=0}
\def\ztvalon{\tracinggroups=1 \tracingassigns=1 \tracingrestores=1}
\def\ztvaloff{\tracinggroups=0 \tracingassigns=0 \tracingrestores=0}
%-tracing-support
