
DEFINITION MODULE Printing;

(* Library module for driving a printer.
 
   Author:           John Forester
   Last Edit:        3 March 86
 
TO USE THIS MODULE:  The calling module must import Printer as
                     well as the procedures that it will use.
                     It must also create a Printer file by the command:
                     FileSystem.Lookup(Printer, 'DK:prn', TRUE); *)

IMPORT FileSystem;

FROM NumberConversion IMPORT CardToString, IntToString;

FROM RealConversions IMPORT RealToString;
 
EXPORT QUALIFIED Printer, Eject, CarrRet, PrintLn, PrintSpace,  
                 PrintString, PFullString, PrintCard, 
                 PrintInt, PrintReal;

VAR Printer  :  FileSystem.File;



PROCEDURE Eject;
(* Ejects a sheet from printer.  Also known as form feed. *)

PROCEDURE CarrRet;
(* Returns the printer head to the left margin *)

PROCEDURE PrintLn;
(* Produces a line feed and carriage return *)

PROCEDURE PrintSpace(n  :  CARDINAL);
(* Causes the printer to print n spaces *)

PROCEDURE PrintString(str  : ARRAY OF CHAR);
(* Causes the printer to print the text length of the string. *)


PROCEDURE PFullString(str  : ARRAY OF CHAR);
(* Causes the printer to print the text length of the string with 
sufficient trailing spaces to reach its full length. *)  

PROCEDURE PrintCard(x, w : CARDINAL);
(* Causes the printer to print the cardinal x in a field of width w. 
   If length exceeds the allowed width, prints asterisks. *)

PROCEDURE PrintInt(x  : INTEGER; w : CARDINAL);
(* Causes the printer to print the integer x in a field of width w.
   If length exceeds the allowed width, prints asterisks. *)

PROCEDURE PrintReal(x : REAL; d, w : INTEGER);
(* Causes the printer to print the real number x in a field of width w 
   with d digits to the right of the decimal point.

   To print in decimal format, make d >= 0.  
   Width is the number of characters in the printing window,
   counting the decimal point and, if present, the - sign.

   To print in exponential format, make d< 0.  
   Requires width = digits to right of decimal point + 8. 

   If the length exceeds the field width, prints asterisks. *)


END Printing.


