,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 23
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
6-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,ce
I/O PROCEDURES

Example : reset (t, filename) ;
             .
             .
          close (t)

close-procedure = close ( device-variable )

CREATE

This procedure is normally used to open a new file on a disk (file variable type). In this usage the string expression is the name to be given to the file and the mode is "input", "output", or "update" which determines the allowable data direction. The attribute expression (truncated to one byte if hex or integer) will be passed to the runtime code and is used as an operating system dependent flag. It will be defaulted to 0 if not included. If the file already exists it will be truncated to zero length (may be deleted first depending on operating system).
 
If the second parameter is one of the standard device names "input", "output", "keyboard", or "auxout" then the device is initialized to be that device. In this case the last two parameters are not used. This is very useful for determining the nature of the device during runtime.

Examples : create (t, 'path1', input) ;
           create (t, 'path1', output, 40) ;
           create (t, input) ;

create-procedure = create ( device-variable ,
                   (standard-device | string-expression) [, mode
                   [, attribute-expression ]] )
standard-device = (input | output | keyboard | auxout)
mode = (input | output | update)


   create    (   device varib    ,      standard device        ,

                                          string expr.


 
             )       integer expr.         ,       mode

                     hex expression

                     character expr.


DEL

This procedure is normally used on disk-file devices to delete the file specified by the string expression. If the file does not exist, an error will occur.
,pg
,ce
I/O PROCEDURES

Example : var
            t : text ;
            s : string ;
          begin
            write ('File to delete : ') ;
            readln (s) ;
            del (t, s)
          end.

del-procedure = del ( device-variable , string-expression ) 

DEVINIT

If a file or device is declared as part of an array or record then the compiler will not automatically initialize the device at the start of the block. This procedure is used for that purpose. As an example, in the following declaration :

var
  x : integer ;
  fgroup : array [1..5] of record
                             status : boolean ;
                             fyle : text
                           end ;

The following code could be used to initialize each file in the array :

  for x := 1 to 5 do
     devinit (fgroup[x].fyle) ;

Devinit is also used to initialize files or devices that do not have any executable block. This occurs if a file or device is declared globally in a module in varib section, since a module does not have a global block.

devinit-procedure = devinit ( device-variable )

DEVSTAT

This procedure can be used as a "wild-card" to perform device-driver dependent operations. Since the second parameter can be any variable, even a structure such as a record, there is really no limit to what can be done with this procedure.

Examples would be device status operations such as data ready, or buffer full, or file size. This procedure could also be used to perform device initializations, or send a break on a serial line, or explode the computer (requires appropriate hardware).

Chapter 3 will detail the format of the second parameter if this procedure is implemented in any of the supplied device drivers.

devstat-procedure = devstat ( device-variable , any-variable )

GET

Will transfer data from a device into its element buffer (device^). If the eof status is set on the device then performing a get will generate an eof runtime error. 

If eof is not set then get will attempt to transfer data from the device into the element buffer. If eof is hit during this transfer then the eof status is set and the element buffer is undefined (space for text devices). If any other error is encountered during the transfer it will generate a runtime error. This procedure will also set the eoln status if appropriate on text devices.
,ce
I/O PROCEDURES

Example : while not eof (infile) do
            begin
              copyfile^ := infile^ ;
              get (infile) ;
              put (copyfile)
            end ;

get-procedure = get ( device-variable )

OPEN

This procedure is normally used to open an existing file on a disk (file variable type). In this usage the string expression is the name to be given to the file and the mode is "input", "output", or "update" which determines the allowable data direction. The attribute expression (truncated to one byte if hex or integer) will be passed to the runtime code and is used as an operating system dependent flag. It will be defaulted to 0 if not included. If the file does not exist a runtime error will be generated.
 
If the second parameter is one of the standard device names "input", "output", "keyboard", or "auxout" then the device is initialized to be that device. In this case the last two parameters are not used. This is very useful for determining the nature of the device during runtime.

open-procedure = open ( device-variable ,
                 (standard-device | string-expression) [, mode
                 [, attribute-expression ]] )
standard-device = (input | output | keyboard | auxout)
mode = (input | output | update)


   open    (   device varib    ,      standard device        ,

                                        string expr.


 
             )       integer expr.         ,       mode

                     hex expression

                     character expr.


PAGE

Will bring the text device to top of form if supported by the device driver. If the device is not currently at the beginning of the line then a writeln will be performed before issuing the top of form. In most cases this procedure is only used when driving a printer. If the parameter is not used then the standard output device will be used as the parameter.

Example : page (auxout) ;

page-procedure = page [ ( device-variable ) ]

PUT

Will transfer data from the device's element buffer (device^) to the actual device. If any errors are encountered during the transfer then a runtime error will be generated.

