1%{
2/*
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.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
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.
24 *
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
35 * SUCH DAMAGE.
36 *
37 *
38 * File: am-utils/amd/sun_map_tok.l
39 *
40 */
41
42#ifdef HAVE_CONFIG_H
43# include <config.h>
44#endif /* HAVE_CONFIG_H */
45/*
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.
52 */
53#ifdef ECHO
54# undef ECHO
55#endif /* ECHO */
56#include <am_defs.h>
57#include <amd.h>
58#include <sun_map_parse.h>
59/* and once again undefine this, just in case */
60#ifdef ECHO
61# undef ECHO
62#endif /* ECHO */
63
64/*
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
67 */
68#ifdef FLEX_SCANNER
69# ifndef ECHO
70#  define ECHO __IGNORE(fwrite( yytext, yyleng, 1, yyout ))
71# endif /* not ECHO */
72#endif /* FLEX_SCANNER */
73
74int yylex(void);
75int sun_map_error(const char *);
76
77/*
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).
81 */
82
83/* assign the buffer to parse */
84void sun_map_tok_setbuff(const char* buff);
85
86/* buffer that contains the string to parse */
87const char *sun_map_tok_buff = NULL;
88
89#ifdef FLEX_SCANNER
90/*
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.
95 */
96
97/* current position of the buffer */
98const char *sun_map_tok_pos = NULL;
99
100/* size of the buffer */
101const char *sun_map_tok_end = NULL;
102
103/* copies the current position + maxsize into buff */
104int sun_map_input(char *buff, int maxsize);
105
106# undef YY_INPUT
107# define YY_INPUT(buff,result,maxsize) (result = sun_map_input(buff,maxsize))
108
109#else
110/*
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.
113 */
114#undef input
115#undef unput
116#define input()  (*(char *)sun_map_tok_buff++)
117#define unput(c) (*(char *)--sun_map_tok_buff = c)
118
119#endif /* FLEX_SCANNER */
120
121/*
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.
125 */
126#if !defined(yywrap) || defined(yylex)
127int yywrap(void);
128#endif /* not yywrap or yylex */
129
130/* no need to use yywrap() */
131#define YY_SKIP_YYWRAP
132
133int sun_map_line = 1;
134int sun_map_tokpos = 1;
135
136%}
137
138/* This option causes Solaris lex to fail.  Use flex.  See BUGS file */
139/* no need to use yyunput() */
140%option nounput
141%option noinput
142
143/* allocate more output slots so lex scanners don't run out of mem */
144%o 1024
145
146WORD_REX       [A-Za-z0-9_/&\.$=]+[A-Za-z0-9_/&\.$=-]*
147COMMENT_REX    ^#.*\n
148WSPACE_REX     [ \t]*
149NEWLINE_REX    [ \t]*\n
150CONTINUE_REX   "\\"\n
151
152%%
153
154{WORD_REX}      {
155                  sun_map_tokpos += yyleng;
156                  xstrlcpy((char *)sun_map_lval.strval,(const char *)yytext,sizeof(sun_map_lval.strval));
157                  return WORD;
158                }
159
160{WSPACE_REX}    {
161                  sun_map_tokpos += yyleng;
162                  return WSPACE;
163                }
164
165{NEWLINE_REX}   {
166                  sun_map_tokpos = 0;
167                  sun_map_line++;
168                  return NEWLINE;
169                }
170
171{CONTINUE_REX}  {
172                  sun_map_tokpos = 0;
173                  sun_map_line++;
174                }
175
176{COMMENT_REX}   {
177                  sun_map_line++;
178                }
179
180.               {
181                  return yytext[0];
182                }
183
184%%
185
186
187int
188sun_map_error(const char* s)
189{
190  return 1;
191}
192
193#ifdef FLEX_SCANNER
194void
195sun_map_tok_setbuff(const char* buff)
196{
197  sun_map_tok_end = buff + strlen(buff);
198  sun_map_tok_pos = buff;
199  sun_map_tok_buff = buff;
200}
201
202
203int
204sun_map_input(char *buff, int maxsize)
205{
206  int size = MIN(maxsize, (sun_map_tok_end - sun_map_tok_pos));
207  if (size > 0) {
208    memcpy(buff,sun_map_tok_pos,size);
209    sun_map_tok_pos += size;
210  }
211
212  return size;
213}
214#else
215void
216sun_map_tok_setbuff(const char* buff)
217{
218  sun_map_tok_buff = buff;
219}
220
221#endif /* FLEX_SCANNER */
222
223/*
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.
227 */
228#if !defined(yywrap) || defined(yylex)
229int yywrap(void)
230{
231  return 1;
232}
233#endif /* not yywrap or yylex */
234