nslexer.l revision 1.8.8.2 1 1.8.8.2 martin %{
2 1.8.8.2 martin /* $NetBSD: nslexer.l,v 1.8.8.2 2008/04/28 20:23:01 martin Exp $ */
3 1.8.8.2 martin
4 1.8.8.2 martin /*-
5 1.8.8.2 martin * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
6 1.8.8.2 martin * All rights reserved.
7 1.8.8.2 martin *
8 1.8.8.2 martin * This code is derived from software contributed to The NetBSD Foundation
9 1.8.8.2 martin * by Luke Mewburn.
10 1.8.8.2 martin *
11 1.8.8.2 martin * Redistribution and use in source and binary forms, with or without
12 1.8.8.2 martin * modification, are permitted provided that the following conditions
13 1.8.8.2 martin * are met:
14 1.8.8.2 martin * 1. Redistributions of source code must retain the above copyright
15 1.8.8.2 martin * notice, this list of conditions and the following disclaimer.
16 1.8.8.2 martin * 2. Redistributions in binary form must reproduce the above copyright
17 1.8.8.2 martin * notice, this list of conditions and the following disclaimer in the
18 1.8.8.2 martin * documentation and/or other materials provided with the distribution.
19 1.8.8.2 martin *
20 1.8.8.2 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.8.8.2 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.8.8.2 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.8.8.2 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.8.8.2 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.8.8.2 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.8.8.2 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.8.8.2 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.8.8.2 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.8.8.2 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.8.8.2 martin * POSSIBILITY OF SUCH DAMAGE.
31 1.8.8.2 martin */
32 1.8.8.2 martin
33 1.8.8.2 martin #include <sys/cdefs.h>
34 1.8.8.2 martin #if defined(LIBC_SCCS) && !defined(lint)
35 1.8.8.2 martin __RCSID("$NetBSD: nslexer.l,v 1.8.8.2 2008/04/28 20:23:01 martin Exp $");
36 1.8.8.2 martin #endif /* LIBC_SCCS and not lint */
37 1.8.8.2 martin
38 1.8.8.2 martin #include "namespace.h"
39 1.8.8.2 martin #include <ctype.h>
40 1.8.8.2 martin #define _NS_PRIVATE
41 1.8.8.2 martin #include <nsswitch.h>
42 1.8.8.2 martin #include <string.h>
43 1.8.8.2 martin #include <syslog.h>
44 1.8.8.2 martin
45 1.8.8.2 martin #include "nsparser.h"
46 1.8.8.2 martin
47 1.8.8.2 martin #define YY_NO_UNPUT
48 1.8.8.2 martin
49 1.8.8.2 martin %}
50 1.8.8.2 martin
51 1.8.8.2 martin %option yylineno
52 1.8.8.2 martin %option never-interactive
53 1.8.8.2 martin
54 1.8.8.2 martin BLANK [ \t]
55 1.8.8.2 martin CR \n
56 1.8.8.2 martin STRING [a-zA-Z][a-zA-Z0-9_]*
57 1.8.8.2 martin
58 1.8.8.2 martin %%
59 1.8.8.2 martin
60 1.8.8.2 martin {BLANK}+ ; /* skip whitespace */
61 1.8.8.2 martin
62 1.8.8.2 martin #.* ; /* skip comments */
63 1.8.8.2 martin
64 1.8.8.2 martin \\{CR} ; /* allow continuation */
65 1.8.8.2 martin
66 1.8.8.2 martin {CR} return NL;
67 1.8.8.2 martin
68 1.8.8.2 martin [sS][uU][cC][cC][eE][sS][sS] return SUCCESS;
69 1.8.8.2 martin [uU][nN][aA][vV][aA][iI][lL] return UNAVAIL;
70 1.8.8.2 martin [nN][oO][tT][fF][oO][uU][nN][dD] return NOTFOUND;
71 1.8.8.2 martin [tT][rR][yY][aA][gG][aA][iI][nN] return TRYAGAIN;
72 1.8.8.2 martin
73 1.8.8.2 martin [rR][eE][tT][uU][rR][nN] return RETURN;
74 1.8.8.2 martin [cC][oO][nN][tT][iI][nN][uU][eE] return CONTINUE;
75 1.8.8.2 martin
76 1.8.8.2 martin {STRING} {
77 1.8.8.2 martin char *p;
78 1.8.8.2 martin size_t i;
79 1.8.8.2 martin
80 1.8.8.2 martin if ((p = strdup(yytext)) == NULL) {
81 1.8.8.2 martin syslog(LOG_ERR, "libc nsdispatch: %m");
82 1.8.8.2 martin return NL;
83 1.8.8.2 martin }
84 1.8.8.2 martin
85 1.8.8.2 martin for (i = 0; i < strlen(p); i++) {
86 1.8.8.2 martin if (isupper((unsigned char)p[i]))
87 1.8.8.2 martin p[i] = tolower((unsigned char)p[i]);
88 1.8.8.2 martin }
89 1.8.8.2 martin _nsyylval.str = p;
90 1.8.8.2 martin return STRING;
91 1.8.8.2 martin }
92 1.8.8.2 martin
93 1.8.8.2 martin . return yytext[0];
94 1.8.8.2 martin
95 1.8.8.2 martin %%
96 1.8.8.2 martin
97 1.8.8.2 martin #undef _nsyywrap
98 1.8.8.2 martin int
99 1.8.8.2 martin _nsyywrap()
100 1.8.8.2 martin {
101 1.8.8.2 martin return 1;
102 1.8.8.2 martin } /* _nsyywrap */
103 1.8.8.2 martin
104 1.8.8.2 martin void
105 1.8.8.2 martin _nsyyerror(msg)
106 1.8.8.2 martin const char *msg;
107 1.8.8.2 martin {
108 1.8.8.2 martin
109 1.8.8.2 martin syslog(LOG_WARNING, "libc nsdispatch: %s line %d: %s at '%s'",
110 1.8.8.2 martin _PATH_NS_CONF, yylineno, msg, yytext);
111 1.8.8.2 martin } /* _nsyyerror */
112