3 * Copyright (c) 1997-2014 Erez Zadok
4 * Copyright (c) 2005 Daniel P. Ottavio
5 * Copyright (c) 1990 Jan-Simon Pendry
6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1990 The Regents of the University of California.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * File: am-utils/amd/sun_map_tok.l
44 #endif /* HAVE_CONFIG_H */
46 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
47 * and their (bad) version of lex defines it too at the very beginning of
48 * the generated lex.yy.c file (before it can be easily undefined),
49 * resulting in a conflict. So undefine it here before needed.
50 * Luckily, it does not appear that this macro is actually used in the rest
51 * of the generated lex.yy.c file.
58 #include <sun_map_parse.h>
59 /* and once again undefine this, just in case */
65 * There are some things that need to be defined only if using GNU flex.
66 * These must not be defined if using standard lex
70 # define ECHO __IGNORE(fwrite( yytext, yyleng, 1, yyout ))
71 # endif /* not ECHO */
72 #endif /* FLEX_SCANNER */
75 int sun_map_error(const char *);
78 * We need to configure lex to parse from a string
79 * instead of a file. Each version of lex has it's
80 * own way of doing this (sigh).
83 /* assign the buffer to parse */
84 void sun_map_tok_setbuff(const char* buff);
86 /* buffer that contains the string to parse */
87 const char *sun_map_tok_buff = NULL;
91 * The flex scanner uses the YY_INPUT to parse the input.
92 * We need to redefine it so that it can parse strings.
93 * In addition to the above string buffer we need to have
94 * a position pointer and a end pointer.
97 /* current position of the buffer */
98 const char *sun_map_tok_pos = NULL;
100 /* size of the buffer */
101 const char *sun_map_tok_end = NULL;
103 /* copies the current position + maxsize into buff */
104 int sun_map_input(char *buff, int maxsize);
107 # define YY_INPUT(buff,result,maxsize) (result = sun_map_input(buff,maxsize))
111 * If this is not Flex than fall back to an AT&T style lex.
112 * We can parse strings by redefining input and unput.
116 #define input() (*(char *)sun_map_tok_buff++)
117 #define unput(c) (*(char *)--sun_map_tok_buff = c)
119 #endif /* FLEX_SCANNER */
122 * some systems such as DU-4.x have a different GNU flex in /usr/bin
123 * which automatically generates yywrap macros and symbols. So I must
124 * distinguish between them and when yywrap is actually needed.
126 #if !defined(yywrap) || defined(yylex)
128 #endif /* not yywrap or yylex */
130 /* no need to use yywrap() */
131 #define YY_SKIP_YYWRAP
133 int sun_map_line = 1;
134 int sun_map_tokpos = 1;
138 /* This option causes Solaris lex to fail. Use flex. See BUGS file */
139 /* no need to use yyunput() */
143 /* allocate more output slots so lex scanners don't run out of mem */
146 WORD_REX [A-Za-z0-9_/&\.$=]+[A-Za-z0-9_/&\.$=-]*
155 sun_map_tokpos += yyleng;
156 xstrlcpy((char *)sun_map_lval.strval,(const char *)yytext,sizeof(sun_map_lval.strval));
161 sun_map_tokpos += yyleng;
188 sun_map_error(const char* s)
195 sun_map_tok_setbuff(const char* buff)
197 sun_map_tok_end = buff + strlen(buff);
198 sun_map_tok_pos = buff;
199 sun_map_tok_buff = buff;
204 sun_map_input(char *buff, int maxsize)
206 int size = MIN(maxsize, (sun_map_tok_end - sun_map_tok_pos));
208 memcpy(buff,sun_map_tok_pos,size);
209 sun_map_tok_pos += size;
216 sun_map_tok_setbuff(const char* buff)
218 sun_map_tok_buff = buff;
221 #endif /* FLEX_SCANNER */
224 * some systems such as DU-4.x have a different GNU flex in /usr/bin
225 * which automatically generates yywrap macros and symbols. So I must
226 * distinguish between them and when yywrap is actually needed.
228 #if !defined(yywrap) || defined(yylex)
233 #endif /* not yywrap or yylex */