REM >Filename REM Library of functions to do with simple file handling REM ======================================================================== DEF FNget_filename(prompt$) REM ======================================================================== LOCAL filename$ REPEAT PRINTprompt$; INPUT filename$ UNTIL FNfilename_valid(filename$)=1 =filename$ REM ======================================================================== DEF FNget_filename_default(prompt$,default$) REM ======================================================================== REM Requires UI library. LOCAL filename$ REPEAT filename$ = FNget_str_param(prompt$, default$) UNTIL FNfilename_valid(filename$)=1 =filename$ REM ======================================================================== DEF FNget_filename_dangerous(prompt$) REM ======================================================================== LOCAL filename$ REPEAT PRINTprompt$; INPUT filename$ UNTIL FNfilename_dangerous_valid(filename$)=1 =filename$ DEF FNfilename_valid(filename$) LOCAL X,Y IF LEN(filename$)=0 THEN =0 IF LEN(filename$)>8 THEN PRINT "- 8 character maximum for ADFS->PC floppies, I'm afraid." REM I've had a nasty incident with this already and don't want another. =0 ENDIF IF INSTR(filename$," ") <> 0 THEN PRINT "- Dozy today? I said no spaces." =0 ENDIF X = OPENIN(filename$) IF X <> 0 THEN CLOSE#X:PRINT "- File exists, choose another." =0 ENDIF LOCAL Y Y = OPENOUT(filename$) IF Y=0 THEN =0 CLOSE#Y REM OSCLI("DELETE "+filename$) REM A bad filename will crash the program, but never mind, REM it's not a crucial stage. Professional programming REM requires an ON ERROR statement. Oh well. REM 29-Jan-99: deleted the file (fed up with clearing up after REM programs that use this function and then are aborted). REM 04-Jun-99: deleting the file UNDER CONSIDERATION after a nasty incident REM in which a program may have failed to check that two filenames were REM different, so overwrote the first of them. REM Leaving the file there prevents that kind of error. REM However, it was the Evenden program using DelayLib, and that does check. REM So where's the data? REM REM 05-Jun-99: solved. The DelayLib on the Arcs was out of date. Bugger. REM But this is too dangerous to trust to user code, so deletion was REMOVED. =1 DEF FNfilename_dangerous_valid(filename$) REM Allows files that already exist. 1 July 99. For AC. REM (1) Removes existence check. REM (2) Does *not* check using OPENOUT/OPENUP. IF LEN(filename$)=0 THEN =0 IF LEN(filename$)>8 THEN PRINT "- 8 character maximum for ADFS->PC floppies, I'm afraid." REM I've had a nasty incident with this already and don't want another. =0 ENDIF IF INSTR(filename$," ") <> 0 THEN PRINT "- Dozy today? I said no spaces." =0 ENDIF =1