A SuperBASIC OPEN_OVER() Function Working with TKII Default Directory
Posted: Tue Feb 04, 2025 12:21 am
The TKII defaults are the horror of horrors for a programmer (but of course superb when using SB as command shell).
I wanted a function which "opens over" a file. If it's not yet existing create it, else delete it (e.g. UQLX does not support overwriting files) and open it new.
It's not so easy, as I first have thought, because of the defaults (DATAD$) of SuperToolkit II. Albeit the following function has only 3 real lines of code, it took me a few hours of making it bullet proof. At least if only one program runs. If it runs in multitasking it still may go wrong, cause the QDOS sheduler may interrupt a BASIC program at any time and if another program creates the just deleted fnam$ after line 20220 (EDIT: Was2020) and creates a new one, the function will (of course) fail. Well live is full of risk and always ends with death.
This function ignores DATAD$. If not a fully qualified pathname, e.g. 'FLP1_filename' ('filename' alone is not a fully qualified filename) this function returns "bad parameter" (-15).
Albeit my function seems to work as expected, I think I will write a SuperBASIC Open-function, which will always ignore the TKII default directories. I wonder, why no one else has yet written such a function (and test function if pathname exists, and if it exists, is it a file or a directory [file type 255]). As I have now detected George Gwilts excellent Assembler gass, this would be a good chance to test it (I normally use QMAC, the Quanta version).
I wanted a function which "opens over" a file. If it's not yet existing create it, else delete it (e.g. UQLX does not support overwriting files) and open it new.
It's not so easy, as I first have thought, because of the defaults (DATAD$) of SuperToolkit II. Albeit the following function has only 3 real lines of code, it took me a few hours of making it bullet proof. At least if only one program runs. If it runs in multitasking it still may go wrong, cause the QDOS sheduler may interrupt a BASIC program at any time and if another program creates the just deleted fnam$ after line 20220 (EDIT: Was2020) and creates a new one, the function will (of course) fail. Well live is full of risk and always ends with death.
This function ignores DATAD$. If not a fully qualified pathname, e.g. 'FLP1_filename' ('filename' alone is not a fully qualified filename) this function returns "bad parameter" (-15).
Albeit my function seems to work as expected, I think I will write a SuperBASIC Open-function, which will always ignore the TKII default directories. I wonder, why no one else has yet written such a function (and test function if pathname exists, and if it exists, is it a file or a directory [file type 255]). As I have now detected George Gwilts excellent Assembler gass, this would be a good chance to test it (I normally use QMAC, the Quanta version).
Code: Select all
20000 REMark Library functions
20010 REMark Required: SuperToolkit II, TurboToolkit
20040 :
20080 DEFine FuNction hps_openOver%(c%,fnam$):REMark Opens device for writing
20090 REMark If it's a file (filename) which already exists it will first be
20100 REMark deleted before the file is opened new (with fop_new(). If the file
20110 REMark could not be opened for read/write, an error is returned
20120 REMark The arguments (parameters) are not altered by the function
20130 REMark W A R N I N G : fnam$ must be a fully qualified name (no default from
20140 REMark SuperToolkit II, e.g. DATAD$ is added before fnam$)! If not a fully
20150 REMark qualified filename, error "bad parameter" (-15) is returned.
20160 REMark Note: File is not really opened with FOP_OVER but it's deleted and
20170 REMark then opened with FOP_NEW(). This means it also will work on UQLX
20180 REMark which does NOT support OPEN_OVER
20190 :
20220 IF DEVICE_STATUS(0,fnam$)>=0:DELETE fnam$
20260 IF DEVICE_STATUS(1,DATAD$&fnam$)>=0:RETurn -15:REMark A fully qualified
20300 REMark filename must be passed to this function!
20340 RETurn FOP_NEW(#c%,fnam$)
20380 END DEFine :REMark hps_openOver()