home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOPAS / CROSSREF.ARK / CR-M03.INC < prev    next >
Text File  |  1987-04-18  |  6KB  |  138 lines

  1. {.pa}
  2. {************************* procedure PrintTree ******************************}
  3.  
  4. procedure PrintTree (var Tree       :TreePointer;
  5.                      var TableFile  :text;
  6.                      var Status     :Info;
  7.                      var SourceName,
  8.                          TableName  :NameType    );
  9.  
  10. { This procedure writes the table of identifiers along with a list of
  11.   appropriate line numbers to a text file specified by the user. }
  12.  
  13. const
  14.    WNumber        = 4;                  { max. width of line number }
  15.    MaxWidthOfPage = 80;                 { max. width of page }
  16.  
  17. var
  18.    I             :integer;              { loop index }
  19.    LNumber,                             { line number }
  20.    TotalPerLine,                        { total number of items per line }
  21.    Sp            :Index;                { spaces to skip identifier field }
  22.    Screen        :text;                 { screen output }
  23.  
  24.    {***************************** procedure DeQueue *************************}
  25.  
  26.    procedure DeQueue (var Entry   :EntryType;
  27.                       var LNumber :Index     );
  28.  
  29.    { This procedure will take a line number from the queue. }
  30.  
  31.    begin
  32.       if Entry.Head <> nil then
  33.          begin
  34.             LNumber := Entry.Head^.LineNumber;
  35.             Entry.Head := Entry.Head^.Next
  36.          end
  37.    end;  { procedure DeQueue }
  38.  
  39.    {************************** procedure VisitAndPrint **********************}
  40.  
  41.    procedure VisitAndPrint (Tree :TreePointer);
  42.  
  43.    { This procedure will print the identifier & its line numbers. }
  44.  
  45.    var
  46.       NumberPerIdent,                        { line numbers per identifier }
  47.       PreviousLNumber,                       { previous line number }
  48.       ItemsPerLine    :Index;                { counter of numbers per line }
  49.  
  50.    begin
  51.       NumberPerIdent := 0;
  52.       PreviousLNumber := 0;
  53.       ItemsPerLine := 0;                     { 1st index of table }
  54.  
  55.       with Tree^ do
  56.          begin
  57.             write(TableFile,Entry.Ident:0,'    ');
  58.             while Entry.Head <> nil do
  59.                begin
  60.                   DeQueue (Entry,LNumber);   { get a LNumber }
  61.                   NumberPerIdent := NumberPerIdent + 1;  { count all idents }
  62.                   if PreviousLNumber <> LNumber then     { no duplicate line }
  63.                      begin                               { numbers allowed }
  64.                         ItemsPerLine := ItemsPerLine + 1;
  65.                         PreviousLNumber := LNumber;
  66.                         if ItemsPerLine <= TotalPerLine then
  67.                            write(TableFile,LNumber:WNumber,' ':WNumber-1)
  68.                         else
  69.                            begin
  70.                               ItemsPerLine := 1;
  71.                               writeln(TableFile);
  72.                               write(TableFile,' ':Sp,LNumber:WNumber,' ':WNumber-1)
  73.                            end
  74.                      end
  75.                end;
  76.             writeln(TableFile);        { carriage return remaining numbers }
  77.             if NumberPerIdent > Status.MostUsedNumber then
  78.                begin
  79.                   Status.MostUsedNumber := NumberPerIdent;
  80.                   Status.MostUsedIdent  := Entry.Ident
  81.                end
  82.             else
  83.                if NumberPerIdent <= Status.LeastUsedNumber then
  84.                   begin
  85.                      Status.LeastUsedNumber := NumberPerIdent;
  86.                      Status.LeastUsedIdent  := Entry.Ident
  87.                   end
  88.          end  { with Tree^ }
  89.    end;  { procedure VisitAndPrint }
  90.  
  91.    {*************************** procedure TraverseLNR ************************}
  92.  
  93.    procedure TraverseLNR (Tree :TreePointer);
  94.  
  95.    { This procedure will visit each node of the tree & print its contents by
  96.      using the LNR method. }
  97.  
  98.    begin
  99.       if Tree <> nil then
  100.          begin
  101.             TraverseLNR (Tree^.Left);
  102.             VisitAndPrint (Tree);
  103.             TraverseLNR (Tree^.Right);
  104.          end
  105.    end;  { procedure TraverseLNR }
  106.  
  107. {*************************** procedure PrintTree ****************************}
  108.  
  109. begin
  110.    Sp := MaxIdentLength + 4;                            { indenting space }
  111.    TotalPerLine := (MaxWidthOfPage-MaxIdentLength - 4)  { compute numbers }
  112.                     div (WNumber * 2);                  { per line }
  113.    assign (Screen,'con:');
  114.    reset  (Screen);
  115.    writeln(TableFile);
  116.    writeln(TableFile,'Cross Reference Table of ',SourceName:0);
  117.    writeln(TableFile);
  118.    for I := 1 to 12 do
  119.       begin                                { clear frame }
  120.          gotoxy(1,I+2); ClrEol;
  121.       end;   { for }
  122.    gotoxy(1,13); write('Writing Table to ',TableName,'':25);
  123.    TraverseLNR (Tree);                     { write identifiers }
  124.    writeln(TableFile);
  125.    writeln(TableFile);
  126.    write  (TableFile,'=====================================' );
  127.    writeln(TableFile,'======================================');
  128.    writeln(TableFile);
  129.    writeln(TableFile,'Analysis of ',SourceName);
  130.    writeln(TableFile);
  131.    DisplayStatus (Status,TableFile);       { write status of source file }
  132.    close(TableFile);
  133.    gotoxy(1,13); clreol;
  134.    gotoxy(1,3); writeln('Analysis of ',SourceName); writeln;
  135.    DisplayStatus (Status,Screen);          { display status of source file }
  136.    release(Tree);
  137. end;  { procedure PrintTree }
  138.