1/* $NetBSD: conf_tok.l,v 1.4 2011/06/22 03:58:51 mrg Exp $ */ 2 3%{ 4/* 5 * Copyright (c) 1997-2009 Erez Zadok 6 * Copyright (c) 1989 Jan-Simon Pendry 7 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 8 * Copyright (c) 1989 The Regents of the University of California. 9 * All rights reserved. 10 * 11 * This code is derived from software contributed to Berkeley by 12 * Jan-Simon Pendry at Imperial College, London. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgment: 24 * This product includes software developed by the University of 25 * California, Berkeley and its contributors. 26 * 4. Neither the name of the University nor the names of its contributors 27 * may be used to endorse or promote products derived from this software 28 * without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * 43 * File: am-utils/amd/conf_tok.l 44 * 45 */ 46 47/* 48 * Lexical analyzer for AMD configuration parser. 49 */ 50 51#ifdef HAVE_CONFIG_H 52# include <config.h> 53#endif /* HAVE_CONFIG_H */ 54/* 55 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>, 56 * and their (bad) version of lex defines it too at the very beginning of 57 * the generated lex.yy.c file (before it can be easily undefined), 58 * resulting in a conflict. So undefine it here before needed. 59 * Luckily, it does not appear that this macro is actually used in the rest 60 * of the generated lex.yy.c file. 61 */ 62#ifdef ECHO 63# undef ECHO 64#endif /* ECHO */ 65#include <am_defs.h> 66#include <amd.h> 67#include <conf_parse.h> 68/* and once again undefine this, just in case */ 69#ifdef ECHO 70# undef ECHO 71#endif /* ECHO */ 72 73/* 74 * There are some things that need to be defined only if using GNU flex. 75 * These must not be defined if using standard lex 76 */ 77#ifdef FLEX_SCANNER 78# ifndef ECHO 79# define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) 80# endif /* not ECHO */ 81#endif /* FLEX_SCANNER */ 82 83int ayylineno = 0; 84 85int yylex(void); 86/* 87 * some systems such as DU-4.x have a different GNU flex in /usr/bin 88 * which automatically generates yywrap macros and symbols. So I must 89 * distinguish between them and when yywrap is actually needed. 90 */ 91#if !defined(yywrap) || defined(yylex) 92int yywrap(void); 93#endif /* not yywrap or yylex */ 94 95#define TOK_DEBUG 0 96 97#if TOK_DEBUG 98# define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s)) 99# define amu_return(v) 100#else /* not TOK_DEBUG */ 101# define dprintf(f,s) 102# define amu_return(v) return((v)) 103#endif /* not TOK_DEBUG */ 104 105/* no need to use yywrap() */ 106#define YY_SKIP_YYWRAP 107 108%} 109 110/* This option causes Solaris lex to fail. Use flex. See BUGS file */ 111/* no need to use yyunput() */ 112%option nounput 113%option noinput 114 115/* allocate more output slots so lex scanners don't run out of mem */ 116%o 1024 117 118DIGIT [0-9] 119ALPHA [A-Za-z] 120ALPHANUM [A-Za-z0-9] 121SYMBOL [A-Za-z0-9_-] 122PATH [A-Za-z0-9_-/] 123NONWSCHAR [^ \t\n\[\]=] 124NONWSEQCHAR [^ \t\n\[\]] 125NONNL [^\n] 126NONQUOTE [^\"] 127 128%% 129 130\n { 131 ayylineno++; 132 amu_return(NEWLINE); 133 } 134 135\[ { 136 dprintf("%8d: Left bracket \"%s\"\n", yytext); 137 yylval.strtype = strdup((char *)yytext); 138 amu_return(LEFT_BRACKET); 139 } 140 141\] { 142 dprintf("%8d: Right bracket \"%s\"\n", yytext); 143 yylval.strtype = strdup((char *)yytext); 144 amu_return(RIGHT_BRACKET); 145 } 146 147= { 148 dprintf("%8d: Equal \"%s\"\n", yytext); 149 yylval.strtype = strdup((char *)yytext); 150 amu_return(EQUAL); 151 } 152 153[ \t]* { 154 dprintf("%8d: Whitespace \"%s\"\n", yytext); 155 } 156"#"[^\n]*\n { 157 /* a comment line includes the terminating \n */ 158 ayylineno++; 159 yytext[strlen((char *)yytext)-1] = '\0'; 160 dprintf("%8d: Comment \"%s\"\n", yytext); 161 } 162 163{NONWSCHAR}{NONWSCHAR}* { 164 dprintf("%8d: Non-WS string \"%s\"\n", yytext); 165 yylval.strtype = strdup((char *)yytext); 166 amu_return(NONWS_STRING); 167 } 168 169\"{NONQUOTE}{NONQUOTE}*\" { 170 dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext); 171 /* must strip quotes */ 172 yytext[strlen((char *)yytext)-1] = '\0'; 173 yylval.strtype = strdup((char *)&yytext[1]); 174 amu_return(QUOTED_NONWSEQ_STRING); 175 } 176 177{NONWSEQCHAR}{NONWSEQCHAR}* { 178 dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext); 179 yylval.strtype = strdup((char *)yytext); 180 amu_return(NONWSEQ_STRING); 181 } 182 183%% 184 185/* 186 * some systems such as DU-4.x have a different GNU flex in /usr/bin 187 * which automatically generates yywrap macros and symbols. So I must 188 * distinguish between them and when yywrap is actually needed. 189 */ 190#if !defined(yywrap) || defined(yylex) 191int yywrap(void) 192{ 193 return 1; 194} 195#endif /* not yywrap or yylex */ 196