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