From cd68fa311a33c5d0c475a754cb1fa5e676356618 Mon Sep 17 00:00:00 2001 From: Roland Heyder Date: Sun, 23 Jun 2024 17:21:06 +0200 Subject: [PATCH] Move function (refactor) - move RemoveDoubleSlashes$() into utilities\file.bas and make it proper case - adapt all calls to it accordingly --- source/ide/ide_methods.bas | 12 ++++++------ source/utilities/file.bas | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index bd689105f..ace653557 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -12288,7 +12288,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE) 'create new folder newpath$ = idenewfolder(path$) IF LEN(newpath$) THEN - f$ = removeDoubleSlashes$(newpath$) + f$ = RemoveDoubleSlashes$(newpath$) GOTO changepath ELSE GOTO ideopenloop @@ -12308,13 +12308,13 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE) IF focus = 3 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 newpath$ = ".." f$ = newpath$ GOTO changepath ELSE - path$ = removeDoubleSlashes$(idezchangepath(path$, newpath$)) + path$ = RemoveDoubleSlashes$(idezchangepath(path$, newpath$)) idetxt(o(2).txt) = idezfilelist$(path$, AllFiles, "") idetxt(o(3).txt) = idezpathlist$(path$) @@ -12345,7 +12345,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE) changepath: IF _DIREXISTS(path$ + idepathsep$ + f$) THEN '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 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 '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 idetxt(o(3).txt) = idezpathlist$(path$) o(3).sel = -1 @@ -12385,7 +12385,7 @@ FUNCTION idefiledialog$(programname$, mode AS _BYTE) END IF 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 mode = 1 THEN diff --git a/source/utilities/file.bas b/source/utilities/file.bas index 544427b03..6bd714f64 100644 --- a/source/utilities/file.bas +++ b/source/utilities/file.bas @@ -216,6 +216,22 @@ FUNCTION GetEscapedPath$ (path_name AS STRING) GetEscapedPath = buf 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 FUNCTION FixDirectoryName$ (dir_name AS STRING) IF LEN(dir_name) > 0 AND RIGHT$(dir_name, 1) <> pathsep$ THEN