home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TBTREE.ZIP / TP4PRINT.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-07-27  |  5.8 KB  |  207 lines

  1. (* TBTree13             Copyright (c)  1988            Dean H. Farwell II    *)
  2.  
  3. (* Version Information
  4.  
  5.    Version 1.1 - No Changes
  6.  
  7.    Version 1.2 - No Changes
  8.  
  9.    Version 1.3 - The file creation date is now printed on every page as part
  10.                  of the header.                                              *)
  11.  
  12. {  This is a fast and dirty program to print out source code listings for
  13.     Turbo Pascal 4.0 listings.  It doesn't do anything too fancy.  It does
  14.     print out a header with the name of the file, the page number, and the
  15.     date and time the file was printed.  You can use the date and time to
  16.     determine if the file on disk was updated since the printout.  One other
  17.     attraction is that it counts lines will only print 59 lines on a page.
  18.     It also allows a forced new page command in the listings.  By placing
  19.     a (*\*) in the first 5 columns of any line of the list will for a new
  20.     page at that point.  The backslash in a comment symbol was chosen since
  21.     the compiler will treat it as a comment and will ignore it.  The program
  22.     uses myprint which is a unit containing a few control codes and
  23.     procedures to implement them.  Myprint was done for a Gemini 10
  24.     printer, so the procedures should work with Epson printers as well.
  25.     If you have a different printer, just make your own myprint unit
  26.     with codes which match your printer.  See myprint unit for details.
  27.  
  28.     Someday I may enhance this by adding more capabilities.
  29.  
  30.     My thanks to Jeff Flading who's ideas and efforts resulted in several
  31.     improvements.
  32.  
  33.     To print source code using this program just compile it and then thye
  34.     the following at the DOS prompt:
  35.  
  36.                      TP4Print  X:YYYY\YYYYYYY\ZZZZZZZZ.ZZZ
  37.  
  38.    where the X is the optional drive specifier, the Y's represent the
  39.    optional directory path info and ZZZZZZZZ.ZZZ represents the actual
  40.    program name including the extension.  The program does not assume
  41.    a defualt extension of PAS or anything else.  If the name has an
  42.    extension, it must be included.                                            }
  43.  
  44.  
  45. program TP4Print;
  46.  
  47. {$R+}
  48.  
  49. uses
  50.     myprint,
  51.     printer,
  52.     strings,
  53.     dos;
  54.  
  55. const
  56.     MAXLINES = 59;
  57.  
  58. var
  59.     sfile   : Text;
  60.     sFName  : String;
  61.     line    : String;
  62.     lineCnt : Byte;
  63.     pgCnt   : Byte;
  64.  
  65. (*\*)
  66. function GetFileToPrint(var fName : String) : Boolean;
  67.  
  68.     begin
  69.     if ParamCount < 1 then
  70.         begin
  71.         Writeln;
  72.         Writeln('To use this routine type the following at the DOS prompt :');
  73.         Writeln;
  74.         Writeln('   TP4Print  X:YYYY\YYYYYYY\ZZZZZZZZ.ZZZ');
  75.         Writeln;
  76.         Writeln('where the X is the optional drive specifier,');
  77.         Writeln('the Ys represent the optional directory path info and');
  78.         Write('ZZZZZZZZ.ZZZ represents the actual program name including ');
  79.         Writeln('the extension.');
  80.         Writeln;
  81.         Writeln;
  82.         GetFileToPrint := FALSE;
  83.         end
  84.     else
  85.         begin
  86.         fName := ParamStr(1);
  87.         GetFileToPrint := TRUE;
  88.         end;
  89.     end;                                    (* end of GetFileToPrint routine *)
  90.  
  91.  
  92. procedure Skip(x : Byte);
  93.  
  94. var
  95.     cnt : Byte;
  96.  
  97.     begin
  98.     for cnt := 1 to x do
  99.         begin
  100.         Writeln(lst);
  101.         end;
  102.     end;                                               (* end of Skip routine *)
  103.  
  104. (*\*)
  105. function ConvertString(x : Word) : String;
  106.  
  107. var
  108.     tempStr : String;
  109.  
  110.     begin
  111.     if x < 10 then
  112.         begin
  113.         Str(x:1,tempStr);
  114.         tempStr := '0' + tempStr;
  115.         end
  116.     else
  117.         begin
  118.         Str(x:2,tempStr);
  119.         end;
  120.     ConvertString := tempStr;
  121.     end;
  122.  
  123.  
  124. procedure PrintDateTime;
  125.  
  126. var
  127.     weekDay : String;
  128.     year,
  129.     month,
  130.     day,
  131.     dayOfWeek,
  132.     hour,
  133.     minute,
  134.     second,
  135.     sec100 : Word;
  136.     time : LongInt;
  137.     fileTime : DateTime;
  138.  
  139.     begin
  140.     GetDate(year,month,day,dayOfWeek);
  141.     GetTime(hour,minute,second,sec100);
  142.     case dayOfWeek of
  143.         0 : weekDay := 'Sunday';
  144.         1 : weekDay := 'Monday';
  145.         2 : weekDay := 'Tuesday';
  146.         3 : weekDay := 'Wednesday';
  147.         4 : weekDay := 'Thursday';
  148.         5 : weekDay := 'Friday';
  149.         6 : weekDay := 'Saturday';
  150.         end;                                        (* end of case statement *)
  151.     Write(lst,'Printed: ',weekDay,' ',month,'-',day,'-',year,
  152.           '      Time: ',ConvertString(hour),':',ConvertString(minute));
  153.     GetFTime(sFile,time);
  154.     UnpackTime(time,fileTime);
  155.     Writeln(lst,'     ','File Creation Date: ',
  156.             fileTime.month,'-',fileTime.day,'-',fileTime.year);
  157.     end;                                     (* end of PrintDateTime routine *)
  158.  
  159. (*\*)
  160. procedure NewPage;
  161.  
  162.     begin
  163.     FormFeed;
  164.     pgCnt := pgCnt + 1;
  165.     SetEmphasizedMode;
  166.     Writeln(lst,'Source File -- ',sFName,'     ','Page - ',pgCnt:2);
  167.     PrintDateTime;
  168.     CancelEmphasizedMode;
  169.     Skip(2);
  170.     lineCnt := 0;
  171.     end;
  172.  
  173.  
  174. begin
  175. if GetFileToPrint(sFName) then
  176.     begin
  177.     Assign(sFile,sFName);
  178.     Reset(sFile);
  179.     lineCnt := 0;
  180.     pgCnt := 1;
  181.     SetEmphasizedMode;
  182.     Writeln(lst,'Source File -- ',sFName,'     ','Page - ',pgCnt:2);
  183.     PrintDateTime;
  184.     CancelEmphasizedMode;
  185.     Skip(3);
  186.     while not Eof(sfile) do
  187.         begin
  188.         Readln(sFile,line);
  189.         if Copy(line,1,5) = '(*\*)' then
  190.             begin
  191.             NewPage;
  192.             end
  193.         else
  194.             begin
  195.             if lineCnt = MAXLINES then
  196.                 begin
  197.                 NewPage;
  198.                 end;
  199.             Writeln(lst,line);
  200.             lineCnt := lineCnt + 1;
  201.             end;
  202.         end;
  203.     FormFeed;
  204.     Close(sFile);
  205.     end;
  206. end.                                               (* end of TP4Print program *)
  207.