From 29ce453957d3eb4ac794deeee4e18cba9ec4bd96 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 28 Mar 2023 21:53:50 -0300 Subject: [PATCH] Searching for datafiles on all win32 possible paths. --- configure.ac | 1 + locale/pt_BR.po | 4 ++-- src/core/windows/util.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- win/build.conf.in | 2 ++ win/ci-build.sh | 5 ++++- 5 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 win/build.conf.in diff --git a/configure.ac b/configure.ac index ffb4777..d303f75 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,7 @@ case "$host" in INSTALL_PACKAGES="$INSTALL_PACKAGES delayed" AC_CONFIG_FILES(win/lib3270.mak) + AC_CONFIG_FILES(win/build.conf) ;; diff --git a/locale/pt_BR.po b/locale/pt_BR.po index d5a4468..98c9c8d 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: pw3270 5.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-13 03:12-0300\n" +"POT-Creation-Date: 2023-03-28 21:15-0300\n" "PO-Revision-Date: 2021-09-01 23:53-0300\n" "Last-Translator: Perry Werneck \n" "Language-Team: Português \n" @@ -2071,7 +2071,7 @@ msgstr "Aguardando resposta do pedido de upload" msgid "Warning" msgstr "Alerta" -#: src/core/windows/util.c:126 src/core/windows/util.c:169 +#: src/core/windows/util.c:123 src/core/windows/util.c:166 #, c-format msgid "Windows error %d" msgstr "Erro windows foi %d" diff --git a/src/core/windows/util.c b/src/core/windows/util.c index 4a8ac0d..a342ff1 100644 --- a/src/core/windows/util.c +++ b/src/core/windows/util.c @@ -219,15 +219,23 @@ LIB3270_EXPORT const char * lib3270_win32_local_charset(void) { #define SECS_TO_100NS 10000000ULL /* 10^7 */ LIB3270_EXPORT char * lib3270_get_installation_path() { - char lpFilename[4096]; + char lpFilename[MAX_PATH]; memset(lpFilename,0,sizeof(lpFilename)); DWORD szPath = GetModuleFileName(hModule,lpFilename,sizeof(lpFilename)); lpFilename[szPath] = 0; - char * ptr = strrchr(lpFilename,'\\'); - if(ptr) - ptr[1] = 0; + char *ptr = strrchr(lpFilename,'\\'); + if(ptr) { + ptr[0] = 0; + + ptr = strrchr(lpFilename,'\\'); + if(ptr && !(strcasecmp(ptr,"\\bin") && strcasecmp(ptr,"\\lib"))) { + *ptr = 0; + } + + strncat(lpFilename,"\\",MAX_PATH); + } return strdup(lpFilename); } @@ -274,13 +282,8 @@ static char * build_filename(const char *str, va_list args) { memset(filename,0,szFilename); -#ifdef DEBUG - filename[0] = '.'; - filename[1] = '\\'; -#else DWORD szPath = GetModuleFileName(hModule,filename,szFilename); filename[szPath] = 0; -#endif // DEBUG ptr = strrchr(filename,'\\'); if(ptr) { @@ -303,14 +306,74 @@ static char * build_filename(const char *str, va_list args) { } char * lib3270_build_data_filename(const char *str, ...) { - va_list args; - va_start (args, str); - char *filename = build_filename(str, args); + char *ptr; + lib3270_autoptr(char) instpath = lib3270_get_installation_path(); - va_end (args); + for(ptr = instpath; *ptr; ptr++) { + if(*ptr == '/') { + *ptr = '\\'; + } + } - return filename; + if( *(instpath+strlen(instpath)-1) = '\\') { + instpath[strlen(instpath)-1] = 0; + } + + char relative[MAX_PATH+1]; + memset(relative,0,MAX_PATH); + + { + va_list args; + va_start (args, str); + + while(str) { + + if(str[0] == '\\' || str[0] == '/') { + strncat(relative,str,MAX_PATH); + } else { + strncat(relative,"\\",MAX_PATH); + strncat(relative,str,MAX_PATH); + } + + str = va_arg(args, const char *); + } + + va_end (args); + } + + for(ptr = relative; *ptr; ptr++) { + if(*ptr == '/') { + *ptr = '\\'; + } + } + + char filename[MAX_PATH+1]; + memset(filename,0,MAX_PATH+1); + + // Check instdir + strncpy(filename,instpath,MAX_PATH); + strncat(filename,"\\share",MAX_PATH); + strncat(filename,relative,MAX_PATH); + + if(access(filename,0) == 0) { + return strdup(filename); + } + + strncpy(filename,instpath,MAX_PATH); + strncat(filename,"\\share\\",MAX_PATH); + strncat(filename,LIB3270_STRINGIZE_VALUE_OF(PRODUCT_NAME),MAX_PATH); + strncat(filename,relative,MAX_PATH); + + if(access(filename,0) == 0) { + return strdup(filename); + } + + // Default behavior. + strncpy(filename,instpath,MAX_PATH); + strncat(filename,relative,MAX_PATH); + + return strdup(filename); } char * lib3270_build_config_filename(const char *str, ...) { diff --git a/win/build.conf.in b/win/build.conf.in new file mode 100644 index 0000000..1cff396 --- /dev/null +++ b/win/build.conf.in @@ -0,0 +1,2 @@ +LIBRARY_VERSION=@WIN32_VERSION@ +TARGET_ARCH=@host_cpu@ diff --git a/win/ci-build.sh b/win/ci-build.sh index 02ce579..55634ac 100755 --- a/win/ci-build.sh +++ b/win/ci-build.sh @@ -27,7 +27,10 @@ echo "Building lib3270" make clean > $LOGFILE 2>&1 || die "Make clean failure" make all > $LOGFILE 2>&1 || die "Make failure" make DESTDIR=.bin/package install -tar --create --xz --file=mingw-lib3270.tar.xz --directory=.bin/package --verbose . + +. ./win/build.conf + +tar --create --xz --file=mingw-lib3270.${TARGET_ARCH}.tar.xz --directory=.bin/package --verbose . -- libgit2 0.21.2