home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / THEPRN14.ZIP / DEMO_PRN.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-15  |  4KB  |  155 lines

  1. (*=========================================================================
  2.  
  3.     Name:       Demo_Prn.Pas   Copyright 1992-94, Rob W. Smetana
  4.                 Support file for The Printer (tm).
  5.  
  6. Requires:       PRINTER.CFG.
  7.  
  8.                 This program displays the contents of Printer.Cfg.
  9.                 Therefore, BEFORE running this, you MUST run Printer.Exe,
  10.                 select a printer, then press F2 to SAVE Printer.Cfg.
  11.  
  12.  
  13.  Purpose:       * Demonstrate reading printer code records.
  14.  
  15.                 * Show how one might display printer codes.
  16.  
  17.                   Something like this might be used inside a
  18.                   program to show users which codes are
  19.                   available (ie., not blank) and perhaps what
  20.                   they should do to invoke each option.
  21.  
  22.     NOTE:       Some printer codes may contain control codes which
  23.                 will screw up the display.  Try a different printer.
  24.                 And in your own programs you might want to use an ASM
  25.                 "quickprint" routine to overcome this problem.
  26.  
  27. =========================================================================*)
  28.  
  29. Program Demo_Prn;
  30.  
  31. Uses DOS,CRT;
  32.  
  33. { ...include two TYPES useful for reading printer codes. }
  34.  
  35. (*{$I The_Prn.Pas} *)
  36.  
  37. {...NOTE:  Although we loaded some TYPEs, we won't use them!  For what     }
  38. {   we're about to do, it's easier to read stuff in simple 14-byte chunks. }
  39.  
  40. Var
  41.  
  42.   F     : File;
  43.   Headr : Array[1..44] of Char;
  44.   Labels: Array[1..980] of Char;
  45.   Codes : Array[1..980] of Char;
  46.  
  47.   Cfg_File: String;
  48.  
  49.   Ch : Char;
  50.   Temp, N, Offset : Integer;
  51.   BytesRead : Word;
  52.   Row, Col : Byte;
  53.  
  54. {=========================================================================}
  55. Procedure PrintHeader;                  { print Manufacturer, model, etc. }
  56. {=========================================================================}
  57.   Begin
  58.   TextAttr := 27; ClrScr;
  59.   For N := 1 to 44 Do                   { print our 44-byte header }
  60.      Begin
  61.         Case N of
  62.           1:  Write ( '  Manufacturer: ');
  63.           16: Write ( '  Model: ');
  64.           30: Write ( '  Emulation: ');
  65.         End;
  66.         Write(Headr [N]);
  67.      End;
  68.    TextAttr := 26;
  69.    End;
  70.  
  71. {=========================================================================}
  72. Begin
  73. {=========================================================================}
  74.  
  75.   Cfg_File := 'Printer.Cfg';
  76.  
  77.   {$I-}
  78.  
  79.   ClrScr;
  80.  
  81.   Assign(F, Cfg_File);
  82.   Reset(F, 1);
  83.  
  84.   If IOResult <> 0 then
  85.      Begin
  86.         Write('Error:  ',Cfg_File, ' was not found! ');
  87.         Close(F);
  88.         Halt;
  89.      End;
  90.  
  91.   { read the header, the labels, the header again and the printer codes }
  92.   BlockRead (F, Headr, SizeOf(Headr), BytesRead);
  93.   BlockRead (F, Labels, SizeOf(Labels), BytesRead);
  94.   BlockRead (F, Headr, SizeOf(Headr), BytesRead);
  95.   BlockRead (F, Codes, SizeOf(Codes), BytesRead);
  96.  
  97.   If IOResult <> 0 then
  98.      Begin
  99.         Write('Error reading: ',Cfg_File,'');
  100.         Close(F);
  101.         Halt;
  102.      End;
  103.  
  104.   Close(F);
  105.  
  106.   PrintHeader;
  107.  
  108.   { Now parse our two 980-byte buffers and print Labels:Codes }
  109.  
  110.   Offset :=1 ;Row := 3; Col := 3;
  111.  
  112.   { Display our 70, 14-byte labels and printer codes }
  113.  
  114.   For Temp := 1 to 70 Do
  115.  
  116.     Begin
  117.  
  118.        GotoXY(Col, Row);
  119.        { Print the labels }
  120.        For N := 1 to 14 Do
  121.            Write(Labels[Offset+N-1]);
  122.  
  123.        Write('    ');
  124.  
  125.        { and now the codes }
  126.        For N := 1 to 14 Do
  127.            Write(Codes[Offset+N-1]);
  128.  
  129.        { move to the next }
  130.        Offset := Offset + 14;
  131.  
  132.        { there are more codes than will fit on a screen, so pause }
  133.  
  134.        If (Temp = 42) then
  135.           Begin
  136.             GotoXY(15, 25); Write ('There''s more.   Press <SPACE> to continue . . .');
  137.             Ch:=ReadKey;
  138.             If Ch = #27 then Halt;
  139.             PrintHeader;
  140.             Row :=2; Col := 3;
  141.           End;
  142.  
  143.        Inc(Row);
  144.  
  145.        If (Row > 23) then
  146.           Begin
  147.             Row :=3; Col := 40;
  148.           End;
  149.     End;
  150.  
  151.     GotoXY(15, 25); Write ('That''s all.     Press <SPACE> to continue . . .');
  152.     Ch:=ReadKey;
  153.  
  154. End.
  155.