- auto conversion of paths on POSIX platforms - based on patch #1005673

- LoadLanguageFile error message improvement


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3636 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2004-08-20 15:40:38 +00:00
parent 827b69fbb5
commit 98caca8be1
8 changed files with 184 additions and 51 deletions

View file

@ -49,14 +49,20 @@ typedef unsigned long HBRUSH;
typedef WORD LANGID; typedef WORD LANGID;
#endif #endif
// system specific
#ifdef _WIN32 // script path separator
# define PATH_SEPARATOR_STR "\\" # define PATH_SEPARATOR_STR "\\"
# define PATH_SEPARATOR_C '\\' # define PATH_SEPARATOR_C '\\'
// system specific separator
#ifdef _WIN32
# define PLATFORM_PATH_SEPARATOR_STR "\\"
# define PLATFORM_PATH_SEPARATOR_C '\\'
#else #else
# define PATH_SEPARATOR_STR "/" # define PLATFORM_PATH_SEPARATOR_STR "/"
# define PATH_SEPARATOR_C '/' # define PLATFORM_PATH_SEPARATOR_C '/'
#endif #endif
// attributes // attributes

View file

@ -34,7 +34,7 @@ void Plugins::FindCommands(char* path, bool displayInfo)
char* pathAndWildcard = new char [length+7]; char* pathAndWildcard = new char [length+7];
strcpy(pathAndWildcard,basePath); strcpy(pathAndWildcard,basePath);
strcat(pathAndWildcard,PATH_SEPARATOR_STR "*.dll"); strcat(pathAndWildcard,PLATFORM_PATH_SEPARATOR_STR "*.dll");
#ifdef _WIN32 #ifdef _WIN32
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
@ -59,7 +59,7 @@ void Plugins::FindCommands(char* path, bool displayInfo)
#ifdef _WIN32 #ifdef _WIN32
{ {
char* dllPath = new char [length+strlen(data.cFileName)+2]; char* dllPath = new char [length+strlen(data.cFileName)+2];
wsprintf(dllPath,"%s" PATH_SEPARATOR_STR "%s",basePath,data.cFileName); wsprintf(dllPath,"%s" PLATFORM_PATH_SEPARATOR_STR "%s",basePath,data.cFileName);
#else #else
char *dllPath = new char [strlen(globbuf.gl_pathv[i])+1]; char *dllPath = new char [strlen(globbuf.gl_pathv[i])+1];
strcpy(dllPath,globbuf.gl_pathv[i]); strcpy(dllPath,globbuf.gl_pathv[i]);
@ -93,7 +93,7 @@ void Plugins::GetExports(char* pathToDll, bool displayInfo)
char signature[1024]; char signature[1024];
dllName[0] = 0; dllName[0] = 0;
char* ptr = strrchr(pathToDll,PATH_SEPARATOR_C); char* ptr = strrchr(pathToDll,PLATFORM_PATH_SEPARATOR_C);
if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1); if (ptr && *ptr && *(ptr+1)) strcpy(dllName,ptr+1);
// find .dll // find .dll

View file

@ -478,7 +478,7 @@ definedlist.add("NSIS_SUPPORT_LANG_IN_STRINGS");
void CEXEBuild::setdirs(char *argv0) void CEXEBuild::setdirs(char *argv0)
{ {
char szNSISDir[NSIS_MAX_STRLEN*2],*fn2; char szNSISDir[NSIS_MAX_STRLEN*2],*fn2;
int len = sizeof(szNSISDir) - sizeof(PATH_SEPARATOR_STR "Include") - 1; int len = sizeof(szNSISDir) - sizeof(PLATFORM_PATH_SEPARATOR_STR "Include") - 1;
#ifdef _WIN32 #ifdef _WIN32
GetModuleFileName(NULL,szNSISDir,len); GetModuleFileName(NULL,szNSISDir,len);
#else #else
@ -487,10 +487,10 @@ void CEXEBuild::setdirs(char *argv0)
szNSISDir[sizeof(szNSISDir)-1] = 0; szNSISDir[sizeof(szNSISDir)-1] = 0;
my_free_realpath(argv0, buffer); my_free_realpath(argv0, buffer);
#endif #endif
fn2=strrchr(szNSISDir,PATH_SEPARATOR_C); fn2=strrchr(szNSISDir,PLATFORM_PATH_SEPARATOR_C);
if(fn2!=NULL) *fn2=0; if(fn2!=NULL) *fn2=0;
definedlist.add("NSISDIR",(char*)szNSISDir); definedlist.add("NSISDIR",(char*)szNSISDir);
strcat(szNSISDir, PATH_SEPARATOR_STR "Include"); strcat(szNSISDir, PLATFORM_PATH_SEPARATOR_STR "Include");
include_dirs.add(szNSISDir,0); include_dirs.add(szNSISDir,0);
} }
@ -2322,7 +2322,7 @@ int CEXEBuild::write_output(void)
// Pack exe header if asked for // Pack exe header if asked for
if (build_packname[0] && build_packcmd[0]) if (build_packname[0] && build_packcmd[0])
{ {
FILE *tmpfile=fopen(build_packname,"wb"); FILE *tmpfile=FOPEN(build_packname,"wb");
if (!tmpfile) if (!tmpfile)
{ {
ERROR_MSG("Error: writing temporary file \"%s\" for pack\n",build_packname); ERROR_MSG("Error: writing temporary file \"%s\" for pack\n",build_packname);
@ -2336,7 +2336,7 @@ int CEXEBuild::write_output(void)
ERROR_MSG("Error: calling packer on \"%s\"\n",build_packname); ERROR_MSG("Error: calling packer on \"%s\"\n",build_packname);
return PS_ERROR; return PS_ERROR;
} }
tmpfile=fopen(build_packname,"rb"); tmpfile=FOPEN(build_packname,"rb");
if (!tmpfile) if (!tmpfile)
{ {
remove(build_packname); remove(build_packname);
@ -2389,7 +2389,7 @@ int CEXEBuild::write_output(void)
my_free_realpath(build_output_filename, buffer); my_free_realpath(build_output_filename, buffer);
#endif #endif
} }
FILE *fp = fopen(build_output_filename,"w+b"); FILE *fp = FOPEN(build_output_filename,"w+b");
if (!fp) if (!fp)
{ {
ERROR_MSG("Can't open output file\n"); ERROR_MSG("Can't open output file\n");
@ -2451,7 +2451,7 @@ int CEXEBuild::write_output(void)
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
if (build_compress_whole) if (build_compress_whole)
{ {
int n; int n;
if (compressor == &lzma_compressor) if (compressor == &lzma_compressor)
n = ((CLZMA *) compressor)->Init(build_compress_level, build_compress_dict_size); n = ((CLZMA *) compressor)->Init(build_compress_level, build_compress_dict_size);
else else
@ -3176,8 +3176,8 @@ void CEXEBuild::build_plugin_table(void)
char* searchPath = new char [strlen(nsisdir)+9]; char* searchPath = new char [strlen(nsisdir)+9];
if (searchPath) if (searchPath)
{ {
sprintf(searchPath,"%s" PATH_SEPARATOR_STR "Plugins",nsisdir); sprintf(searchPath,"%s" PLATFORM_PATH_SEPARATOR_STR "Plugins",nsisdir);
INFO_MSG("Processing plugin dlls: \"%s" PATH_SEPARATOR_STR "*.dll\"\n",searchPath); INFO_MSG("Processing plugin dlls: \"%s" PLATFORM_PATH_SEPARATOR_STR "*.dll\"\n",searchPath);
m_plugins.FindCommands(searchPath,display_info?true:false); m_plugins.FindCommands(searchPath,display_info?true:false);
INFO_MSG("\n"); INFO_MSG("\n");
delete[] searchPath; delete[] searchPath;

View file

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "build.h" #include "build.h"
#include "util.h"
#include "DialogTemplate.h" #include "DialogTemplate.h"
#include "exehead/resource.h" #include "exehead/resource.h"
@ -730,9 +731,9 @@ BOOL IsValidCodePage(UINT CodePage)
// NSIS Language File parser // NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(char *filename) { LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
FILE *f = fopen(filename, "r"); FILE *f = FOPEN(filename, "r");
if (!f) { if (!f) {
ERROR_MSG("Error: Can't open language file!\n"); ERROR_MSG("Error: Can't open language file - \"%s\"!\n",filename);
return 0; return 0;
} }

View file

@ -271,7 +271,7 @@ int main(int argc, char **argv)
exepath[1023]=0; exepath[1023]=0;
char *p=exepath; char *p=exepath;
while (*p) p++; while (*p) p++;
while (p > exepath && *p != PATH_SEPARATOR_C) p=CharPrev(exepath,p); while (p > exepath && *p != PLATFORM_PATH_SEPARATOR_C) p=CharPrev(exepath,p);
if (p>exepath) p++; if (p>exepath) p++;
strcpy(p,"nsisconf.nsh"); strcpy(p,"nsisconf.nsh");
FILE *cfg=fopen(exepath,"rt"); FILE *cfg=fopen(exepath,"rt");
@ -336,10 +336,10 @@ int main(int argc, char **argv)
p=CharPrev(dirbuf,p); p=CharPrev(dirbuf,p);
#else #else
getcwd(dirbuf,sizeof(dirbuf)-strlen(sfile)-2); getcwd(dirbuf,sizeof(dirbuf)-strlen(sfile)-2);
if (dirbuf[strlen(dirbuf)-1]!=PATH_SEPARATOR_C) if (dirbuf[strlen(dirbuf)-1]!=PLATFORM_PATH_SEPARATOR_C)
strcat(dirbuf,PATH_SEPARATOR_STR); strcat(dirbuf,PLATFORM_PATH_SEPARATOR_STR);
strcat(dirbuf,sfile); strcat(dirbuf,sfile);
p=strrchr(dirbuf,PATH_SEPARATOR_C); p=strrchr(dirbuf,PLATFORM_PATH_SEPARATOR_C);
#endif #endif
if (!p) p=dirbuf; if (!p) p=dirbuf;
*p=0; *p=0;

View file

@ -634,7 +634,7 @@ int CEXEBuild::parseScript()
int CEXEBuild::includeScript(char *f) int CEXEBuild::includeScript(char *f)
{ {
SCRIPT_MSG("!include: \"%s\"\n",f); SCRIPT_MSG("!include: \"%s\"\n",f);
FILE *incfp=fopen(f,"rt"); FILE *incfp=FOPEN(f,"rt");
if (!incfp) if (!incfp)
{ {
ERROR_MSG("!include: could not open file: \"%s\"\n",f); ERROR_MSG("!include: could not open file: \"%s\"\n",f);
@ -1335,7 +1335,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
FILE *fp; FILE *fp;
unsigned int datalen; unsigned int datalen;
fp=fopen(file,"rb"); fp=FOPEN(file,"rb");
if (!fp) if (!fp)
{ {
ERROR_MSG("LicenseLangString: open failed \"%s\"\n",file); ERROR_MSG("LicenseLangString: open failed \"%s\"\n",file);
@ -1643,7 +1643,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (!idx) if (!idx)
{ {
unsigned int datalen; unsigned int datalen;
FILE *fp=fopen(file,"rb"); FILE *fp=FOPEN(file,"rb");
if (!fp) if (!fp)
{ {
ERROR_MSG("LicenseData: open failed \"%s\"\n",file); ERROR_MSG("LicenseData: open failed \"%s\"\n",file);
@ -2196,7 +2196,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int k=line.gettoken_enum(1, "all\0IDD_LICENSE\0IDD_DIR\0IDD_SELCOM\0IDD_INST\0IDD_INSTFILES\0IDD_UNINST\0IDD_VERIFY\0IDD_LICENSE_FSRB\0IDD_LICENSE_FSCB\0"); int k=line.gettoken_enum(1, "all\0IDD_LICENSE\0IDD_DIR\0IDD_SELCOM\0IDD_INST\0IDD_INSTFILES\0IDD_UNINST\0IDD_VERIFY\0IDD_LICENSE_FSRB\0IDD_LICENSE_FSCB\0");
if (k<0) PRINTHELP(); if (k<0) PRINTHELP();
FILE *fui = fopen(line.gettoken_str(2), "rb"); FILE *fui = FOPEN(line.gettoken_str(2), "rb");
if (!fui) { if (!fui) {
ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2)); ERROR_MSG("Error: Can't open \"%s\"!\n", line.gettoken_str(2));
return PS_ERROR; return PS_ERROR;
@ -2589,7 +2589,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
int cmpv=line.gettoken_int(3,&success); int cmpv=line.gettoken_int(3,&success);
if (!success && comp != 4) PRINTHELP() if (!success && comp != 4) PRINTHELP()
SCRIPT_MSG("!system: \"%s\"\n",exec); SCRIPT_MSG("!system: \"%s\"\n",exec);
#ifdef _WIN32
int ret=system(exec); int ret=system(exec);
#else
char *execfixed = my_convert(exec);
int ret=system(execfixed);
my_convert_free(execfixed);
#endif
if (comp == 0 && ret < cmpv); if (comp == 0 && ret < cmpv);
else if (comp == 1 && ret > cmpv); else if (comp == 1 && ret > cmpv);
else if (comp == 2 && ret != cmpv); else if (comp == 2 && ret != cmpv);
@ -2616,7 +2622,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
} }
#else #else
system(exec); char *execfixed = my_convert(exec);
system(execfixed);
my_convert_free(execfixed);
#endif #endif
SCRIPT_MSG("!execute: \"%s\"\n",exec); SCRIPT_MSG("!execute: \"%s\"\n",exec);
} }
@ -2652,7 +2660,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
char *incfile = (char *) malloc(malloced); char *incfile = (char *) malloc(malloced);
strcpy(incfile, f); strcpy(incfile, f);
glob_t globbuf; glob_t globbuf;
if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) if (!GLOB(incfile, GLOB_NOSORT, NULL, &globbuf))
{ {
for (unsigned int i = 0; i < globbuf.gl_pathc; i++) for (unsigned int i = 0; i < globbuf.gl_pathc; i++)
{ {
@ -2700,7 +2708,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (includeScript(incfile) != PS_OK) if (includeScript(incfile) != PS_OK)
#else #else
if (!glob(incfile, GLOB_NOSORT, NULL, &globbuf)) if (!GLOB(incfile, GLOB_NOSORT, NULL, &globbuf))
{ {
for (unsigned int i = 0; i < globbuf.gl_pathc; i++) for (unsigned int i = 0; i < globbuf.gl_pathc; i++)
{ {
@ -4021,7 +4029,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (!*on||line.getnumtokens()!=a+1||strstr(on,"*") || strstr(on,"?")) PRINTHELP() if (!*on||line.getnumtokens()!=a+1||strstr(on,"*") || strstr(on,"?")) PRINTHELP()
int tf=0; int tf=0;
#ifdef _WIN32
int v=do_add_file(line.gettoken_str(a), attrib, 0, linecnt,&tf,on); int v=do_add_file(line.gettoken_str(a), attrib, 0, linecnt,&tf,on);
#else
char *fn = my_convert(line.gettoken_str(a));
int v=do_add_file(fn, attrib, 0, linecnt,&tf,on);
my_convert_free(fn);
#endif
if (v != PS_OK) return v; if (v != PS_OK) return v;
if (tf > 1) PRINTHELP() if (tf > 1) PRINTHELP()
if (!tf) if (!tf)
@ -4039,11 +4053,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_OK; return PS_OK;
} }
#ifdef _WIN32
else if (line.gettoken_str(a)[0] == '/') PRINTHELP() else if (line.gettoken_str(a)[0] == '/') PRINTHELP()
#endif
if (line.getnumtokens()<a+1) PRINTHELP() if (line.getnumtokens()<a+1) PRINTHELP()
while (a < line.getnumtokens()) while (a < line.getnumtokens())
{ {
#ifdef _WIN32
if (line.gettoken_str(a)[0]=='/') PRINTHELP() if (line.gettoken_str(a)[0]=='/') PRINTHELP()
#endif
char buf[32]; char buf[32];
char *t=line.gettoken_str(a++); char *t=line.gettoken_str(a++);
if (t[0] && CharNext(t)[0] == ':' && CharNext(t)[1] == '\\' && !CharNext(t)[2]) if (t[0] && CharNext(t)[0] == ':' && CharNext(t)[1] == '\\' && !CharNext(t)[2])
@ -4053,7 +4071,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
t=buf; t=buf;
} }
int tf=0; int tf=0;
#ifdef _WIN32
int v=do_add_file(t, attrib, rec, linecnt,&tf,NULL,which_token == TOK_FILE); int v=do_add_file(t, attrib, rec, linecnt,&tf,NULL,which_token == TOK_FILE);
#else
char *fn = my_convert(t);
int v=do_add_file(fn, attrib, rec, linecnt,&tf,NULL,which_token == TOK_FILE);
my_convert_free(fn);
#endif
if (v != PS_OK) return v; if (v != PS_OK) return v;
if (!tf) if (!tf)
{ {
@ -4337,7 +4361,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
*p=0; *p=0;
} }
strcat(nrpath,path); strcat(nrpath,path);
FILE *f=fopen(nrpath, "r"); FILE *f=FOPEN(nrpath, "r");
if (f) { if (f) {
path=nrpath; path=nrpath;
fclose(f); fclose(f);
@ -5283,7 +5307,13 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (line.getnumtokens() == 2) if (line.getnumtokens() == 2)
{ {
SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1)); SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1));
#ifdef _WIN32
m_plugins.FindCommands(line.gettoken_str(1),display_info?true:false); m_plugins.FindCommands(line.gettoken_str(1),display_info?true:false);
#else
char *converted_path = my_convert(line.gettoken_str(1));
m_plugins.FindCommands(converted_path,display_info?true:false);
my_convert_free(converted_path);
#endif
return PS_OK; return PS_OK;
} }
} }
@ -5310,7 +5340,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
// DLL name on the user machine // DLL name on the user machine
char tempDLL[NSIS_MAX_STRLEN]; char tempDLL[NSIS_MAX_STRLEN];
wsprintf(tempDLL, "$PLUGINSDIR%s", strrchr(dllPath,'\\')); char *dllName = strrchr(dllPath,PLATFORM_PATH_SEPARATOR_C);
if (dllName && *dllName == PLATFORM_PATH_SEPARATOR_C)
dllName++;
wsprintf(tempDLL, "$PLUGINSDIR%c%s", PATH_SEPARATOR_C, dllName);
// Add the DLL to the installer // Add the DLL to the installer
if (data_handle == -1) if (data_handle == -1)
@ -5491,11 +5524,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
strcpy(dir,lgss); strcpy(dir,lgss);
{ {
char *s=dir+strlen(dir); char *s=dir+strlen(dir);
while (s > dir && *s != PATH_SEPARATOR_C) s=CharPrev(dir,s); while (s > dir && *s != PLATFORM_PATH_SEPARATOR_C) s=CharPrev(dir,s);
if (s == dir) if (s == dir)
{ {
if (*s == PATH_SEPARATOR_C) if (*s == PLATFORM_PATH_SEPARATOR_C)
sprintf(dir,"%c.",PATH_SEPARATOR_C); sprintf(dir,"%c.",PLATFORM_PATH_SEPARATOR_C);
else else
strcpy(dir,"."); strcpy(dir,".");
} }
@ -5512,14 +5545,14 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
if ((d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) if ((d.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{ {
#else #else
glob(lgss, GLOB_NOSORT, NULL, &globbuf); GLOB(lgss, GLOB_NOSORT, NULL, &globbuf);
{ {
for (unsigned int i = 0; i < globbuf.gl_pathc; i++) for (unsigned int i = 0; i < globbuf.gl_pathc; i++)
{ {
struct stat s; struct stat s;
if (!stat(globbuf.gl_pathv[i], &s) && S_ISREG(s.st_mode)) if (!stat(globbuf.gl_pathv[i], &s) && S_ISREG(s.st_mode))
{ {
char *filename = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); char *filename = strrchr(globbuf.gl_pathv[i], PLATFORM_PATH_SEPARATOR_C);
if (filename) if (filename)
filename++; filename++;
else else
@ -5532,7 +5565,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
#ifdef _WIN32 #ifdef _WIN32
HANDLE hFile; HANDLE hFile;
sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); sprintf(newfn,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",d.cFileName);
hFile = CreateFile( hFile = CreateFile(
newfn, newfn,
GENERIC_READ, GENERIC_READ,
@ -5559,10 +5592,10 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
#else #else
int fd; int fd;
sprintf(newfn,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",filename); sprintf(newfn,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",filename);
len = (DWORD) s.st_size; len = (DWORD) s.st_size;
fd = open(newfn, O_RDONLY); fd = OPEN(newfn, O_RDONLY);
if (fd == -1) if (fd == -1)
{ {
globfree(&globbuf); globfree(&globbuf);
@ -5792,7 +5825,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
if (a==INVALID_FILE_ATTRIBUTES) if (a==INVALID_FILE_ATTRIBUTES)
{ {
a=GetFileAttributes(dir); a=GetFileAttributes(dir);
sprintf(newfn,"%s%s*.*",dir,dir[0]?PATH_SEPARATOR_STR:""); sprintf(newfn,"%s%s*.*",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"");
} }
#else #else
int a; int a;
@ -5800,7 +5833,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
if (stat(lgss, &st)) if (stat(lgss, &st))
{ {
stat(dir, &st); stat(dir, &st);
sprintf(newfn,"%s%s*",dir,dir[0]?PATH_SEPARATOR_STR:""); sprintf(newfn,"%s%s*",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"");
} }
#endif #endif
else else
@ -5828,14 +5861,14 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
#else #else
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
{ {
if (!glob(newfn, GLOB_NOSORT, NULL, &globbuf)) if (!GLOB(newfn, GLOB_NOSORT, NULL, &globbuf))
{ {
for (unsigned int i = 0; i < globbuf.gl_pathc; i++) for (unsigned int i = 0; i < globbuf.gl_pathc; i++)
{ {
struct stat s; struct stat s;
if (!stat(globbuf.gl_pathv[i], &s) && S_ISDIR(s.st_mode)) if (!stat(globbuf.gl_pathv[i], &s) && S_ISDIR(s.st_mode))
{ {
char *dirname = strrchr(globbuf.gl_pathv[i], PATH_SEPARATOR_C); char *dirname = strrchr(globbuf.gl_pathv[i], PLATFORM_PATH_SEPARATOR_C);
if (dirname) if (dirname)
dirname++; dirname++;
else else
@ -5876,12 +5909,12 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
char spec[1024]; char spec[1024];
#ifdef _WIN32 #ifdef _WIN32
wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",d.cFileName); wsprintf(spec,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",d.cFileName);
#else #else
wsprintf(spec,"%s%s%s",dir,dir[0]?PATH_SEPARATOR_STR:"",dirname); wsprintf(spec,"%s%s%s",dir,dir[0]?PLATFORM_PATH_SEPARATOR_STR:"",dirname);
#endif #endif
SCRIPT_MSG("%sFile: Descending to: \"%s\"\n",generatecode?"":"Reserve",spec); SCRIPT_MSG("%sFile: Descending to: \"%s\"\n",generatecode?"":"Reserve",spec);
strcat(spec,PATH_SEPARATOR_STR); strcat(spec,PLATFORM_PATH_SEPARATOR_STR);
strcat(spec,fspec); strcat(spec,fspec);
if (generatecode) if (generatecode)
{ {
@ -5914,7 +5947,7 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int linecn
FindClose(htemp); FindClose(htemp);
#else #else
glob_t globbuf2; glob_t globbuf2;
glob(spec, GLOB_NOSORT, NULL, &globbuf2); GLOB(spec, GLOB_NOSORT, NULL, &globbuf2);
if (globbuf2.gl_pathc) if (globbuf2.gl_pathc)
{ {
#endif #endif

View file

@ -2,11 +2,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <string.h>
#include "exedata.h" #include "exedata.h"
#include "exehead/fileform.h" #include "exehead/fileform.h"
#include "util.h" #include "util.h"
#include "strlist.h" #include "strlist.h"
#ifndef _WIN32
# include <ctype.h>
#endif
int g_dopause=0; int g_dopause=0;
extern int g_display_errors; extern int g_display_errors;
extern FILE *g_output; extern FILE *g_output;
@ -28,7 +33,7 @@ void dopause(void)
// Returns -3 if the size doesn't match // Returns -3 if the size doesn't match
// Returns -4 if the bpp doesn't match // Returns -4 if the bpp doesn't match
int update_bitmap(CResourceEditor* re, WORD id, char* filename, int width/*=0*/, int height/*=0*/, int maxbpp/*=0*/) { int update_bitmap(CResourceEditor* re, WORD id, char* filename, int width/*=0*/, int height/*=0*/, int maxbpp/*=0*/) {
FILE *f = fopen(filename, "rb"); FILE *f = FOPEN(filename, "rb");
if (!f) return -1; if (!f) return -1;
if (fgetc(f) != 'B' || fgetc(f) != 'M') { if (fgetc(f) != 'B' || fgetc(f) != 'M') {
@ -128,7 +133,7 @@ typedef struct {
// -1 - Bad icon file // -1 - Bad icon file
int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) int replace_icon(CResourceEditor* re, WORD wIconId, char* filename)
{ {
FILE* f = fopen(filename, "rb"); FILE* f = FOPEN(filename, "rb");
if (!f) return -1; if (!f) return -1;
IconGroupHeader igh; IconGroupHeader igh;
@ -204,7 +209,7 @@ unsigned char* generate_uninstall_icon_data(char* filename)
{ {
int i; int i;
FILE* f = fopen(filename, "rb"); FILE* f = FOPEN(filename, "rb");
if (!f) return 0; if (!f) return 0;
IconGroupHeader igh; IconGroupHeader igh;
@ -379,7 +384,7 @@ char *CharPrev(const char *s, const char *p) {
char *CharNext(const char *s) { char *CharNext(const char *s) {
int l = 0; int l = 0;
if (s && *s) if (s && *s)
l = max(1, mblen(s, strlen(s))); l = max(1, mblen(s, MB_CUR_MAX));
return (char *) s + l; return (char *) s + l;
} }
@ -416,7 +421,76 @@ void my_free_realpath(char *path, char *buffer)
#endif #endif
} }
#define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}}
char *my_convert(const char *path)
{
char *converted_path = strdup(path);
size_t len = strlen(path);
if(!converted_path)
{
MY_ERROR_MSG("Error: could not allocate memory in my_convert()\n");
return (char*) path; /* dirty */
}
/* Replace drive letter X: by /X */
if(len >= 2)
{
if (path[1] == ':')
{
converted_path[0] = '/';
converted_path[1] = (char) tolower((int) path[0]);
}
}
char *p = converted_path;
do
{
if (*p == '\\')
{
*p = '/';
}
p = CharNext(p);
}
while (*p);
return converted_path;
}
void my_convert_free(char *converted_path)
{
free(converted_path);
}
int my_open(const char *pathname, int flags)
{
char *converted_pathname = my_convert(pathname);
int result = open(converted_pathname, flags);
my_convert_free(converted_pathname);
return result;
}
FILE *my_fopen(const char *path, const char *mode)
{
char *converted_path = my_convert(path);
FILE *result = fopen(converted_path, mode);
my_convert_free(converted_path);
return result;
}
int my_glob(const char *pattern, int flags,
int errfunc(const char * epath, int eerrno), glob_t *pglob)
{
char *converted_pattern = my_convert(pattern);
int result = glob(converted_pattern, flags, errfunc, pglob);
my_convert_free(converted_pattern);
return result;
}
#endif #endif
void *operator new(size_t size) { void *operator new(size_t size) {

View file

@ -3,6 +3,8 @@
#ifndef _WIN32 #ifndef _WIN32
# include <iconv.h> # include <iconv.h>
# include <stdio.h>
# include <glob.h>
#endif #endif
#include "ResourceEditor.h" #include "ResourceEditor.h"
@ -44,6 +46,23 @@ inline size_t __iconv_adaptor
{ {
return iconv_func (cd, (T)inbuf, inbytesleft, outbuf, outbytesleft); return iconv_func (cd, (T)inbuf, inbytesleft, outbuf, outbytesleft);
} }
char *my_convert(const char *path);
void my_convert_free(char *converted_path);
int my_open(const char *pathname, int flags);
FILE *my_fopen(const char *path, const char *mode);
int my_glob(const char *pattern, int flags,
int errfunc(const char * epath, int eerrno), glob_t *pglob);
#define FOPEN(a, b) my_fopen(a, b)
#define GLOB(a, b, c, d) my_glob(a, b, c, d)
#define OPEN(a, b) my_open(a, b)
#else
#define FOPEN(a, b) fopen(a, b)
#define GLOB(a, b, c, d) glob(a, b, c, d)
#define OPEN(a, b) open(a, b)
#endif #endif
#endif //_UTIL_H_ #endif //_UTIL_H_