[prev in list] [next in list] [prev in thread] [next in thread]
List: openbsd-tech
Subject: PATCH: last round for parse.y
From: Pierre-Yves Ritschard <pyr () spootnik ! org>
Date: 2006-10-25 17:33:50
Message-ID: 453F9FFE.8010603 () spootnik ! org
[Download RAW message or body]
just like the previous patch this removes pdebug (not needed for bgpd)
and moves atoul to strtonum for the remaining daemon configuration file
parsers:
Index: parse.y
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.195
diff -u -r1.195 parse.y
--- parse.y 19 Sep 2006 12:15:29 -0000 1.195
+++ parse.y 25 Oct 2006 16:59:42 -0000
@@ -119,7 +119,6 @@
int symset(const char *, const char *, int);
char *symget(const char *);
-int atoul(char *, u_long *);
int getcommunity(char *);
int parsecommunity(char *, int *, int *);
@@ -203,14 +202,16 @@
;
number : STRING {
- u_long ulval;
+ u_int32_t uval;
+ const char *errstr;
- if (atoul($1, &ulval) == -1) {
- yyerror("\"%s\" is not a number", $1);
+ uval = strtonum($1, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ yyerror("number %s is %s", $1, errstr);
free($1);
YYERROR;
} else
- $$ = ulval;
+ $$ = uval;
free($1);
}
;
@@ -2127,39 +2128,21 @@
}
int
-atoul(char *s, u_long *ulvalp)
-{
- u_long ulval;
- char *ep;
-
- errno = 0;
- ulval = strtoul(s, &ep, 0);
- if (s[0] == '\0' || *ep != '\0')
- return (-1);
- if (errno == ERANGE && ulval == ULONG_MAX)
- return (-1);
- *ulvalp = ulval;
- return (0);
-}
-
-int
getcommunity(char *s)
{
- u_long ulval;
+ int val;
+ const char *errstr;
if (strcmp(s, "*") == 0)
return (COMMUNITY_ANY);
if (strcmp(s, "neighbor-as") == 0)
return (COMMUNITY_NEIGHBOR_AS);
- if (atoul(s, &ulval) == -1) {
- yyerror("\"%s\" is not a number", s);
- return (COMMUNITY_ERROR);
- }
- if (ulval > USHRT_MAX) {
- yyerror("Community too big: max %u", USHRT_MAX);
+ val = strtonum(s, 0, USHRT_MAX, &errstr);
+ if (errstr) {
+ yyerror("Community %s is %s (max: %s)", s, errstr, USHRT_MAX);
return (COMMUNITY_ERROR);
}
- return (ulval);
+ return (val);
}
int
Index: parse.y
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/dvmrpd/parse.y,v
retrieving revision 1.1
diff -u -r1.1 parse.y
--- parse.y 1 Jun 2006 14:12:20 -0000 1.1
+++ parse.y 25 Oct 2006 17:12:29 -0000
@@ -46,7 +46,6 @@
static FILE *fin = NULL;
static int lineno = 1;
static int errors = 0;
-static int pdebug = 1;
char *infile;
char *start_state;
@@ -88,7 +87,6 @@
int symset(const char *, const char *, int);
char *symget(const char *);
-int atoul(char *, u_long *);
struct iface *conf_get_if(struct kif *);
struct iface *new_group(void);
@@ -126,14 +124,16 @@
;
number : STRING {
- u_long ulval;
+ u_int32_t uval;
+ const char *errstr;
- if (atoul($1, &ulval) == -1) {
- yyerror("%s is not a number", $1);
+ uval = strtonum($1, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ yyerror("number %s is %s", $1, errstr);
free($1);
YYERROR;
} else
- $$ = ulval;
+ $$ = uval;
free($1);
}
;
@@ -403,15 +403,10 @@
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
sizeof(keywords[0]), kw_cmp);
- if (p) {
- if (pdebug > 1)
- fprintf(stderr, "%s: %d\n", s, p->k_val);
+ if (p)
return (p->k_val);
- } else {
- if (pdebug > 1)
- fprintf(stderr, "string: %s\n", s);
+ else
return (STRING);
- }
}
#define MAXPUSHBACK 128
@@ -741,22 +736,6 @@
return (sym->val);
}
return (NULL);
-}
-
-int
-atoul(char *s, u_long *ulvalp)
-{
- u_long ulval;
- char *ep;
-
- errno = 0;
- ulval = strtoul(s, &ep, 0);
- if (s[0] == '\0' || *ep != '\0')
- return (-1);
- if (errno == ERANGE && ulval == ULONG_MAX)
- return (-1);
- *ulvalp = ulval;
- return (0);
}
struct iface *
Index: parse.y
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/ifstated/parse.y,v
retrieving revision 1.14
diff -u -r1.14 parse.y
--- parse.y 26 May 2006 01:06:12 -0000 1.14
+++ parse.y 25 Oct 2006 17:08:41 -0000
@@ -44,7 +44,6 @@
static FILE *fin = NULL;
static int lineno = 1;
static int errors = 0;
-static int pdebug = 1;
char *infile;
char *start_state;
@@ -73,7 +72,6 @@
void link_states(struct ifsd_action *);
int symset(const char *, const char *, int);
char *symget(const char *);
-int atoul(char *, u_long *);
void set_expression_depth(struct ifsd_expression *, int);
void init_state(struct ifsd_state *);
struct ifsd_ifstate *new_ifstate(u_short, int);
@@ -121,14 +119,16 @@
;
number : STRING {
- u_long ulval;
+ u_int32_t uval;
+ const char *errstr;
- if (atoul($1, &ulval) == -1) {
- yyerror("%s is not a number", $1);
+ uval = strtonum($1, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ yyerror("number %s is %s", $1, errstr);
free($1);
YYERROR;
} else
- $$ = ulval;
+ $$ = uval;
free($1);
}
;
@@ -413,15 +413,10 @@
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
sizeof(keywords[0]), kw_cmp);
- if (p) {
- if (pdebug > 1)
- fprintf(stderr, "%s: %d\n", s, p->k_val);
+ if (p)
return (p->k_val);
- } else {
- if (pdebug > 1)
- fprintf(stderr, "string: %s\n", s);
+ else
return (STRING);
- }
}
#define MAXPUSHBACK 128
@@ -785,22 +780,6 @@
return (sym->val);
}
return (NULL);
-}
-
-int
-atoul(char *s, u_long *ulvalp)
-{
- u_long ulval;
- char *ep;
-
- errno = 0;
- ulval = strtoul(s, &ep, 0);
- if (s[0] == '\0' || *ep != '\0')
- return (-1);
- if (errno == ERANGE && ulval == ULONG_MAX)
- return (-1);
- *ulvalp = ulval;
- return (0);
}
void
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic