hi ted,

the diff is ok by me

gilles

On Sun, Aug 22, 2010 at 05:56:32PM -0400, Ted Unangst wrote:
> I think this is slightly better, though there isn't much functional 
> change.  This code certainly gets around...
> 
> Index: dvmrpctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/dvmrpctl/parser.c,v
> retrieving revision 1.4
> diff -u -r1.4 parser.c
> --- dvmrpctl/parser.c 13 Nov 2009 20:09:54 -0000      1.4
> +++ dvmrpctl/parser.c 22 Aug 2010 21:44:37 -0000
> @@ -107,18 +107,21 @@
>  };
>  
>  
> -static struct parse_result   res;
> +static void show_valid_args(const struct token *);
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -141,8 +144,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -163,7 +167,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case FLAG:
> @@ -171,35 +175,35 @@
>                           strlen(word)) == 0) {
>                               match++;
>                               t = &table[i];
> -                             res.flags |= t->value;
> +                             res->flags |= t->value;
>                       }
>                       break;
>               case ADDRESS:
> -                     if (parse_addr(word, &res.addr)) {
> +                     if (parse_addr(word, &res->addr)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case PREFIX:
> -                     if (parse_prefix(word, &res.addr, &res.prefixlen)) {
> +                     if (parse_prefix(word, &res->addr, &res->prefixlen)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case IFNAME:
>                       if (!match && word != NULL && strlen(word) > 0) {
> -                             if (strlcpy(res.ifname, word,
> -                                 sizeof(res.ifname)) >=
> -                                 sizeof(res.ifname))
> +                             if (strlcpy(res->ifname, word,
> +                                 sizeof(res->ifname)) >=
> +                                 sizeof(res->ifname))
>                                       err(1, "interface name too long");
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>  
> @@ -221,7 +225,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: dvmrpctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/dvmrpctl/parser.h,v
> retrieving revision 1.3
> diff -u -r1.3 parser.h
> --- dvmrpctl/parser.h 13 Nov 2009 20:09:54 -0000      1.3
> +++ dvmrpctl/parser.h 22 Aug 2010 21:41:43 -0000
> @@ -51,8 +51,6 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token   *match_token(const char *, const struct token *);
> -void                  show_valid_args(const struct token *);
>  int                   parse_addr(const char *, struct in_addr *);
>  int                   parse_prefix(const char *, struct in_addr *,
>                            u_int8_t *);
> Index: ldpctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ldpctl/parser.c,v
> retrieving revision 1.3
> diff -u -r1.3 parser.c
> --- ldpctl/parser.c   13 Jan 2010 11:33:12 -0000      1.3
> +++ ldpctl/parser.c   22 Aug 2010 21:54:03 -0000
> @@ -114,18 +114,21 @@
>       {ENDTOKEN,      "",             NONE,                   NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
> +static void show_valid_args(const struct token *);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -148,8 +151,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -170,7 +174,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case FLAG:
> @@ -178,35 +182,35 @@
>                           strlen(word)) == 0) {
>                               match++;
>                               t = &table[i];
> -                             res.flags |= t->value;
> +                             res->flags |= t->value;
>                       }
>                       break;
>               case ADDRESS:
> -                     if (parse_addr(word, &res.addr)) {
> +                     if (parse_addr(word, &res->addr)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case PREFIX:
> -                     if (parse_prefix(word, &res.addr, &res.prefixlen)) {
> +                     if (parse_prefix(word, &res->addr, &res->prefixlen)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case IFNAME:
>                       if (!match && word != NULL && strlen(word) > 0) {
> -                             if (strlcpy(res.ifname, word,
> -                                 sizeof(res.ifname)) >=
> -                                 sizeof(res.ifname))
> +                             if (strlcpy(res->ifname, word,
> +                                 sizeof(res->ifname)) >=
> +                                 sizeof(res->ifname))
>                                       err(1, "interface name too long");
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>  
> @@ -228,7 +232,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: ldpctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ldpctl/parser.h,v
> retrieving revision 1.3
> diff -u -r1.3 parser.h
> --- ldpctl/parser.h   13 Jan 2010 11:33:12 -0000      1.3
> +++ ldpctl/parser.h   22 Aug 2010 21:52:46 -0000
> @@ -50,8 +50,6 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token   *match_token(const char *, const struct token *);
> -void                  show_valid_args(const struct token *);
>  int                   parse_addr(const char *, struct in_addr *);
>  int                   parse_prefix(const char *, struct in_addr *,
>                            u_int8_t *);
> Index: ospf6ctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ospf6ctl/parser.c,v
> retrieving revision 1.9
> diff -u -r1.9 parser.c
> --- ospf6ctl/parser.c 20 Jul 2010 05:26:06 -0000      1.9
> +++ ospf6ctl/parser.c 22 Aug 2010 21:52:16 -0000
> @@ -139,18 +139,21 @@
>       {ENDTOKEN,      "",             NONE,                   NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
> +static void show_valid_args(const struct token *);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -173,8 +176,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -195,7 +199,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case FLAG:
> @@ -203,35 +207,35 @@
>                           strlen(word)) == 0) {
>                               match++;
>                               t = &table[i];
> -                             res.flags |= t->value;
> +                             res->flags |= t->value;
>                       }
>                       break;
>               case ADDRESS:
> -                     if (parse_addr(word, &res.addr)) {
> +                     if (parse_addr(word, &res->addr)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case PREFIX:
> -                     if (parse_prefix(word, &res.addr, &res.prefixlen)) {
> +                     if (parse_prefix(word, &res->addr, &res->prefixlen)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case IFNAME:
>                       if (!match && word != NULL && strlen(word) > 0) {
> -                             if (strlcpy(res.ifname, word,
> -                                 sizeof(res.ifname)) >=
> -                                 sizeof(res.ifname))
> +                             if (strlcpy(res->ifname, word,
> +                                 sizeof(res->ifname)) >=
> +                                 sizeof(res->ifname))
>                                       err(1, "interface name too long");
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>  
> @@ -253,7 +257,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: ospf6ctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ospf6ctl/parser.h,v
> retrieving revision 1.7
> diff -u -r1.7 parser.h
> --- ospf6ctl/parser.h 13 Jan 2010 11:33:12 -0000      1.7
> +++ ospf6ctl/parser.h 22 Aug 2010 21:38:22 -0000
> @@ -62,8 +62,6 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token   *match_token(const char *, const struct token *);
> -void                  show_valid_args(const struct token *);
>  int                   parse_addr(const char *, struct in6_addr *);
>  int                   parse_prefix(const char *, struct in6_addr *,
>                            u_int8_t *);
> Index: ospfctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ospfctl/parser.c,v
> retrieving revision 1.18
> diff -u -r1.18 parser.c
> --- ospfctl/parser.c  19 Feb 2010 10:35:52 -0000      1.18
> +++ ospfctl/parser.c  22 Aug 2010 21:44:59 -0000
> @@ -138,18 +138,21 @@
>       {ENDTOKEN,      "",             NONE,                   NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
> +static void show_valid_args(const struct token *);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -172,8 +175,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -194,7 +198,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case FLAG:
> @@ -202,35 +206,35 @@
>                           strlen(word)) == 0) {
>                               match++;
>                               t = &table[i];
> -                             res.flags |= t->value;
> +                             res->flags |= t->value;
>                       }
>                       break;
>               case ADDRESS:
> -                     if (parse_addr(word, &res.addr)) {
> +                     if (parse_addr(word, &res->addr)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case PREFIX:
> -                     if (parse_prefix(word, &res.addr, &res.prefixlen)) {
> +                     if (parse_prefix(word, &res->addr, &res->prefixlen)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case IFNAME:
>                       if (!match && word != NULL && strlen(word) > 0) {
> -                             if (strlcpy(res.ifname, word,
> -                                 sizeof(res.ifname)) >=
> -                                 sizeof(res.ifname))
> +                             if (strlcpy(res->ifname, word,
> +                                 sizeof(res->ifname)) >=
> +                                 sizeof(res->ifname))
>                                       err(1, "interface name too long");
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>  
> @@ -252,7 +256,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: ospfctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ospfctl/parser.h,v
> retrieving revision 1.11
> diff -u -r1.11 parser.h
> --- ospfctl/parser.h  19 Feb 2010 10:35:52 -0000      1.11
> +++ ospfctl/parser.h  22 Aug 2010 21:35:17 -0000
> @@ -62,8 +62,6 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token   *match_token(const char *, const struct token *);
> -void                  show_valid_args(const struct token *);
>  int                   parse_addr(const char *, struct in_addr *);
>  int                   parse_prefix(const char *, struct in_addr *,
>                            u_int8_t *);
> Index: relayctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/relayctl/parser.c,v
> retrieving revision 1.23
> diff -u -r1.23 parser.c
> --- relayctl/parser.c 11 Jan 2010 06:40:14 -0000      1.23
> +++ relayctl/parser.c 22 Aug 2010 21:51:20 -0000
> @@ -131,18 +131,21 @@
>       {ENDTOKEN,      "",             NONE,           NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
> +static void show_valid_args(const struct token *);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -165,8 +168,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -188,16 +192,16 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case HOSTID:
>                       if (word == NULL)
>                               break;
> -                     res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
> +                     res->id.id = strtonum(word, 0, UINT_MAX, &errstr);
>                       if (errstr) {
> -                             strlcpy(res.id.name, word, sizeof(res.id.name));
> -                             res.id.id = EMPTY_ID;
> +                             strlcpy(res->id.name, word, 
> sizeof(res->id.name));
> +                             res->id.id = EMPTY_ID;
>                       }
>                       t = &table[i];
>                       match++;
> @@ -205,10 +209,10 @@
>               case TABLEID:
>                       if (word == NULL)
>                               break;
> -                     res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
> +                     res->id.id = strtonum(word, 0, UINT_MAX, &errstr);
>                       if (errstr) {
> -                             strlcpy(res.id.name, word, sizeof(res.id.name));
> -                             res.id.id = EMPTY_ID;
> +                             strlcpy(res->id.name, word, 
> sizeof(res->id.name));
> +                             res->id.id = EMPTY_ID;
>                       }
>                       t = &table[i];
>                       match++;
> @@ -216,10 +220,10 @@
>               case RDRID:
>                       if (word == NULL)
>                               break;
> -                     res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
> +                     res->id.id = strtonum(word, 0, UINT_MAX, &errstr);
>                       if (errstr) {
> -                             strlcpy(res.id.name, word, sizeof(res.id.name));
> -                             res.id.id = EMPTY_ID;
> +                             strlcpy(res->id.name, word, 
> sizeof(res->id.name));
> +                             res->id.id = EMPTY_ID;
>                       }
>                       t = &table[i];
>                       match++;
> @@ -242,7 +246,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: relayctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/relayctl/parser.h,v
> retrieving revision 1.12
> diff -u -r1.12 parser.h
> --- relayctl/parser.h 11 Jan 2010 06:40:14 -0000      1.12
> +++ relayctl/parser.h 22 Aug 2010 21:45:59 -0000
> @@ -44,5 +44,3 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token      *match_token(const char *, const struct token *);
> -void                     show_valid_args(const struct token *);
> Index: ripctl/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ripctl/parser.c,v
> retrieving revision 1.4
> diff -u -r1.4 parser.c
> --- ripctl/parser.c   13 Nov 2009 20:09:54 -0000      1.4
> +++ ripctl/parser.c   22 Aug 2010 21:39:47 -0000
> @@ -115,18 +115,21 @@
>       {ENDTOKEN,      "",             NONE,                   NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token *,
> +    struct parse_result *);
> +static void show_valid_args(const struct token *table)
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -149,8 +152,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token *table)
> +static const struct token *
> +match_token(const char *word, const struct token *table,
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -171,7 +175,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case FLAG:
> @@ -179,35 +183,35 @@
>                           strlen(word)) == 0) {
>                               match++;
>                               t = &table[i];
> -                             res.flags |= t->value;
> +                             res->flags |= t->value;
>                       }
>                       break;
>               case ADDRESS:
> -                     if (parse_addr(word, &res.addr)) {
> +                     if (parse_addr(word, &res->addr)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case PREFIX:
> -                     if (parse_prefix(word, &res.addr, &res.prefixlen)) {
> +                     if (parse_prefix(word, &res->addr, &res->prefixlen)) {
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case IFNAME:
>                       if (!match && word != NULL && strlen(word) > 0) {
> -                             if (strlcpy(res.ifname, word,
> -                                 sizeof(res.ifname)) >=
> -                                 sizeof(res.ifname))
> +                             if (strlcpy(res->ifname, word,
> +                                 sizeof(res->ifname)) >=
> +                                 sizeof(res->ifname))
>                                       err(1, "interface name too long");
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>  
> @@ -229,7 +233,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token *table)
>  {
>       int     i;
> Index: ripctl/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/ripctl/parser.h,v
> retrieving revision 1.3
> diff -u -r1.3 parser.h
> --- ripctl/parser.h   13 Nov 2009 20:09:54 -0000      1.3
> +++ ripctl/parser.h   22 Aug 2010 21:36:26 -0000
> @@ -50,8 +50,6 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token   *match_token(const char *, const struct token *);
> -void                  show_valid_args(const struct token *);
>  int                   parse_addr(const char *, struct in_addr *);
>  int                   parse_prefix(const char *, struct in_addr *,
>                            u_int8_t *);
> Index: smtpd/parser.c
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/smtpd/parser.c,v
> retrieving revision 1.14
> diff -u -r1.14 parser.c
> --- smtpd/parser.c    1 Jun 2010 23:06:23 -0000       1.14
> +++ smtpd/parser.c    22 Aug 2010 21:50:27 -0000
> @@ -121,18 +121,21 @@
>       {ENDTOKEN,      "",                     NONE,           NULL}
>  };
>  
> -static struct parse_result   res;
> +static const struct token *match_token(const char *, const struct token [],
> +    struct parse_result *res);
> +static void show_valid_args(const struct token []);
>  
>  struct parse_result *
>  parse(int argc, char *argv[])
>  {
> +     static struct parse_result      res;
>       const struct token      *table = t_main;
>       const struct token      *match;
>  
>       bzero(&res, sizeof(res));
>  
>       while (argc >= 0) {
> -             if ((match = match_token(argv[0], table)) == NULL) {
> +             if ((match = match_token(argv[0], table, &res)) == NULL) {
>                       fprintf(stderr, "valid commands/args:\n");
>                       show_valid_args(table);
>                       return (NULL);
> @@ -155,8 +158,9 @@
>       return (&res);
>  }
>  
> -const struct token *
> -match_token(const char *word, const struct token table[])
> +static const struct token *
> +match_token(const char *word, const struct token table[],
> +    struct parse_result *res)
>  {
>       u_int                    i, match;
>       const struct token      *t = NULL;
> @@ -177,7 +181,7 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value)
> -                                     res.action = t->value;
> +                                     res->action = t->value;
>                       }
>                       break;
>               case VARIABLE:
> @@ -185,8 +189,8 @@
>                               match++;
>                               t = &table[i];
>                               if (t->value) {
> -                                     res.action = t->value;
> -                                     res.data = word;
> +                                     res->action = t->value;
> +                                     res->data = word;
>                               }
>                       }
>                       break;
> @@ -208,7 +212,7 @@
>       return (t);
>  }
>  
> -void
> +static void
>  show_valid_args(const struct token table[])
>  {
>       int     i;
> Index: smtpd/parser.h
> ===================================================================
> RCS file: /home/tedu/cvs/src/usr.sbin/smtpd/parser.h,v
> retrieving revision 1.13
> diff -u -r1.13 parser.h
> --- smtpd/parser.h    1 Jun 2010 23:06:23 -0000       1.13
> +++ smtpd/parser.h    22 Aug 2010 21:47:46 -0000
> @@ -44,5 +44,3 @@
>  };
>  
>  struct parse_result  *parse(int, char *[]);
> -const struct token      *match_token(const char *, const struct token *);
> -void                     show_valid_args(const struct token *);
> 

-- 
Gilles Chehade

Reply via email to