[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    PATCH: atoul to strtonum in ospfd's parse.y
From:       Pierre-Yves Ritschard <pyr () spootnik ! org>
Date:       2006-10-25 11:54:30
Message-ID: 453F5076.8030207 () spootnik ! org
[Download RAW message or body]

Ok here is a revised patch for ospfd's parse.y.
It does two things:
  1. move atoul to strtonum and use errstr as claudio requested
  2. allow braces  to fit on one line for single options.

The second option allows constructs like these:

area 0.0.0.1 {
	interface trunk0
	interface trunk1 { passive }
}

This didn't work previously.
I also spotted a pdebug which probably was previously used for debugging 
symbol insertion/removal, if it is a leftover the second patch removes it.

Alternately patches are available here:
http://spootnik.org/files/ospfd_parse_y.diff
http://spootnik.org/files/ospfd_parse_y_2.diff

Index: parse.y
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/ospfd/parse.y,v
retrieving revision 1.34
diff -u -r1.34 parse.y
--- parse.y     31 May 2006 03:59:51 -0000      1.34
+++ parse.y     25 Oct 2006 11:40:07 -0000
@@ -93,7 +93,6 @@

  int                     symset(const char *, const char *, int);
  char                   *symget(const char *);
-int                     atoul(char *, u_long *);
  struct area            *conf_get_area(struct in_addr);
  struct iface           *conf_get_if(struct kif *);

@@ -130,10 +129,13 @@
                 ;

  number         : STRING {
-                       u_long  ulval;
+                       u_long           ulval;
+                       const char      *errstr;

-                       if (atoul($1, &ulval) == -1) {
-                               yyerror("%s is not a number", $1);
+                       ulval = strtonum($1, 0, UINT_MAX, &errstr);
+                       if (errstr) {
+                               yyerror("%s is not a number: %s",
+                                       $1, errstr);
                                 free($1);
                                 YYERROR;
                         } else
@@ -404,12 +406,12 @@
                 }
                 ;

-areaopts_l     : areaopts_l areaoptsl
-               | areaoptsl
+areaopts_l     : areaopts_l areaoptsl nl
+               | areaoptsl optnl
                 ;

-areaoptsl      : interface nl
-               | defaults nl
+areaoptsl      : interface
+               | defaults
                 ;

  interface      : INTERFACE STRING      {
@@ -455,12 +457,12 @@
                 |
                 ;

-interfaceopts_l        : interfaceopts_l interfaceoptsl
-               | interfaceoptsl
+interfaceopts_l        : interfaceopts_l interfaceoptsl nl
+               | interfaceoptsl optnl
                 ;

-interfaceoptsl : PASSIVE nl            { iface->passive = 1; }
-               | defaults nl
+interfaceoptsl : PASSIVE               { iface->passive = 1; }
+               | defaults
                 ;

  %%
@@ -866,22 +868,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 area *

Index: parse.y
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/ospfd/parse.y,v
retrieving revision 1.34
diff -u -r1.34 parse.y
--- parse.y     31 May 2006 03:59:51 -0000      1.34
+++ parse.y     25 Oct 2006 11:48:01 -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;

@@ -524,15 +523,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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic