Home | History | Annotate | Line # | Download | only in cgdconfig
cgdlex.l revision 1.4
      1 %{
      2 /* $NetBSD: cgdlex.l,v 1.4 2009/10/28 20:59:46 christos Exp $ */
      3 
      4 /*-
      5  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to The NetBSD Foundation
      9  * by Roland C. Dowdeswell.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 #ifndef lint
     35 __RCSID("$NetBSD: cgdlex.l,v 1.4 2009/10/28 20:59:46 christos Exp $");
     36 #endif
     37 
     38 #include <err.h>
     39 #include <stdio.h>
     40 
     41 #include "utils.h"
     42 #include "cgdparse.h"
     43 
     44 #define YY_NO_UNPUT
     45 /*
     46  * We use macros here to separate the C from the tokeniser, to
     47  * ease reading each.
     48  */
     49 
     50 #define	RETSTRING(x)	do {					\
     51 		yylval.string = string_new(yytext, yyleng);	\
     52 		return (x);					\
     53 	} while (0)
     54 #define RETTOKEN(x)	do {					\
     55 		yylval.token.text = yytext;			\
     56 		yylval.token.length = yyleng;			\
     57 		return (x);					\
     58 	} while (0)
     59 #define RETINTEGER(x)	do {					\
     60 		yylval.integer = atoi(yytext);			\
     61 		return (x);					\
     62 	} while (0)
     63 
     64 #define QUOTEDBEGIN() do {						\
     65 		BEGIN(quoted);						\
     66 		quoted_string = string_zero();				\
     67 	} while (0)
     68 #define QUOTEDADD() do {						\
     69 		string_t	*tmp;					\
     70 									\
     71 		tmp = string_new(yytext, yyleng);			\
     72 		quoted_string = string_add_d(quoted_string, tmp);	\
     73 	} while (0)
     74 #define RETQUOTED(x) do {						\
     75 		yylval.string = quoted_string;				\
     76 		quoted_string = NULL;					\
     77 		BEGIN(INITIAL);						\
     78 		return(x);						\
     79 	} while (0)
     80 
     81 int yylineno;
     82 
     83 string_t	*quoted_string;
     84 
     85 void	yyerror(const char *);
     86 int	yylex(void);
     87 %}
     88 
     89 %x quoted
     90 
     91 %%
     92 
     93 [0-9]+					{ RETINTEGER(INTEGER); }
     94 algorithm				{ RETTOKEN(ALGORITHM); }
     95 keylength				{ RETTOKEN(KEYLENGTH); }
     96 iv-method				{ RETTOKEN(IVMETHOD); }
     97 verify_method				{ RETTOKEN(VERIFY_METHOD); }
     98 keygen					{ RETTOKEN(KEYGEN); }
     99 salt					{ RETTOKEN(SALT); }
    100 iterations				{ RETTOKEN(ITERATIONS); }
    101 key					{ RETTOKEN(KEY); }
    102 cmd					{ RETTOKEN(CMD); }
    103 keygen_method				{ RETTOKEN(KEYGEN_METHOD); }
    104 keygen_salt				{ RETTOKEN(KEYGEN_SALT); }
    105 keygen_iterations			{ RETTOKEN(KEYGEN_ITERATIONS); }
    106 xor_key					{ RETTOKEN(XOR_KEY); }
    107 [;\n]					{ return EOL; }
    108 \\\n					/* ignore a quoted nl */
    109 [ \t]					/* ignore spaces and tabs */
    110 #[^;\n]*				/* ignore comments */
    111 [^ }{\t\n;"]+				{ RETSTRING(STRINGLIT); }
    112 
    113 \"					{ QUOTEDBEGIN(); }
    114 <quoted>[^\"]+				{ QUOTEDADD(); }
    115 <quoted>\"				{ RETQUOTED(STRINGLIT); }
    116 
    117 .					{ return yytext[0]; }
    118 
    119 %%
    120 
    121 void
    122 yyerror(const char *msg)
    123 {
    124 
    125          warnx("%s line %d: %s at '%s'", "foo", yylineno, msg, yytext);
    126 }
    127