veriexecctl_conf.l revision 1.12 1 %{
2 /* $NetBSD: veriexecctl_conf.l,v 1.12 2008/08/31 23:37:45 dholland 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 %%
85
86 /* path */
87 \/{PCHAR}+ {
88 if ((yylval.string = dequote(yytext)) == NULL)
89 err(1, "Cannot allocate string");
90 return PATH;
91 }
92
93 /* string (fingerprint, type, options) */
94 {STRING} {
95 if ((yylval.string = strdup(yytext)) == NULL)
96 err(1, "Cannot allocate string");
97 return STRING;
98 }
99
100 /* comments, white-outs */
101 [ \t\r] |
102 #.* ;
103 ^#.*\n |
104 #.*\n |
105 \\\n |
106 ^\n { line++; }
107
108 /* eol on a line with data. need a call to ioctl, return eol */
109 \n {
110 line++;
111 return EOL;
112 }
113
114 "," {
115 return TOKEN_COMMA;
116 }
117
118 . {
119 if (verbose)
120 warnx("Invalid character '%c' in line %zu",
121 *yytext, line);
122 }
123
124 %%
125
126 int
127 yywrap(void)
128 {
129 return 1;
130 }
131