home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 29 / pascal / prpascal.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-19  |  6.3 KB  |  207 lines

  1. PROGRAM Printpascal ;
  2.     { Program to make a printout of a pascal listing     }
  3.     { puts header with program name & date               }
  4.     { puts a footer with page number                     }
  5.     { use item selector box to get the file              }
  6.     { WILLIAM R. GOOD JULY 1986                          }
  7.  
  8.   CONST
  9.     {$I GEMCONST.PAS}
  10.  
  11.   TYPE
  12.     {$I gemtype.pas}
  13.     prtype = FILE OF TEXT ;
  14.     tftype = FILE OF TEXT ;
  15.  
  16.   VAR
  17.     pathname, filename : Path_Name ;
  18.     selection : boolean ;
  19.     textfile : tftype ;
  20.     prtfile : prtype ;
  21.  
  22.   {$I gemsubs}          { and that ".PAS" is default }
  23.  
  24. { the next two functions are added to personal pascal }
  25.  
  26. FUNCTION t_getdate : integer ;
  27.    GEMDOS( $2a ) ;
  28.  
  29. FUNCTION t_gettime : integer ;
  30.    GEMDOS( $2c ) ;
  31.  
  32. PROCEDURE info ;
  33.    { prints the copyright notice on the screen }
  34.    { in a alert box. OSS wants this            }
  35.    VAR
  36.        button : integer ;
  37.        alerttext : string[255] ;
  38.        part1, part2, part3, part4, part5 : string ;
  39.    BEGIN
  40.        part1 := '[3][Printpascal by William R. Good|' ;
  41.        part2 := 'Portions of this product are|' ;
  42.        part3 := 'Copyright (c) 1986 OSS and CCD|' ;
  43.        part4 := 'Used by Permission of OSS.|' ;
  44.        part5 := 'Written on 06-29-86 ][ OK ]' ;
  45.        alerttext := Concat ( part1, part2, part3, part4, part5 ) ;
  46.        button := Do_Alert(alerttext,1) ;
  47.    END ; {info}
  48.   
  49. PROCEDURE Inttostr (int : integer; VAR inttext : string);
  50. {Generic procedure to convert integers to strings, packs front with zeros.}
  51. VAR
  52.    place,digit : integer;
  53.    tempstr : string ;
  54. BEGIN
  55.    tempstr := '' ;
  56.    FOR place:=1 DOWNTO 0 DO
  57.       BEGIN
  58.          digit:=int DIV Round(PwrOfTen(place));
  59.          tempstr := concat (tempstr, chr(digit+ord('0'))) ;
  60.          int:=int MOD Round(PwrOfTen(place));
  61.       END;
  62.    inttext := tempstr ;
  63. END; {Inttostr}
  64.  
  65. PROCEDURE getdate (var datestr : string ) ;
  66. { procedure to return the date in a string }
  67.    VAR
  68.       dateint,tempint,
  69.       yearint, monthint, dayint : integer ;
  70.       yearstr, monthstr, daystr : string ;
  71.    BEGIN
  72.       dateint := t_getdate ;
  73.       yearint := dateint div 512 ;
  74.       yearint := yearint + 80 ;
  75.       tempint := dateint mod 512 ;
  76.       monthint := tempint div 32 ;
  77.       dayint := tempint mod 32 ;
  78.       inttostr( yearint, yearstr ) ;
  79.       inttostr( monthint, monthstr ) ;
  80.       inttostr( dayint, daystr ) ;
  81.       datestr := concat( monthstr, '/', daystr, '/', yearstr ) ;
  82.    END ; { getdate }
  83.  
  84. PROCEDURE gettime (var timestr : string ) ;
  85. { procedure to return the time in a string }
  86.    VAR
  87.       timeint,tempint,
  88.       hourint, minint, secint : integer ;
  89.       hourstr, minstr, secstr : string ;
  90.    BEGIN
  91.       timeint := t_gettime ;
  92.       hourint := timeint div 2048 ;
  93.       tempint := timeint mod 2058 ;
  94.       minint := tempint div 32 ;
  95.       secint := tempint mod 32 ;
  96.       secint := secint * 2 ;
  97.       inttostr( hourint, hourstr ) ;
  98.       inttostr( minint, minstr ) ;
  99.       inttostr( secint, secstr ) ;
  100.       timestr := concat( hourstr, ':', minstr, ':', secstr ) ;
  101.    END ; { gettime }
  102.  
  103. PROCEDURE printhead ;
  104.         { prints header with full pathname  }
  105.         { and date                          }
  106.    var
  107.       times1, times2 : integer ;
  108.       headline, time, date : string ;
  109.    begin
  110.       rewrite( prtfile, 'LST:' ) ;
  111.       for times1 := 1 to 2 do
  112.          begin
  113.             writeln( prtfile ) ;  { space down some lines }
  114.          end ;
  115.       getdate ( date ) ;
  116.       gettime ( time ) ;
  117.       headline := concat(filename, '                      ', time,' ', date ) ;
  118.       writeln( prtfile, headline ) ; { need to add filename here }
  119.       for times2 := 1 to 2 do
  120.          begin
  121.             writeln( prtfile ) ;
  122.          end ;
  123.    end ; { printhead }
  124.  
  125. PROCEDURE printfoot( pagenum : integer ) ;
  126.         { prints footer with page number  }
  127.         { at the bottom of page in center }
  128.    var 
  129.       line, textline : string ;
  130.       pagestr : string ;
  131.       tempnum, index, times1, times2 : integer ;
  132.    begin
  133.       rewrite( prtfile, 'LST:' ) ;
  134.       for times1 := 1 to 2 do
  135.          begin
  136.             writeln( prtfile ) ;
  137.          end ;
  138.       inttostr( pagenum, pagestr ) ;
  139.       textline := '                            PAGE NUMBER : ' ;
  140.       textline := concat( textline, pagestr ) ;
  141.       writeln( prtfile, textline ) ;
  142.       for times2 := 1 to 2 do
  143.          begin
  144.             writeln( prtfile ) ;
  145.          end
  146.    end ; { printfoot}
  147.  
  148. PROCEDURE printfile ;
  149.    { prints the pascal file to the printer       }
  150.    { prints header and footer with page number   }
  151.    VAR
  152.       textfile : tftype ;
  153.       prtfile : prtype ;
  154.       number, tempnum, strline : string ;
  155.       check, linecount, pagenumber : integer ;
  156.    BEGIN
  157.       pagenumber := 0 ;
  158.       linecount := 1 ;
  159.       rewrite( prtfile, 'LST:' ) ;
  160.       pathname := 'A:\*.PAS' ;
  161.       selection := true ;
  162.       selection := Get_In_File( pathname, filename ) ;
  163.       if selection then
  164.          begin
  165.          set_mouse(m_bee) ;
  166.          printhead ;
  167.          reset( textfile, filename ) ;
  168.          while (not eof( textfile )) do
  169.             begin
  170.                readln ( textfile, strline ) ;
  171.                writeln ( prtfile, strline ) ;
  172.                linecount := linecount + 1 ;
  173.                if linecount = 57 then
  174.                   begin
  175.                      pagenumber := pagenumber + 1 ;
  176.                      printfoot ( pagenumber ) ;
  177.                      printhead ;
  178.                      linecount := 1 ;
  179.                   end ;
  180.             end ;
  181.             if linecount < 57 then
  182.                begin
  183.                   repeat
  184.                      writeln ( prtfile ) ;
  185.                      linecount := linecount + 1 ;
  186.                   until linecount = 57 ;
  187.                   pagenumber := pagenumber + 1 ;
  188.                   printfoot ( pagenumber ) ;
  189.                end ;
  190.          set_mouse(m_arrow) ;
  191.          end ;         
  192.    end ; { end printfile }
  193.  
  194.   BEGIN  {Main Module}
  195.     IF Init_Gem >= 0 THEN
  196.       BEGIN
  197.          info ;
  198.          printfile ;
  199.          close( textfile ) ;
  200.          close( prtfile ) ;
  201.         Exit_Gem ;
  202.       END ;
  203.   END. {Printpascal}
  204.  
  205.  
  206.  
  207. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə