veriexecctl_conf.l revision 1.14 1 %{
2 /* $NetBSD: veriexecctl_conf.l,v 1.14 2009/10/29 14:49:03 christos Exp $ */
3
4 /*-
5 * Copyright 2005 Elad Efrat <elad (at) NetBSD.org>
6 * Copyright 2005 Brett Lymn <blymn (at) netbsd.org>
7 *
8 * All rights reserved.
9 *
10 * This code has been donated to The NetBSD Foundation by the Author.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. The name of the author may not be used to endorse or promote products
18 * derived from this software withough specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 *
32 */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <err.h>
38
39 #include <prop/proplib.h>
40
41 #include "veriexecctl_parse.h"
42
43 int yylex(void);
44
45 extern size_t line;
46 extern int verbose;
47
48 static char *
49 dequote(const char *s)
50 {
51 size_t len;
52 const char *p;
53 char *buf, *q;
54
55 len = 0;
56 p = s;
57 while (*p) {
58 if (*p == '\\' && *(p+1))
59 ++p;
60 ++len;
61 ++p;
62 }
63
64 buf = malloc(len + 1);
65 if (buf == NULL)
66 return NULL;
67
68 p = s;
69 q = buf;
70 while (*p) {
71 if (*p == '\\' && *(p+1))
72 ++p;
73 *q++ = *p++;
74 }
75 *q++ = '\0';
76
77 return buf;
78 }
79 %}
80
81 STRING [0-9a-zA-Z]+
82 PCHAR (\\.|[^ \t])
83
84 %option nounput
85
86 %%
87
88 /* path */
89 \/{PCHAR}+ {
90 if ((yylval.string = dequote(yytext)) == NULL)
91 err(1, "Cannot allocate string");
92 return PATH;
93 }
94
95 /* string (fingerprint, type, options) */
96 {STRING} {
97 if ((yylval.string = strdup(yytext)) == NULL)
98 err(1, "Cannot allocate string");
99 return STRING;
100 }
101
102 /* comments, white-outs */
103 [ \t\r] |
104 #.* ;
105 ^#.*\n |
106 #.*\n |
107 \\\n |
108 ^\n { line++; }
109
110 /* eol on a line with data. need a call to ioctl, return eol */
111 \n {
112 line++;
113 return EOL;
114 }
115
116 "," {
117 return TOKEN_COMMA;
118 }
119
120 . {
121 if (verbose)
122 warnx("Invalid character '%c' in line %zu",
123 *yytext, line);
124 }
125
126 %%
127
128 int
129 yywrap(void)
130 {
131 return 1;
132 }
133