138494Sobrien/*
2174294Sobrien * Copyright (c) 1997-2006 Erez Zadok
338494Sobrien * Copyright (c) 1989 Jan-Simon Pendry
438494Sobrien * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
538494Sobrien * Copyright (c) 1989 The Regents of the University of California.
638494Sobrien * All rights reserved.
738494Sobrien *
838494Sobrien * This code is derived from software contributed to Berkeley by
938494Sobrien * Jan-Simon Pendry at Imperial College, London.
1038494Sobrien *
1138494Sobrien * Redistribution and use in source and binary forms, with or without
1238494Sobrien * modification, are permitted provided that the following conditions
1338494Sobrien * are met:
1438494Sobrien * 1. Redistributions of source code must retain the above copyright
1538494Sobrien *    notice, this list of conditions and the following disclaimer.
1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1738494Sobrien *    notice, this list of conditions and the following disclaimer in the
1838494Sobrien *    documentation and/or other materials provided with the distribution.
1938494Sobrien * 3. All advertising materials mentioning features or use of this software
2042629Sobrien *    must display the following acknowledgment:
2138494Sobrien *      This product includes software developed by the University of
2238494Sobrien *      California, Berkeley and its contributors.
2338494Sobrien * 4. Neither the name of the University nor the names of its contributors
2438494Sobrien *    may be used to endorse or promote products derived from this software
2538494Sobrien *    without specific prior written permission.
2638494Sobrien *
2738494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2838494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2938494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3038494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3138494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3238494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3338494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3438494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3538494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3638494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3738494Sobrien * SUCH DAMAGE.
3838494Sobrien *
3938494Sobrien *
40174294Sobrien * File: am-utils/amd/conf_parse.y
4138494Sobrien *
4238494Sobrien */
4338494Sobrien
4438494Sobrien%{
4538494Sobrien#ifdef HAVE_CONFIG_H
4638494Sobrien# include <config.h>
4738494Sobrien#endif /* HAVE_CONFIG_H */
4838494Sobrien#include <am_defs.h>
4938494Sobrien#include <amd.h>
5038494Sobrien
5138494Sobrienextern char *yytext;
52131702Smbrextern int ayylineno;
5338494Sobrienextern int yylex(void);
5438494Sobrien
5538494Sobrienstatic int yyerror(const char *s);
5638494Sobrienstatic int retval;
5738494Sobrienstatic char *header_section = NULL; /* start with no header section */
5838494Sobrien
5938494Sobrien#define YYDEBUG 1
6038494Sobrien
6138494Sobrien#define PARSE_DEBUG 0
6238494Sobrien
6338494Sobrien#if PARSE_DEBUG
64131702Smbr# define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s))
6538494Sobrien# define amu_return(v)
66131702Smbr#else /* not PARSE_DEBUG */
6738494Sobrien# define dprintf(f,s)
6838494Sobrien# define amu_return(v) return((v))
69131702Smbr#endif /* not PARSE_DEBUG */
7038494Sobrien
7138494Sobrien%}
7238494Sobrien
7338494Sobrien%union {
7438494Sobrienchar *strtype;
7538494Sobrien}
7638494Sobrien
7738494Sobrien%token LEFT_BRACKET RIGHT_BRACKET EQUAL
7838494Sobrien%token NEWLINE
7938494Sobrien%token <strtype> NONWS_STRING
8038494Sobrien%token <strtype> NONWSEQ_STRING
8138494Sobrien%token <strtype> QUOTED_NONWSEQ_STRING
8238494Sobrien
8338494Sobrien%start file
8438494Sobrien%%
8538494Sobrien
8638494Sobrien/****************************************************************************/
8738494Sobrienfile		: { yydebug = PARSE_DEBUG; } newlines map_sections
8838494Sobrien		| { yydebug = PARSE_DEBUG; } map_sections
8938494Sobrien		;
9038494Sobrien
9138494Sobriennewlines	: NEWLINE
9238494Sobrien		| NEWLINE newlines
9338494Sobrien		;
9438494Sobrien
9538494Sobrienmap_sections	: map_section
9638494Sobrien		| map_section map_sections
9738494Sobrien		;
9838494Sobrien
9938494Sobrienmap_section	: sec_header kv_pairs
10038494Sobrien		;
10138494Sobrien
10238494Sobriensec_header	: LEFT_BRACKET NONWS_STRING RIGHT_BRACKET NEWLINE
10338494Sobrien		{
10438494Sobrien		  if (yydebug)
10538494Sobrien		    fprintf(stderr, "sec_header1 = \"%s\"\n", $2);
10638494Sobrien		  header_section = $2;
10738494Sobrien		}
10838494Sobrien		;
10938494Sobrien
11038494Sobrienkv_pairs	: kv_pair
11138494Sobrien		| kv_pair kv_pairs
11238494Sobrien		;
11338494Sobrien
11438494Sobrienkv_pair		: NONWS_STRING EQUAL NONWS_STRING NEWLINE
11538494Sobrien		{
11638494Sobrien		  if (yydebug)
11738494Sobrien		    fprintf(stderr,"parse1: key=\"%s\", val=\"%s\"\n", $1, $3);
11838494Sobrien		  retval = set_conf_kv(header_section, $1, $3);
11938494Sobrien		  if (retval != 0) {
12038494Sobrien		    yyerror("syntax error");
12138494Sobrien		    YYABORT;
12238494Sobrien		  }
12338494Sobrien		}
12438494Sobrien		| NONWS_STRING EQUAL NONWSEQ_STRING NEWLINE
12538494Sobrien		{
12638494Sobrien		  if (yydebug)
12738494Sobrien		    fprintf(stderr,"parse2: key=\"%s\", val=\"%s\"\n", $1, $3);
12838494Sobrien		  retval = set_conf_kv(header_section, $1, $3);
12938494Sobrien		  if (retval != 0) {
13038494Sobrien		    yyerror("syntax error");
13138494Sobrien		    YYABORT;
13238494Sobrien		  }
13338494Sobrien		}
13438494Sobrien		| NONWS_STRING EQUAL QUOTED_NONWSEQ_STRING NEWLINE
13538494Sobrien		{
13638494Sobrien		  if (yydebug)
13738494Sobrien		    fprintf(stderr,"parse3: key=\"%s\", val=\"%s\"\n", $1, $3);
13838494Sobrien		  retval = set_conf_kv(header_section, $1, $3);
13938494Sobrien		  if (retval != 0) {
14038494Sobrien		    yyerror("syntax error");
14138494Sobrien		    YYABORT;
14238494Sobrien		  }
14338494Sobrien		}
14438494Sobrien		| NEWLINE
14538494Sobrien		;
14638494Sobrien
14738494Sobrien/****************************************************************************/
14838494Sobrien%%
14938494Sobrien
15038494Sobrienstatic int
15138494Sobrienyyerror(const char *s)
15238494Sobrien{
15338494Sobrien  fprintf(stderr, "AMDCONF: %s on line %d (section %s)\n",
154131702Smbr	  s, ayylineno,
15538494Sobrien	  (header_section ? header_section : "null"));
15638494Sobrien  exit(1);
15738494Sobrien  return 1;	/* to full compilers that insist on a return statement */
15838494Sobrien}
159