home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / modula2 / lpr / inout.def < prev    next >
Encoding:
Modula Definition  |  1994-09-22  |  5.3 KB  |  135 lines

  1. DEFINITION MODULE InOut;
  2.  
  3. (*       Input/output facilities as defined by N.Wirth          
  4.  
  5.          Original material Copyright 1984 ETH Zurich            
  6.          with some extensions.                                *)
  7.  
  8.   CONST EOL = 15C;
  9.  
  10.   VAR Done:  BOOLEAN;
  11.       termCH:  CHAR;  (*terminating character in
  12.                         ReadString, ReadInt, and ReadCard
  13.                         (but not in ReadLine) *)
  14.  
  15.   PROCEDURE OpenInput ( name : ARRAY OF CHAR );
  16.      (*closes the input stream "In" and opens a new input stream *)
  17.  
  18.   PROCEDURE OpenOutput ( name : ARRAY OF CHAR );
  19.      (*closes the output stream "Out" and opens a new output stream. *)
  20.  
  21.      (*If name is a valid file-name or one of the special
  22.        streamnames:
  23.        
  24.                 "CON:"    the Terminal.
  25.                 "AUX:"    the seriel port (RS 232).
  26.                 "PRN:"    the parallel port (the printer)
  27.                 
  28.        that file or stream is opened immedially if possible.
  29.        (In OpenInput "PRN:" causes Done=FALSE.)
  30.        
  31.        Valid examples of file names include:
  32.        
  33.           .DAT (the Modula-2 standard), *.DAT, DATA.*, *A.D*, DATA.D??,
  34.           B:DATA.DAT, G:\*.D?T, C:\FOLDER\?ATA.D?T, etc
  35.           
  36.        If the name is a valid and complete file name (ie contains a name
  37.        but no wildcards ( * or ? )) then this file is opened immediately.
  38.        Else a standard GEM File Selector reflecting as much as possible
  39.        of the given name shows up on the screen offering the user the
  40.        possibility to select the wantet file. A click on Cancel causes 
  41.        Done= FALSE.
  42.        
  43.        If the file or stream is successfully opened subsequent in- or 
  44.        output will be from (to) that file or stream and Done is returned
  45.        TRUE. Else subsequent in- or output will be to the Terminal and
  46.        Done is returned FALSE.
  47.        
  48.        If an already existing file is opened by OpenOutput, that file is 
  49.        first deleted and a new file with the same name is created. *)
  50.        
  51.  
  52.   PROCEDURE CloseInput;
  53.      (* closes input stream "In"; returns input to the keyboard *)
  54.  
  55.   PROCEDURE CloseOutput;
  56.      (* closes output stream "Out"; returns output to screen *)
  57.  
  58.   PROCEDURE Read ( VAR ch : CHAR );
  59.      (* Done := ch was successfully read 
  60.         ie the last char of the stream was not allready read *)
  61.  
  62.   PROCEDURE ReadString ( VAR s : ARRAY OF CHAR );
  63.      (*read a string, i.e. sequence of characters not containing
  64.        blanks nor control characters, from stream "In";
  65.        leading blanks are ignored.
  66.        Input is terminated by any character <= " ";
  67.        this character is assigned to termCH.
  68.        Done:="all characters were read, and assigned 
  69.        to the elements of s".*)
  70.  
  71.   PROCEDURE ReadLine ( VAR s : ARRAY OF CHAR );
  72.      (*read a line, i.e. sequence of characters not containing
  73.        control characters, from stream "In".
  74.        Input is terminated by any character < " ";
  75.        ASCII.NUL (CHR(0)) is assigned to termCH
  76.        and to the first character of S not read into.
  77.        Done:="all characters were read, and assigned 
  78.        to the elements of s".*)
  79.  
  80.   PROCEDURE ReadInt ( VAR x : INTEGER );
  81.      (*read string from stream "In" using ReadString 
  82.        and convert to integer.
  83.        Syntax:
  84.          integer = ["+"|"-"] digit {digit} ["B"|"C"|"H"].
  85.            "B"|"C"   : interpreted as an octal number.
  86.            "H"       : interpreted as a hexadecimal number.
  87.            No letter : interpreted as a decimal number.
  88.        Leading blanks are ignored.
  89.        Done := "integer was read"*)
  90.  
  91.   PROCEDURE ReadCard ( VAR x : CARDINAL );
  92.      (*read string from stream "In" using ReadString
  93.        and convert to cardinal. 
  94.        Syntax:
  95.          cardinal = digit {digit} ["B"|"C"|"H"]. 
  96.            "B"|"C"   : interpreted as an octal number.
  97.            "H"       : interpreted as a hexadecimal number.
  98.            No letter : interpreted as a decimal number.
  99.        Leading blanks are ignored.
  100.        Done := "cardinal was read"*)
  101.  
  102.   PROCEDURE Write ( ch : CHAR );
  103.      (* Writes any 8 bit character on stream "Out" *)
  104.  
  105.   PROCEDURE WriteLn;
  106.      (* terminate line by writing ASCII.CR and ASCII.LF on stream "Out" *)
  107.  
  108.   PROCEDURE WriteString ( s : ARRAY OF CHAR );
  109.      (* the string is a sequence of characters ending with ASCII.NUL,
  110.         it is writen on stream "Out" *)
  111.  
  112.   PROCEDURE WriteStringRight ( s : ARRAY OF CHAR; n : INTEGER );
  113.      (* The string is writen on stream "Out".
  114.         If n is greater than the number of character needed,
  115.         blanks are added preceding the string to make the total 
  116.         number of characters equal to n *)
  117.  
  118.   PROCEDURE WriteInt ( x : INTEGER ; n : CARDINAL );
  119.      (* write integer x with (at least) n characters on stream "Out",
  120.         using WriteStringRight *)
  121.         
  122.   PROCEDURE WriteCard ( x, n : CARDINAL);
  123.   PROCEDURE WriteOct  ( x, n : CARDINAL);
  124.   PROCEDURE WriteHex  ( x, n : CARDINAL);
  125.      (*write cardinal x decimal, octal, or hexadecimal,
  126.        analog to WriteInt *)
  127.  
  128.   PROCEDURE ConvFromStr(T : ARRAY OF CHAR;
  129.                   VAR res : LONGCARD;
  130.                       max : LONGCARD;
  131.                       neg : BOOLEAN;
  132.                  VAR done : BOOLEAN);
  133.  
  134. END (* Of DEFINITION MODULE *) InOut.
  135.