summaryrefslogtreecommitdiff
path: root/support/popt.c
diff options
context:
space:
mode:
authorErik Troan <ewt@src.gnome.org>1997-01-20 22:16:31 +0000
committerErik Troan <ewt@src.gnome.org>1997-01-20 22:16:31 +0000
commit35feb966b7490c06b27414cc619febe5b30e94e7 (patch)
treef64b9407f604edef6b8da26a3875c43c1a81bbd4 /support/popt.c
parent943cbcdb0898e818bc0f6eaaae8236ca3c2b06f4 (diff)
downloadgnome-common-35feb966b7490c06b27414cc619febe5b30e94e7.tar.gz
added poptBadOption(), poptStrerror(), flags argument to poptAddAlias2-3-3
svn path=/trunk/; revision=4
Diffstat (limited to 'support/popt.c')
-rw-r--r--support/popt.c40
1 files changed, 37 insertions, 3 deletions
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";
+ }
+}