1%{ 2/*- 3 * SPDX-License-Identifier: BSD-4-Clause 4 * 5 * Copyright (c) 2003 6 * Bill Paul <wpaul@windriver.com>. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Bill Paul. 19 * 4. Neither the name of the author nor the names of any co-contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> 37__FBSDID("$FreeBSD$"); 38 39#include <regex.h> 40#include <ctype.h> 41#include <err.h> 42#include <stdio.h> 43#include <stdlib.h> 44#include <string.h> 45#include "y.tab.h" 46 47int lineno = 1; 48 49int yylex(void); 50void yyerror(const char *); 51 52static void 53update_lineno(const char *cp) 54{ 55 while (*cp) 56 if (*cp++ == '\n') 57 lineno++; 58} 59 60%} 61 62%option noyywrap 63%option nounput 64%option noinput 65 66%% 67 68[ \t]+ ; 69\n { lineno++; return EOL; } 70\r ; 71;.*$ ; 72\/\/.*$ ; 73= { return EQUALS; } 74, { return COMMA; } 75\"(\\\"|[^"]|\"\")*\" { 76 int len = strlen(yytext) - 2; 77 int blen = len + 1; 78 char *walker; 79 int i; 80 update_lineno(yytext); 81 yylval.str = (char *)malloc(blen); 82 if (yylval.str == NULL) 83 goto out; 84 walker = yylval.str; 85 for (i = 1; i <= len; i++) { 86 if (yytext[i] == '\"') { 87 switch (yytext[i + 1]) { 88 case '\"': 89 i++; 90 break; 91 default: 92 break; 93 } 94 } 95 if (yytext[i] == '\\') { 96 switch (yytext[i + 1]) { 97 case '\n': 98 i += 2; 99 while(isspace(yytext[i])) 100 i++; 101 break; 102 case '\"': 103 i++; 104 break; 105 case '(': 106 i++; 107 break; 108 default: 109 break; 110 } 111 } 112 *walker++ = yytext[i]; 113 } 114 *walker++ = '\0'; 115 out:; 116 return STRING; 117 } 118\[[a-zA-Z0-9%&\{\}\-\.\/_\\\*\ ]+\] { 119 int len = strlen(yytext); 120 yytext[len-1] = '\0'; 121 yylval.str = strdup(yytext+1); 122 return SECTION; 123 } 124[a-zA-Z0-9%&\{\}\-\.\/_\\\*]+ { 125 yylval.str = strdup(yytext); 126 return WORD; 127 } 128%% 129 130void 131yyerror(const char *s) 132{ 133 errx(1, "line %d: %s%s %s.", lineno, yytext, yytext?":":"", s); 134} 135