%constinteger trace in length = 23
%constinteger tbuffs = 511

%externalroutinespec connect file(%string(255) file, %integer zero,
                                  %integername s, l)

%recordformat trace fm(%integer context, inout, %string(55) text)
%recordformat tbuff fm(%integer q,
                       %record(trace fm)%array t(0 : tbuffs),
                       %integer p)
%constinteger trace in  = 0
%constinteger trace out = 1

%begin
   %record(tbuff fm)%name tbuff
   %record(trace fm)%name t
   %integer s, l, i, context
   %string(127) command = ""
      %on 9 %start;  %stop;  %finish
      connect file("$:TRACE", 0, s, l)
      tbuff == record(s)
      ! printstring("Pointer p at ");  write(tbuff_p, 0);  newline
      ! printstring("Pointer q at ");  write(tbuff_q, 0);  newline
      prompt("Context: ");  read(context)
      %for i = tbuff_p, 1, tbuffs + tbuff_q %cycle
         t == tbuff_t(i & tbuffs)
         %if t_context = context %start
            %if t_inout = trace in %start
               %if command # "" %start
                  spaces(trace in length - length(command))
                  printstring(command)
                  printstring(" / *** No reply ***")
                  newline
               %finish
               command = t_text
            %else
               command = "..." %if command = ""
               spaces(trace in length - length(command))
               printstring(command)
               printstring(" / ")
               printstring(t_text)
               newline
               command = ""
            %finish
         %finish
      %repeat
      %if command # "" %start
         spaces(trace in length - length(command))
         printstring(command)
         printstring(" / *** No reply ***")
         newline
      %finish
%end %of %program
