diff options
author | jbj <devnull@localhost> | 2000-05-24 17:53:35 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2000-05-24 17:53:35 +0000 |
commit | c7273eb0bca1a7b4d7ccfea11fe9562b88034c53 (patch) | |
tree | 2f0a268637bab51fe1ab844e014795bba563e02f /popt | |
parent | 0d1548767532377b8e0fcce719e9a42f567da5c3 (diff) | |
download | rpm-c7273eb0bca1a7b4d7ccfea11fe9562b88034c53.tar.gz rpm-c7273eb0bca1a7b4d7ccfea11fe9562b88034c53.tar.bz2 rpm-c7273eb0bca1a7b4d7ccfea11fe9562b88034c53.zip |
- change popt exec alias in oreder to exec rpm children.
- split rpm into 5 pieces along major mode fault lines with popt glue.
CVS patchset: 3750
CVS date: 2000/05/24 17:53:35
Diffstat (limited to 'popt')
-rw-r--r-- | popt/findme.c | 5 | ||||
-rw-r--r-- | popt/po/popt.pot | 2 | ||||
-rw-r--r-- | popt/po/ro.po | 2 | ||||
-rw-r--r-- | popt/po/sk.po | 2 | ||||
-rw-r--r-- | popt/po/tr.po | 2 | ||||
-rw-r--r-- | popt/popt.c | 104 | ||||
-rwxr-xr-x | popt/testit.sh | 11 |
7 files changed, 82 insertions, 46 deletions
diff --git a/popt/findme.c b/popt/findme.c index 6d1b41c18..8518be13c 100644 --- a/popt/findme.c +++ b/popt/findme.c @@ -11,15 +11,14 @@ const char * findProgramPath(const char * argv0) { char * start, * chptr; char * buf; - /* If there is a / in the argv[0], it has to be an absolute - path */ + /* If there is a / in the argv[0], it has to be an absolute path */ if (strchr(argv0, '/')) return xstrdup(argv0); if (!path) return NULL; start = pathbuf = alloca(strlen(path) + 1); - buf = malloc(strlen(path) + strlen(argv0) + 2); + buf = malloc(strlen(path) + strlen(argv0) + sizeof("/")); strcpy(pathbuf, path); chptr = NULL; diff --git a/popt/po/popt.pot b/popt/po/popt.pot index dc108e199..49ad01ee1 100644 --- a/popt/po/popt.pot +++ b/popt/po/popt.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2000-04-22 14:29-0400\n" +"POT-Creation-Date: 2000-05-24 13:46-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/popt/po/ro.po b/popt/po/ro.po index a9dd784ec..3cbf5752b 100644 --- a/popt/po/ro.po +++ b/popt/po/ro.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: POPT\n" -"POT-Creation-Date: 2000-04-22 14:29-0400\n" +"POT-Creation-Date: 2000-05-24 13:46-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Cristian Gafton <gafton@redhat.com>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/popt/po/sk.po b/popt/po/sk.po index fa860e3a6..37466a2b7 100644 --- a/popt/po/sk.po +++ b/popt/po/sk.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: popt\n" -"POT-Creation-Date: 2000-04-22 14:29-0400\n" +"POT-Creation-Date: 2000-05-24 13:46-0400\n" "PO-Revision-Date: 1999-08-04 21:40+0200\n" "Last-Translator: Stanislav Meduna <stano@eunet.sk>\n" "Language-Team: Slovak <sk-i18n@rak.isternet.sk>\n" diff --git a/popt/po/tr.po b/popt/po/tr.po index 3eb8394c2..7e5c3db6d 100644 --- a/popt/po/tr.po +++ b/popt/po/tr.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: popt 1.2\n" -"POT-Creation-Date: 2000-04-22 14:29-0400\n" +"POT-Creation-Date: 2000-05-24 13:46-0400\n" "PO-Revision-Date: 2000-01-06 13:01+0100\n" "Last-Translator: Fatih Demir <kabalak@gmx.net>\n" "Language-Team: Turkish Gnome Tranlation Team <gnotrap@gmx.net>\n" diff --git a/popt/popt.c b/popt/popt.c index 43de9f614..0706ccc0d 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -2,6 +2,8 @@ file accompanying popt source distributions, available from ftp://ftp.redhat.com/pub/code/popt */ +#undef MYDEBUG + #include "system.h" #include "findme.h" #include "poptint.h" @@ -218,37 +220,43 @@ static int handleAlias(poptContext con, const char * longName, char shortName, static void execCommand(poptContext con) { const char ** argv; - int pos = 0; - const char * script = con->doExec->script; + int argc = 0; + const char ** sargv; + int sargc = 0; - argv = malloc(sizeof(*argv) * - (6 + con->numLeftovers + con->finalArgvCount)); + poptParseArgvString(con->doExec->script, &sargc, &sargv); - if (!con->execAbsolute && strchr(script, '/')) return; + if (sargv == NULL || sargc < 1 || + (!con->execAbsolute && strchr(sargv[0], '/'))) + return; - if (!strchr(script, '/') && con->execPath) { - char *s = alloca(strlen(con->execPath) + strlen(script) + 2); - sprintf(s, "%s/%s", con->execPath, script); - argv[pos] = s; + argv = malloc(sizeof(*argv) * + (6 + sargc + con->numLeftovers + con->finalArgvCount)); + + if (!strchr(sargv[0], '/') && con->execPath) { + char *s = alloca(strlen(con->execPath) + strlen(sargv[0]) + sizeof("/")); + sprintf(s, "%s/%s", con->execPath, sargv[0]); + argv[argc] = s; } else { - argv[pos] = script; + argv[argc] = findProgramPath(sargv[0]); } - pos++; + if (argv[argc++] == NULL) return; - argv[pos] = findProgramPath(con->os->argv[0]); - if (argv[pos]) pos++; - argv[pos++] = ";"; + if (sargc > 1) { + memcpy(argv + argc, sargv + 1, sizeof(*argv) * (sargc - 1)); + argc += (sargc - 1); + } - memcpy(argv + pos, con->finalArgv, sizeof(*argv) * con->finalArgvCount); - pos += con->finalArgvCount; + memcpy(argv + argc, con->finalArgv, sizeof(*argv) * con->finalArgvCount); + argc += con->finalArgvCount; if (con->numLeftovers) { - argv[pos++] = "--"; - memcpy(argv + pos, con->leftovers, sizeof(*argv) * con->numLeftovers); - pos += con->numLeftovers; + argv[argc++] = "--"; + memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers); + argc += con->numLeftovers; } - argv[pos++] = NULL; + argv[argc++] = NULL; #ifdef __hpux setresuid(getuid(), getuid(),-1); @@ -267,6 +275,17 @@ static void execCommand(poptContext con) { #endif #endif + if (argv[0] == NULL) + return; +#ifdef MYDEBUG + { const char ** arg; + fprintf(stderr, "==> execvp(%s):", argv[0]); + for (arg = argv; *arg; arg++) + fprintf(stderr, " %s", *arg); + fprintf(stderr, "\n"); + } +#endif + execvp(argv[0], (char *const *)argv); } @@ -386,7 +405,7 @@ static /*@only@*/ const char * expandNextArg(poptContext con, const char * s) static void poptStripArg(poptContext con, int which) { - if(con->arg_strip == NULL) { + if (con->arg_strip == NULL) { con->arg_strip = PBM_ALLOC(con->optionStack[0].argc); } PBM_SET(which, con->arg_strip); @@ -438,6 +457,20 @@ static int poptSaveInt(const struct poptOption * opt, long aLong) { return 0; } +#ifdef MYDEBUG +static void prtcon(const char *msg, poptContext con) +{ + if (msg) fprintf(stderr, "%s", msg); + fprintf(stderr, "\tcon %p os %p nextCharArg %p \"%s\" argv[%d] \"%s\"\n", + con, con->os, + con->os->nextCharArg, + (con->os->nextCharArg ? con->os->nextCharArg : ""), + con->os->next, + (con->os->argv && con->os->argv[con->os->next] + ? con->os->argv[con->os->next] : "")); +} +#endif + /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ int poptGetNextOpt(poptContext con) { @@ -470,7 +503,7 @@ int poptGetNextOpt(poptContext con) con->os->next++; continue; } - thisopt=con->os->next; + thisopt = con->os->next; origOptString = con->os->argv[con->os->next++]; if (con->restLeftover || *origOptString != '-') { @@ -525,7 +558,7 @@ int poptGetNextOpt(poptContext con) if (!opt) { con->os->nextCharArg = origOptString + 1; } else { - if(con->os == con->optionStack && + if (con->os == con->optionStack && opt->argInfo & POPT_ARGFLAG_STRIP) { canstrip = 1; poptStripArg(con, thisopt); @@ -541,11 +574,14 @@ int poptGetNextOpt(poptContext con) if (handleAlias(con, NULL, *origOptString, origOptString + 1)) { - origOptString++; continue; } - if (handleExec(con, NULL, *origOptString)) + if (handleExec(con, NULL, *origOptString)) { + /* Restore rest of short options for further processing */ + origOptString++; + if (*origOptString) con->os->nextCharArg = origOptString; continue; + } opt = findOption(con->options, NULL, *origOptString, &cb, &cbData, 0); @@ -553,8 +589,7 @@ int poptGetNextOpt(poptContext con) return POPT_ERROR_BADOPT; origOptString++; - if (*origOptString) - con->os->nextCharArg = origOptString; + if (*origOptString) con->os->nextCharArg = origOptString; } if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { @@ -585,7 +620,7 @@ int poptGetNextOpt(poptContext con) /* make sure this isn't part of a short arg or the result of an alias expansion */ - if(con->os == con->optionStack && + if (con->os == con->optionStack && opt->argInfo & POPT_ARGFLAG_STRIP && canstrip) { poptStripArg(con, con->os->next); @@ -642,7 +677,7 @@ int poptGetNextOpt(poptContext con) sizeof(*con->finalArgv) * con->finalArgvAlloced); } - { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3); + { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3); if (opt->longName) sprintf(s, "--%s", opt->longName); else @@ -650,8 +685,9 @@ int poptGetNextOpt(poptContext con) con->finalArgv[con->finalArgvCount++] = s; } - if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE - && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL) { + if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { + } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) { + } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { con->finalArgv[con->finalArgvCount++] = xstrdup(con->os->nextArg); } } @@ -800,16 +836,16 @@ int poptStrippedArgv(poptContext con, int argc, char **argv) int i,j=1, numargs=argc; for(i=1; i<argc; i++) { - if(PBM_ISSET(i, con->arg_strip)) { + if (PBM_ISSET(i, con->arg_strip)) { numargs--; } } for(i=1; i<argc; i++) { - if(PBM_ISSET(i, con->arg_strip)) { + if (PBM_ISSET(i, con->arg_strip)) { continue; } else { - if(j<numargs) { + if (j<numargs) { argv[j++]=argv[i]; } else { argv[j++]='\0'; diff --git a/popt/testit.sh b/popt/testit.sh index e9b7198aa..a3221761f 100755 --- a/popt/testit.sh +++ b/popt/testit.sh @@ -15,6 +15,7 @@ run() { } builddir=`pwd` +srcdir=$builddir cd ${srcdir} test1=${builddir}/test1 echo "Running tests in `pwd`" @@ -39,11 +40,11 @@ run test1 "test1 - 15" "arg1: 0 arg2: foo inc: 1" -i --arg2 foo POSIX_ME_HARDER=1 run test1 "test1 - 16" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something POSIXLY_CORRECT=1 run test1 "test1 - 17" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something run test1 "test1 - 18" "callback: c sampledata bar arg1: 1 arg2: (none)" --arg1 --cb bar -run test1 "test1 - 19" "${test1} ;" --echo-args -run test1 "test1 - 20" "${test1} ; --arg1" --echo-args --arg1 -run test1 "test1 - 21" "${test1} ; --arg2 something" -T something -e -run test1 "test1 - 22" "${test1} ; --arg2 something -- more args" -T something -a more args -run test1 "test1 - 23" "${test1} ; --echo-args -a" --echo-args -e -a +run test1 "test1 - 19" "" --echo-args +run test1 "test1 - 20" "--arg1" --echo-args --arg1 +run test1 "test1 - 21" "--arg2 something" -T something -e +run test1 "test1 - 22" "--arg2 something -- more args" -T something -a more args +run test1 "test1 - 23" "--echo-args -a" --echo-args -e -a run test1 "test1 - 24" "arg1: 0 arg2: (none) short: 1" -shortoption run test1 "test1 - 25" "arg1: 0 arg2: (none) short: 1" --shortoption run test1 "test1 - 26" "callback: c arg for cb2 foo arg1: 0 arg2: (none)" --cb2 foo |