diff options
author | Erik Troan <ewt@src.gnome.org> | 1998-07-29 16:02:55 +0000 |
---|---|---|
committer | Erik Troan <ewt@src.gnome.org> | 1998-07-29 16:02:55 +0000 |
commit | dddcdc03b8d648b4fa7f54cb29ecf8865576352d (patch) | |
tree | cc62b04a34f5045c6894b2e32496e0f58a8211c3 /support | |
parent | b89b2b7b82792187c64344b99d719aede8bbb968 (diff) | |
download | shared-mime-info-dddcdc03b8d648b4fa7f54cb29ecf8865576352d.tar.gz |
added poptSetExecPath()
svn path=/trunk/; revision=304
Diffstat (limited to 'support')
-rw-r--r-- | support/popt-gnome.h | 1 | ||||
-rw-r--r-- | support/popt.c | 20 | ||||
-rw-r--r-- | support/popt.h | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/support/popt-gnome.h b/support/popt-gnome.h index 55e63a5c..850a8cdd 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 f71e7731..7d16614d 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 55e63a5c..850a8cdd 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 |