added poptBadOption(), poptStrerror(), flags argument to poptAddAlias 2-3-3
authorErik Troan <ewt@src.gnome.org>
Mon, 20 Jan 1997 22:16:31 +0000 (22:16 +0000)
committerErik Troan <ewt@src.gnome.org>
Mon, 20 Jan 1997 22:16:31 +0000 (22:16 +0000)
svn path=/trunk/; revision=4

support/popt-gnome.h
support/popt.c
support/popt.h

index fab92bc..1dc03b1 100644 (file)
 
 #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
index 2659dd2..930cc5e 100644 (file)
@@ -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";
+    }
+}
index fab92bc..1dc03b1 100644 (file)
 
 #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