include_HEADERS = popt.h
lib_LTLIBRARIES = libpopt.la
libpopt_la_SOURCES = popt.c findme.c poptparse.c poptconfig.c popthelp.c
+
man_MANS = popt.3
+.PHONY: lclint
+lclint:
+ lclint ${DEFS} ${INCLUDES} ${libpopt_la_SOURCES}
+
CVSTAG = $(PACKAGE)-$(subst .,_,$(VERSION))
.PHONY: archive
if (!(flags & POPT_CONTEXT_KEEP_FIRST))
con->os->next = 1; /* skip argv[0] */
- con->leftovers = malloc(sizeof(char *) * (argc + 1));
+ con->leftovers = calloc( (argc + 1), sizeof(char *) );
con->options = options;
- con->finalArgv = malloc(sizeof(*con->finalArgv) * (argc * 2));
con->finalArgvAlloced = argc * 2;
+ con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
con->flags = flags;
con->execAbsolute = 1;
if (con->flags & POPT_CONTEXT_NO_EXEC)
return 1;
- if (!con->doExec) {
+ if (con->doExec == NULL) {
con->doExec = con->execs + i;
return 1;
}
/* Only one of longName, shortName may be set at a time */
static int handleAlias(poptContext con, const char * longName, char shortName,
- const char * nextCharArg) {
+ /*@keep@*/ const char * nextCharArg) {
int i;
if (con->os->currAlias && con->os->currAlias->longName && longName &&
con->os++;
con->os->next = 0;
con->os->stuffed = 0;
- con->os->nextArg = con->os->nextCharArg = NULL;
+ con->os->nextArg = NULL;
+ con->os->nextCharArg = NULL;
con->os->currAlias = con->aliases + i;
con->os->argc = con->os->currAlias->argc;
con->os->argv = con->os->currAlias->argv;
execvp(argv[0], (char *const *)argv);
}
-static const struct poptOption * findOption(const struct poptOption * table,
- const char * longName,
- char shortName,
- poptCallbackType * callback,
- const void ** callbackData,
- int singleDash) {
+/*@observer@*/ static const struct poptOption *
+findOption(const struct poptOption * table, const char * longName,
+ char shortName,
+ /*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData,
+ int singleDash)
+{
const struct poptOption * opt = table;
const struct poptOption * opt2;
const struct poptOption * cb = NULL;
const struct poptOption * opt = NULL;
int done = 0;
int i;
- poptCallbackType cb;
- const void * cbData;
+ poptCallbackType cb = NULL;
+ const void * cbData = NULL;
int singleDash;
while (!done) {
default:
fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"),
opt->argInfo & POPT_ARG_MASK);
- exit(1);
+ exit(EXIT_FAILURE);
}
}
}
free(con);
}
-int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) {
+int poptAddAlias(poptContext con, struct poptAlias newAlias,
+ /*@unused@*/ int flags)
+{
int aliasNum = con->numAliases++;
struct poptAlias * alias;
sizeof(newAlias) * con->numAliases);
alias = con->aliases + aliasNum;
- *alias = newAlias;
- if (alias->longName)
- alias->longName = strcpy(malloc(strlen(alias->longName) + 1),
- alias->longName);
- else
- alias->longName = NULL;
+ alias->longName = (newAlias->longName)
+ ? strcpy(malloc(strlen(newAlias->longName) + 1), newAlias->longName)
+ : NULL;
+ alias->shortName = newAlias->shortName;
+ alias->argc = newAlias->argc;
+ alias->argv = newAlias->argv;
return 0;
}
#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
-const char * poptStrerror(const int error) {
+const char *const poptStrerror(const int error) {
switch (error) {
case POPT_ERROR_NOARG:
return POPT_("missing argument");
if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
- for (i = 0; argv[i]; i++);
+ for (i = 0; argv[i]; i++)
+ ;
con->os++;
con->os->next = 0;
- con->os->nextArg = con->os->nextCharArg = NULL;
+ con->os->nextArg = NULL;
+ con->os->nextCharArg = NULL;
con->os->currAlias = NULL;
con->os->argc = i;
con->os->argv = argv;
/*@observer@*/ /*@null@*/ const char * longName; /* may be NULL */
char shortName; /* may be '\0' */
int argInfo;
- /*@dependent@*/ /*@null@*/ void * arg; /* depends on argInfo */
+ /*@shared@*/ /*@null@*/ void * arg; /* depends on argInfo */
int val; /* 0 means don't return, just update flag */
- /*@null@*/ const char * descrip; /* description for autohelp -- may be NULL */
- /*@null@*/ const char * argDescrip; /* argument description for autohelp */
+ /*@shared@*/ /*@null@*/ const char * descrip; /* description for autohelp -- may be NULL */
+ /*@shared@*/ /*@null@*/ const char * argDescrip; /* argument description for autohelp */
};
struct poptAlias {
- /*@null@*/ const char * longName; /* may be NULL */
+ /*@owned@*/ /*@null@*/ const char * longName; /* may be NULL */
char shortName; /* may be '\0' */
int argc;
- const char ** argv; /* must be free()able */
+ /*@owned@*/ const char ** argv; /* must be free()able */
};
extern struct poptOption poptHelpOptions[];
const struct poptOption * opt,
const char * arg, const void * data);
-poptContext poptGetContext(const char * name, int argc, char ** argv,
- const struct poptOption * options, int flags);
+/*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name,
+ int argc, /*@keep@*/ char ** argv,
+ /*@keep@*/ const struct poptOption * options, int flags);
void poptResetContext(poptContext con);
/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
int poptGetNextOpt(poptContext con);
/* returns NULL if no argument is available */
-char * poptGetOptArg(poptContext con);
+/*@observer@*/ /*@null@*/ char * poptGetOptArg(poptContext con);
/* returns NULL if no more options are available */
-char * poptGetArg(poptContext con);
-const char * poptPeekArg(poptContext con);
-const char ** poptGetArgs(poptContext con);
+/*@observer@*/ /*@null@*/ char * poptGetArg(poptContext con);
+/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con);
+/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con);
/* returns the option which caused the most recent error */
-const char * poptBadOption(poptContext con, int flags);
-void poptFreeContext(poptContext con);
-int poptStuffArgs(poptContext con, const char ** argv);
+/*@observer@*/ const char * poptBadOption(poptContext con, int flags);
+void poptFreeContext( /*@only@*/ poptContext con);
+int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv);
int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
int poptReadConfigFile(poptContext con, const char * fn);
/* like above, but reads /etc/popt and $HOME/.popt along with environment
the same as " and both may include \ quotes */
int poptParseArgvString(const char * s,
/*@out@*/ int * argcPtr, /*@out@*/ char *** argvPtr);
-const char * poptStrerror(const int error);
+/*@observer@*/ const char *const poptStrerror(const int error);
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute);
void poptPrintHelp(poptContext con, FILE * f, int flags);
void poptPrintUsage(poptContext con, FILE * f, int flags);
void poptSetOtherOptionHelp(poptContext con, const char * text);
-const char * poptGetInvocationName(poptContext con);
+/*@observer@*/ const char * poptGetInvocationName(poptContext con);
#ifdef __cplusplus
}
}
fileLength = lseek(fd, 0, SEEK_END);
- lseek(fd, 0, 0);
+ (void) lseek(fd, 0, 0);
file = alloca(fileLength + 1);
if (read(fd, file, fileLength) != fileLength) {
break;
default:
*dst++ = *chptr++;
+ break;
}
}
return 0;
}
-int poptReadDefaultConfig(poptContext con, int useEnv) {
+int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) {
char * fn, * home;
int rc;
#include "popt.h"
#include "poptint.h"
-static void displayArgs(poptContext con, enum poptCallbackReason foo,
- struct poptOption * key,
- const char * arg, void * data) {
+static void displayArgs(poptContext con,
+ /*@unused@*/ enum poptCallbackReason foo,
+ struct poptOption * key,
+ /*@unused@*/ const char * arg, /*@unused@*/ void * data) {
if (key->shortName== '?')
poptPrintHelp(con, stdout, 0);
else
}
struct poptOption poptHelpOptions[] = {
- { 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 }
+ { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL },
+ { "help", '?', 0, NULL, '?', N_("Show this help message"), NULL },
+ { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL },
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
} ;
-static const char *
+/*@observer@*/ /*@null@*/ static const char *const
getTableTranslationDomain(const struct poptOption *table)
{
const struct poptOption *opt;
return NULL;
}
-static const char * getArgDescrip(const struct poptOption * opt,
- const char *translation_domain) {
+/*@observer@*/ /*@null@*/ static const char *const
+getArgDescrip(const struct poptOption * opt, const char *translation_domain)
+{
if (!(opt->argInfo & POPT_ARG_MASK)) return NULL;
if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2))
return len;
}
-void poptPrintHelp(poptContext con, FILE * f, int flags) {
+void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) {
int leftColWidth;
showHelpIntro(con, f);
const struct poptOption * opt,
const char *translation_domain) {
int len = 3;
- char shortStr[2];
+ char shortStr[2] = { '\0', '\0' };
const char * item = shortStr;
const char * argDescrip = getArgDescrip(opt, translation_domain);
char s[300]; /* this is larger then the ascii set, so
it should do just fine */
- if (!str) {
+ s[0] = '\0';
+ if (str == NULL) {
+ memset(s, 0, sizeof(s));
str = s;
- memset(str, 0, sizeof(s));
}
while (opt->longName || opt->shortName || opt->arg) {
return strlen(s) + 4;
}
-void poptPrintUsage(poptContext con, FILE * f, int flags) {
+void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) {
int cursor;
cursor = showHelpIntro(con, f);
struct optionStackEntry {
int argc;
- const char ** argv;
+ /*@keep@*/ const char ** argv;
int next;
- const char * nextArg;
- const char * nextCharArg;
- struct poptAlias * currAlias;
+ /*@keep@*/ const char * nextArg;
+ /*@keep@*/ const char * nextCharArg;
+ /*@dependent@*/ struct poptAlias * currAlias;
int stuffed;
};
};
struct poptContext_s {
- struct optionStackEntry optionStack[POPT_OPTION_DEPTH], * os;
- const char ** leftovers;
+ struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
+ /*@dependent@*/ struct optionStackEntry * os;
+ /*@owned@*/ const char ** leftovers;
int numLeftovers;
int nextLeftover;
- const struct poptOption * options;
+ /*@keep@*/ const struct poptOption * options;
int restLeftover;
- const char * appName;
- struct poptAlias * aliases;
+ /*@owned@*/ const char * appName;
+ /*@owned@*/ struct poptAlias * aliases;
int numAliases;
int flags;
struct execEntry * execs;
int numExecs;
- const char ** finalArgv;
+ /*@owned@*/ const char ** finalArgv;
int finalArgvCount;
int finalArgvAlloced;
- struct execEntry * doExec;
- const char * execPath;
+ /*@dependent@*/ struct execEntry * doExec;
+ /*@owned@*/ const char * execPath;
int execAbsolute;
- const char * otherHelp;
+ /*@owned@*/ const char * otherHelp;
};
#define xfree(_a) free((void *)_a)
#include <libintl.h>
#endif
-#ifdef HAVE_GETTEXT
+#if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
#define _(foo) gettext(foo)
#else
#define _(foo) (foo)
#endif
-#ifdef HAVE_DGETTEXT
+#if defined(HAVE_DGETTEXT) && !defined(__LCLINT__)
#define D_(dom, str) dgettext(dom, str)
#define POPT_(foo) D_("popt", foo)
#else
free(argv);
return POPT_ERROR_BADQUOTE;
}
- /* fallthrough */
+ /*@fallthrough@*/
default:
*buf++ = *src;
+ break;
}
src++;