1123475Swpaul%{ 2123475Swpaul/* 3124060Swpaul * Copyright (c) 2003 4124060Swpaul * Bill Paul <wpaul@windriver.com>. All rights reserved. 5124060Swpaul * 6124060Swpaul * Redistribution and use in source and binary forms, with or without 7124060Swpaul * modification, are permitted provided that the following conditions 8124060Swpaul * are met: 9124060Swpaul * 1. Redistributions of source code must retain the above copyright 10124060Swpaul * notice, this list of conditions and the following disclaimer. 11124060Swpaul * 2. Redistributions in binary form must reproduce the above copyright 12124060Swpaul * notice, this list of conditions and the following disclaimer in the 13124060Swpaul * documentation and/or other materials provided with the distribution. 14124060Swpaul * 3. All advertising materials mentioning features or use of this software 15124060Swpaul * must display the following acknowledgement: 16124060Swpaul * This product includes software developed by Bill Paul. 17124060Swpaul * 4. Neither the name of the author nor the names of any co-contributors 18124060Swpaul * may be used to endorse or promote products derived from this software 19124060Swpaul * without specific prior written permission. 20124060Swpaul * 21124060Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 22124060Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23124060Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24124060Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25124060Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26124060Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27124060Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28124060Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29124060Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30124060Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31124060Swpaul * THE POSSIBILITY OF SUCH DAMAGE. 32123475Swpaul */ 33123475Swpaul 34123475Swpaul#include <sys/cdefs.h> 35123475Swpaul__FBSDID("$FreeBSD$"); 36123475Swpaul 37123475Swpaul#include <regex.h> 38123475Swpaul#include <ctype.h> 39123475Swpaul#include <err.h> 40123475Swpaul#include <stdio.h> 41123475Swpaul#include <stdlib.h> 42123475Swpaul#include <string.h> 43123475Swpaul#include "y.tab.h" 44123475Swpaul 45123475Swpaulint lineno = 1; 46123475Swpaul 47123475Swpaulint yylex(void); 48123475Swpaulvoid yyerror(const char *); 49123475Swpaul 50123475Swpaulstatic void 51123475Swpaulupdate_lineno(const char *cp) 52123475Swpaul{ 53123475Swpaul while (*cp) 54123475Swpaul if (*cp++ == '\n') 55123475Swpaul lineno++; 56123475Swpaul} 57123475Swpaul 58123475Swpaul%} 59123475Swpaul 60250227Sjkim%option nounput 61250227Sjkim%option noinput 62250227Sjkim 63123475Swpaul%% 64123475Swpaul 65123475Swpaul[ \t]+ ; 66123475Swpaul\n { lineno++; return EOL; } 67123475Swpaul\r ; 68123475Swpaul;.*$ ; 69124401Smdodd\/\/.*$ ; 70123475Swpaul= { return EQUALS; } 71123475Swpaul, { return COMMA; } 72124401Smdodd\"(\\\"|[^"]|\"\")*\" { 73123475Swpaul int len = strlen(yytext) - 2; 74123475Swpaul int blen = len + 1; 75123475Swpaul char *walker; 76123475Swpaul int i; 77123475Swpaul update_lineno(yytext); 78123475Swpaul yylval.str = (char *)malloc(blen); 79123475Swpaul if (yylval.str == NULL) 80123475Swpaul goto out; 81123475Swpaul walker = yylval.str; 82123475Swpaul for (i = 1; i <= len; i++) { 83124401Smdodd if (yytext[i] == '\"') { 84124401Smdodd switch (yytext[i + 1]) { 85124401Smdodd case '\"': 86124401Smdodd i++; 87124401Smdodd break; 88124401Smdodd default: 89124401Smdodd break; 90124401Smdodd } 91124401Smdodd } 92123475Swpaul if (yytext[i] == '\\') { 93123475Swpaul switch (yytext[i + 1]) { 94123475Swpaul case '\n': 95123475Swpaul i += 2; 96123475Swpaul while(isspace(yytext[i])) 97123475Swpaul i++; 98123475Swpaul break; 99123475Swpaul case '\"': 100123475Swpaul i++; 101123475Swpaul break; 102123475Swpaul case '(': 103123475Swpaul i++; 104123475Swpaul break; 105123475Swpaul default: 106123475Swpaul break; 107123475Swpaul } 108123475Swpaul } 109123475Swpaul *walker++ = yytext[i]; 110123475Swpaul } 111123475Swpaul *walker++ = '\0'; 112123475Swpaul out:; 113123475Swpaul return STRING; 114123475Swpaul } 115123475Swpaul\[[a-zA-Z0-9%&\{\}\-\.\/_\\\*\ ]+\] { 116123475Swpaul int len = strlen(yytext); 117123475Swpaul yytext[len-1] = '\0'; 118123475Swpaul yylval.str = strdup(yytext+1); 119123475Swpaul return SECTION; 120123475Swpaul } 121123475Swpaul[a-zA-Z0-9%&\{\}\-\.\/_\\\*]+ { 122123475Swpaul yylval.str = strdup(yytext); 123123475Swpaul return WORD; 124123475Swpaul } 125123475Swpaul%% 126123475Swpaul 127123475Swpaulvoid 128123475Swpaulyyerror(const char *s) 129123475Swpaul{ 130123475Swpaul errx(1, "line %d: %s%s %s.", lineno, yytext, yytext?":":"", s); 131123475Swpaul} 132