1 /* $NetBSD: sun_map_tok.l,v 1.1.1.2 2009/03/20 20:26:50 christos Exp $ */
5 * Copyright (c) 1997-2009 Erez Zadok
6 * Copyright (c) 2005 Daniel P. Ottavio
7 * Copyright (c) 1990 Jan-Simon Pendry
8 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
9 * Copyright (c) 1990 The Regents of the University of California.
10 * All rights reserved.
12 * This code is derived from software contributed to Berkeley by
13 * Jan-Simon Pendry at Imperial College, London.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgment:
25 * This product includes software developed by the University of
26 * California, Berkeley and its contributors.
27 * 4. Neither the name of the University nor the names of its contributors
28 * may be used to endorse or promote products derived from this software
29 * without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * File: am-utils/amd/sun_map_tok.l
50 #endif /* HAVE_CONFIG_H */
52 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
53 * and their (bad) version of lex defines it too at the very beginning of
54 * the generated lex.yy.c file (before it can be easily undefined),
55 * resulting in a conflict. So undefine it here before needed.
56 * Luckily, it does not appear that this macro is actually used in the rest
57 * of the generated lex.yy.c file.
64 #include <sun_map_parse.h>
65 /* and once again undefine this, just in case */
71 * There are some things that need to be defined only if using GNU flex.
72 * These must not be defined if using standard lex
76 # define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
77 # endif /* not ECHO */
78 #endif /* FLEX_SCANNER */
81 int yyerror(const char *);
84 * We need to configure lex to parse from a string
85 * instead of a file. Each version of lex has it's
86 * own way of doing this (sigh).
89 /* assign the buffer to parse */
90 void sun_map_tok_setbuff(const char* buff);
92 /* buffer that contains the string to parse */
93 const char *sun_map_tok_buff = NULL;
97 * The flex scanner uses the YY_INPUT to parse the input.
98 * We need to redefine it so that it can parse strings.
99 * In addition to the above string buffer we need to have
100 * a position pointer and a end pointer.
103 /* current position of the buffer */
104 const char *sun_map_tok_pos = NULL;
106 /* size of the buffer */
107 const char *sun_map_tok_end = NULL;
109 /* copies the current position + maxsize into buff */
110 int sun_map_input(char *buff, int maxsize);
113 # define YY_INPUT(buff,result,maxsize) (result = sun_map_input(buff,maxsize))
117 * If this is not Flex than fall back to an AT&T style lex.
118 * We can parse strings by redefining input and unput.
122 #define input() (*(char *)sun_map_tok_buff++)
123 #define unput(c) (*(char *)--sun_map_tok_buff = c)
125 #endif /* FLEX_SCANNER */
128 * some systems such as DU-4.x have a different GNU flex in /usr/bin
129 * which automatically generates yywrap macros and symbols. So I must
130 * distinguish between them and when yywrap is actually needed.
132 #if !defined(yywrap) || defined(yylex)
134 #endif /* not yywrap or yylex */
136 /* no need to use yywrap() */
137 #define YY_SKIP_YYWRAP
140 int sun_map_line = 1;
141 int sun_map_tokpos = 1;
145 /* This option causes Solaris lex to fail. Use flex. See BUGS file */
146 /* no need to use yyunput() */
149 /* allocate more output slots so lex scanners don't run out of mem */
152 WORD_REX [A-Za-z0-9_/&\.$=]+[A-Za-z0-9_/&\.$=-]*
161 sun_map_tokpos += yyleng;
162 xstrlcpy((char *)yylval.strval,(const char *)yytext,sizeof(yylval.strval));
167 sun_map_tokpos += yyleng;
194 yyerror(const char* s)
201 sun_map_tok_setbuff(const char* buff)
203 sun_map_tok_end = buff + strlen(buff);
204 sun_map_tok_pos = buff;
205 sun_map_tok_buff = buff;
210 sun_map_input(char *buff, int maxsize)
212 int size = MIN(maxsize, (sun_map_tok_end - sun_map_tok_pos));
214 memcpy(buff,sun_map_tok_pos,size);
215 sun_map_tok_pos += size;
222 sun_map_tok_setbuff(const char* buff)
224 sun_map_tok_buff = buff;
227 #endif /* FLEX_SCANNER */
230 * some systems such as DU-4.x have a different GNU flex in /usr/bin
231 * which automatically generates yywrap macros and symbols. So I must
232 * distinguish between them and when yywrap is actually needed.
234 #if !defined(yywrap) || defined(yylex)
239 #endif /* not yywrap or yylex */