home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mastlkt.zip / PRN-PART.PAS < prev    next >
Pascal/Delphi Source File  |  1986-10-06  |  4KB  |  156 lines

  1. Program PrnPart; { Author: David Bennett / 10-06-86 }
  2.  
  3. {$G16384,P16384,D-}    {To allow DOS redirection}
  4.  
  5. {
  6.   Compile and Run this code WITHOUT parameters to see description
  7.   of program. You may also look at the procedure Explain
  8. }
  9.  
  10. Const
  11.   Whole    = 1;
  12.   From     = 2;
  13.   FromTo   = 3;
  14.   LineFeed = ^L;
  15.  
  16. Type
  17.   AnyString = String[255];
  18.  
  19. Var
  20.   DiskFile : Text;
  21.   DiskName : String[64];
  22.   FirstPage,
  23.   LastPage : Integer;
  24.   PrnType  : Integer;
  25.  
  26. Procedure Error(Message : AnyString);
  27.  
  28. Begin
  29.   WriteLn (CON,Chr(7));
  30.   WriteLn (CON,'An ERROR has occured ',Message);
  31.   Halt;
  32. End;
  33.  
  34. Procedure IOCheck;
  35.  
  36. Begin
  37.   If IOResult > 0 Then Error('concerning the disk file '+DiskName);
  38. End;
  39.  
  40. Procedure Explain;
  41.  
  42. Begin
  43.   WriteLn(CON,'* Program: PRN-PART.COM / Author: David Bennett / 10-06-86');
  44.   WriteLn(CON,'');
  45.   WriteLn(CON,'* Usage:');
  46.   WriteLn(CON,'  PRN-PART <filespec> <first page> <last page>');
  47.   WriteLn(CON,'');
  48.   WriteLn(CON,'* Description:');
  49.   WriteLn(CON,'  This program is to be used when you wish only to print part of a document');
  50.   WriteLn(CON,'  file. If <last page> is not entered then printing will start and page');
  51.   WriteLn(CON,'  <first page> and continue to the end of the document. If <first page> is');
  52.   WriteLn(CON,'  not entered then file <filespec> will be printed in it''s entirety.');
  53.   WriteLn(CON,'');
  54.   WriteLn(CON,'  A>PRN-PART WHATSUP.DOC 5 14       ->  Will print pages 5 to 14 of file');
  55.   WriteLn(CON,'                                        A:WHATSUP.DOC to the CONSOLE');
  56.   WriteLn(CON,'');
  57.   WriteLn(CON,'  A>PRN-PART WHATSUP.DOC 21 > PRN   ->  Will print page 21 through the');
  58.   WriteLn(CON,'                                        end of the file to the PRINTER');
  59.   WriteLn(CON,'');
  60.   WriteLn(CON,'*** A CONTRIBUTION OF $5.00 IS EXPECTED FOR GAINFUL USE OF THIS PROGRAM ***');
  61.   WriteLn(CON,'');
  62.   WriteLn(CON,'    DAVID BENNETT');
  63.   WriteLn(CON,'    555 SUNSHINE ROAD');
  64.   WriteLn(CON,'    KANSAS CITY, KANSAS 66115');
  65. End;
  66.  
  67. Procedure OpenFiles;
  68.  
  69. Var
  70.   P : Integer;
  71.  
  72. Begin
  73.   If ParamCount = 0 Then Begin
  74.     ClrScr;
  75.     Explain;
  76.     Halt;
  77.   End;
  78.   If ParamCount > 0 Then Begin
  79.     DiskName := ParamStr(1);
  80.     PrnType := Whole;
  81.   End;
  82.   If ParamCount > 1 Then Begin
  83.    Val(ParamStr(2),FirstPage,P);
  84.     If P > 0 Then Error('with parameter 2 - '+ParamStr(2));
  85.     PrnType := From;
  86.   End;
  87.   If ParamCount > 2 Then Begin
  88.     Val(ParamStr(3),LastPage,P);
  89.     If P > 0 Then Error('with parameter 3 - '+ParamStr(3));
  90.     PrnType := FromTo;
  91.   End;
  92.   {$I-}
  93.   Assign(DiskFile,DiskName); IOCheck;
  94.   ReSet(DiskFile); IOCheck;
  95.   {$I+}
  96. End;
  97.  
  98. Procedure PrintPage;
  99.  
  100. Var
  101.   LineCount : Integer;
  102.   FileChar  : Char;
  103.  
  104. Begin
  105.   LineCount := 0;
  106.   Repeat
  107.     {$I-}
  108.     Read (DiskFile,FileChar); IOCheck;
  109.     {$I-}
  110.     Write(FileChar);
  111.     If EoLn(DiskFile) Then LineCount := LineCount + 1
  112.   Until (LineCount = 66) Or (FileChar = LineFeed) Or (Eof(DiskFile));
  113. End;
  114.  
  115. Procedure GotoPage(PageNum : Integer);
  116.  
  117. Var
  118.   PageCount,
  119.   LineCount : Integer;
  120.   FileChar  : Char;
  121.  
  122. Begin
  123.   PageCount := 1;
  124.   While PageNum > PageCount Do Begin
  125.     LineCount := 0;
  126.     Repeat
  127.       {$I-}
  128.       Read(DiskFile,FileChar); IOCheck;
  129.       {$I+}
  130.       If EoLn(DiskFile) Then LineCount := LineCount + 1;
  131.     Until (LineCount = 66) or (FileChar = LineFeed);
  132.     PageCount := PageCount + 1;
  133.   End;
  134. End;
  135.  
  136. Var
  137.   PrnLoop : Integer;
  138.  
  139. Begin
  140.   OpenFiles;
  141.   Case PrnType of
  142.     Whole  : While Not(Eof(DiskFile)) Do PrintPage;
  143.     From   : Begin
  144.                GotoPage(FirstPage);
  145.                While Not(Eof(DiskFile)) Do PrintPage;
  146.              End;
  147.     FromTo : Begin
  148.                GotoPage(FirstPage);
  149.                For PrnLoop := 0 to LastPage - FirstPage Do
  150.                 If Not(Eof(DiskFile)) Then PrintPage;
  151.              End;
  152.     Else Error('UnKnown');
  153.   End;
  154.   Close(DiskFile);
  155. End.
  156.