veriexecctl_conf.l revision 1.13 1 %{
2 /* $NetBSD: veriexecctl_conf.l,v 1.13 2009/10/28 17:25:44 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 #define YY_NO_UNPUT
44 int yylex(void);
45
46 extern size_t line;
47 extern int verbose;
48
49 static char *
50 dequote(const char *s)
51 {
52 size_t len;
53 const char *p;
54 char *buf, *q;
55
56 len = 0;
57 p = s;
58 while (*p) {
59 if (*p == '\\' && *(p+1))
60 ++p;
61 ++len;
62 ++p;
63 }
64
65 buf = malloc(len + 1);
66 if (buf == NULL)
67 return NULL;
68
69 p = s;
70 q = buf;
71 while (*p) {
72 if (*p == '\\' && *(p+1))
73 ++p;
74 *q++ = *p++;
75 }
76 *q++ = '\0';
77
78 return buf;
79 }
80 %}
81
82 STRING [0-9a-zA-Z]+
83 PCHAR (\\.|[^ \t])
84
85 %%
86
87 /* path */
88 \/{PCHAR}+ {
89 if ((yylval.string = dequote(yytext)) == NULL)
90 err(1, "Cannot allocate string");
91 return PATH;
92 }
93
94 /* string (fingerprint, type, options) */
95 {STRING} {
96 if ((yylval.string = strdup(yytext)) == NULL)
97 err(1, "Cannot allocate string");
98 return STRING;
99 }
100
101 /* comments, white-outs */
102 [ \t\r] |
103 #.* ;
104 ^#.*\n |
105 #.*\n |
106 \\\n |
107 ^\n { line++; }
108
109 /* eol on a line with data. need a call to ioctl, return eol */
110 \n {
111 line++;
112 return EOL;
113 }
114
115 "," {
116 return TOKEN_COMMA;
117 }
118
119 . {
120 if (verbose)
121 warnx("Invalid character '%c' in line %zu",
122 *yytext, line);
123 }
124
125 %%
126
127 int
128 yywrap(void)
129 {
130 return 1;
131 }
132