1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-19 23:44:46 +00:00

Move function (refactor)

- move RemoveDoubleSlashes$() into utilities\file.bas and make it proper case
- adapt all calls to it accordingly
This commit is contained in:
Roland Heyder 2024-06-23 17:21:06 +02:00
parent c021b96eda
commit cd68fa311a
2 changed files with 22 additions and 6 deletions

View file

@ -12288,7 +12288,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE)
'create new folder 'create new folder
newpath$ = idenewfolder(path$) newpath$ = idenewfolder(path$)
IF LEN(newpath$) THEN IF LEN(newpath$) THEN
f$ = removeDoubleSlashes$(newpath$) f$ = RemoveDoubleSlashes$(newpath$)
GOTO changepath GOTO changepath
ELSE ELSE
GOTO ideopenloop GOTO ideopenloop
@ -12308,13 +12308,13 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE)
IF focus = 3 THEN IF focus = 3 THEN
IF (K$ = CHR$(13) OR info = 1) AND o(3).sel >= 1 THEN IF (K$ = CHR$(13) OR info = 1) AND o(3).sel >= 1 THEN
newpath$ = removeDoubleSlashes$(idetxt(o(3).stx)) newpath$ = RemoveDoubleSlashes$(idetxt(o(3).stx))
IF newpath$ = "" THEN IF newpath$ = "" THEN
newpath$ = ".." newpath$ = ".."
f$ = newpath$ f$ = newpath$
GOTO changepath GOTO changepath
ELSE ELSE
path$ = removeDoubleSlashes$(idezchangepath(path$, newpath$)) path$ = RemoveDoubleSlashes$(idezchangepath(path$, newpath$))
idetxt(o(2).txt) = idezfilelist$(path$, AllFiles, "") idetxt(o(2).txt) = idezfilelist$(path$, AllFiles, "")
idetxt(o(3).txt) = idezpathlist$(path$) idetxt(o(3).txt) = idezpathlist$(path$)
@ -12345,7 +12345,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE)
changepath: changepath:
IF _DIREXISTS(path$ + idepathsep$ + f$) THEN IF _DIREXISTS(path$ + idepathsep$ + f$) THEN
'check/acquire file path 'check/acquire file path
path$ = removeDoubleSlashes$(idezgetfilepath$(path$, f$ + idepathsep$)) 'note: path ending with pathsep needn't contain a file path$ = RemoveDoubleSlashes$(idezgetfilepath$(path$, f$ + idepathsep$)) 'note: path ending with pathsep needn't contain a file
IF ideerror > 1 THEN EXIT FUNCTION IF ideerror > 1 THEN EXIT FUNCTION
IF LEN(newpath$) = 0 THEN IF LEN(newpath$) = 0 THEN
@ -12365,7 +12365,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE)
IF INSTR(f$, "?") > 0 OR INSTR(f$, "*") > 0 THEN IF INSTR(f$, "?") > 0 OR INSTR(f$, "*") > 0 THEN
IF INSTR(f$, "/") > 0 OR INSTR(f$, "\") > 0 THEN IF INSTR(f$, "/") > 0 OR INSTR(f$, "\") > 0 THEN
'path + wildcards 'path + wildcards
path$ = removeDoubleSlashes$(idezgetfilepath$(path$, f$)) 'note: path ending with pathsep needn't contain a file path$ = RemoveDoubleSlashes$(idezgetfilepath$(path$, f$)) 'note: path ending with pathsep needn't contain a file
IF ideerror > 1 THEN EXIT FUNCTION IF ideerror > 1 THEN EXIT FUNCTION
idetxt(o(3).txt) = idezpathlist$(path$) idetxt(o(3).txt) = idezpathlist$(path$)
o(3).sel = -1 o(3).sel = -1
@ -12385,7 +12385,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE)
END IF END IF
DirectLoad: DirectLoad:
path$ = removeDoubleSlashes$(idezgetfilepath$(path$, f$)) 'repeat in case of DirectLoad path$ = RemoveDoubleSlashes$(idezgetfilepath$(path$, f$)) 'repeat in case of DirectLoad
IF ideerror > 1 THEN EXIT FUNCTION IF ideerror > 1 THEN EXIT FUNCTION
IF mode = 1 THEN IF mode = 1 THEN

View file

@ -216,6 +216,22 @@ FUNCTION GetEscapedPath$ (path_name AS STRING)
GetEscapedPath = buf GetEscapedPath = buf
END FUNCTION END FUNCTION
' Returns a path/file with single slashes only, effectively unescaping "\"
FUNCTION RemoveDoubleSlashes$(f2$)
f$ = f2$ 'avoid arg side effects
DO 'sp% = 0 at function entry
sp% = INSTR(sp% + 1, f$, "//")
IF sp% > 0 THEN f$ = LEFT$(f$, sp% - 1) + MID$(f$, sp% + 1)
LOOP UNTIL sp% = 0
DO 'sp% = 0 again from 1st loop end
sp% = INSTR(sp% + 1, f$, "\\")
IF sp% > 0 THEN f$ = LEFT$(f$, sp% - 1) + MID$(f$, sp% + 1)
LOOP UNTIL sp% = 0
RemoveDoubleSlashes$ = f$
END FUNCTION
' Adds a trailing \ or / to a directory name if needed ' Adds a trailing \ or / to a directory name if needed
FUNCTION FixDirectoryName$ (dir_name AS STRING) FUNCTION FixDirectoryName$ (dir_name AS STRING)
IF LEN(dir_name) > 0 AND RIGHT$(dir_name, 1) <> pathsep$ THEN IF LEN(dir_name) > 0 AND RIGHT$(dir_name, 1) <> pathsep$ THEN