a few less #ifdef's

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5955 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2009-03-28 09:47:26 +00:00
parent 49276c77c7
commit 501dc3c699
3 changed files with 26 additions and 47 deletions

View file

@ -1166,13 +1166,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
case TOK_P_DELFILE:
{
char *file = line.gettoken_str(1);
#ifndef _WIN32
file = my_convert(file);
#endif
PATH_CONVERT(file);
int result = unlink(file);
#ifndef _WIN32
my_convert_free(file);
#endif
if (result == -1) {
ERROR_MSG("!delfile: \"%s\" couldn't be deleted.\n", line.gettoken_str(1));
return PS_ERROR;
@ -2911,9 +2906,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
#ifdef _WIN32
int ret=sane_system(exec);
#else
char *execfixed = my_convert(exec);
int ret=system(execfixed);
my_convert_free(execfixed);
PATH_CONVERT(exec);
int ret=system(exec);
#endif
if (comp == 0 && ret < cmpv);
else if (comp == 1 && ret > cmpv);
@ -2948,16 +2942,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
SCRIPT_MSG("!execute: \"%s\"\n",exec);
}
case TOK_P_ADDINCLUDEDIR:
#ifdef _WIN32
include_dirs.add(line.gettoken_str(1),0);
#else
{
char *f = line.gettoken_str(1);
char *fc = my_convert(f);
include_dirs.add(fc,0);
my_convert_free(fc);
PATH_CONVERT(f);
include_dirs.add(f,0);
}
#endif
return PS_OK;
case TOK_P_INCLUDE:
{
@ -2975,11 +2964,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
PRINTHELP();
}
#ifdef _WIN32
char *fc = f;
#else
char *fc = my_convert(f);
#endif
int included = 0;
string dir = get_dir_name(fc);
@ -2991,9 +2976,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
basedir = "";
}
#ifndef _WIN32
my_convert_free(fc);
#endif
// search working directory
boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
@ -4550,13 +4533,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
}
int tf=0;
#ifdef _WIN32
int v=do_add_file(line.gettoken_str(a), attrib, 0, &tf, on);
#else
char *fn = my_convert(line.gettoken_str(a));
char *fn = line.gettoken_str(a);
PATH_CONVERT(fn);
int v=do_add_file(fn, attrib, 0, &tf, on);
my_convert_free(fn);
#endif
if (v != PS_OK) return v;
if (tf > 1) PRINTHELP()
if (!tf)
@ -4608,13 +4587,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
t=buf;
}
int tf=0;
#ifdef _WIN32
int v=do_add_file(t, attrib, rec, &tf, NULL, which_token == TOK_FILE, NULL, excluded);
#else
char *fn = my_convert(t);
int v=do_add_file(fn, attrib, rec, &tf, NULL, which_token == TOK_FILE, NULL, excluded);
my_convert_free(fn);
#endif
if (v != PS_OK) return v;
if (!tf)
{
@ -5836,13 +5811,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (line.getnumtokens() == 2)
{
SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1));
#ifdef _WIN32
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
char *path = line.gettoken_str(1);
PATH_CONVERT(path);
m_plugins.FindCommands(path, display_info?true:false);
return PS_OK;
}
}

View file

@ -328,19 +328,15 @@ void my_convert_free(char *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);
PATH_CONVERT(pathname);
int result = open(pathname, flags);
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);
PATH_CONVERT(path);
FILE *result = fopen(path, mode);
return result;
}
#endif//!_WIN32

View file

@ -74,8 +74,12 @@ FILE *my_fopen(const char *path, const char *mode);
#else
#define my_convert(x) (x)
#define my_convert_free(x)
#define FOPEN(a, b) fopen(a, b)
#define OPEN(a, b) open(a, b)
#endif
// round a value up to be a multiple of 512
@ -142,5 +146,13 @@ RM_DEFINE_FREEFUNC(close);
RM_DEFINE_FREEFUNC(CloseHandle);
RM_DEFINE_FREEFUNC(fclose);
RM_DEFINE_FREEFUNC(free);
RM_DEFINE_FREEFUNC(my_convert_free);
// Auto path conversion
#ifndef _WIN32
# define PATH_CONVERT(x) x = my_convert(x); MANAGE_WITH(x, my_convert_free);
#else
# define PATH_CONVERT(x)
#endif
#endif //_UTIL_H_