From bdc2be0a078a729dca51648d4608e9c6eef662ad Mon Sep 17 00:00:00 2001 From: ewt Date: Sun, 2 Nov 1997 16:12:55 +0000 Subject: [PATCH] implmented POPT_ARG_INT and POPT_ARG_LONG CVS patchset: 1887 CVS date: 1997/11/02 16:12:55 --- popt/Makefile | 2 +- popt/popt.c | 21 +++++++++++++++++++++ popt/popt.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/popt/Makefile b/popt/Makefile index 4a6998d..b76b25e 100644 --- a/popt/Makefile +++ b/popt/Makefile @@ -1,6 +1,6 @@ LIBOBJECTS = popt.o -DEFCFLAGS=-O2 +DEFCFLAGS=-O2 -Wall SOURCES =$(subst .o,.c,$(LIBOBJECTS)) LIBPOPT = libpopt.a diff --git a/popt/popt.c b/popt/popt.c index d4dee02..57b0041 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -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/popt/popt.h b/popt/popt.h index 1b208d4..0072e25 100644 --- a/popt/popt.h +++ b/popt/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 */ -- 2.7.4