
                                        San Jos, August 1st, 1987



Power User
PC Magazine
One Park Avenue
New York, NY 10016

Gentlemen:

I'd  like  to submit my contribution to your column.  This one  is 
dandy to debug selectively parts or your Turbo program.

Debugging always requires one to look  at many  variable contents, 
and this can be done only using write statements (unless of course 
you get a symbolic debugger).  My  is problem  comes after  I have 
debugged the program, and it's time to get  rid of  all superflous 
write statements. Oftentimes I delete one too many lines, and wind 
up with a bigger mess I started with.

My solution is a partial one: instead of deleting lines, what I do 
is  to  hide  them  using appropiate  IF statements,  as shown  in 
Figure-1.  The set variable trace contains all the trace points in 
the  program.   Note  that  as  a  bonus it  is posible  to define 
synchronized writes: two or more writes that are either hidden  or 
alive altogether.   As an  IF statement  takes any  condition, the 
opportunity is there to use really complex debugging logic.

To enable a debugging write statement, just include  in trace  the 
corresponding trace element.  To disable it, remove it from trace. 
Caveat emptor: be carefull not to over do it, or you might wind up 
debugging the debugging trace statements!

I should write sometime a program to get rid of all the statements 
that belong to a debug block. I'll do that sometime in the future. 
In the mean time, I delete all those  blocks by  hand at  the very 
end of programming, when doing it will not side track my mine from 
the program's logic.

Sincerely;




                        ------------------
                          Adolfo Di Mare
                         Apdo 4249, 1000
                       San Jos, Costa Rica
                         CENTRAL AMERICA
.pa
The program:

program useTrace (input,output);
{ Shows how to trace a program }
const
   Blank = ' ';
   Dot   = '.';
type
   StrT = string[255];
   CharS = set of char;
   TraceE = (    { this is the trace vector type             }
      Tsk,       { prints input and output strins in skipper }
      Tskndx     { traces skipper char by char               }
   );
   TraceS = set of TraceE;
var
   s:  StrT;
   cs: CharS;
   trace : TraceS;

procedure tracer;   { to define all needed trace values }
begin {tracer}
trace := [Tsk];
trace := [Tsk,Tskndx];  { reorder these 3 to see }
trace := [];            { how trace behaves      }
end; {tracer}

function skipper(
   var l: StrT; cset: CharS; skipOnEqual: boolean): StrT;
{ If skipOnEqual is true, then skip the first characters in }
{ l that belong to set c, and return this shorter string.   }
{ Otherwise it skips the ones not in set cset.              }
var
   quit: boolean;
   i: integer;
begin {skipper}
if Tsk in trace then begin
   writeln; write('before:',l,':');
end;
quit := false;  i := 0;
while (i < length(l)) and not quit do begin
   if ((l[i+1] in cset) and skipOnEqual) or
      (not (l[i+1] in cset) and not skipOnEqual) then begin
      if (Tskndx in trace) and (Tsk in trace) then write('^');
      i := i+1
   end
   else
      quit := true;
end;
skipper := copy(l, i+1, length(l)-i);
if Tsk in trace then begin
   writeln;
   writeln('after-:', copy(l, i+1, length(l)-i),':');
end;
end; {skipper}

begin {useTrace}
tracer;
s  :=  Dot+Dot+Blank+ 'Dot+Dot+Blank+Me';
cs :=  [Blank,Dot];

writeln('true->', ':',s,':', skipper(s,cs,true ),':');  writeln;
writeln('false>', ':',s,':', skipper(s,cs,false),':');
end. {useTrace}




Program output for different trace settings:

No trace at all:
true->:.. Dot+Dot+Blank+Me:Dot+Dot+Blank+Me:

false>:.. Dot+Dot+Blank+Me:.. Dot+Dot+Blank+Me:


Tsk trace on only:
true->:.. Dot+Dot+Blank+Me:
before:.. Dot+Dot+Blank+Me:
after-:Dot+Dot+Blank+Me:
Dot+Dot+Blank+Me:

false>:.. Dot+Dot+Blank+Me:
before:.. Dot+Dot+Blank+Me:
after-:.. Dot+Dot+Blank+Me:
.. Dot+Dot+Blank+Me:


Tsk and Tskndx on:
true->:.. Dot+Dot+Blank+Me:
before:.. Dot+Dot+Blank+Me:^^^
after-:Dot+Dot+Blank+Me:
Dot+Dot+Blank+Me:

false>:.. Dot+Dot+Blank+Me:
before:.. Dot+Dot+Blank+Me:
after-:.. Dot+Dot+Blank+Me:
.. Dot+Dot+Blank+Me:
