diff options
author | Erik Troan <ewt@src.gnome.org> | 1997-11-02 16:12:56 +0000 |
---|---|---|
committer | Erik Troan <ewt@src.gnome.org> | 1997-11-02 16:12:56 +0000 |
commit | fa601d8fb2294c43aaa03365b23a03e59fba252e (patch) | |
tree | 98510332aa0122f23fa6389f48347497a066f865 | |
parent | e23459d6b908207705df046dd0067d1976be3532 (diff) | |
download | gnome-common-fa601d8fb2294c43aaa03365b23a03e59fba252e.tar.gz |
implmented POPT_ARG_INT and POPT_ARG_LONG
svn path=/trunk/; revision=37
-rw-r--r-- | support/popt-gnome.h | 2 | ||||
-rw-r--r-- | support/popt.c | 21 | ||||
-rw-r--r-- | support/popt.h | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/support/popt-gnome.h b/support/popt-gnome.h index 1b208d4..0072e25 100644 --- a/support/popt-gnome.h +++ b/support/popt-gnome.h @@ -13,6 +13,8 @@ #define POPT_ERROR_OPTSTOODEEP -13 #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ +#define POPT_ERROR_BADNUMBER -17 +#define POPT_ERROR_OVERFLOW -18 #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */ diff --git a/support/popt.c b/support/popt.c index d4dee02..57b0041 100644 --- a/support/popt.c +++ b/support/popt.c @@ -1,6 +1,7 @@ #include <errno.h> #include <ctype.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -75,6 +76,8 @@ int poptGetNextOpt(poptContext con) { char * optString, * chptr, * localOptString; char * longArg = NULL; char * origOptString; + long aLong; + char * end; struct poptOption * opt = NULL; int done = 0; int i; @@ -214,6 +217,24 @@ int poptGetNextOpt(poptContext con) { case POPT_ARG_STRING: *((char **) opt->arg) = con->os->nextArg; break; + + case POPT_ARG_INT: + case POPT_ARG_LONG: + aLong = strtol(con->os->nextArg, &end, 0); + if (*end) + return POPT_ERROR_BADNUMBER; + + if (aLong == LONG_MIN || aLong == LONG_MAX) + return POPT_ERROR_OVERFLOW; + if (opt->argInfo == POPT_ARG_LONG) { + *((long *) opt->arg) = aLong; + } else { + if (aLong > INT_MAX || aLong < INT_MIN) + return POPT_ERROR_OVERFLOW; + *((int *) opt->arg) =aLong; + } + break; + default: printf("option type not implemented in popt\n"); exit(1); diff --git a/support/popt.h b/support/popt.h index 1b208d4..0072e25 100644 --- a/support/popt.h +++ b/support/popt.h @@ -13,6 +13,8 @@ #define POPT_ERROR_OPTSTOODEEP -13 #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ +#define POPT_ERROR_BADNUMBER -17 +#define POPT_ERROR_OVERFLOW -18 #define POPT_BADOPTION_NOALIAS (1 << 0) /* don't go into an alias */ |