1226031Sstas%{ 2226031Sstas/* 3226031Sstas * Copyright (c) 2004, 2008 Kungliga Tekniska H��gskolan 4226031Sstas * (Royal Institute of Technology, Stockholm, Sweden). 5226031Sstas * All rights reserved. 6226031Sstas * 7226031Sstas * Redistribution and use in source and binary forms, with or without 8226031Sstas * modification, are permitted provided that the following conditions 9226031Sstas * are met: 10226031Sstas * 11226031Sstas * 1. Redistributions of source code must retain the above copyright 12226031Sstas * notice, this list of conditions and the following disclaimer. 13226031Sstas * 14226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 15226031Sstas * notice, this list of conditions and the following disclaimer in the 16226031Sstas * documentation and/or other materials provided with the distribution. 17226031Sstas * 18226031Sstas * 3. Neither the name of the Institute nor the names of its contributors 19226031Sstas * may be used to endorse or promote products derived from this software 20226031Sstas * without specific prior written permission. 21226031Sstas * 22226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32226031Sstas * SUCH DAMAGE. 33226031Sstas */ 34226031Sstas 35226031Sstas/* $Id$ */ 36226031Sstas 37226031Sstas#ifdef HAVE_CONFIG_H 38226031Sstas#include <config.h> 39226031Sstas#endif 40226031Sstas 41226031Sstas#undef ECHO 42226031Sstas 43226031Sstas#include <stdio.h> 44226031Sstas#include <string.h> 45226031Sstas#include <stdarg.h> 46226031Sstas#include <stdlib.h> 47226031Sstas#include "sel.h" 48226031Sstas#include "sel-gram.h" 49226031Sstasunsigned lineno = 1; 50226031Sstas 51226031Sstasstatic char * handle_string(void); 52226031Sstasstatic int lex_input(char *, int); 53234027Sstasstatic int lex_classic_input(void); 54226031Sstas 55226031Sstasstruct hx_expr_input _hx509_expr_input; 56226031Sstas 57226031Sstas#ifndef YY_NULL 58226031Sstas#define YY_NULL 0 59226031Sstas#endif 60226031Sstas 61226031Sstas#define YY_NO_UNPUT 1 62226031Sstas 63226031Sstas#undef YY_INPUT 64226031Sstas#define YY_INPUT(buf,res,maxsize) (res = lex_input(buf, maxsize)) 65226031Sstas 66226031Sstas#undef ECHO 67226031Sstas 68226031Sstas%} 69226031Sstas%% 70226031Sstas 71226031SstasTRUE { return kw_TRUE; } 72226031SstasFALSE { return kw_FALSE; } 73226031SstasAND { return kw_AND; } 74226031SstasOR { return kw_OR; } 75226031SstasIN { return kw_IN; } 76226031SstasTAILMATCH { return kw_TAILMATCH; } 77226031Sstas 78226031Sstas[A-Za-z][-A-Za-z0-9_]* { 79226031Sstas yylval.string = strdup ((const char *)yytext); 80226031Sstas return IDENTIFIER; 81226031Sstas } 82226031Sstas"\"" { yylval.string = handle_string(); return STRING; } 83226031Sstas\n { ++lineno; } 84226031Sstas[,.!={}()%] { return *yytext; } 85226031Sstas[ \t] ; 86226031Sstas%% 87226031Sstas 88226031Sstasstatic char * 89226031Sstashandle_string(void) 90226031Sstas{ 91226031Sstas char x[1024]; 92226031Sstas int i = 0; 93226031Sstas int c; 94226031Sstas int quote = 0; 95226031Sstas while((c = input()) != EOF){ 96226031Sstas if(quote) { 97226031Sstas x[i++] = '\\'; 98226031Sstas x[i++] = c; 99226031Sstas quote = 0; 100226031Sstas continue; 101226031Sstas } 102226031Sstas if(c == '\n'){ 103226031Sstas _hx509_sel_yyerror("unterminated string"); 104226031Sstas lineno++; 105226031Sstas break; 106226031Sstas } 107226031Sstas if(c == '\\'){ 108226031Sstas quote++; 109226031Sstas continue; 110226031Sstas } 111226031Sstas if(c == '\"') 112226031Sstas break; 113226031Sstas x[i++] = c; 114226031Sstas } 115226031Sstas x[i] = '\0'; 116226031Sstas return strdup(x); 117226031Sstas} 118226031Sstas 119226031Sstasint 120226031Sstasyywrap () 121226031Sstas{ 122226031Sstas return 1; 123226031Sstas} 124226031Sstas 125226031Sstasstatic int 126226031Sstaslex_input(char *buf, int max_size) 127226031Sstas{ 128226031Sstas int n; 129226031Sstas 130226031Sstas n = _hx509_expr_input.length - _hx509_expr_input.offset; 131226031Sstas if (max_size < n) 132226031Sstas n = max_size; 133226031Sstas if (n <= 0) 134226031Sstas return YY_NULL; 135226031Sstas 136226031Sstas memcpy(buf, _hx509_expr_input.buf + _hx509_expr_input.offset, n); 137226031Sstas _hx509_expr_input.offset += n; 138226031Sstas 139226031Sstas return n; 140226031Sstas} 141