home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPUHEAD.ZIP / TPUHEAD.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-06-04  |  8.5 KB  |  273 lines

  1. { =============================================================================
  2.  
  3.                                TPUHEAD
  4.  
  5.   A program to copy the HEADER (everything from the top through the
  6.   IMPLEMENTATION) of a TP4 Unit into a separate file for reference
  7.   purposes.
  8.  
  9.   TPUHead accepts standard wildcards (*,?) when specifying the files
  10.   to process as well as drive & path.
  11.  
  12.                   e.g.,  TPUHEAD d:\tpufiles\*.pas
  13.  
  14.   Each file meeting the user criteria is evaluated.  It is determined
  15.   to be a valid TP4 unit if the keywords UNIT, INTERFACE, & IMPLEMENTATION
  16.   are found, in order, and within the first 10 charcters on a line.  This
  17.   was necessary since I often put in comments which would otherwise cause
  18.   TPUHEAD to think the file was a unit when in fact it was not.
  19.  
  20.   Further, only files which have not been processed, or those which need
  21.   to have updates are processed.  The trigger is date matching between the
  22.   TPUHEAD output file  ".TOP" & the source.  When a .TOP file is created,
  23.   it is date stamped exactly as the source.  Thus, if a source file is
  24.   later updated (getting a new update date), TPUHEAD can identify it as
  25.   needing updating.  Otherwise, it is skipped.
  26.  
  27.   By the way, the .TOP file is given the same filename as the source.  The
  28.   file extent becomes ".TOP".
  29.  
  30.   As files are processed, the output filename is shown on the screen.  You
  31.   may find this strange  ( e.g.,  "type SOURCE.TOP >> %1").  Actually, it
  32.   is done to minimize steps necessary to later concat all output files
  33.   into a single file.  Why?  I use WordPerfect.  Once I have the single
  34.   file created, I go into WP, search for "== END" and start a new page.
  35.   Then I build a Table of Contents & an Index (using my own concordance
  36.   generator ... look for it soon).  When finished, I have a notebook with
  37.   all unit interface sections.  No more looking for files & trying to read
  38.   them online, or digging for the full print out to find what functions &
  39.   procedures are there and how to call them.
  40.  
  41.   If you notice in the example given in the preceding paragraph, it shows
  42.   the output including the redirection symbol ">>".  For this to make sense,
  43.   the first output should also be redirected to a batch file;
  44.  
  45.                    e.g., TPUHEAD *.pas > headers.bat
  46.  
  47.   Then each of the "type .... >> %1" lines of output are directed into the
  48.   specified batch file.  When the batch file is run;
  49.  
  50.                    e.g., headers Headers.All
  51.  
  52.   The individual ".TOP" files are concatenated into HEADERS.ALL which can
  53.   then be used in your word processor.  (Of course, all the separate .TOP
  54.   files are still there.  Be sure to keep them if you want TPUHEAD to be
  55.   able to determine which files do/do not need updating.
  56.  
  57.   These techniques were possible by using TP4's FINDFIRST/FINDNEXT procs
  58.   along with the redefinition of the "standard" output.
  59.  
  60. ============================================================================= }
  61.  
  62. {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L- }
  63. {$M 16384,0,655360 }
  64.  
  65. program TPUHEAD;
  66.  
  67. uses DOS,CRT,qwik;
  68.  
  69. var
  70.   OneLine,
  71.   CmdLine,
  72.   PathName,
  73.   FileSource,
  74.   FileOut     : string;
  75.   FvarS,
  76.   FvarO       : text;
  77.   DosErr      : byte;
  78.   InBuffer    : array[1..512] of char;
  79.   SourceTime,
  80.   OutputTime  : longint;
  81.   FileRec     : SearchRec;
  82.  
  83. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  84.  
  85. function UpperCase(St : string):string;
  86. var
  87.   i : integer;
  88. begin
  89.   if length(St) > 1 then
  90.   begin
  91.     for i := 1 to length(St) do St[i] := upcase(St[i]);
  92.   end;
  93.   UpperCase := St;
  94. end; { function }
  95.  
  96. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  97.  
  98. function GetCmdLine:boolean;
  99. begin
  100.   if paramcount > 0 then
  101.   begin
  102.     CmdLine := uppercase(paramstr(1));
  103.     GetCmdLine := true;
  104.   end    { if paramcount > 0 }
  105.   else GetCmdLine := false;
  106. end; { proc }
  107.  
  108. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  109.  
  110. procedure SetFileNames;
  111. var i : byte;
  112. begin
  113.   i := pos('.',FileSource);
  114.   if i < 1 then
  115.   begin
  116.     FileOut := FileSource + '.TOP';
  117.   end
  118.   else FileOut := copy(FileSource,1,i) + 'TOP';
  119. end; { proc }
  120.  
  121. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  122.  
  123. procedure ProcessSource;
  124. var
  125.   i,
  126.   Counter : byte;
  127.   Skip    : boolean;
  128. begin
  129.   { set up source & get its date/time }
  130.   Assign(FvarS,FileSource);
  131.   Reset (FvarS);
  132.   SetTextBuf(FvarS,InBuffer);
  133.   SourceTime := FileRec.Time;
  134.  
  135.   { verify source is a unit by looking for UNIT, INTERFACE, &   }
  136.   { IMPLEMENTATION.  Keywords are expected to appear w/in the   }
  137.   { first 10 characters of a line & must appear in order.       }
  138.   OneLine := '';
  139.   Counter := 0;
  140.   while (Counter < 3) and (not EoF(FvarS)) do
  141.   begin
  142.     readln(FvarS,OneLine);
  143.     case Counter of
  144.       0 : begin
  145.             i := pos('UNIT',uppercase(OneLine));
  146.             if (i > 0) AND (i < 10)                { found UNIT }
  147.             then Counter := 1;
  148.           end;
  149.       1 : begin
  150.             i := pos('INTERFACE',uppercase(OneLine));
  151.             if (i > 0) and (i < 10)
  152.             then Counter := 2;
  153.           end;
  154.       2 : begin
  155.             i := pos('IMPLEMENTATION',uppercase(OneLine));
  156.             if (i > 0) and (i < 10)
  157.             then Counter := 3;
  158.           end;
  159.     end; { case }
  160.   end; { while do }
  161.   Close(FvarS);
  162.  
  163.   if Counter < 3 then
  164.   begin
  165.     { not a unit }
  166.     Exit;
  167.   end;
  168.  
  169.   Assign(FvarO,FileOut);
  170.   {$I-}
  171.   Reset(FvarO);
  172.   Close(FvarO);
  173.   {$I+}
  174.   if (IOresult = 0) then
  175.   begin
  176.     { If output date/time >= source date/time, then no need to    }
  177.     { recreate (output date/time is set = to source when created. }
  178.     GetFTime(FvarO,OutputTime);
  179.     if OutputTime >= SourceTime then Skip := true;
  180.   end
  181.   else Skip := false;
  182.  
  183.   if not Skip then
  184.   begin
  185.     writeln(Output,'type ',FileOut,' >> %1');
  186.     OneLine := '';
  187.     Reset(FvarS);                 { reset source for processing }
  188.     Assign(FvarO,FileOut);
  189.     ReWrite(FvarO);                    { set output for writing }
  190.  
  191.     writeln(FvarO,'{=====  START of ',FileSource,'  =====}');
  192.     while (not Eof(FvarS))
  193.     and   (pos('IMPLEMENTATION',UpperCase(OneLine)) < 1) do
  194.     begin
  195.       writeln(FvarO,OneLine);
  196.       readln(FvarS,OneLine);
  197.     end; { while .. do }
  198.     writeln(FvarO,'{=====   END  of ',FileSource,'  =====}');
  199.  
  200.     Close(FvarS);
  201.     Close(FvarO);
  202.     Reset(FvarO);                     { adjust output date/time }
  203.     SetFTime(FvarO,SourceTime);       { to equal source         }
  204.     Close(FvarO);
  205.   end; {if not skip}
  206. end; { proc }
  207.  
  208. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  209. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  210. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  211. (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  212.  
  213. begin
  214.   clrscr;
  215.   CmdLine := '';
  216.  
  217.   { allow redirection of screen output to user file via DOS }
  218.   { redirection; e.g.,  TPUINTFC *.pas > tpu.log            }
  219.   assign(Output,'');
  220.   rewrite(Output);
  221.  
  222.   { Read command line for file to process  }
  223.   { Output file will be filename.INT       }
  224.   if not GetCmdLine then
  225.   begin
  226.     writeln('       TPUHEAD - the TPU documentation creator');
  227.     writeln;
  228.     writeln('syntax:');
  229.     writeln('         TPUHEAD d:\path\filename.ext [> output.bat]');
  230.     writeln;
  231.     writeln('Each source file will be processed into a ".TOP" file.');
  232.     writeln('Only TP4 UNIT files will be processed. Only files which');
  233.     writeln('need processing will be included.  No need for you to');
  234.     writeln('try to weed out programs from units or ones previously');
  235.     writeln('done from those needing to be done.');
  236.     writeln;
  237.     writeln('Screen output may be redirected to a batch file for later');
  238.     writeln('use in concatenating all headers into a single file for');
  239.     writeln('yet more processing.');
  240.     writeln;
  241.     writeln('Released for NON-PROFIT use only!');
  242.     writeln('(c) 1988 by Robert W. Reed  (407) 695-6837');
  243.     writeln;
  244.     halt(1);
  245.   end;
  246.  
  247.   { Get first file to process              }
  248.   PathName := CmdLine;
  249.   {$I-}
  250.   FindFirst(PathName,$20,FileRec);
  251.   {$I+}
  252.   DosErr := DOSError;
  253.   if DosErr > 0 then
  254.   begin
  255.     writeln(Output,'Source directory or file not found!');
  256.     halt;
  257.   end;
  258.  
  259.   { Process each file until no more left }
  260.   while DosErr = 0 do
  261.   begin
  262.     FileSource := FileRec.Name;
  263.     SetFileNames;
  264.     if  (length(FileSource) > 0) then ProcessSource;
  265.  
  266.     {$I-}
  267.     FindNext(FileRec);
  268.     {$I+}
  269.     DosErr := DOSError;
  270.   end; { while doserr do }
  271.   Close(Output);
  272. end.
  273.