1 /* $NetBSD: conf_tok.l,v 1.3 2009/03/20 20:30:52 christos 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 83 int ayylineno = 0; 84 85 int 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) 92 int 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 114 /* allocate more output slots so lex scanners don't run out of mem */ 115 %o 1024 116 117 DIGIT [0-9] 118 ALPHA [A-Za-z] 119 ALPHANUM [A-Za-z0-9] 120 SYMBOL [A-Za-z0-9_-] 121 PATH [A-Za-z0-9_-/] 122 NONWSCHAR [^ \t\n\[\]=] 123 NONWSEQCHAR [^ \t\n\[\]] 124 NONNL [^\n] 125 NONQUOTE [^\"] 126 127 %% 128 129 \n { 130 ayylineno++; 131 amu_return(NEWLINE); 132 } 133 134 \[ { 135 dprintf("%8d: Left bracket \"%s\"\n", yytext); 136 yylval.strtype = strdup((char *)yytext); 137 amu_return(LEFT_BRACKET); 138 } 139 140 \] { 141 dprintf("%8d: Right bracket \"%s\"\n", yytext); 142 yylval.strtype = strdup((char *)yytext); 143 amu_return(RIGHT_BRACKET); 144 } 145 146 = { 147 dprintf("%8d: Equal \"%s\"\n", yytext); 148 yylval.strtype = strdup((char *)yytext); 149 amu_return(EQUAL); 150 } 151 152 [ \t]* { 153 dprintf("%8d: Whitespace \"%s\"\n", yytext); 154 } 155 "#"[^\n]*\n { 156 /* a comment line includes the terminating \n */ 157 ayylineno++; 158 yytext[strlen((char *)yytext)-1] = '\0'; 159 dprintf("%8d: Comment \"%s\"\n", yytext); 160 } 161 162 {NONWSCHAR}{NONWSCHAR}* { 163 dprintf("%8d: Non-WS string \"%s\"\n", yytext); 164 yylval.strtype = strdup((char *)yytext); 165 amu_return(NONWS_STRING); 166 } 167 168 \"{NONQUOTE}{NONQUOTE}*\" { 169 dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext); 170 /* must strip quotes */ 171 yytext[strlen((char *)yytext)-1] = '\0'; 172 yylval.strtype = strdup((char *)&yytext[1]); 173 amu_return(QUOTED_NONWSEQ_STRING); 174 } 175 176 {NONWSEQCHAR}{NONWSEQCHAR}* { 177 dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext); 178 yylval.strtype = strdup((char *)yytext); 179 amu_return(NONWSEQ_STRING); 180 } 181 182 %% 183 184 /* 185 * some systems such as DU-4.x have a different GNU flex in /usr/bin 186 * which automatically generates yywrap macros and symbols. So I must 187 * distinguish between them and when yywrap is actually needed. 188 */ 189 #if !defined(yywrap) || defined(yylex) 190 int yywrap(void) 191 { 192 return 1; 193 } 194 #endif /* not yywrap or yylex */ 195