From 5bd319249150633552bad0e59c88076f5f2b4c92 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Thu, 23 Mar 2023 05:33:28 +0530 Subject: [PATCH] Fix #124 --- source/qb64pe.bas | 42 +++++++++++++++++++++++++++++++-------- source/utilities/file.bas | 35 ++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index ee25cb495..8847727e9 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -4140,25 +4140,21 @@ DO END IF NEXT + og_libpath$ = libpath$ ' save the original libpath + 'Accept ./ and .\ as a reference to the source file 'folder, replacing it with the actual full path, if available IF libpath$ = "./" OR libpath$ = ".\" THEN libpath$ = "" IF NoIDEMode THEN - libpath$ = path.source$ - IF LEN(libpath$) > 0 AND RIGHT$(libpath$, 1) <> pathsep$ THEN libpath$ = libpath$ + pathsep$ + libpath$ = FixDirectoryName(path.source$) ELSE IF LEN(ideprogname) THEN libpath$ = idepath$ + pathsep$ END IF END IF 'Create a path which can be used for inline code (uses \\ instead of \) - libpath_inline$ = "" - FOR z = 1 TO LEN(libpath$) - a = ASC(libpath$, z) - libpath_inline$ = libpath_inline$ + CHR$(a) - IF a = 92 THEN libpath_inline$ = libpath_inline$ + "\" - NEXT + libpath_inline$ = GetEscapedPath(libpath$) IF LEN(x$) THEN IF dynamiclibrary = 0 THEN @@ -4475,6 +4471,21 @@ DO sfheader = 1 GOTO GotHeader END IF + ' a740g: Fallback to source path + libpath$ = FixDirectoryName(idepath$) + og_libpath$ + libpath_inline$ = GetEscapedPath(libpath$) + IF _FILEEXISTS(libpath$ + x$ + ".h") THEN + headername$ = libpath_inline$ + x$ + ".h" + IF customtypelibrary = 0 THEN sfdeclare = 0 + sfheader = 1 + GOTO GotHeader + END IF + IF _FILEEXISTS(libpath$ + x$ + ".hpp") THEN + headername$ = libpath_inline$ + x$ + ".hpp" + IF customtypelibrary = 0 THEN sfdeclare = 0 + sfheader = 1 + GOTO GotHeader + END IF END IF 'Windows IF os$ = "LNX" THEN @@ -4527,6 +4538,21 @@ DO sfheader = 1 GOTO GotHeader END IF + ' a740g: Fallback to source path + libpath$ = FixDirectoryName(idepath$) + og_libpath$ + libpath_inline$ = GetEscapedPath(libpath$) + IF _FILEEXISTS(libpath$ + x$ + ".h") THEN + headername$ = libpath_inline$ + x$ + ".h" + IF customtypelibrary = 0 THEN sfdeclare = 0 + sfheader = 1 + GOTO GotHeader + END IF + IF _FILEEXISTS(libpath$ + x$ + ".hpp") THEN + headername$ = libpath_inline$ + x$ + ".hpp" + IF customtypelibrary = 0 THEN sfdeclare = 0 + sfheader = 1 + GOTO GotHeader + END IF END IF 'Linux GotHeader: diff --git a/source/utilities/file.bas b/source/utilities/file.bas index 84b10b5bd..9f7ce5e8a 100644 --- a/source/utilities/file.bas +++ b/source/utilities/file.bas @@ -4,19 +4,19 @@ ' ' Returns: 0 on success, 1 on error FUNCTION CopyFile& (sourceFile$, destFile$) - DIM sourcefileNo, destFileNo + DIM sourceFileNo, destFileNo DIM fileLength AS _INTEGER64 E = 0 sourceFileNo = FREEFILE - OPEN sourceFile$ FOR BINARY as #sourceFileNo - if E = 1 THEN GOTO errorCleanup + OPEN sourceFile$ FOR BINARY AS #sourceFileNo + IF E = 1 THEN GOTO errorCleanup fileLength = LOF(sourceFileNo) destFileNo = FREEFILE - OPEN destFile$ FOR BINARY as #destFileNo - if E = 1 THEN GOTO errorCleanup + OPEN destFile$ FOR BINARY AS #destFileNo + IF E = 1 THEN GOTO errorCleanup ' Read the file in one go buffer$ = SPACE$(fileLength) @@ -24,7 +24,7 @@ FUNCTION CopyFile& (sourceFile$, destFile$) GET #sourceFileNo, , buffer$ PUT #destFileNo, , buffer$ -errorCleanup: + errorCleanup: IF sourceFileNo <> 0 THEN CLOSE #sourceFileNo IF destFileNo <> 0 THEN CLOSE #destFileNo @@ -99,3 +99,26 @@ SUB PATH_SLASH_CORRECT (a$) NEXT END IF END SUB + +' Return a pathname where all "\" are correctly escaped +FUNCTION GetEscapedPath$ (path_name AS STRING) + DIM buf AS STRING, z AS _UNSIGNED LONG, a AS _UNSIGNED _BYTE + + FOR z = 1 TO LEN(path_name) + a = ASC(path_name, z) + buf = buf + CHR$(a) + IF a = 92 THEN buf = buf + "\" + NEXT + + GetEscapedPath = buf +END FUNCTION + +' Adds a trailing \ or / if to the name if needed +FUNCTION FixDirectoryName$ (dir_name AS STRING) + IF LEN(dir_name) > 0 AND RIGHT$(dir_name, 1) <> pathsep$ THEN + FixDirectoryName = dir_name + pathsep$ + ELSE + FixDirectoryName = dir_name + END IF +END FUNCTION +