lex.l revision 127807
150764Smarkm%{ 250764Smarkm/* 3127807Snectar * Copyright (c) 1998 - 2000 Kungliga Tekniska H�gskolan 450764Smarkm * (Royal Institute of Technology, Stockholm, Sweden). 550764Smarkm * All rights reserved. 650764Smarkm * 750764Smarkm * Redistribution and use in source and binary forms, with or without 850764Smarkm * modification, are permitted provided that the following conditions 950764Smarkm * are met: 1050764Smarkm * 1150764Smarkm * 1. Redistributions of source code must retain the above copyright 1250764Smarkm * notice, this list of conditions and the following disclaimer. 1350764Smarkm * 1450764Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1550764Smarkm * notice, this list of conditions and the following disclaimer in the 1650764Smarkm * documentation and/or other materials provided with the distribution. 1750764Smarkm * 18127807Snectar * 3. Neither the name of the Institute nor the names of its contributors 1950764Smarkm * may be used to endorse or promote products derived from this software 2050764Smarkm * without specific prior written permission. 2150764Smarkm * 2250764Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2350764Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2450764Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2550764Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2650764Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2750764Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2850764Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2950764Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3050764Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3150764Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3250764Smarkm * SUCH DAMAGE. 3350764Smarkm */ 34127807Snectar/* $FreeBSD: head/contrib/com_err/lex.l 127807 2004-04-03 21:17:01Z nectar $ */ 3550764Smarkm 3650764Smarkm/* 3750764Smarkm * This is to handle the definition of this symbol in some AIX 3850764Smarkm * headers, which will conflict with the definition that lex will 3950764Smarkm * generate for it. It's only a problem for AIX lex. 4050764Smarkm */ 4150764Smarkm 4250764Smarkm#undef ECHO 4350764Smarkm 4450764Smarkm#include "compile_et.h" 4550764Smarkm#include "parse.h" 46127807Snectar#include "lex.h" 4750764Smarkm 4850880Smarkm#if 0 49127807SnectarRCSID("$Id: lex.l,v 1.6 2000/06/22 00:42:52 assar Exp $"); 5050880Smarkm#endif 5150764Smarkm 5250764Smarkmstatic unsigned lineno = 1; 53127807Snectarstatic int getstring(void); 5450764Smarkm 55127807Snectar#define YY_NO_UNPUT 56127807Snectar 57127807Snectar#undef ECHO 58127807Snectar 5950764Smarkm%} 6050764Smarkm 6150764Smarkm 6250764Smarkm%% 6350764Smarkmet { return ET; } 6450764Smarkmerror_table { return ET; } 6550764Smarkmec { return EC; } 6650764Smarkmerror_code { return EC; } 6750764Smarkmprefix { return PREFIX; } 6850764Smarkmindex { return INDEX; } 6950764Smarkmid { return ID; } 7050764Smarkmend { return END; } 7150764Smarkm[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 7250764Smarkm#[^\n]* ; 7350764Smarkm[ \t] ; 7450764Smarkm\n { lineno++; } 7550764Smarkm\" { return getstring(); } 7650764Smarkm[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 7750764Smarkm. { return *yytext; } 7850764Smarkm%% 7950764Smarkm 8050764Smarkm#ifndef yywrap /* XXX */ 8150764Smarkmint 8250764Smarkmyywrap () 8350764Smarkm{ 8450764Smarkm return 1; 8550764Smarkm} 8650764Smarkm#endif 8750764Smarkm 88127807Snectarstatic int 8950764Smarkmgetstring(void) 9050764Smarkm{ 9150764Smarkm char x[128]; 9250764Smarkm int i = 0; 9350764Smarkm int c; 9450764Smarkm int quote = 0; 9550764Smarkm while((c = input()) != EOF){ 9650764Smarkm if(quote) { 9750764Smarkm x[i++] = c; 9850764Smarkm quote = 0; 9950764Smarkm continue; 10050764Smarkm } 10150764Smarkm if(c == '\n'){ 10250764Smarkm error_message("unterminated string"); 10350764Smarkm lineno++; 10450764Smarkm break; 10550764Smarkm } 10650764Smarkm if(c == '\\'){ 10750764Smarkm quote++; 10850764Smarkm continue; 10950764Smarkm } 11050764Smarkm if(c == '\"') 11150764Smarkm break; 11250764Smarkm x[i++] = c; 11350764Smarkm } 11450764Smarkm x[i] = '\0'; 11550764Smarkm yylval.string = strdup(x); 11650764Smarkm return STRING; 11750764Smarkm} 11850764Smarkm 11950764Smarkmvoid 120127807Snectarerror_message (const char *format, ...) 12150764Smarkm{ 12250764Smarkm va_list args; 12350764Smarkm 12450764Smarkm va_start (args, format); 12550764Smarkm fprintf (stderr, "%s:%d:", filename, lineno); 12650764Smarkm vfprintf (stderr, format, args); 12750764Smarkm va_end (args); 12850764Smarkm numerror++; 12950764Smarkm} 130