diff options
Diffstat (limited to 'popt')
-rw-r--r-- | popt/findme.h | 3 | ||||
-rw-r--r-- | popt/popt.c | 58 | ||||
-rw-r--r-- | popt/popt.h | 14 | ||||
-rw-r--r-- | popt/poptconfig.c | 5 | ||||
-rw-r--r-- | popt/popthelp.c | 82 | ||||
-rw-r--r-- | popt/poptint.h | 5 |
6 files changed, 98 insertions, 69 deletions
diff --git a/popt/findme.h b/popt/findme.h index 1626ee5c6..bb54ec780 100644 --- a/popt/findme.h +++ b/popt/findme.h @@ -14,6 +14,7 @@ * @param argv0 name of executable * @return (malloc'd) absolute path to executable (or NULL) */ -/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0); +/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0) + /*@modifies fileSystem @*/; #endif diff --git a/popt/popt.c b/popt/popt.c index 8c42f90c3..851f6ab9c 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -66,7 +66,9 @@ static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt) poptCallbackType cb = (poptCallbackType)opt->arg; /*@=castfcnptr@*/ /* Perform callback. */ + /*@-moduncon@*/ cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip); + /*@=moduncon@*/ } } } @@ -86,7 +88,9 @@ static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt) poptCallbackType cb = (poptCallbackType)opt->arg; /*@=castfcnptr@*/ /* Perform callback. */ + /*@-moduncon@*/ cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip); + /*@=moduncon@*/ } } } @@ -123,8 +127,10 @@ static void invokeCallbacksOPTION(poptContext con, const void * cbData = (cbopt->descrip ? cbopt->descrip : myData); /* Perform callback. */ if (cb != NULL) { /* XXX program error */ + /*@-moduncon@*/ cb(con, POPT_CALLBACK_REASON_OPTION, myOpt, con->os->nextArg, cbData); + /*@=moduncon@*/ } /* Terminate (unless explcitly continuing). */ if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE)) @@ -143,18 +149,18 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv, con->os = con->optionStack; con->os->argc = argc; - /*@-dependenttrans@*/ /* FIX: W2DO? */ + /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ con->os->argv = argv; - /*@=dependenttrans@*/ + /*@=dependenttrans =assignexpose@*/ con->os->argb = NULL; if (!(flags & POPT_CONTEXT_KEEP_FIRST)) con->os->next = 1; /* skip argv[0] */ con->leftovers = calloc( (argc + 1), sizeof(char *) ); - /*@-dependenttrans@*/ /* FIX: W2DO? */ + /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ con->options = options; - /*@=dependenttrans@*/ + /*@=dependenttrans =assignexpose@*/ con->aliases = NULL; con->numAliases = 0; con->flags = flags; @@ -181,6 +187,7 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv, static void cleanOSE(/*@special@*/ struct optionStackEntry *os) /*@uses os @*/ /*@releases os->nextArg, os->argv, os->argb @*/ + /*@modifies os @*/ { os->nextArg = _free(os->nextArg); os->argv = _free(os->argv); @@ -224,6 +231,7 @@ static int handleExec(/*@special@*/ poptContext con, /*@null@*/ const char * longName, char shortName) /*@uses con->execs, con->numExecs, con->flags, con->doExec, con->finalArgv, con->finalArgvAlloced, con->finalArgvCount @*/ + /*@modifies con @*/ { int i; @@ -280,6 +288,7 @@ static int handleAlias(/*@special@*/ poptContext con, /*@keep@*/ /*@null@*/ const char * nextCharArg) /*@uses con->aliases, con->numAliases, con->optionStack, con->os, con->os->currAlias, con->os->currAlias->longName @*/ + /*@modifies con @*/ { int rc; int i; @@ -480,6 +489,7 @@ static const char * findNextArg(/*@special@*/ poptContext con, unsigned argx, int delete_arg) /*@uses con->optionStack, con->os, con->os->next, con->os->argb, con->os->argc, con->os->argv @*/ + /*@modifies con @*/ { struct optionStackEntry * os = con->os; const char * arg; @@ -500,7 +510,7 @@ static const char * findNextArg(/*@special@*/ poptContext con, if (os->argb != NULL) /* XXX can't happen */ PBM_SET(i, os->argb); } - break; + /*@innerbreak@*/ break; } if (os > con->optionStack) os--; } while (arg == NULL); @@ -555,7 +565,9 @@ expandNextArg(/*@special@*/ poptContext con, const char * s) return t; } -static void poptStripArg(poptContext con, int which) +static void poptStripArg(/*@special@*/ poptContext con, int which) + /*@uses con->arg_strip, con->optionStack @*/ + /*@defines con->arg_strip @*/ /*@modifies con @*/ { if (con->arg_strip == NULL) @@ -699,7 +711,7 @@ int poptGetNextOpt(poptContext con) /* Check for "--long=arg" option. */ for (oe = optString; *oe && *oe != '='; oe++) - ; + {}; if (*oe == '=') { *oe++ = '\0'; /* XXX longArg is mapped back to persistent storage. */ @@ -993,24 +1005,26 @@ int poptAddAlias(poptContext con, struct poptAlias newAlias, /*@unused@*/ int flags) { int aliasNum = con->numAliases++; - struct poptAlias * alias; /* SunOS won't realloc(NULL, ...) */ - if (!con->aliases) - con->aliases = malloc(sizeof(newAlias) * con->numAliases); + if (con->aliases == NULL) + con->aliases = malloc(con->numAliases * sizeof(newAlias)); else con->aliases = realloc(con->aliases, - sizeof(newAlias) * con->numAliases); - alias = con->aliases + aliasNum; - - alias->longName = (newAlias.longName) - /*@-nullpass@*/ /* FIX: malloc can return NULL. */ - ? strcpy(malloc(strlen(newAlias.longName) + 1), newAlias.longName) - /*@=nullpass@*/ - : NULL; - alias->shortName = newAlias.shortName; - alias->argc = newAlias.argc; - alias->argv = newAlias.argv; + con->numAliases * sizeof(newAlias)); + + if (con->aliases) { + struct poptAlias * alias = con->aliases + aliasNum; + + alias->longName = (newAlias.longName) + /*@-nullpass@*/ /* FIX: malloc can return NULL. */ + ? strcpy(malloc(strlen(newAlias.longName) + 1), newAlias.longName) + /*@=nullpass@*/ + : NULL; + alias->shortName = newAlias.shortName; + alias->argc = newAlias.argc; + alias->argv = newAlias.argv; + } return 0; } @@ -1064,7 +1078,7 @@ int poptStuffArgs(poptContext con, const char ** argv) return POPT_ERROR_OPTSTOODEEP; for (argc = 0; argv[argc]; argc++) - ; + {}; con->os++; con->os->next = 0; diff --git a/popt/popt.h b/popt/popt.h index 52819f5f0..a195947f0 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -195,7 +195,7 @@ void poptResetContext(/*@null@*/poptContext con) * @return next option val, -1 on last item, POPT_ERROR_* on error */ int poptGetNextOpt(/*@null@*/poptContext con) - /*@modifies con @*/; + /*@modifies con, fileSystem @*/; /*@-redecl@*/ /** \ingroup popt @@ -340,20 +340,20 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) /** \ingroup popt * Print detailed description of options. * @param con context - * @param f ouput file handle + * @param fp ouput file handle * @param flags (unused) */ -void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) - /*@modifies *f @*/; +void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags) + /*@modifies *fp, fileSystem @*/; /** \ingroup popt * Print terse description of options. * @param con context - * @param f ouput file handle + * @param fp ouput file handle * @param flags (unused) */ -void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) - /*@modifies *f @*/; +void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags) + /*@modifies *fp, fileSystem @*/; /** \ingroup popt * Provide text to replace default "[OPTION...]" in help/usage output. diff --git a/popt/poptconfig.c b/popt/poptconfig.c index f53dd5d37..8fddbcdf7 100644 --- a/popt/poptconfig.c +++ b/popt/poptconfig.c @@ -9,9 +9,9 @@ #include "system.h" #include "poptint.h" +/*@-mustmod@*/ /* LCL: *line is modified @*/ static void configLine(poptContext con, char * line) - /*@modifies *line, - con->execs, con->numExecs @*/ + /*@modifies *line, con->execs, con->numExecs @*/ { int nameLength = strlen(con->appName); const char * opt; @@ -63,6 +63,7 @@ static void configLine(poptContext con, char * line) /*@=noeffect@*/ } } +/*@=mustmod@*/ int poptReadConfigFile(poptContext con, const char * fn) { diff --git a/popt/popthelp.c b/popt/popthelp.c index 62822fa64..a5e19800b 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -34,6 +34,7 @@ struct poptOption poptHelpOptions[] = { /*@observer@*/ /*@null@*/ static const char *const getTableTranslationDomain(/*@null@*/ const struct poptOption *table) + /*@*/ { const struct poptOption *opt; @@ -50,6 +51,7 @@ getArgDescrip(const struct poptOption * opt, /*@-paramuse@*/ /* FIX: wazzup? */ /*@null@*/ const char * translation_domain) /*@=paramuse@*/ + /*@*/ { if (!(opt->argInfo & POPT_ARG_MASK)) return NULL; @@ -70,9 +72,10 @@ getArgDescrip(const struct poptOption * opt, } } -static void singleOptionHelp(FILE * f, int maxLeftCol, +static void singleOptionHelp(FILE * fp, int maxLeftCol, const struct poptOption * opt, /*@null@*/ const char *translation_domain) + /*@modifies *fp, fileSystem @*/ { int indentLength = maxLeftCol + 5; int lineLength = 79 - indentLength; @@ -146,9 +149,9 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, } if (help) - fprintf(f," %-*s ", maxLeftCol, left); + fprintf(fp," %-*s ", maxLeftCol, left); else { - fprintf(f," %s\n", left); + fprintf(fp," %s\n", left); goto out; } @@ -164,20 +167,21 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, ch++; sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength); - fprintf(f, format, help, " "); + fprintf(fp, format, help, " "); help = ch; while (isspace(*help) && *help) help++; helpLength = strlen(help); } - if (helpLength) fprintf(f, "%s\n", help); + if (helpLength) fprintf(fp, "%s\n", help); out: - free(left); + left = _free(left); } static int maxArgWidth(const struct poptOption * opt, /*@null@*/ const char * translation_domain) + /*@*/ { int max = 0; int len = 0; @@ -212,9 +216,10 @@ static int maxArgWidth(const struct poptOption * opt, return max; } -static void singleTableHelp(FILE * f, +static void singleTableHelp(FILE * fp, /*@null@*/ const struct poptOption * table, int left, /*@null@*/ const char * translation_domain) + /*@modifies *fp, fileSystem @*/ { const struct poptOption * opt; const char *sub_transdom; @@ -223,7 +228,7 @@ static void singleTableHelp(FILE * f, for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) { if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) - singleOptionHelp(f, left, opt, translation_domain); + singleOptionHelp(fp, left, opt, translation_domain); } if (table != NULL) @@ -234,49 +239,51 @@ static void singleTableHelp(FILE * f, sub_transdom = translation_domain; if (opt->descrip) - fprintf(f, "\n%s\n", D_(sub_transdom, opt->descrip)); + fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip)); - singleTableHelp(f, opt->arg, left, sub_transdom); + singleTableHelp(fp, opt->arg, left, sub_transdom); } } } -static int showHelpIntro(poptContext con, FILE * f) +static int showHelpIntro(poptContext con, FILE * fp) + /*@modifies *fp, fileSystem @*/ { int len = 6; const char * fn; - fprintf(f, POPT_("Usage:")); + fprintf(fp, POPT_("Usage:")); if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) { /*@-nullderef@*/ /* LCL: wazzup? */ fn = con->optionStack->argv[0]; /*@=nullderef@*/ if (fn == NULL) return len; if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1; - fprintf(f, " %s", fn); + fprintf(fp, " %s", fn); len += strlen(fn) + 1; } return len; } -void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) +void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags) { int leftColWidth; - (void) showHelpIntro(con, f); + (void) showHelpIntro(con, fp); if (con->otherHelp) - fprintf(f, " %s\n", con->otherHelp); + fprintf(fp, " %s\n", con->otherHelp); else - fprintf(f, " %s\n", POPT_("[OPTION...]")); + fprintf(fp, " %s\n", POPT_("[OPTION...]")); leftColWidth = maxArgWidth(con->options, NULL); - singleTableHelp(f, con->options, leftColWidth, NULL); + singleTableHelp(fp, con->options, leftColWidth, NULL); } -static int singleOptionUsage(FILE * f, int cursor, +static int singleOptionUsage(FILE * fp, int cursor, const struct poptOption * opt, /*@null@*/ const char *translation_domain) + /*@modifies *fp, fileSystem @*/ { int len = 3; char shortStr[2] = { '\0', '\0' }; @@ -300,11 +307,11 @@ static int singleOptionUsage(FILE * f, int cursor, len += strlen(argDescrip) + 1; if ((cursor + len) > 79) { - fprintf(f, "\n "); + fprintf(fp, "\n "); cursor = 7; } - fprintf(f, " [-%s%s%s%s]", + fprintf(fp, " [-%s%s%s%s]", ((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"), item, (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""), @@ -313,9 +320,10 @@ static int singleOptionUsage(FILE * f, int cursor, return cursor + len + 1; } -static int singleTableUsage(FILE * f, +static int singleTableUsage(FILE * fp, int cursor, const struct poptOption * opt, /*@null@*/ const char * translation_domain) + /*@modifies *fp, fileSystem @*/ { /*@-branchstate@*/ /* FIX: W2DO? */ if (opt != NULL) @@ -324,10 +332,10 @@ static int singleTableUsage(FILE * f, translation_domain = (const char *)opt->arg; } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { if (opt->arg) /* XXX program error */ - cursor = singleTableUsage(f, cursor, opt->arg, translation_domain); + cursor = singleTableUsage(fp, cursor, opt->arg, translation_domain); } else if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { - cursor = singleOptionUsage(f, cursor, opt, translation_domain); + cursor = singleOptionUsage(fp, cursor, opt, translation_domain); } } /*@=branchstate@*/ @@ -335,8 +343,9 @@ static int singleTableUsage(FILE * f, return cursor; } -static int showShortOptions(const struct poptOption * opt, FILE * f, +static int showShortOptions(const struct poptOption * opt, FILE * fp, /*@null@*/ char * str) + /*@modifies *str, *fp, fileSystem @*/ { char * s = alloca(300); /* larger then the ascii set */ @@ -354,34 +363,35 @@ static int showShortOptions(const struct poptOption * opt, FILE * f, str[strlen(str)] = opt->shortName; else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) if (opt->arg) /* XXX program error */ - (void) showShortOptions(opt->arg, f, str); + (void) showShortOptions(opt->arg, fp, str); } if (s != str || *s != '\0') return 0; - fprintf(f, " [-%s]", s); + fprintf(fp, " [-%s]", s); return strlen(s) + 4; } -void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) +void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags) { int cursor; - cursor = showHelpIntro(con, f); - cursor += showShortOptions(con->options, f, NULL); - (void) singleTableUsage(f, cursor, con->options, NULL); + cursor = showHelpIntro(con, fp); + cursor += showShortOptions(con->options, fp, NULL); + (void) singleTableUsage(fp, cursor, con->options, NULL); if (con->otherHelp) { cursor += strlen(con->otherHelp) + 1; - if (cursor > 79) fprintf(f, "\n "); - fprintf(f, " %s", con->otherHelp); + if (cursor > 79) fprintf(fp, "\n "); + fprintf(fp, " %s", con->otherHelp); } - fprintf(f, "\n"); + fprintf(fp, "\n"); } -void poptSetOtherOptionHelp(poptContext con, const char * text) { - if (con->otherHelp) free((void *)con->otherHelp); +void poptSetOtherOptionHelp(poptContext con, const char * text) +{ + con->otherHelp = _free(con->otherHelp); con->otherHelp = xstrdup(text); } diff --git a/popt/poptint.h b/popt/poptint.h index 59841e0db..fe8430b76 100644 --- a/popt/poptint.h +++ b/popt/poptint.h @@ -14,7 +14,10 @@ * @param p memory to free * @retval NULL always */ -/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * p) { +/*@unused@*/ static inline /*@null@*/ void * +_free(/*@only@*/ /*@null@*/ const void * p) + /*@modifies p @*/ +{ if (p != NULL) free((void *)p); return NULL; } |