<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>


#OPEN Search:

In File I/O Words in TurboForth Kernal

Word Name: #OPEN
Type: Standard word
Data Stack Signature: file_id -- flag
Return Stack Signature: --
Availability: V1.0  V1.1  V1.2
Description:

Opens a file with the file name and attributes specified in the buffer starting at file_id.

Example:

none

Comment:

The buffer (actually a PAB) is set-up with FILE.

E.g. FBUF: SERIAL S" RS232.BA=9600 DV80O" SERIAL FILE SERIAL #OPEN

The above attempts to open the serial port for output as a Display Variable 80 type file.

A file buffer called SERIAL is declared (using FBUF:), and this is fed to FILE (along with the string that describes the file). FILE builds the PAB in the buffer named SERIAL.

#OPEN leaves a FALSE on the stack if the file was opened successfully. If the file could not be opened, it leaves a TRUE on the stack. This allows easy trapping with ABORT" as shown below:

SERIAL #OPEN ABORT" Can't open file"

In the event of a file error, IOERR can be read to get the DSR error code. If IOERR returns -1 (>FFFF) then this means that no free file IO slots were found. A maximum of 3 open files are supported (2 if block files are also to be used). Note that block files are immediately closed after they are accessed for either reading or writing, so 3 generic file I/O streams are available when no blocks files are being used.

See Also: #CLOSE  #EOF?  #GET  #PUT  #REC  FILE 

<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>