From 35feb966b7490c06b27414cc619febe5b30e94e7 Mon Sep 17 00:00:00 2001 From: Erik Troan Date: Mon, 20 Jan 1997 22:16:31 +0000 Subject: [PATCH] added poptBadOption(), poptStrerror(), flags argument to poptAddAlias svn path=/trunk/; revision=4 --- support/popt-gnome.h | 9 ++++++--- support/popt.c | 40 +++++++++++++++++++++++++++++++++++++--- support/popt.h | 9 ++++++--- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/support/popt-gnome.h b/support/popt-gnome.h index fab92bc..1dc03b1 100644 --- a/support/popt-gnome.h +++ b/support/popt-gnome.h @@ -10,12 +10,12 @@ #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' */ @@ -44,8 +44,10 @@ char * poptGetOptArg(poptContext con); 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 */ @@ -53,5 +55,6 @@ 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); +const char * poptStrerror(const int error); #endif diff --git a/support/popt.c b/support/popt.c index 2659dd2..930cc5e 100644 --- a/support/popt.c +++ b/support/popt.c @@ -223,7 +223,7 @@ void poptFreeContext(poptContext con) { 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; @@ -342,7 +342,7 @@ static void configLine(poptContext con, char * line) { if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; alias.longName = opt; - poptAddAlias(con, alias); + poptAddAlias(con, alias, 0); } } @@ -448,7 +448,7 @@ int poptReadDefaultConfig(poptContext con, int useEnv) { if (chptr) *chptr = '\0'; poptParseArgvString(envValue, &alias.argc, &alias.argv); - poptAddAlias(con, alias); + poptAddAlias(con, alias, 0); if (chptr) envValue = chptr + 1; @@ -459,3 +459,37 @@ int poptReadDefaultConfig(poptContext con, int useEnv) { 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"; + } +} diff --git a/support/popt.h b/support/popt.h index fab92bc..1dc03b1 100644 --- a/support/popt.h +++ b/support/popt.h @@ -10,12 +10,12 @@ #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' */ @@ -44,8 +44,10 @@ char * poptGetOptArg(poptContext con); 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 */ @@ -53,5 +55,6 @@ 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); +const char * poptStrerror(const int error); #endif -- 2.7.4