diff options
author | jbj <devnull@localhost> | 1999-07-27 22:05:43 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 1999-07-27 22:05:43 +0000 |
commit | 3952d8e797bae56a0122ef96b2361686305c4852 (patch) | |
tree | 541af0f587ac2615ba0c2d13d05c3057a490c59b /popt | |
parent | 12dacc46fba0fb50e984e11f6d391c9b69f5cf8b (diff) | |
download | rpm-3952d8e797bae56a0122ef96b2361686305c4852.tar.gz rpm-3952d8e797bae56a0122ef96b2361686305c4852.tar.bz2 rpm-3952d8e797bae56a0122ef96b2361686305c4852.zip |
popt: heavy dose of const.
CVS patchset: 3206
CVS date: 1999/07/27 22:05:43
Diffstat (limited to 'popt')
-rw-r--r-- | popt/CHANGES | 3 | ||||
-rw-r--r-- | popt/findme.c | 2 | ||||
-rw-r--r-- | popt/findme.h | 2 | ||||
-rw-r--r-- | popt/po/popt.pot | 2 | ||||
-rw-r--r-- | popt/popt.c | 86 | ||||
-rw-r--r-- | popt/popt.h | 22 | ||||
-rw-r--r-- | popt/poptconfig.c | 4 | ||||
-rw-r--r-- | popt/popthelp.c | 4 | ||||
-rw-r--r-- | popt/poptint.h | 22 | ||||
-rw-r--r-- | popt/poptparse.c | 4 | ||||
-rw-r--r-- | popt/test1.c | 2 |
11 files changed, 81 insertions, 72 deletions
diff --git a/popt/CHANGES b/popt/CHANGES index 50c150f50..054a00f9b 100644 --- a/popt/CHANGES +++ b/popt/CHANGES @@ -1,3 +1,6 @@ +1.3 -> + - heavy dose of const's + 1.2.3 -> 1.3 - added support for single - - misc bug fixes diff --git a/popt/findme.c b/popt/findme.c index 1cda62c51..4ba4950e5 100644 --- a/popt/findme.c +++ b/popt/findme.c @@ -22,7 +22,7 @@ #include "findme.h" -char * findProgramPath(char * argv0) { +const char * findProgramPath(const char * argv0) { char * path = getenv("PATH"); char * pathbuf; char * start, * chptr; diff --git a/popt/findme.h b/popt/findme.h index fdd01d520..5e93963d6 100644 --- a/popt/findme.h +++ b/popt/findme.h @@ -5,6 +5,6 @@ #ifndef H_FINDME #define H_FINDME -char * findProgramPath(char * argv0); +const char * findProgramPath(const char * argv0); #endif diff --git a/popt/po/popt.pot b/popt/po/popt.pot index 110311a3e..d359df26f 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: 1999-07-15 16:51-0400\n" +"POT-Creation-Date: 1999-07-27 17:51-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/popt.c b/popt/popt.c index bfcc0054e..9808ac309 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -36,7 +36,7 @@ static char * strerror(int errno) { #endif void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { - if (con->execPath) free(con->execPath); + if (con->execPath) xfree(con->execPath); con->execPath = strdup(path); con->execAbsolute = allowAbsolute; } @@ -60,7 +60,7 @@ static void invokeCallbacks(poptContext con, const struct poptOption * table, } } -poptContext poptGetContext(char * name, int argc, char ** argv, +poptContext poptGetContext(const char * name, int argc, char ** argv, const struct poptOption * options, int flags) { poptContext con = malloc(sizeof(*con)); @@ -68,7 +68,7 @@ poptContext poptGetContext(char * name, int argc, char ** argv, con->os = con->optionStack; con->os->argc = argc; - con->os->argv = argv; + con->os->argv = (const char **)argv; /* XXX don't change the API */ if (!(flags & POPT_CONTEXT_KEEP_FIRST)) con->os->next = 1; /* skip argv[0] */ @@ -106,7 +106,7 @@ void poptResetContext(poptContext con) { con->doExec = NULL; for (i = 0; i < con->finalArgvCount; i++) - free(con->finalArgv[i]); + xfree(con->finalArgv[i]); con->finalArgvCount = 0; } @@ -143,18 +143,20 @@ static int handleExec(poptContext con, char * longName, char shortName) { } i = con->finalArgvCount++; - con->finalArgv[i] = malloc((longName ? strlen(longName) : 0) + 3); - if (longName) - sprintf(con->finalArgv[i], "--%s", longName); - else - sprintf(con->finalArgv[i], "-%c", shortName); + { char *s = malloc((longName ? strlen(longName) : 0) + 3); + if (longName) + sprintf(s, "--%s", longName); + else + sprintf(s, "-%c", shortName); + con->finalArgv[i] = s; + } return 1; } /* Only one of longName, shortName may be set at a time */ -static int handleAlias(poptContext con, char * longName, char shortName, - char * nextCharArg) { +static int handleAlias(poptContext con, const char * longName, char shortName, + const char * nextCharArg) { int i; if (con->os->currAlias && con->os->currAlias->longName && longName && @@ -194,9 +196,9 @@ static int handleAlias(poptContext con, char * longName, char shortName, } static void execCommand(poptContext con) { - char ** argv; + const char ** argv; int pos = 0; - char * script = con->doExec->script; + const char * script = con->doExec->script; argv = malloc(sizeof(*argv) * (6 + con->numLeftovers + con->finalArgvCount)); @@ -204,8 +206,9 @@ static void execCommand(poptContext con) { 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); + char *s = alloca(strlen(con->execPath) + strlen(script) + 2); + sprintf(s, "%s/%s", con->execPath, script); + argv[pos] = s; } else { argv[pos] = script; } @@ -243,14 +246,14 @@ static void execCommand(poptContext con) { #endif #endif - execvp(argv[0], argv); + execvp(argv[0], (char *const *)argv); } static const struct poptOption * findOption(const struct poptOption * table, const char * longName, char shortName, poptCallbackType * callback, - void ** callbackData, + const void ** callbackData, int singleDash) { const struct poptOption * opt = table; const struct poptOption * opt2; @@ -296,15 +299,15 @@ static const struct poptOption * findOption(const struct poptOption * table, /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ int poptGetNextOpt(poptContext con) { char * optString, * chptr, * localOptString; - char * longArg = NULL; - char * origOptString; + const char * longArg = NULL; + const char * origOptString; long aLong; char * end; const struct poptOption * opt = NULL; int done = 0; int i; poptCallbackType cb; - void * cbData; + const void * cbData; int singleDash; while (!done) { @@ -412,7 +415,7 @@ int poptGetNextOpt(poptContext con) { if (opt->arg) { switch (opt->argInfo & POPT_ARG_MASK) { case POPT_ARG_STRING: - *((char **) opt->arg) = con->os->nextArg; + *((const char **) opt->arg) = con->os->nextArg; break; case POPT_ARG_INT: @@ -452,12 +455,13 @@ int poptGetNextOpt(poptContext con) { } i = con->finalArgvCount++; - con->finalArgv[i] = - malloc((opt->longName ? strlen(opt->longName) : 0) + 3); - if (opt->longName) - sprintf(con->finalArgv[i], "--%s", opt->longName); - else - sprintf(con->finalArgv[i], "-%c", opt->shortName); + { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3); + if (opt->longName) + sprintf(s, "--%s", opt->longName); + else + sprintf(s, "-%c", opt->shortName); + con->finalArgv[i] = s; + } if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL) @@ -468,22 +472,22 @@ int poptGetNextOpt(poptContext con) { } char * poptGetOptArg(poptContext con) { - char * ret = con->os->nextArg; + char * ret = (char *)con->os->nextArg; /* XXX don't change the API */ con->os->nextArg = NULL; return ret; } char * poptGetArg(poptContext con) { if (con->numLeftovers == con->nextLeftover) return NULL; - return (con->leftovers[con->nextLeftover++]); + return (char *)con->leftovers[con->nextLeftover++]; /* XXX don't change the API */ } -char * poptPeekArg(poptContext con) { +const char * poptPeekArg(poptContext con) { if (con->numLeftovers == con->nextLeftover) return NULL; - return (con->leftovers[con->nextLeftover]); + return con->leftovers[con->nextLeftover]; } -char ** poptGetArgs(poptContext con) { +const char ** poptGetArgs(poptContext con) { if (con->numLeftovers == con->nextLeftover) return NULL; /* some apps like [like RPM ;-) ] need this NULL terminated */ @@ -496,24 +500,24 @@ void poptFreeContext(poptContext con) { int i; for (i = 0; i < con->numAliases; i++) { - if (con->aliases[i].longName) free(con->aliases[i].longName); + if (con->aliases[i].longName) xfree(con->aliases[i].longName); free(con->aliases[i].argv); } for (i = 0; i < con->numExecs; i++) { - if (con->execs[i].longName) free(con->execs[i].longName); - free(con->execs[i].script); + if (con->execs[i].longName) xfree(con->execs[i].longName); + xfree(con->execs[i].script); } for (i = 0; i < con->finalArgvCount; i++) - free(con->finalArgv[i]); + xfree(con->finalArgv[i]); free(con->leftovers); free(con->finalArgv); - if (con->appName) free(con->appName); + if (con->appName) xfree(con->appName); if (con->aliases) free(con->aliases); - if (con->otherHelp) free(con->otherHelp); - if (con->execPath) free(con->execPath); + if (con->otherHelp) xfree(con->otherHelp); + if (con->execPath) xfree(con->execPath); free(con); } @@ -539,7 +543,7 @@ int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) { return 0; } -char * poptBadOption(poptContext con, int flags) { +const char * poptBadOption(poptContext con, int flags) { struct optionStackEntry * os; if (flags & POPT_BADOPTION_NOALIAS) @@ -577,7 +581,7 @@ const char * poptStrerror(const int error) { } } -int poptStuffArgs(poptContext con, char ** argv) { +int poptStuffArgs(poptContext con, const char ** argv) { int i; if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) diff --git a/popt/popt.h b/popt/popt.h index 2fea9e80c..c252e6b8a 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -57,15 +57,15 @@ struct poptOption { int argInfo; void * arg; /* depends on argInfo */ int val; /* 0 means don't return, just update flag */ - char * descrip; /* description for autohelp -- may be NULL */ - char * argDescrip; /* argument description for autohelp */ + const char * descrip; /* description for autohelp -- may be NULL */ + const char * argDescrip; /* argument description for autohelp */ }; struct poptAlias { - char * longName; /* may be NULL */ + const char * longName; /* may be NULL */ char shortName; /* may be '\0' */ int argc; - char ** argv; /* must be free()able */ + const char ** argv; /* must be free()able */ }; extern struct poptOption poptHelpOptions[]; @@ -83,9 +83,9 @@ enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, typedef void (*poptCallbackType)(poptContext con, enum poptCallbackReason reason, const struct poptOption * opt, - const char * arg, void * data); + const char * arg, const void * data); -poptContext poptGetContext(char * name, int argc, char ** argv, +poptContext poptGetContext(const char * name, int argc, char ** argv, const struct poptOption * options, int flags); void poptResetContext(poptContext con); @@ -95,14 +95,14 @@ int poptGetNextOpt(poptContext con); char * poptGetOptArg(poptContext con); /* returns NULL if no more options are available */ char * poptGetArg(poptContext con); -char * poptPeekArg(poptContext con); -char ** poptGetArgs(poptContext con); +const char * poptPeekArg(poptContext con); +const char ** poptGetArgs(poptContext con); /* returns the option which caused the most recent error */ -char * poptBadOption(poptContext con, int flags); +const char * poptBadOption(poptContext con, int flags); void poptFreeContext(poptContext con); -int poptStuffArgs(poptContext con, char ** argv); +int poptStuffArgs(poptContext con, const char ** argv); int poptAddAlias(poptContext con, struct poptAlias alias, int flags); -int poptReadConfigFile(poptContext con, char * fn); +int poptReadConfigFile(poptContext con, const char * fn); /* like above, but reads /etc/popt and $HOME/.popt along with environment vars */ int poptReadDefaultConfig(poptContext con, int useEnv); diff --git a/popt/poptconfig.c b/popt/poptconfig.c index fce6d74ea..ea670e78b 100644 --- a/popt/poptconfig.c +++ b/popt/poptconfig.c @@ -51,7 +51,7 @@ static void configLine(poptContext con, char * line) { shortName = opt[1]; if (!strcmp(entryType, "alias")) { - if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; + if (poptParseArgvString(line, &alias.argc, (char ***)&alias.argv)) return; alias.longName = longName, alias.shortName = shortName; poptAddAlias(con, alias, 0); } else if (!strcmp(entryType, "exec")) { @@ -69,7 +69,7 @@ static void configLine(poptContext con, char * line) { } } -int poptReadConfigFile(poptContext con, char * fn) { +int poptReadConfigFile(poptContext con, const char * fn) { char * file, * chptr, * end; char * buf, * dst; int fd, rc; diff --git a/popt/popthelp.c b/popt/popthelp.c index ca86f34e4..05570bb78 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -180,7 +180,7 @@ static void singleTableHelp(FILE * f, const struct poptOption * table, static int showHelpIntro(poptContext con, FILE * f) { int len = 6; - char * fn; + const char * fn; fprintf(f, POPT_("Usage:")); if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) { @@ -306,6 +306,6 @@ void poptPrintUsage(poptContext con, FILE * f, int flags) { } void poptSetOtherOptionHelp(poptContext con, const char * text) { - if (con->otherHelp) free(con->otherHelp); + if (con->otherHelp) xfree(con->otherHelp); con->otherHelp = strdup(text); } diff --git a/popt/poptint.h b/popt/poptint.h index 8fc6a84ca..62cc60af8 100644 --- a/popt/poptint.h +++ b/popt/poptint.h @@ -7,42 +7,44 @@ struct optionStackEntry { int argc; - char ** argv; + const char ** argv; int next; - char * nextArg; - char * nextCharArg; + const char * nextArg; + const char * nextCharArg; struct poptAlias * currAlias; int stuffed; }; struct execEntry { - char * longName; + const char * longName; char shortName; - char * script; + const char * script; }; struct poptContext_s { struct optionStackEntry optionStack[POPT_OPTION_DEPTH], * os; - char ** leftovers; + const char ** leftovers; int numLeftovers; int nextLeftover; const struct poptOption * options; int restLeftover; - char * appName; + const char * appName; struct poptAlias * aliases; int numAliases; int flags; struct execEntry * execs; int numExecs; - char ** finalArgv; + const char ** finalArgv; int finalArgvCount; int finalArgvAlloced; struct execEntry * doExec; - char * execPath; + const char * execPath; int execAbsolute; - char * otherHelp; + const char * otherHelp; }; +#define xfree(_a) free((void *)_a) + #ifdef HAVE_LIBINTL_H #include <libintl.h> #endif diff --git a/popt/poptparse.c b/popt/poptparse.c index ebad66a60..92af27a0c 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -37,7 +37,7 @@ int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) { char quote = '\0'; int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA; char ** argv = malloc(sizeof(*argv) * argvAlloced); - char ** argv2; + const char ** argv2; int argc = 0; int i, buflen; @@ -105,7 +105,7 @@ int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) { free(argv); - *argvPtr = argv2; + *argvPtr = (char **)argv2; /* XXX don't change the API */ *argcPtr = argc; return 0; diff --git a/popt/test1.c b/popt/test1.c index 0039415d0..4a33287f7 100644 --- a/popt/test1.c +++ b/popt/test1.c @@ -59,7 +59,7 @@ static struct poptOption options[] = { int main(int argc, char ** argv) { int rc; poptContext optCon; - char ** rest; + const char ** rest; int help = 0; int usage = 0; |