Appendix 6--ISO Support Modules For This Text

All the modules in this section are system specific modules. They were written by the author in support of a personal trial implementation of the ISO library on the Macintosh computer. Since some references are made to these modules in the text, their definitions are reproduced here from highest level to lowest level.

A6.1 RedirStdIO

  
 DEFINITION MODULE RedirStdIO;

(* =========================================
  Definition and Implementation © 1993-1997
                by R. Sutcliffe
        Trinity Western University
7600 Glover Rd., Langley, BC Canada V3A 6H4
         e-mail: rsutc@twu.ca
    Last modification date 1997 07 02
=========================================== *)

IMPORT ChanConsts;

TYPE
  OpenResults = ChanConsts.OpenResults;
	
PROCEDURE OpenResult () : OpenResults;
(* returns the result of the last attempt to open a file for redirection *)

PROCEDURE OpenOutput;
(* engages the user in a dialog to obtain a file for redirection of standard Output and attempts to open the file so obtained *)

PROCEDURE OpenOutputFile (VAR fileName: ARRAY OF CHAR);
(* opens the file specified by fileName for redirection of output.  If the name supplied is the empty string or the file could not be opened, control passes to OpenOutput and the filename eventually used is returned in the parameter. *)

PROCEDURE CloseOutput;
(* returns the standard output channel to the default value *)

PROCEDURE OpenInput;
(* engages the user in a dialog to obtain a file for redirection of standard Input and attempts to open the file so obtained *)

PROCEDURE OpenInputFile (VAR fileName: ARRAY OF CHAR);
(* Opens the file specified by fileName for redirection of input.  If the name supplied is the empty string or is not found, control passes to OpenInput and the filename eventually used is returned in the parameter. *)

PROCEDURE CloseInput;
(* returns the standard input channel to the default value *)

END RedirStdIO.

A6.2 Filer

As can be seen from the credits, this module has a long history. With minor modifications, it has served the author for a decade of Modula-2 work, and it proved a simple matter to implement the ISO library on top of it.

DEFINITION MODULE Filer;

(* =========================================
  Definition and Implementation © 1985-1995
                by R. Sutcliffe
        Trinity Western University
7600 Glover Rd., Langley, BC Canada V3A 6H4
         e-mail: rsutc@twu.ca
    Last modification date 1995 01 10
=========================================== *)

(*
Copyright 1985  by R. Sutcliffe as "Files"
Version 1 for Apple ][ UCSD p-system 1985 by R. Sutcliffe 
Version 2 for MS-DOS PCollier compiler 1987 by R. Sutcliffe 
Version 3  for Sempersoft Modula-2 compiler using MPW
  September 1988
  research and first design by Greg Manning
   Implementation by R. Sutcliffe 
Version 4 for Sun Modula-2 (UNIX) 1989 by R. Sutcliffe 
Version 5 Redesign version3 for the MetCom compiler 1990 09 12
  by R. Sutcliffe 
  MPW and PSE versions implemented
Version 6 For Metrowerks PSE 4.03 compiler
  Renamed "Channels" for a mid-level ISO-like implementation 1993 08 01 by R. Sutcliffe
  initial research by Gord Tischer
  redesign and implementation as part of ISO-like I/O suite by R. Sutcliffe
  name changed to "Filer" to avoid toolbox conflict
  changed order of parameters in Read/Write Bytes to typical ISO order
  length parameter in Read/Write Bytes changed to VAR and CARDINAL
Version 6.1 last modification date 1993 10 21  read/open => var param
Version 6.2 last modification date 1994 01 28
     added the concept of mode to support ISO
     changed most file parameters from VAR to value
Version 6.2.1 last modification date 1994 05 18
  to p1 MPW; requires LONGINT ==> INTEGER
Version 6.2.2 last modification date 1994 10 22
    add OpenMode to record mode of original opening for additional ISO utility 
  added flush capability 
  fixed close finally
    changed open semantics so that if it fails, the memory is deallocated 
    fixed a bug in reading by making the chrBuf and chrRead file by file 1995 01 06 
Version 6.2.3 Added Lookup modified 1995 01 10 *)
    
(* This module provides basic file capabilities in a consistent interface to other modules. *)

FROM SYSTEM IMPORT
  BYTE, WORD, ADDRESS;
