155682Smarkm%{ 255682Smarkm/* 390926Snectar * Copyright (c) 1998 - 2001 Kungliga Tekniska H�gskolan 455682Smarkm * (Royal Institute of Technology, Stockholm, Sweden). 555682Smarkm * All rights reserved. 655682Smarkm * 755682Smarkm * Redistribution and use in source and binary forms, with or without 855682Smarkm * modification, are permitted provided that the following conditions 955682Smarkm * are met: 1055682Smarkm * 1155682Smarkm * 1. Redistributions of source code must retain the above copyright 1255682Smarkm * notice, this list of conditions and the following disclaimer. 1355682Smarkm * 1455682Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1555682Smarkm * notice, this list of conditions and the following disclaimer in the 1655682Smarkm * documentation and/or other materials provided with the distribution. 1755682Smarkm * 1855682Smarkm * 3. Neither the name of the Institute nor the names of its contributors 1955682Smarkm * may be used to endorse or promote products derived from this software 2055682Smarkm * without specific prior written permission. 2155682Smarkm * 2255682Smarkm * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2355682Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2455682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2555682Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2655682Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2755682Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2855682Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2955682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3055682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3155682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3255682Smarkm * SUCH DAMAGE. 3355682Smarkm */ 3455682Smarkm 3572445Sassar#undef ECHO 3672445Sassar 3755682Smarkm#include "make_cmds.h" 3855682Smarkm#include "parse.h" 3955682Smarkm 40178825SdfrRCSID("$Id: lex.l 10703 2001-09-16 23:10:10Z assar $"); 4155682Smarkm 4255682Smarkmstatic unsigned lineno = 1; 4372445Sassarstatic int getstring(void); 4455682Smarkm 4572445Sassar#define YY_NO_UNPUT 4672445Sassar 4790926Snectar#undef ECHO 4890926Snectar 4955682Smarkm%} 5055682Smarkm 5155682Smarkm 5255682Smarkm%% 5355682Smarkmcommand_table { return TABLE; } 5455682Smarkmrequest { return REQUEST; } 5555682Smarkmunknown { return UNKNOWN; } 5655682Smarkmunimplemented { return UNIMPLEMENTED; } 5755682Smarkmend { return END; } 5855682Smarkm#[^\n]* ; 5955682Smarkm[ \t] ; 6055682Smarkm\n { lineno++; } 6155682Smarkm\" { return getstring(); } 6255682Smarkm[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 6355682Smarkm. { return *yytext; } 6455682Smarkm%% 6555682Smarkm 6655682Smarkm#ifndef yywrap /* XXX */ 6755682Smarkmint 6855682Smarkmyywrap () 6955682Smarkm{ 7055682Smarkm return 1; 7155682Smarkm} 7255682Smarkm#endif 7355682Smarkm 7472445Sassarstatic int 7555682Smarkmgetstring(void) 7655682Smarkm{ 7755682Smarkm char x[128]; 7855682Smarkm int i = 0; 7955682Smarkm int c; 8055682Smarkm int backslash = 0; 8155682Smarkm while((c = input()) != EOF){ 8255682Smarkm if(backslash) { 8355682Smarkm if(c == 'n') 8455682Smarkm c = '\n'; 8555682Smarkm else if(c == 't') 8655682Smarkm c = '\t'; 8755682Smarkm x[i++] = c; 8855682Smarkm backslash = 0; 8955682Smarkm continue; 9055682Smarkm } 9155682Smarkm if(c == '\n'){ 9255682Smarkm error_message("unterminated string"); 9355682Smarkm lineno++; 9455682Smarkm break; 9555682Smarkm } 9655682Smarkm if(c == '\\'){ 9755682Smarkm backslash++; 9855682Smarkm continue; 9955682Smarkm } 10055682Smarkm if(c == '\"') 10155682Smarkm break; 10255682Smarkm x[i++] = c; 10355682Smarkm } 10455682Smarkm x[i] = '\0'; 10555682Smarkm yylval.string = strdup(x); 10655682Smarkm return STRING; 10755682Smarkm} 10855682Smarkm 10955682Smarkmvoid 11072445Sassarerror_message (const char *format, ...) 11155682Smarkm{ 11255682Smarkm va_list args; 11355682Smarkm 11455682Smarkm va_start (args, format); 11555682Smarkm fprintf (stderr, "%s:%d: ", filename, lineno); 11655682Smarkm vfprintf (stderr, format, args); 11755682Smarkm va_end (args); 11855682Smarkm numerror++; 11955682Smarkm} 120