free(con);
}
-int poptAddAlias(poptContext con, struct poptAlias newAlias) {
+int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) {
int aliasNum = con->numAliases++;
struct poptAlias * alias;
if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
alias.longName = opt;
- poptAddAlias(con, alias);
+ poptAddAlias(con, alias, 0);
}
}
if (chptr) *chptr = '\0';
poptParseArgvString(envValue, &alias.argc, &alias.argv);
- poptAddAlias(con, alias);
+ poptAddAlias(con, alias, 0);
if (chptr)
envValue = chptr + 1;
return 0;
}
+
+char * poptBadOption(poptContext con, int flags) {
+ struct optionStackEntry * os;
+
+ if (flags & POPT_BADOPTION_NOALIAS)
+ os = con->optionStack;
+ else
+ os = con->os;
+
+ return os->argv[os->next - 1];
+}
+
+#define POPT_ERROR_NOARG -10
+#define POPT_ERROR_BADOPT -11
+#define POPT_ERROR_OPTSTOODEEP -13
+#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
+#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
+
+const char * poptStrerror(const int error) {
+ switch (error) {
+ case POPT_ERROR_NOARG:
+ return "missing argument";
+ case POPT_ERROR_BADOPT:
+ return "unknown option";
+ case POPT_ERROR_OPTSTOODEEP:
+ return "aliases nested too deeply";
+ case POPT_ERROR_BADQUOTE:
+ return "error in paramter quoting";
+ case POPT_ERROR_ERRNO:
+ return strerror(errno);
+ default:
+ return "unknown error";
+ }
+}
#define POPT_ERROR_NOARG -10
#define POPT_ERROR_BADOPT -11
-#define POPT_ERROR_BADALIAS -12
#define POPT_ERROR_OPTSTOODEEP -13
-#define POPT_ERROR_UNEXPARG -14
#define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */
#define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */
+#define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */
+
struct poptOption {
const char * longName; /* may be NULL */
char shortName; /* may be '\0' */
char * poptGetArg(poptContext con);
char * poptPeekArg(poptContext con);
char ** poptGetArgs(poptContext con);
+/* returns the option which caused the most recent error */
+char * poptBadOption(poptContext con, int flags);
void poptFreeContext(poptContext con);
-int poptAddAlias(poptContext con, struct poptAlias alias);
+int poptAddAlias(poptContext con, struct poptAlias alias, int flags);
int poptReadConfigFile(poptContext con, char * fn);
/* like above, but reads /etc/popt and $HOME/.popt along with environment
vars */
/* 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);
+const char * poptStrerror(const int error);
#endif