FROM Types IMPORT
  Str255;
FROM MacFileTypes IMPORT
  NameType;

TYPE
  File;

  (* Each file procedure will return a result of type "FileErr".
     The meaning of each possible result is explained below. *)

  FileErr = (FileOK,     (* everything worked *)
  EOF,           (* an read was made past the end of a file *)
  DiskError,     (* media is corrupted *)
  FileExists, (* a file with that name already exists *)
  FSErr,         (* error in external file system *)
  FileAbsent, (* no file with that name exists *)
  TooManyOpen,   (* tried to open too many files*)
  BadName,       (* an illegal file name was used: perhaps too long, or contains a colon *)
  DiskFull,      (* there is no more room on the disk *)
  FileLocked, (* fileges can't be made to locked files *)
  FileBusy,   (* that file is already open *)
  NotOpen,       (* attempt to access file not open *)
  OtherError);   (* one of the rarer errors has occurred *)
  
  Mode = (none, input, output, both, invalid);
  OpenMode = (notSet, read, write, readwrite, append, other);

VAR
  FileDone : FileErr;
  useDialogs  : BOOLEAN; (* set to FALSE, but if reset by user, create and open bring up standard dialog boxes *)


PROCEDURE Lookup (filename : ARRAY OF CHAR) : BOOLEAN;
(* If the file with the given name is present returns TRUE and sets FileDone to FileOK
if not, returns FALSE and sets FileDone to FileAbsent or another error *)

PROCEDURE Create (VAR filename : ARRAY OF CHAR; creator, type : NameType);
  (* Creates a new, empty file in the current directory.
     The new file will be named as specified in 'name'.
     The new file will have a signature as specified in 'creator'.
     The new file will have a type as specified in 'type'.
     Latter two only in Mac version
     NB. A newly created file must still be opened to be used.
     The standard dialog is used if useDialogs is set to TRUE or
     if the filename passed is an empty string. In that case, the actual filename opened by the user is passed back in filename. *)

PROCEDURE Open (VAR file : File; VAR filename : ARRAY OF CHAR);
  (* Creates the variable "file"
     Opens an already existent file in the current directory.
     The file whose name is specified in 'filename' will be opened.
     'file' is set to refer to the opened file.
     Any information previously stored in 'file' will be lost.
     It is important to close all opened files before ending a program. 
     The standard dialog is used if the filename passed is an empty string.
     The mode is set to "both" as a default as this is a low level proc 
	 The OpenMode is set to notSet
     If the open fails, the memory for the file variable is deallocated *)


(* The following procedures operate on files specified by name only. *)

PROCEDURE Delete (filename : ARRAY OF CHAR);
  (* Deletes the file specified in 'filename'.  Use with caution! *)
  
PROCEDURE Rename (oldname, newname : ARRAY OF CHAR);
  (* Renames the file specified by 'oldname' as specified by 'newname'. *)

(*================================================================
The following procedures require that 'file' refer to a previously opened file.  Calling one of them when 'file' is invalid may produce unpredicable results.  Hopefully an error will result if 'file' was invalid, but it is possible that 'file' contains a valid value by accident. *)

PROCEDURE GetName (file: File; VAR filename : ARRAY OF CHAR);
(* Returns the name of the file that was used when it was opened *)

PROCEDURE Eof (file : File) : BOOLEAN;
  (* Returns TRUE if the file position is at or past logical EOF 
  The return result is defined only if the error  state is FileOK *)
  
PROCEDURE GetMode (file : File) : Mode;
  (* Returns the currently mode on this file *)

PROCEDURE SetMode (file : File; mode : Mode);
  (* Sets the current mode on this file *)

PROCEDURE GetOpenMode (file : File) : OpenMode;
  (* Returns the open mode on this file *)

PROCEDURE SetOpenMode (file : File; mode : OpenMode);
  (* If the OpenMode is notSet, Sets the open mode on this file;
     If the OpenMode is anything else, does nothing, but no error condition is set should only be done just after opening *)

PROCEDURE FileState (file : File) : FileErr;
  (* Returns the currently set error on this file *)
  
PROCEDURE Flush (file : File);
  (* The volume on which the file is located will be flushed.
     There is no guarantee that any date for a file has been written to the disk until the associated volume has been flushed, either by this procedure or by closing the file. *)

PROCEDURE Close (file : File);
  (* The file specified in 'file' will be closed.
     After calling this procedure, if the close was successful, the memory is deallocated and variable is set to NIL; if it is not successful, the mode becomes invalid, and the variable is retained. The file cannot be reopened with the same file record, but another attempt to close can be made. *)
  
PROCEDURE ReadByte (file : File; VAR input : BYTE);
 (* Reads the next byte from the file 'file' and stores it in 'input'. *)

PROCEDURE Look (file : File; VAR ch : CHAR);
 (* Reads but does not remove from the input stream the next character from the file 'file' and stores it in 'ch'. *)

PROCEDURE Skip (file : File);
 (* Removes from the input stream the next byte from the file 'file' *)

PROCEDURE SkipLook (file : File; VAR ch : CHAR);
 (* Does a skip followed by a look *)

PROCEDURE ReadChar (file : File; VAR ch : CHAR);
 (* Reads the next character from the file 'file' and stores it in 'ch'. *)
     
PROCEDURE ReadWord (file : File; VAR input : WORD);
 (* Reads the next word from the file 'file' and stores it in 'input'. *)

PROCEDURE ReadBytes (file : File; buffer : ADDRESS; VAR length : CARDINAL);
  (* Reads 'length' bytes from the file 'file' and stores them at 'buffer'.
     Actual number of bytes read returned in length 
     If the buffer is too small, data will be overwritten.
     This is a low level procedure -- dont use unless you know what you are doing *)

PROCEDURE ReadRec(file : File; VAR rec : ARRAY OF BYTE);
  (* This is a safer high level procedure for reading records *)

PROCEDURE WriteByte(file : File; output : BYTE);
  (* Writes the byte in 'output' to the file 'file'. *)

PROCEDURE WriteChar(file : File; ch : CHAR);
  (* Writes the char in 'ch' to the file 'file'. *)

PROCEDURE WriteWord(file : File; output : WORD);
 (* Writes the word in 'output' to the file 'file'. *)

PROCEDURE WriteBytes(file : File; buffer : ADDRESS; VAR length : CARDINAL);
  (* Writes the 'length' bytes starting at 'buffer' to the file 'file'.
     Actual number of bytes read returned in length 
     If the buffer is too small, undefined bytes will be written. 
     So don't use this unless you know what you are doing *) 

PROCEDURE WriteRec(file : File; rec : ARRAY OF BYTE);
  (* This is a safe high level procedure for writing records *)

(* Following for random access files *)

PROCEDURE GetPos (file : File; VAR pos : INTEGER);

PROCEDURE GetEOF (file : File; VAR pos : INTEGER);

PROCEDURE SetPos (file : File; pos : INTEGER);
  (* sets from beginning of file *)

PROCEDURE SetEOF (file : File; pos : INTEGER);

END Filer.

A6.3 Keyboard

As suggested in the appendix on classical I/O modules, a keyboard reading module is a common item in many implementations. The author's follows.

DEFINITION MODULE Keyboard;

(* =========================================
  Definition and Implementation © 1993
                by R. Sutcliffe
=========================================== *)

PROCEDURE BusyRead (VAR ch: CHAR);
  (* return character if one is there, otherwise return 0C *)
  
PROCEDURE Read (VAR ch: CHAR);
  (* return character *)
  
END Keyboard.

A6.4 CharBuffer

In order to implement the ISO library Look functionality, the author decided to employ a buffer to store text coming from the keyboard until it was "read" by the I/O routines. Because this seemed like a general problem, the required functionality was included in a library. The maximum buffer size is arbitrary.

DEFINITION MODULE CharBuffer;

(* =========================================
  Definition and Implementation © 1993
                by R. Sutcliffe
=========================================== *)

(* provides a first in first out 1024 character buffer facility *)

TYPE
  Buffer;
  
PROCEDURE Init (VAR b : Buffer);
(* create a new empty buffer *)

PROCEDURE Destroy (VAR b: Buffer);
(* give all memory back to the system *)

PROCEDURE Flush (b : Buffer);
(* empty a buffer *)

PROCEDURE Full (b: Buffer) : BOOLEAN;
(* returns TRUE if the buffer cannot take any more characters
FALSE if it can *)

PROCEDURE Empty (b: Buffer) : BOOLEAN;
(* returns TRUE if the buffer cannot give back any more characters
FALSE if it can *)

PROCEDURE Enter (b : Buffer; ch: CHAR);
(* Enters the character.  If it was full, the first in is lost. 
 If you don't like that way of doing it, write your own. *)

PROCEDURE Look (b : Buffer; VAR ch: CHAR);
(* get the first in without removing it *)

PROCEDURE Skip (b : Buffer);
(* remove the first in *)

PROCEDURE Erase (b : Buffer);
(* remove the last in *)

PROCEDURE Fetch (b : Buffer; VAR ch: CHAR);
(* get the first in and removes it *)

PROCEDURE Size (b : Buffer) : CARDINAL;
(* returns number of characters in the buffer *)

END CharBuffer.

A6.5 STerminal

A student terminal package was implemented so as to allow programs to have pull down menus and require an explicit quit command to exit. This makes it easier to copy or print material from the terminal window.

DEFINITION MODULE STerminal;
FROM SYSTEM IMPORT ADDRESS;
(* exported procedures *)
PROCEDURE WriteChar (ch : CHAR);
PROCEDURE WriteCharRef (adr : ADDRESS);
PROCEDURE WriteString (str : ARRAY OF CHAR);
PROCEDURE WriteStringRef (adr : ADDRESS; howMany : CARDINAL);
PROCEDURE WriteLn;
PROCEDURE BusyRead (VAR ch : CHAR);
PROCEDURE ReadChar (VAR ch : CHAR);
PROCEDURE ReadString (VAR str : ARRAY OF CHAR);
END STerminal.

A6.6 ASCII

DEFINITION MODULE ASCII;

(* R. Sutcliffe. Last Modification 1997 10 15 *)

CONST
  nul = 00C; soh = 01C; stx = 02C; etx = 03C; eot = 04C; enq = 05C;
  ack = 06C; bel = 07C; bs  = 10C; ht  = 11C; lf  = 12C; vt  = 13C;
  ff  = 14C; cr  = 15C; so  = 16C; si  = 17C; dle = 20C; dc1 = 21C;
  dc2 = 22C; dc3 = 23C; dc4 = 24C; nak = 25C; syn = 26C; etb = 27C;
  can = 30C; em  = 31C; sub = 32C; esc = 33C; fs  = 34C; gs  = 35C;
  rs  = 36C; us  = 37C; space = 40C; del = 177C; 

END ASCII.

A6.7 SComplexIO

DEFINITION MODULE SComplexIO;

(* =========================================
          © 1996 by R. Sutcliffe
    Last modification date 1996 10 30
===========================================*)

  (* Input and output of complex numbers in decimal text form over the default channels. The read result is of the type IOConsts.ReadResults. *)
 
IMPORT IOChan;
 
  (* The text form of a complex number is
       realNumber, space ["+" | "-"], [space,] [realnumber, i] |
       [realNumber, space] ["+" | "-"], [space,] realnumber, i
     where the real numbers in each case are in the 
     format specified for fixed or floating reals.
  *)
 
PROCEDURE ReadComplex (VAR complex: COMPLEX);
  (* Skips leading spaces, and removes any remaining characters from cid that form part of a complex number.  The value of this number is assigned to complex. The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or  endOfInput. *)
 
PROCEDURE WriteFloat (complex: COMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* Writes the value of complex to cid in floating-point real text form, with sigFigs significant figures, in a field of the given minimum width. The width for the real parts is 0 if the supplied width is 3 or less, and it is (width - 4) DIV 2 otherwise.  *)
 
PROCEDURE WriteEng (complex: COMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* As for WriteFloat, except that the number is scaled with one to three
digits in the whole number part, and with an exponent that is a multiple of three. *)
 
PROCEDURE WriteFixed (complex: COMPLEX; place: INTEGER; width: CARDINAL);
  (* Writes the value of complex to cid in fixed-point text form, with real parts rounded to the given place relative to the decimal point, in a field of the given minimum width. *)
 
PROCEDURE WriteComplex (complex: COMPLEX; width: CARDINAL);
  (* Writes the value of complex to cid, as WriteFixed if the sign and magnitude can be shown in the given width, or otherwise as WriteFloat.  The number of places or significant digits depends on the given width.  *)
 
END SComplexIO.

A6.8 SLongComplexIO

DEFINITION MODULE SLongComplexIO;

(* =========================================
          © 1996 by R. Sutcliffe
    Last modification date 1996 11 01
===========================================*)

  (* Input and output of longcomplex numbers in decimal text form over the default channels. The read result is of the type IOConsts.ReadResults. *)
 
IMPORT IOChan;
 
  (* The text form of a LongComplex number is
       realNumber, [space], ["+" | "-"], [space,] [realnumber, i] |
       [realNumber, [space],] ["+" | "-"], [space,] realnumber, i
     where the real numbers in each case are in the 
     format specified for fixed or floating longreals.
  *)
 
PROCEDURE ReadComplex (VAR complex: LONGCOMPLEX);
  (* Skips leading spaces, and removes any remaining characters from cid that form part of a complex number.  The value of this number is assigned to complex. The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or  endOfInput. *)
 
PROCEDURE WriteFloat (complex: LONGCOMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* Writes the value of complex to cid in floating-point real text form, with sigFigs significant figures, in a field of the given minimum width. The width for the real parts is 0 if the supplied width is 3 or less, and it is (width - 4) DIV 2 otherwise.  *)
 
PROCEDURE WriteEng (complex: LONGCOMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* As for WriteFloat, except that the number is scaled with one to three
digits in the whole number part, and with an exponent that is a multiple of three. *)
 
PROCEDURE WriteFixed (complex: LONGCOMPLEX; place: INTEGER; width: CARDINAL);
  (* Writes the value of complex to cid in fixed-point text form, with real parts rounded to the given place relative to the decimal point, in a field of the given minimum width. *)
 
PROCEDURE WriteComplex (complex: LONGCOMPLEX; width: CARDINAL);
  (* Writes the value of complex to cid, as WriteFixed if the sign and magnitude can be shown in the given width, or otherwise as WriteFloat.  The number of places or significant digits depends on the given width.  *)
 
END SLongComplexIO.

A6.9 ComplexIO

DEFINITION MODULE ComplexIO;

(* =========================================
          © 1996 by R. Sutcliffe
    Last modification date 1996 10 30
===========================================*)

  (* Input and output of complex numbers in decimal text form over specified channels. The read result is of the type IOConsts.ReadResults. *)
 
IMPORT IOChan;
 
  (* The text form of a complex number is
       realNumber, [space], ["+" | "-"], [space,] [realnumber, i] |
       [realNumber, [space],] ["+" | "-"], [space,] realnumber, i
     where the real numbers in each case are in the 
     format specified for fixed or floating reals.
  *)
   
PROCEDURE ReadComplex (cid: IOChan.ChanId; VAR complex: COMPLEX);
  (* Skips leading spaces, and removes any remaining characters from cid that form part of a complex number.  The value of this number is assigned to complex. The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or  endOfInput. *)
 
(* following procedure affects all the Write procs below *)
PROCEDURE SetVerbose (verbose : BOOLEAN);
  (* if true prints both components even if one is zero; else prints only one if the other is zero. The default is false. *)

PROCEDURE WriteFloat (cid: IOChan.ChanId; complex: COMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* Writes the value of complex to cid in floating-point real text form, with sigFigs significant figures, in a field of the given minimum width. The width for the real parts is 0 if the supplied width is 3 or less, and it is (width - 4) DIV 2 otherwise.  *)
 
PROCEDURE WriteEng (cid: IOChan.ChanId; complex: COMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* As for WriteFloat, except that the number is scaled with one to three
digits in the whole number part, and with an exponent that is a multiple of three. *)
 
PROCEDURE WriteFixed (cid: IOChan.ChanId; complex: COMPLEX; place: INTEGER; width: CARDINAL);
  (* Writes the value of complex to cid in fixed-point text form, with real parts rounded to the given place relative to the decimal point, in a field of the given minimum width. *)
 
PROCEDURE WriteComplex (cid: IOChan.ChanId; complex: COMPLEX; width: CARDINAL);
  (* Writes the value of complex to cid, as WriteFixed if the sign and magnitude can be shown in the given width, or otherwise as WriteFloat.  The number of places or significant digits depends on the given width.  *)
 
END ComplexIO.

A6.10 LongComplexIO

DEFINITION MODULE LongComplexIO;

(* =========================================
          © 1996 by R. Sutcliffe
    Last modification date 1996 11 01
===========================================*)

  (* Input and output of LongComplex numbers in decimal text form over specified channels. The read result is of the type IOConsts.ReadResults. *)
 
IMPORT IOChan;
 
  (* The text form of a LongComplex number is
       realNumber, [space], ["+" | "-"], [space,] [realnumber, i] |
       [realNumber, [space],] ["+" | "-"], [space,] realnumber, i
     where the real numbers in each case are in the 
     format specified for fixed or floating longreals.
  *)
   
PROCEDURE ReadComplex (cid: IOChan.ChanId; VAR complex: LONGCOMPLEX);
  (* Skips leading spaces, and removes any remaining characters from cid that form part of a complex number.  The value of this number is assigned to complex. The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or  endOfInput. *)
 
(* following procedure affects all the Write procs below *)
PROCEDURE SetVerbose (verbose : BOOLEAN);
  (* if true prints both components even if one is zero; else prints only one if the other is zero. The default is false. *)

PROCEDURE WriteFloat (cid: IOChan.ChanId; complex: LONGCOMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* Writes the value of complex to cid in floating-point real text form, with sigFigs significant figures, in a field of the given minimum width. The width for the real parts is 0 if the supplied width is 3 or less, and it is (width - 4) DIV 2 otherwise.  *)
 
PROCEDURE WriteEng (cid: IOChan.ChanId; complex: LONGCOMPLEX; sigFigs: CARDINAL; width: CARDINAL);
  (* As for WriteFloat, except that the number is scaled with one to three
digits in the whole number part, and with an exponent that is a multiple of three. *)
 
PROCEDURE WriteFixed (cid: IOChan.ChanId; complex: LONGCOMPLEX; place: INTEGER; width: CARDINAL);
  (* Writes the value of complex to cid in fixed-point text form, with real parts rounded to the given place relative to the decimal point, in a field of the given minimum width. *)
 
PROCEDURE WriteComplex (cid: IOChan.ChanId; complex: LONGCOMPLEX; width: CARDINAL);
  (* Writes the value of complex to cid, as WriteFixed if the sign and magnitude can be shown in the given width, or otherwise as WriteFloat.  The number of places or significant digits depends on the given width.  *)
 
END LongComplexIO.

A6.11 GraphPaper

DEFINITION MODULE GraphPaper;

(* Original design copyright 1996 by R. Sutcliffe
    Original implementation 1996 using p1 on the Macintosh
    Windows implementation 1998 05 12 by Joel Schwartz
        with use of examples written by Stony Brook
        Last revision by RS 1998 07 11
*)

TYPE
  CoordSystem = (MacWin, bearing, standard); (* default = standard *)
(* The MacWin Coordinate system grows down and has the origin at the top
   left hand corner with angles measured clockwise. In the bearing
   system the home position (0,0) is the middle of the screen
   from which angles are measured clockwise. The standard system also
   starts in mid screen and grows up but measures from east as zero and
   thence counterclockwise. *)

  AngleType = (deg, rad, grad); (* Allows for angle type specification *)
  LabelType = ARRAY [0..50] OF CHAR;  (* Standard format for labels *)

PROCEDURE SetCoordSystem (kind : CoordSystem);
(* Allows the user to set the system. The default is the standard system so this has to be called only if a change is desired. This procedure concludes by calling Home. Any shift in the system origin must be made after calling this procedure.  *)
PROCEDURE SetAngleType (kind : AngleType);
(* Allows the user to set the angle measurement type. The default is degrees so this has to be called only if a change is desired. This procedure concludes by calling Home. Any shift in the system origin must be made after calling this procedure.  *)

PROCEDURE Home;
(* moves to 0,0 and then
     In the bearing system:
       - sets angle to 0 (North)
       - sets the rotational direction to clockwise
     In the MacWin & standard system:
       - sets the angle to 0 (East)
       - sets the rotational direction to clockwise (MacWin)
               or to counterclockwise (standard) *)

PROCEDURE ShiftOrigin (deltaX, deltaY : INTEGER);
(* Translate the origin by the amount specified.  The direction of the translation on the screen depends, of course, on the coordinate system being used. Drawing is now with respect to the new origin. Does not call home or change  any other settings. *)

PROCEDURE GetDimensions (VAR x, y: INTEGER);
  (* obtains the overall width and height of the drawing screen *)
PROCEDURE GetLocation (VAR x, y: INTEGER);
  (* get the drawing pen location in current coordinates *)

(* The following three procedures work in the current coordinate
system and on the stored pen position only but do no actual drawing. *)

PROCEDURE MoveBy (distance: INTEGER);
  (* move in the stored direction by the supplied distance *)
PROCEDURE MoveTo (x, y : INTEGER);
  (* move the drawing pen to the specified coordinates *)
PROCEDURE Move (dx, dy : INTEGER);
  (* move the drawing pen to a point (x + dx, y + dy) from the currently stored point *)

(* The following three procedures work in the current coordinate system on the stored pen direction only but do no actual drawing. 
The angle is assumed to be in the currently set units. *)

PROCEDURE GetCurrentAngle () : REAL;
  (* Return the current angle in the current units *)
PROCEDURE Turn (angle : REAL);
  (* change the stored pen direction by adding its angle to the one supplied *)
PROCEDURE TurnTo (angle : REAL);
(* change the stored pen direction by setting its angle to the one supplied *)

(* The following two procedures use the pen to draw a line and change the stored position. *)

PROCEDURE LineBy (distance: INTEGER);
  (* Draws in the stored pen direction the number of units supplied. *)
PROCEDURE LineTo (x, y : INTEGER);
(* Draws a line from the current stored position to the supplied one without using or changing the stored direction. *)
PROCEDURE Line (dx, dy : INTEGER);
(* Line to a point (x + dx, y + dy) from the current point without using or changing the stored direction. *)

(* The following two procedures place a dot on the screen, but do not change the pen direction. Measurement is in pixels; not scaled. *)

PROCEDURE Dot;
   (* places a dot at the present location *)
PROCEDURE DotAt (x, y : INTEGER);
   (* does a MoveTo, then a dot *)

(* These procedures are for annotating the graph paper with a scale and labels for the axes. *)

PROCEDURE SetLabels (horix, vert : LabelType);
   (* Sets the names for the horizontal and vertical axes. *)
PROCEDURE ShowLabels;
   (* Show the labels - if no label is set then "x" and "y" are used *)
PROCEDURE ShowAxes;
   (* Show the axes for the graph *)

(* The following procedures allow for a scaling of the graph paper and the plotting of points according to the scale. If the scale is 10, there is one unit every ten division marks. This will make the plotting of functions more readible. The default is one unit per division mark.
    EXAMPLE: setting the scale to 5 using cm's as the unit means 1 cm = 5 division marks.*)

PROCEDURE SetScale (dataPerDivision : CARDINAL);
   (* Set the scale by which the graph is measured *)
PROCEDURE PlotPoint( x, y : REAL);
   (* Plot a scaled point on the graph *)
PROCEDURE PolarPlotPoint (radius, angle : REAL);
   (* Moves to a given angle and radius and places a scaled dot at that point.
	 The angle is assumed to be in the currently set units. *)

END GraphPaper.

A6.12 GraphWindow

DEFINITION MODULE GraphWindow;

(* Design and Macintosh implementattion by R.  Sutcliffe
   Windows implementation by Joel Schwartz
   Last revision: 1998 07 07 *)
   
(* This module obtains and passes to applications that need it a simple graphics window and its dimensions. Some applications will need only to import this module, and possibly get the window dimensions, as graphing takes place in the current grafport anyway, and this module will set that port, so GetWindow may not have to be imported. *)

IMPORT (* MacOS *) Quickdraw; (* Windows: IMPORT WIN32; *) 

(* for convenience we export the type of the reference; this makes it more compatible to the 
Windows version where we import the HDC type and define WindowRef to be an HDC. *)

TYPE 
  WindowRef = Quickdraw.WindowRef;  (* Windows: WindowRef = WIN32.HDC *)

PROCEDURE GetWindow () : WindowRef;
PROCEDURE GetWDimensions (VAR width, height : INTEGER);

END GraphWindow.


Contents