| 1 |
%{ |
| 2 |
/* |
| 3 |
* Copyright (c) 2004 - 2017 Kungliga Tekniska Högskolan |
| 4 |
* (Royal Institute of Technology, Stockholm, Sweden). |
| 5 |
* All rights reserved. |
| 6 |
* |
| 7 |
* Redistribution and use in source and binary forms, with or without |
| 8 |
* modification, are permitted provided that the following conditions |
| 9 |
* are met: |
| 10 |
* |
| 11 |
* 1. Redistributions of source code must retain the above copyright |
| 12 |
* notice, this list of conditions and the following disclaimer. |
| 13 |
* |
| 14 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 15 |
* notice, this list of conditions and the following disclaimer in the |
| 16 |
* documentation and/or other materials provided with the distribution. |
| 17 |
* |
| 18 |
* 3. Neither the name of the Institute nor the names of its contributors |
| 19 |
* may be used to endorse or promote products derived from this software |
| 20 |
* without specific prior written permission. |
| 21 |
* |
| 22 |
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 23 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 28 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 29 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 31 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 |
* SUCH DAMAGE. |
| 33 |
*/ |
| 34 |
|
| 35 |
/* $Id$ */ |
| 36 |
|
| 37 |
#ifdef __GNUC__ |
| 38 |
#pragma GCC diagnostic ignored "-Wunused-function" |
| 39 |
#endif |
| 40 |
|
| 41 |
|
| 42 |
#ifdef HAVE_CONFIG_H |
| 43 |
#include <config.h> |
| 44 |
#endif |
| 45 |
|
| 46 |
#undef ECHO |
| 47 |
|
| 48 |
#include <stdio.h> |
| 49 |
#include <string.h> |
| 50 |
#include <stdarg.h> |
| 51 |
#include <stdlib.h> |
| 52 |
#include "sel.h" |
| 53 |
#include "sel-gram.h" |
| 54 |
unsigned lineno = 1; |
| 55 |
|
| 56 |
static char * handle_string(void); |
| 57 |
static int lex_input(char *, int); |
| 58 |
|
| 59 |
struct hx_expr_input _hx509_expr_input; |
| 60 |
|
| 61 |
#ifndef YY_NULL |
| 62 |
#define YY_NULL 0 |
| 63 |
#endif |
| 64 |
|
| 65 |
#define YY_NO_UNPUT 1 |
| 66 |
|
| 67 |
#undef YY_INPUT |
| 68 |
#define YY_INPUT(buf,res,maxsize) (res = lex_input(buf, maxsize)) |
| 69 |
|
| 70 |
#undef ECHO |
| 71 |
|
| 72 |
%} |
| 73 |
%% |
| 74 |
|
| 75 |
TRUE { return kw_TRUE; } |
| 76 |
FALSE { return kw_FALSE; } |
| 77 |
AND { return kw_AND; } |
| 78 |
OR { return kw_OR; } |
| 79 |
IN { return kw_IN; } |
| 80 |
TAILMATCH { return kw_TAILMATCH; } |
| 81 |
|
| 82 |
[A-Za-z][-A-Za-z0-9_]* { |
| 83 |
yylval.string = strdup ((const char *)yytext); |
| 84 |
return IDENTIFIER; |
| 85 |
} |
| 86 |
"\"" { yylval.string = handle_string(); return STRING; } |
| 87 |
\n { ++lineno; } |
| 88 |
[,.!={}()%] { return *yytext; } |
| 89 |
[ \t] ; |
| 90 |
%% |
| 91 |
|
| 92 |
static char * |
| 93 |
handle_string(void) |
| 94 |
{ |
| 95 |
char x[1024]; |
| 96 |
int i = 0; |
| 97 |
int c; |
| 98 |
int quote = 0; |
| 99 |
while((c = input()) != EOF){ |
| 100 |
if(quote) { |
| 101 |
x[i++] = '\\'; |
| 102 |
x[i++] = c; |
| 103 |
quote = 0; |
| 104 |
continue; |
| 105 |
} |
| 106 |
if(c == '\n'){ |
| 107 |
_hx509_sel_yyerror("unterminated string"); |
| 108 |
lineno++; |
| 109 |
break; |
| 110 |
} |
| 111 |
if(c == '\\'){ |
| 112 |
quote++; |
| 113 |
continue; |
| 114 |
} |
| 115 |
if(c == '\"') |
| 116 |
break; |
| 117 |
x[i++] = c; |
| 118 |
} |
| 119 |
x[i] = '\0'; |
| 120 |
return strdup(x); |
| 121 |
} |
| 122 |
|
| 123 |
#if !defined(yywrap) |
| 124 |
#define yywrap _hx509_sel_yywrap |
| 125 |
#endif |
| 126 |
|
| 127 |
int |
| 128 |
yywrap () |
| 129 |
{ |
| 130 |
return 1; |
| 131 |
} |
| 132 |
|
| 133 |
static int |
| 134 |
lex_input(char *buf, int max_size) |
| 135 |
{ |
| 136 |
int n; |
| 137 |
|
| 138 |
n = _hx509_expr_input.length - _hx509_expr_input.offset; |
| 139 |
if (max_size < n) |
| 140 |
n = max_size; |
| 141 |
if (n <= 0) |
| 142 |
return YY_NULL; |
| 143 |
|
| 144 |
memcpy(buf, _hx509_expr_input.buf + _hx509_expr_input.offset, n); |
| 145 |
_hx509_expr_input.offset += n; |
| 146 |
|
| 147 |
return n; |
| 148 |
} |