diff options
author | Bret Lambert <blambert@cvs.openbsd.org> | 2010-09-04 08:06:10 +0000 |
---|---|---|
committer | Bret Lambert <blambert@cvs.openbsd.org> | 2010-09-04 08:06:10 +0000 |
commit | 3ac5cbff0c78ae8c85ca0007ac380f4ea99353ab (patch) | |
tree | 2acfcf25e3e033d3d833dd50129de3e1f50db91a /sbin | |
parent | e4e43e8f70a7ebdb754f8dcace9685a7415403ab (diff) |
sort generated keywords in order to replace linear probe with bsearch(3)
(more people should know about how to properly use libc-provided tools)
make keywords.h depend upon keywords.sh, so that it gets automatically
rebuilt when keywords.sh is edited
ok claudio@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/route/Makefile | 5 | ||||
-rw-r--r-- | sbin/route/keywords.h | 15 | ||||
-rw-r--r-- | sbin/route/keywords.sh | 8 | ||||
-rw-r--r-- | sbin/route/route.c | 17 |
4 files changed, 28 insertions, 17 deletions
diff --git a/sbin/route/Makefile b/sbin/route/Makefile index 81d7a57691d..8b038511d94 100644 --- a/sbin/route/Makefile +++ b/sbin/route/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.10 2005/11/27 18:27:41 deraadt Exp $ +# $OpenBSD: Makefile,v 1.11 2010/09/04 08:06:09 blambert Exp $ PROG= route MAN= route.8 @@ -6,4 +6,7 @@ SRCS= route.c show.c route.o .depend lint tags: keywords.h +keywords.h: keywords.sh + /bin/sh ${.CURDIR}/keywords.sh + .include <bsd.prog.mk> diff --git a/sbin/route/keywords.h b/sbin/route/keywords.h index 722ff225f08..93742b46edb 100644 --- a/sbin/route/keywords.h +++ b/sbin/route/keywords.h @@ -1,4 +1,4 @@ -/* $OpenBSD: keywords.h,v 1.26 2009/12/01 16:21:46 reyk Exp $ */ +/* $OpenBSD: keywords.h,v 1.27 2010/09/04 08:06:09 blambert Exp $ */ /* WARNING! This file was generated by keywords.sh */ @@ -22,15 +22,15 @@ enum { K_GATEWAY, K_GENMASK, K_GET, - K_HOST, K_HOPCOUNT, - K_IFACE, - K_INTERFACE, + K_HOST, K_IFA, + K_IFACE, K_IFP, K_IN, K_INET, K_INET6, + K_INTERFACE, K_JUMBO, K_LABEL, K_LINK, @@ -80,15 +80,15 @@ struct keytab keywords[] = { { "gateway", K_GATEWAY }, { "genmask", K_GENMASK }, { "get", K_GET }, - { "host", K_HOST }, { "hopcount", K_HOPCOUNT }, - { "iface", K_IFACE }, - { "interface", K_INTERFACE }, + { "host", K_HOST }, { "ifa", K_IFA }, + { "iface", K_IFACE }, { "ifp", K_IFP }, { "in", K_IN }, { "inet", K_INET }, { "inet6", K_INET6 }, + { "interface", K_INTERFACE }, { "jumbo", K_JUMBO }, { "label", K_LABEL }, { "link", K_LINK }, @@ -122,6 +122,5 @@ struct keytab keywords[] = { { "static", K_STATIC }, { "swap", K_SWAP }, { "xresolve", K_XRESOLVE }, - { 0, 0 } }; diff --git a/sbin/route/keywords.sh b/sbin/route/keywords.sh index 9273e30c7f2..a4c9a4023c9 100644 --- a/sbin/route/keywords.sh +++ b/sbin/route/keywords.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: keywords.sh,v 1.24 2009/12/01 16:16:46 reyk Exp $ +# $OpenBSD: keywords.sh,v 1.25 2010/09/04 08:06:09 blambert Exp $ # $NetBSD: keywords.sh,v 1.2 1996/11/15 18:57:21 gwr Exp $ # @(#)keywords 8.2 (Berkeley) 3/19/94 # @@ -8,7 +8,8 @@ # This program requires "new" awk (or GNU awk). awk=${AWK:-awk} -cat << _EOF_ > _keywords.t1 +# the following must be sorted +cat << _EOF_ | sort > _keywords.t1 add blackhole change @@ -106,8 +107,7 @@ $awk '{ printf("\t{ \"%s\",\tK_%s },\n", $1, $2); }' < _keywords.t2 -echo ' { 0, 0 } -}; +echo '}; ' # tail diff --git a/sbin/route/route.c b/sbin/route/route.c index 69688dd93e9..779cf378de3 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.148 2010/09/02 14:03:21 sobrado Exp $ */ +/* $OpenBSD: route.c,v 1.149 2010/09/04 08:06:09 blambert Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -1512,12 +1512,21 @@ bprintf(FILE *fp, int b, char *s) } int +keycmp(const void *key, const void *kt) +{ + return (strcmp(key, ((struct keytab *)kt)->kt_cp)); +} + +int keyword(char *cp) { - struct keytab *kt = keywords; + struct keytab *kt; + + kt = bsearch(cp, keywords, sizeof(keywords)/sizeof(keywords[0]), + sizeof(keywords[0]), keycmp); + if (!kt) + return (0); - while (kt->kt_cp && strcmp(kt->kt_cp, cp)) - kt++; return (kt->kt_i); } |