home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / TBTREE16.ZIP / TP4PRINT.PAS < prev    next >
Pascal/Delphi Source File  |  1989-07-13  |  8KB  |  284 lines

  1. (* TBTree16             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.    Version 1.4 - No changes
  13.  
  14.    Version 1.5 - No Changes
  15.  
  16.    Version 1.6 - No Changes                                                  *)
  17.  
  18. {   This is a fast and dirty program to print out source code listings for
  19.     Turbo Pascal 4.0 thru 5.5 listings.  It doesn't do anything too fancy.  It
  20.     does print out a header with the name of the file, the page number, and
  21.     the date and time the file was printed.  You can use the date and time to
  22.     determine if the file on disk was updated since the printout.  One other
  23.     attraction is that it counts lines will only print 59 lines on a page. It
  24.     also allows a forced new page command in the listings.  By placing a (*\*)
  25.     in the first 5 columns of any line of the program will force a new page at
  26.     that point.  The backslash in a comment symbol was chosen since the
  27.     compiler will treat it as a comment and will ignore it.  The program uses
  28.     myprint which is a unit containing a few control codes and procedures to
  29.     implement them.  Myprint was done for a Gemini 10 printer, so the
  30.     procedures should work with Epson printers as well.  I have tried it on a
  31.     newer star printer (NX-2400 and it works perfectly.  If you have a
  32.     different printer, just make your own myprint unit with codes which match
  33.     your printer.  See myprint unit for details.
  34.  
  35.     Someday I may enhance this by adding more capabilities.
  36.  
  37.     My thanks to Jeff Flading who's ideas and efforts resulted in several
  38.     improvements.
  39.  
  40.     To print source code using this program just compile it and then the
  41.     the following at the DOS prompt:
  42.  
  43.                      TP4Print  X:YYYY\YYYYYYY\ZZZZZZZZ.ZZZ  I
  44.  
  45.    where the X is the optional drive specifier, the Y's represent the
  46.    optional directory path info and ZZZZZZZZ.ZZZ represents the actual
  47.    program name including the extension.  The program does not assume
  48.    a defualt extension of PAS or anything else.  If the name has an
  49.    extension, it must be included.  The I is an optional parameter.  If you
  50.    put the I (or a small i will work) after the file name, only the
  51.    interface part of the file will be printed.  For this to work, the source
  52.    code must have a (*!*) located in the first 5 columns of a line. If this
  53.    control code is encountered, the program will terminate and nothing more
  54.    will be printed.  In all of my source code, this control code is placed
  55.    before the implmentation part of the code.  Therefore, if you include the i
  56.    after the file name, only the interface code will be printed
  57.  
  58.    I intend to add a few more bells and whistles later if I can think of any.  }
  59.  
  60. (*\*)
  61. program TP4Print;
  62.  
  63. {$R+}
  64.  
  65. uses
  66.     myprint,
  67.     printer,
  68.     strings,
  69.     dos;
  70.  
  71. const
  72.     MAXLINES = 59;
  73.  
  74. type LineType = (IMPLEMENT,NEWPAGE);
  75.  
  76. var
  77.     sfile   : Text;
  78.     sFName  : String;
  79.     line    : String;
  80.     lineCnt : Byte;
  81.     pgCnt   : Byte;
  82.     done    : Boolean;
  83.     lType   : LineType;
  84.     interfaceOnly : Boolean;
  85.  
  86. (*\*)
  87. function GetFileToPrint(var fName : String) : Boolean;
  88.  
  89.     begin
  90.     if ParamCount < 1 then
  91.         begin
  92.         Writeln;
  93.         Writeln('To use this routine type the following at the DOS prompt :');
  94.         Writeln;
  95.         Writeln('   TP4Print  X:YYYY\YYYYYYY\ZZZZZZZZ.ZZZ');
  96.         Writeln;
  97.         Writeln('where the X is the optional drive specifier,');
  98.         Writeln('the Ys represent the optional directory path info and');
  99.         Write('ZZZZZZZZ.ZZZ represents the actual program name including ');
  100.         Writeln('the extension.');
  101.         Writeln;
  102.         Writeln;
  103.         GetFileToPrint := FALSE;
  104.         end
  105.     else
  106.         begin
  107.         fName := ParamStr(1);
  108.         GetFileToPrint := TRUE;
  109.         end;
  110.     end;                                    (* end of GetFileToPrint routine *)
  111.  
  112.  
  113. procedure GetOptions;
  114.  
  115. var
  116.     cnt : Byte;
  117.     str : String;
  118.  
  119.     begin
  120.     interfaceOnly := FALSE;
  121.     cnt := 2;
  122.     while cnt <= ParamCount do
  123.         begin
  124.         str := ParamStr(cnt);
  125.         if (str = 'I') or (str = 'i') then
  126.             begin
  127.             interfaceOnly := TRUE;
  128.             end;
  129.         Inc(cnt);
  130.         end;
  131.     end;                                        (* end of GetOptions routine *)
  132.  
  133.  
  134. procedure Skip(x : Byte);
  135.  
  136. var
  137.     cnt : Byte;
  138.  
  139.     begin
  140.     for cnt := 1 to x do
  141.         begin
  142.         Writeln(lst);
  143.         end;
  144.     end;                                               (* end of Skip routine *)
  145.  
  146. (*\*)
  147. function ConvertString(x : Word) : String;
  148.  
  149. var
  150.     tempStr : String;
  151.  
  152.     begin
  153.     if x < 10 then
  154.         begin
  155.         Str(x:1,tempStr);
  156.         tempStr := '0' + tempStr;
  157.         end
  158.     else
  159.         begin
  160.         Str(x:2,tempStr);
  161.         end;
  162.     ConvertString := tempStr;
  163.     end;
  164.  
  165.  
  166. procedure PrintDateTime;
  167.  
  168. var
  169.     weekDay : String;
  170.     year,
  171.     month,
  172.     day,
  173.     dayOfWeek,
  174.     hour,
  175.     minute,
  176.     second,
  177.     sec100 : Word;
  178.     time : LongInt;
  179.     fileTime : DateTime;
  180.  
  181.     begin
  182.     GetDate(year,month,day,dayOfWeek);
  183.     GetTime(hour,minute,second,sec100);
  184.     case dayOfWeek of
  185.         0 : weekDay := 'Sunday';
  186.         1 : weekDay := 'Monday';
  187.         2 : weekDay := 'Tuesday';
  188.         3 : weekDay := 'Wednesday';
  189.         4 : weekDay := 'Thursday';
  190.         5 : weekDay := 'Friday';
  191.         6 : weekDay := 'Saturday';
  192.         end;                                        (* end of case statement *)
  193.     Write(lst,'Printed: ',weekDay,' ',month,'-',day,'-',year,
  194.           '     Time: ',ConvertString(hour),':',ConvertString(minute));
  195.     GetFTime(sFile,time);
  196.     UnpackTime(time,fileTime);
  197.     Writeln(lst,'    ','File Creation Date: ',
  198.             fileTime.month,'-',fileTime.day,'-',fileTime.year);
  199.     end;                                     (* end of PrintDateTime routine *)
  200.  
  201. (*\*)
  202. procedure GoNewPage;
  203.  
  204.     begin
  205.     FormFeed;
  206.     pgCnt := pgCnt + 1;
  207.     SetEmphasizedMode;
  208.     Writeln(lst,'Source File -- ',sFName,'     ','Page - ',pgCnt:2);
  209.     PrintDateTime;
  210.     CancelEmphasizedMode;
  211.     Skip(2);
  212.     lineCnt := 0;
  213.     end;
  214.  
  215.  
  216. function ControlLine(var lType : LineType) : Boolean;
  217.  
  218.     begin
  219.     if (Copy(line,1,5) = '(*\*)') then
  220.         begin
  221.         lType := NEWPAGE;
  222.         ControlLine := TRUE;
  223.         end
  224.     else
  225.         begin
  226.         if (Copy(line,1,5) = '(*!*)') then
  227.             begin
  228.             lType := IMPLEMENT;
  229.             ControlLine := TRUE;
  230.             end
  231.         else
  232.             begin
  233.             ControlLine := FALSE;
  234.             end;
  235.         end;
  236.     end;                                       (* end of ControlLine routine *)
  237.  
  238. (*\*)
  239. begin
  240. if GetFileToPrint(sFName) then
  241.     begin
  242.     GetOptions;
  243.     Assign(sFile,sFName);
  244.     Reset(sFile);
  245.     lineCnt := 0;
  246.     pgCnt := 1;
  247.     SetEmphasizedMode;
  248.     Writeln(lst,'Source File -- ',sFName,'     ','Page - ',pgCnt:2);
  249.     PrintDateTime;
  250.     CancelEmphasizedMode;
  251.     Skip(3);
  252.     done := FALSE;
  253.     while not (Eof(sfile) or done) do
  254.         begin
  255.         Readln(sFile,line);
  256.         if ControlLine(lType) then
  257.             begin
  258.             case lType of
  259.                 NEWPAGE : GoNewPage;
  260.                 IMPLEMENT : begin
  261.                             if interfaceOnly then
  262.                                 begin
  263.                                 done := TRUE;
  264.                                 end;
  265.                             end;
  266.                 end;                                (* end of case statement *)
  267.             end
  268.         else
  269.             begin
  270.             if lineCnt = MAXLINES then
  271.                 begin
  272.                 GoNewPage;
  273.                 end;
  274.             Writeln(lst,line);
  275.             lineCnt := lineCnt + 1;
  276.             end;
  277.         end;
  278.     FormFeed;
  279.     Close(sFile);
  280.     end;
  281. Writeln;
  282. Writeln('A total of ',pgCnt:2,' pages printed');
  283. end.                                               (* end of TP4Print program *)
  284.