Node:Printer, Next:, Previous:Ports, Up:GPC Units



BP compatibility: Printer, portable

The following listing contains the interface of the Printer unit.

This unit provides printer access, compatible to BP's Printer unit, for Dos (using printer devices) and Unix systems (using printer utilities).

For BP compatibility, the variable Lst is provided, but for newly written programs, it is recommended to use the AssignPrinter procedure on a text file, and close the file when done (thereby committing the printer job). This method allows for sending multiple printer jobs in the same program.

{ BP compatible printer unit with extensions

  Copyright (C) 1998-2003 Free Software Foundation, Inc.

  Author: Frank Heckenbach <frank@pascal.gnu.de>

  This file is part of GNU Pascal.

  GNU Pascal is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2, or (at your
  option) any later version.

  GNU Pascal is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with GNU Pascal; see the file COPYING. If not, write to the
  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA.

  As a special exception, if you link this file with files compiled
  with a GNU compiler to produce an executable, this does not cause
  the resulting executable to be covered by the GNU General Public
  License. This exception does not however invalidate any other
  reasons why the executable file might be covered by the GNU
  General Public License. }

{$gnu-pascal,I-}
{$if __GPC_RELEASE__ < 20030303}
{$error This unit requires GPC release 20030303 or newer.}
{$endif}

unit Printer;

interface

uses GPC {$ifndef __OS_DOS__}, Pipe {$endif};

var
  { Dos-like systems: writing to a printer device }

  { The file name to write printer output into }
  PrinterDeviceName: PString = @'prn';

  { Unix-like systems: printing via a printer program }

  { The file name of the printer program. If it contains a '/', it
    will be taken as a complete path, otherwise the file name will
    be searched for in the PATH with FSearchExecutable. }
  PrinterCommand: PString = @'lpr';

  { Optional command line parameters for the printer program.
    Ignored when nil. }
  PrinterArguments: PPStrings = nil;

  { How to deal with the printer spooler after the printer pipe is
    closed, cf. the Pipe unit. }
  PrinterPipeSignal : Integer = 0;
  PrinterPipeSeconds: Integer = 0;
  PrinterPipeWait   : Boolean = True;

{ Text file opened to default printer }
var
  Lst: Text;

{ Assign a file to the printer. Lst will be assigned to the default
  printer at program start, but other files can be assigned to the
  same or other printers (possibly after changing the variables
  above). SpoolerOutput, if not Null, will be redirected from the
  printer spooler's standard output and error. If you use this, note
  that a deadlock might arise when trying to write data to the
  spooler while its output is not being read, though this seems
  quite unlikely, since most printer spoolers don't write so much
  output that could fill a pipe. Under Dos, where no spooler is
  involved, SpoolerOutput, if not Null, will be reset to an empty
  file for compatibility. }
procedure AssignPrinter (var f: AnyFile; var SpoolerOutput:
  AnyFile);