diff --git a/src/ChangeLog b/src/ChangeLog index 69ba72759..5b465dfc3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +1999-07-21 Norbert Warmuth + + * popt.c, popt.h, poptconfig.c, popthelp.c, poptparse.c: updated + to the version found in the popt module + + * features.inc: added report information for smbfs + 1999-06-01 Robert Brady * file.c (move_dir_dir): Give an error when an attempt is made to diff --git a/src/features.inc b/src/features.inc index 158853eb8..e5495fc2c 100644 --- a/src/features.inc +++ b/src/features.inc @@ -31,6 +31,9 @@ char *features = # ifdef USE_TERMNET " (with termnet support)" # endif +# ifdef WITH_SMBFS + ", smbfs" +# endif #endif #ifdef USE_EXT2FSLIB ", undelfs" diff --git a/src/popt.c b/src/popt.c index 219e5d764..bfcc0054e 100644 --- a/src/popt.c +++ b/src/popt.c @@ -41,20 +41,18 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { con->execAbsolute = allowAbsolute; } -static void invokeCallbacks(poptContext con, - enum poptCallbackReason reason, - const struct poptOption * table, +static void invokeCallbacks(poptContext con, const struct poptOption * table, int post) { const struct poptOption * opt = table; poptCallbackType cb; while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { - invokeCallbacks(con, 0, opt->arg, post); + invokeCallbacks(con, opt->arg, post); } else if (((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) && ((!post && (opt->argInfo & POPT_CBFLAG_PRE)) || ( post && (opt->argInfo & POPT_CBFLAG_POST)))) { - cb = opt->arg; + cb = (poptCallbackType)opt->arg; cb(con, post ? POPT_CALLBACK_REASON_POST : POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip); } @@ -88,12 +86,14 @@ poptContext poptGetContext(char * name, int argc, char ** argv, if (name) con->appName = strcpy(malloc(strlen(name) + 1), name); - invokeCallbacks(con, 0, con->options, 0); + invokeCallbacks(con, con->options, 0); return con; } void poptResetContext(poptContext con) { + int i; + con->os = con->optionStack; con->os->currAlias = NULL; con->os->nextCharArg = NULL; @@ -104,6 +104,10 @@ void poptResetContext(poptContext con) { con->nextLeftover = 0; con->restLeftover = 0; con->doExec = NULL; + + for (i = 0; i < con->finalArgvCount; i++) + free(con->finalArgv[i]); + con->finalArgvCount = 0; } @@ -156,7 +160,8 @@ static int handleAlias(poptContext con, char * longName, char shortName, if (con->os->currAlias && con->os->currAlias->longName && longName && !strcmp(con->os->currAlias->longName, longName)) return 0; - if (con->os->currAlias && shortName == con->os->currAlias->shortName) + if (con->os->currAlias && shortName && + shortName == con->os->currAlias->shortName) return 0; i = con->numAliases - 1; @@ -224,15 +229,17 @@ static void execCommand(poptContext con) { #ifdef __hpux setresuid(getuid(), getuid(),-1); #else -#ifndef OS2_NT -# if defined (HAVE_SETUID) - setuid(getuid()); -# elif defined (HAVE_SETREUID) - setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ -# else - ; /* Can't drop privileges */ -# endif - +/* + * XXX " ... on BSD systems setuid() should be preferred over setreuid()" + * XXX sez' Timur Bakeyev + * XXX from Norbert Warmuth + */ +#if defined(HAVE_SETUID) + setuid(getuid()); +#elif defined (HAVE_SETREUID) + setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ +#else + ; /* Can't drop privileges */ #endif #endif @@ -241,7 +248,7 @@ static void execCommand(poptContext con) { static const struct poptOption * findOption(const struct poptOption * table, const char * longName, - const char shortName, + char shortName, poptCallbackType * callback, void ** callbackData, int singleDash) { @@ -249,6 +256,10 @@ static const struct poptOption * findOption(const struct poptOption * table, const struct poptOption * opt2; const struct poptOption * cb = NULL; + /* This happens when a single - is given */ + if (singleDash && !shortName && !*longName) + shortName = '-'; + while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { opt2 = findOption(opt->arg, longName, shortName, callback, @@ -274,7 +285,7 @@ static const struct poptOption * findOption(const struct poptOption * table, *callbackData = NULL; *callback = NULL; if (cb) { - *callback = cb->arg; + *callback = (poptCallbackType)cb->arg; if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) *callbackData = cb->descrip; } @@ -301,7 +312,7 @@ int poptGetNextOpt(poptContext con) { && con->os > con->optionStack) con->os--; if (!con->os->nextCharArg && con->os->next == con->os->argc) { - invokeCallbacks(con, 0, con->options, 1); + invokeCallbacks(con, con->options, 1); if (con->doExec) execCommand(con); return -1; } @@ -378,9 +389,11 @@ int poptGetNextOpt(poptContext con) { con->os->nextCharArg = origOptString; } - if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) + if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { *((int *)opt->arg) = 1; - else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { + } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) { + if (opt->arg) *((int *) opt->arg) = opt->val; + } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { if (longArg) { con->os->nextArg = longArg; } else if (con->os->nextCharArg) { @@ -405,7 +418,7 @@ int poptGetNextOpt(poptContext con) { case POPT_ARG_INT: case POPT_ARG_LONG: aLong = strtol(con->os->nextArg, &end, 0); - if (*end) + if (!(end && *end == '\0')) return POPT_ERROR_BADNUMBER; if (aLong == LONG_MIN || aLong == LONG_MAX) @@ -429,7 +442,7 @@ int poptGetNextOpt(poptContext con) { if (cb) cb(con, POPT_CALLBACK_REASON_OPTION, opt, con->os->nextArg, cbData); - else if (opt->val) + else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)) done = 1; if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) { @@ -446,7 +459,8 @@ int poptGetNextOpt(poptContext con) { else sprintf(con->finalArgv[i], "-%c", opt->shortName); - if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) + if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE + && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL) con->finalArgv[con->finalArgvCount++] = strdup(con->os->nextArg); } @@ -499,6 +513,7 @@ void poptFreeContext(poptContext con) { if (con->appName) free(con->appName); if (con->aliases) free(con->aliases); if (con->otherHelp) free(con->otherHelp); + if (con->execPath) free(con->execPath); free(con); } diff --git a/src/popt.h b/src/popt.h index e21604949..2fea9e80c 100644 --- a/src/popt.h +++ b/src/popt.h @@ -5,6 +5,10 @@ #ifndef H_POPT #define H_POPT +#ifdef __cplusplus +extern "C" { +#endif + #include /* for FILE * */ #define POPT_OPTION_DEPTH 10 @@ -22,6 +26,7 @@ for this table and any included tables; arg points to the domain string */ +#define POPT_ARG_VAL 7 /* arg should take value val */ #define POPT_ARG_MASK 0x0000FFFF #define POPT_ARGFLAG_ONEDASH 0x80000000 /* allow -longoption */ #define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /* don't show in help/usage */ @@ -103,7 +108,7 @@ int poptReadConfigFile(poptContext con, char * fn); int poptReadDefaultConfig(poptContext con, int useEnv); /* argv should be freed -- this allows ', ", and \ quoting, but ' is treated the same as " and both may include \ quotes */ -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); +int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); void poptPrintHelp(poptContext con, FILE * f, int flags); @@ -111,4 +116,8 @@ void poptPrintUsage(poptContext con, FILE * f, int flags); void poptSetOtherOptionHelp(poptContext con, const char * text); const char * poptGetInvocationName(poptContext con); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/poptconfig.c b/src/poptconfig.c index 8f2656d7b..fce6d74ea 100644 --- a/src/poptconfig.c +++ b/src/poptconfig.c @@ -87,7 +87,7 @@ int poptReadConfigFile(poptContext con, char * fn) { lseek(fd, 0, 0); file = alloca(fileLength + 1); - if ((fd = read(fd, file, fileLength)) != fileLength) { + if (read(fd, file, fileLength) != fileLength) { rc = errno; close(fd); errno = rc; diff --git a/src/popthelp.c b/src/popthelp.c index c45464035..ca86f34e4 100644 --- a/src/popthelp.c +++ b/src/popthelp.c @@ -13,6 +13,10 @@ #include #include +#ifdef HAVE_ALLOCA_H +#include +#endif + #include "popt.h" #include "poptint.h" @@ -27,7 +31,7 @@ static void displayArgs(poptContext con, enum poptCallbackReason foo, } struct poptOption poptHelpOptions[] = { - { NULL, '\0', POPT_ARG_CALLBACK, &displayArgs, '\0', NULL }, + { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL }, { "help", '?', 0, NULL, '?', N_("Show this help message") }, { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message") }, { NULL, '\0', 0, NULL, 0 } @@ -69,10 +73,12 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, int helpLength; const char * ch; char format[10]; - char * left = alloca(maxLeftCol + 1); + char * left; const char * argDescrip = getArgDescrip(opt, translation_domain); + left = malloc(maxLeftCol + 1); *left = '\0'; + if (opt->longName && opt->shortName) sprintf(left, "-%c, --%s", opt->shortName, opt->longName); else if (opt->shortName) @@ -89,7 +95,7 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, fprintf(f," %-*s ", maxLeftCol, left); else { fprintf(f," %s\n", left); - return; + goto out; } helpLength = strlen(help); @@ -108,6 +114,9 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, } if (helpLength) fprintf(f, "%s\n", help); + +out: + free(left); } static int maxArgWidth(const struct poptOption * opt, @@ -233,7 +242,7 @@ static int singleOptionUsage(FILE * f, int cursor, return cursor + len + 1; } -int singleTableUsage(FILE * f, int cursor, const struct poptOption * table, +static int singleTableUsage(FILE * f, int cursor, const struct poptOption * table, const char *translation_domain) { const struct poptOption * opt; @@ -261,7 +270,7 @@ static int showShortOptions(const struct poptOption * opt, FILE * f, if (!str) { str = s; - memset(str, 0, sizeof(str)); + memset(str, 0, sizeof(s)); } while (opt->longName || opt->shortName || opt->arg) { diff --git a/src/poptparse.c b/src/poptparse.c index cd97ec6e8..ebad66a60 100644 --- a/src/poptparse.c +++ b/src/poptparse.c @@ -10,25 +10,44 @@ #include #include +/* AIX requires this to be the first thing in the file. */ +#ifndef __GNUC__ +# if HAVE_ALLOCA_H +# include +# else +# ifdef _AIX +#pragma alloca +# else +# ifndef alloca /* predefined by HP cc +Olibcalls */ +char *alloca (); +# endif +# endif +# endif +#elif defined(__GNUC__) && defined(__STRICT_ANSI__) +#define alloca __builtin_alloca +#endif + #include "popt.h" -int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { - char * buf = strcpy(alloca(strlen(s) + 1), s); - char * bufStart = buf; - char * src, * dst; +#define POPT_ARGV_ARRAY_GROW_DELTA 5 + +int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) { + char * buf, * bufStart, * dst; + const char * src; char quote = '\0'; - int argvAlloced = 5; + int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA; char ** argv = malloc(sizeof(*argv) * argvAlloced); char ** argv2; int argc = 0; - int i; + int i, buflen; + + buflen = strlen(s) + 1; + bufStart = buf = alloca(buflen); + memset(buf, '\0', buflen); src = s; - dst = buf; argv[argc] = buf; - memset(buf, '\0', strlen(s) + 1); - while (*src) { if (quote == *src) { quote = '\0'; @@ -46,7 +65,7 @@ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr) { if (*argv[argc]) { buf++, argc++; if (argc == argvAlloced) { - argvAlloced += 5; + argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA; argv = realloc(argv, sizeof(*argv) * argvAlloced); } argv[argc] = buf;