put-procedure = put ( device-variable ) 

READ AND READLN

These two procedures transfer data from a device to one or more variables. Readln is identical to read except it can only be used on text devices and will skip data up until the next end of line marker if necessary, thereby making sure that the next read or readln will start at the beginning of a new line.

For non-text devices the ISO standard specifies that read is equivalent to :

variable := device^ ;
get (device)

But in OmegaSoft Pascal a method is used to handle both interactive files and random access which requires a flag be used to indicate whether or not the contents of the element buffer is valid. Using this method a read is equivalent to :

if device^ is not valid
  then
    get (device) ;
variable := device^ ;
device^ := not valid

This will rarely make any difference in the operation of a standard ISO program. The only affect of this method is that data is not transferred into the element buffer until actually needed. The exception to this is when an eof or eoln function is performed on a non-interactive device which would do a get to check for those devices - this would set device^ valid so that a read procedure that follows would not do the initial get.

If the device is of type text then internal conversions are done using the boolean, integer, hex, longhex, longinteger, real, and longreal functions for boolean and numeric values using a string parameter. The read procedure will skip leading blanks when reading these types (this includes the blank that represents end of line) until it finds the end of a non-blank sequence. If a character is being read then nothing will be skipped and a space will be read in place of the end of line mark. If a string is read then it will read all characters up to but not including the end of line mark. Note that if a string read is attempted while eoln is true then a null string will be returned and eoln will still be true.

The sequence :

readln (device, var1, var2, var3)
,pg
,ce
I/O PROCEDURES

is equivalent to :

read (device, var1)
read (device, var2)
readln (device, var3)

and so it makes no sense to read multiple strings in this manner since the read of var1 will leave you on the eoln mark and so var2 and var3 must receive a null string. Multiple string reads must be done with multiple readln procedures - one per string.

If the eof status for the devices is true when a read is called then a runtime error will be generated.

If the first parameter is not a device variable then the standard input device will be used.

read-procedure = read [( (device-variable [{, variable}] |
                          variable {, variable}) )]
readln-procedure = readln [( (device-variable [{, variable}] |
                              variable {, variable}) )]


   read
                (      device-var       ,     variable       )
  readln


RESET

There are two forms of the reset procedure. The first one includes only a device parameter and is used to open a file for input using a file name derived from the command line. As an example :

program test (input,output,file1,file2) ;
  var
    file1 : text ;
    file2 : file of integer ;
  begin
    reset (file1) ;
    reset (file2) ;

file1 will be opened using the first command line parameter and file2 will be opened using the second command line parameter. This is a result of the declaration of the two device variables in the program parameter list. In this case reset (file1) is equivalent to reset (file1, cline(1)) (second form below). If this form is used and the device name is not in the program parameter list then a null string will be used for the file name.

The second form of reset uses an additional string parameter which specifies the file name to use. This second parameter will override the default file name if the device is declared in the program parameter list. 

reset (device, name) 

is equivalent to :

open (device, name, input).
,pg
,ce
I/O PROCEDURES

reset-procedure = reset ( device-variable [, string-expression] )

REWRITE

There are two forms of the rewrite procedure. The first one includes only a device parameter and is used to create a new file for output using a file name derived from the command line. As an example :

program test (input,output,file1,file2) ;
  var
    file1 : text ;
    file2 : file of integer ;
  begin
    rewrite (file1) ;
    rewrite (file2) ;

file1 will be created using the first command line parameter and file2 will be created using the second command line parameter. This is a result of the declaration of the two device variables in the program parameter list. In this case rewrite (file1) is equivalent to rewrite (file1, cline(1)) (second form below). If this form is used and the device name is not in the program parameter list then a null string will be used for the file name.

The second form of rewrite uses an additional string parameter which specifies the file name to use. This second parameter will override the default file name if the device is declared in the program parameter list. 

rewrite (device, name) 

is equivalent to :

create (device, name, output).

rewrite-procedure = rewrite ( device-variable
                              [, string-expression] )

SEEK

Is normally used to access records on a disk file. The parameter is used as the record number to move to, this is multiplied by the size of the element to obtain a 32 bit byte offset into the file. After a seek is done either a read/get or write/put can be done and the file then acts sequentially until a new seek is done. The first record of a file is 0 and therefore seek (device,0) is equivalent to a rewind operation.

seek-procedure = seek ( device-variable , (integer-expression |
                       hex-expression | longinteger-expression |
                       longhex-expression) )

WRITE AND WRITELN

These two procedures transfer data from one or more expressions to a device. Writeln is identical to write except it can only be used on text devices and will add a carriage return (and possibly a line feed depending on the device) to the end of the data to move to the next line.

