DOS Interfacing (Part II)
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 NOV 1989 | 1.15+ | EXPERT | DOS, OSOPEN, OPEN, SETPTR, IMPORT.READ, INP, OUT, FILE.SIZE, DISKSIZE, STATUS |
Issue 4 considered the routines available for querying the DOS environment. This month's investigates the routines available for interfacing to DOS and DOS file structures. Whilst some of these routines are documented we will consider how their use may be extended. It is worth pointing out that this article is NOT exhaustive, there are other routines that can be used to interface to DOS - these will be covered at a later date.
OSOPEN
Internal statement. Used to open a DOS file for direct access. If an attempt is made to open a DOS file that does not exist, an error code of 4 will be returned in STATUS(). If an attempt is made to open a DOS subdirectory, an error code of 2 will be returned in STATUS(). Thus to see if a DOS directory exists, OSOPEN it and check the status. If the status is 2, the directory exists, if 2 a file exists with that name.
OPEN
Internal statement. The normal OPEN command can be used to access the various DOS special devices. Thus the printer could be addressed directly by
OPEN "PRN" TO PRN.FILE THEN WRITE STRING TO PRN.FILE END
SETPTR
External subroutine (C or Assembler). Used by PDISK to redirect printer output to file. Passed Filename and Flag, returns Flag indicating status or requested operation. Filename must be appended with a CHAR(0) (this tends to imply a 'C' routine as 'C' uses CHAR(0) as an end of string marker). Flag should be set on entry to 1 for overwrite existing file or 0 for no overwrite.
FILENAME = "C:\AREV\PRN.DAT" FILENAME := CHAR(0) FLAG = 1 CALL SETPTR(FILENAME,FLAG)
The exit conditions are, unfortunately not just 0 or 1! They appear not to conform to the standard OSOPEN error conditions, but those of which I am aware are
2 | Invalid Path |
3 | No such path |
5 | Access denied |
20 | File exists |
21 | Redirected OK |
IMPORT.READ
External subroutine. Used to read records sequentially from a DOS file. With this routine, if the filename and dos delimiters/record length are known, the developer can sequentially access records in a DOS file without access to OSBREAD! The calling syntax is
CALL IMPORT.READ(A,B,C,D,E,F,G)
where
A | is the DOS file var (OSOPENED) |
B | is the offset within the file |
C | is the record delimiter |
D | is the End of File marker |
E | is the record length |
F | is the record returned |
G | is a flag indicating OK (1) or EOF (2). |
Thus to process all records in TEST.DAT which is a CRLF delimited ASCII file with Ctrl-Z as EOF we would
OSOPEN "TEST.DAT" TO A ELSE STOP B = 0 ; * offset, auto-incremented C = CHAR(13) : CHAR(10) D = CHAR(26) E = "" F = "" ; G = "" LOOP UNTIL G = 2 DO CALL IMPORT.READ(A,B,C,D,E,F,G) PRINT F REPEAT
INP
Used to query a port address directly. As this is so hardware specific it can be dangerous to use as it is not portable.
OUT
Used to output to a port address directly. As this is so hardware specific it can be dangerous to use as it is not specific.
FILE.SIZE
A function passed one parameter, the name of the Revelation file that is being sized. The routine returns the size of the DOS file indicating the overflow frames. Using this in conjunction with the DISKSIZE function allows the programmer to see whether there is enough space on disk for a file before attempting to move it, eg
DECLARE FUNCTION FILE.SIZE,DISKSIZE DECLARE SUBROUTINE MSG SPACE.NEEDED = FILE.SIZE("BP") AVAILABLE = disksize("C")<2> IF SPACE.NEEDED > AVAILABLE THEN MSG("ERROR - No Room","","","") END ELSE * * Transfer logic here * END
(Volume 1, Issue 6, Pages 4,5)