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