From dddcdc03b8d648b4fa7f54cb29ecf8865576352d Mon Sep 17 00:00:00 2001 From: Erik Troan Date: Wed, 29 Jul 1998 16:02:55 +0000 Subject: [PATCH] added poptSetExecPath() svn path=/trunk/; revision=304 --- support/popt-gnome.h | 1 + support/popt.c | 20 +++++++++++++++++++- support/popt.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/support/popt-gnome.h b/support/popt-gnome.h index 55e63a5..850a8cd 100644 --- a/support/popt-gnome.h +++ b/support/popt-gnome.h @@ -65,5 +65,6 @@ int poptReadDefaultConfig(poptContext con, int useEnv); the same as " and both may include \ quotes */ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); #endif diff --git a/support/popt.c b/support/popt.c index f71e773..7d16614 100644 --- a/support/popt.c +++ b/support/popt.c @@ -47,6 +47,8 @@ struct poptContext_s { int finalArgvCount; int finalArgvAlloced; struct execEntry * doExec; + char * execPath; + int execAbsolute; }; #ifndef HAVE_STRERROR @@ -61,6 +63,12 @@ static char * strerror(int errno) { } #endif +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { + if (con->execPath) free(con->execPath); + con->execPath = strdup(con->execPath); + con->execAbsolute = allowAbsolute; +} + poptContext poptGetContext(char * name, int argc, char ** argv, const struct poptOption * options, int flags) { poptContext con = malloc(sizeof(*con)); @@ -184,10 +192,20 @@ static int handleAlias(poptContext con, char * longName, char shortName, static void execCommand(poptContext con) { char ** argv; int pos = 0; + char * script = con->doExec->script; argv = malloc(sizeof(*argv) * (6 + con->numLeftovers + con->finalArgvCount)); - argv[pos++] = con->doExec->script; + + if (!con->execAbsolute && strchr(script, '/')) return; + + if (!strchr(script, '/') && con->execPath) { + argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2); + sprintf(argv[pos], "%s/%s", con->execPath, script); + } else { + argv[pos] = script; + } + pos++; argv[pos] = findProgramPath(con->os->argv[0]); if (argv[pos]) pos++; diff --git a/support/popt.h b/support/popt.h index 55e63a5..850a8cd 100644 --- a/support/popt.h +++ b/support/popt.h @@ -65,5 +65,6 @@ int poptReadDefaultConfig(poptContext con, int useEnv); the same as " and both may include \ quotes */ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); #endif -- 2.7.4