| OPEN | |||||||||||||||||
| Syntax | OPEN filename (OPEN filename mode) OPEN [] (OPEN [] mode) OPEN type-descriptors (OPEN type-descriptors mode) |
||||||||||||||||
| Explanation | OPEN prepares for input or output the
file specified by its input. When a file has been opened,
OPEN returns a channel number which can be used for I/O.
The channel number may be assigned to one of the built-in
variables STANDARD.INPUT
or STANDARD.OUTPUT.
Data may then be read using READ,
READCHAR, READLINE, READLIST, READQUOTE and other Logo
primitives. Data may be written using all Logo commands
that print, such as PRINT, or TYPE. If the specified file does not
exist, OPEN throws an I/O error. Many Logo commands that do I/O also accept a channel number as an optional, additional input. The I/O is made using that channel instead of the channel number stored in STANDARD.INPUT or STANDARD.OUTPUT. This makes it easier to perform I/O with multiple channels. A file is opened for read access in text mode if no
other inputs are given. The second input, however, may be
a combination of the following characters:
OPEN is also capable of displaying a standard file open/save dialog box. In order to open a dialog box instead of a file, the file name contains a list of file type descriptors. A file type descriptor is a file type, optionally followed by an "=" and a description. The text "lgo=Logo source file" would be a vaild file type descriptor for all files ending with ".LGO". More than one file descriptor may be supplied; in this case, separate the descriptors with commas. The file open/save dialog would display all files ending with the given file type. A Windows dialog would also display the description of the file types, while a Macintosh dialog would display the matching files only. The Logo command OPEN "|lgo=Logo source file,txt=Text file| would, for example, display all files ending with .LGO or .TXT. If you use "*" as a file type, the file open/save dialog displays all available files. This is done differently on Windows and Macintosh. A Windows dialog would initially display all files with the first type, and offer all additional file types as choices. The Macintosh dialog would always display all files matching all file types. If you use the empty word or the empty list as a file name, Logo automatically opens a file open/save dialog displaying all available files. Clicking the Cancel button in a file open/save dialog makes the OPEN command return -1 as the channel number. |
||||||||||||||||
| Examples | TO TYPE.FILE :FILE MAKE "CHANNEL OPEN :FILE MAKE "STANDARD.INPUT :CHANNEL WHILE [NOT EOF?] [PRINT RQ] CLOSE :CHANNEL END TYPE.FILE defined TYPE.FILE "LINES.TXT This is line 1 This is line 2 This is line 3 |
||||||||||||||||