nslexer.l revision 250227
165532Snectar%{
265532Snectar/*	$NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $	*/
365532Snectar
465532Snectar/*-
565532Snectar * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
665532Snectar * All rights reserved.
765532Snectar *
865532Snectar * This code is derived from software contributed to The NetBSD Foundation
965532Snectar * by Luke Mewburn.
1065532Snectar *
1165532Snectar * Redistribution and use in source and binary forms, with or without
1265532Snectar * modification, are permitted provided that the following conditions
1365532Snectar * are met:
1465532Snectar * 1. Redistributions of source code must retain the above copyright
1565532Snectar *    notice, this list of conditions and the following disclaimer.
1665532Snectar * 2. Redistributions in binary form must reproduce the above copyright
1765532Snectar *    notice, this list of conditions and the following disclaimer in the
1865532Snectar *    documentation and/or other materials provided with the distribution.
1965532Snectar * 3. All advertising materials mentioning features or use of this software
2065532Snectar *    must display the following acknowledgement:
2165532Snectar *        This product includes software developed by the NetBSD
2265532Snectar *        Foundation, Inc. and its contributors.
2365532Snectar * 4. Neither the name of The NetBSD Foundation nor the names of its
2465532Snectar *    contributors may be used to endorse or promote products derived
2565532Snectar *    from this software without specific prior written permission.
2665532Snectar *
2765532Snectar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2865532Snectar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2965532Snectar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3065532Snectar * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3165532Snectar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3265532Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3365532Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3465532Snectar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3565532Snectar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3665532Snectar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3765532Snectar * POSSIBILITY OF SUCH DAMAGE.
3865532Snectar */
3965532Snectar
4065532Snectar#include <sys/cdefs.h>
4165532Snectar#if defined(LIBC_SCCS) && !defined(lint)
4265532Snectarstatic char *rcsid =
4365532Snectar  "$FreeBSD: head/lib/libc/net/nslexer.l 250227 2013-05-03 23:51:32Z jkim $";
4465532Snectar#endif /* LIBC_SCCS and not lint */
4565532Snectar
46111618Snectar#include "namespace.h"
4765532Snectar#include <ctype.h>
4865532Snectar#define _NS_PRIVATE
4965532Snectar#include <nsswitch.h>
5065532Snectar#include <string.h>
51113595Snectar#include <syslog.h>
52111618Snectar#include "un-namespace.h"
5365532Snectar
5465532Snectar#include "nsparser.h"
5565532Snectar
5665532Snectar%}
5765532Snectar
58250227Sjkim%option noinput
59250227Sjkim%option nounput
6065532Snectar%option yylineno
6165532Snectar
6265532SnectarBLANK		[ \t]
6365532SnectarCR		\n
6465532SnectarSTRING		[a-zA-Z][a-zA-Z0-9_]*
6565532Snectar
6665532Snectar%%
6765532Snectar
6865532Snectar{BLANK}+	;			/* skip whitespace */
6965532Snectar
7065532Snectar#.*		;			/* skip comments */
7165532Snectar
7265532Snectar\\{CR}		;			/* allow continuation */
7365532Snectar
7465532Snectar{CR}		return NL;
7565532Snectar
7665532Snectar[sS][uU][cC][cC][eE][sS][sS]		return SUCCESS;
7765532Snectar[uU][nN][aA][vV][aA][iI][lL]		return UNAVAIL;
7865532Snectar[nN][oO][tT][fF][oO][uU][nN][dD]	return NOTFOUND;
7965532Snectar[tT][rR][yY][aA][gG][aA][iI][nN]	return TRYAGAIN;
8065532Snectar
8165532Snectar[rR][eE][tT][uU][rR][nN]		return RETURN;
8265532Snectar[cC][oO][nN][tT][iI][nN][uU][eE]	return CONTINUE;
8365532Snectar
8465532Snectar{STRING}	{
8565532Snectar			char *p;
8665532Snectar			int i;
8765532Snectar
88113595Snectar			if ((p = strdup(yytext)) == NULL) {
89113595Snectar				syslog(LOG_ERR,
90113595Snectar			       "NSSWITCH(nslexer): memory allocation failure");
91113595Snectar				return ERRORTOKEN;
92113595Snectar			}
9365532Snectar			for (i = 0; i < strlen(p); i++) {
9465532Snectar				if (isupper((unsigned char)p[i]))
9565532Snectar					p[i] = tolower((unsigned char)p[i]);
9665532Snectar			}
9765532Snectar			_nsyylval.str = p;
9865532Snectar			return STRING;
9965532Snectar		}
10065532Snectar
10186162Sfenner.		return yytext[0];
10265532Snectar
10365532Snectar%%
10465532Snectar
10565532Snectar#undef _nsyywrap
10665532Snectarint
10765532Snectar_nsyywrap()
10865532Snectar{
10965532Snectar	return 1;
11065532Snectar} /* _nsyywrap */
11165532Snectar
11265532Snectarvoid
11365532Snectar_nsyyerror(msg)
11465532Snectar	const char *msg;
11565532Snectar{
11665532Snectar
117113595Snectar	 syslog(LOG_ERR, "NSSWITCH(nslexer): %s line %d: %s at '%s'",
118113595Snectar	     _PATH_NS_CONF, yylineno, msg, yytext);
11965532Snectar} /* _nsyyerror */
120