apmdparse.y revision 48731
1%{
2/*-
3 * APM (Advanced Power Management) Event Dispatcher
4 *
5 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
6 * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * 	$Id: apmdparse.y,v 1.1.3.5 1999/06/08 09:01:47 koie Exp $
31 */
32
33#include <stdio.h>
34#include <bitstring.h>
35#include "apmd.h"
36
37#ifdef DEBUG
38#define YYDEBUG 1
39#endif
40
41extern int first_time;
42
43%}
44
45%union {
46	char *str;
47	bitstr_t bit_decl(evlist, EVENT_MAX);
48	int ev;
49	struct event_cmd * evcmd;
50}
51
52%token BEGINBLOCK ENDBLOCK
53%token COMMA SEMICOLON
54%token APMEVENT
55%token EXECCMD REJECTCMD
56%token <ev> EVENT
57%token <str> STRING UNKNOWN
58
59%type <str> string
60%type <str> unknown
61%type <evlist> event_list
62%type <evcmd> cmd_list
63%type <evcmd> cmd
64%type <evcmd> exec_cmd reject_cmd
65
66%%
67
68config_file
69	: { first_time = 1; } config_list
70	;
71
72config_list
73	: config
74	| config_list config
75	;
76
77config
78	: apm_event_statement
79	;
80
81apm_event_statement
82	: APMEVENT event_list BEGINBLOCK cmd_list ENDBLOCK
83		{
84			if (register_apm_event_handlers($2, $4) < 0)
85				abort(); /* XXX */
86			free_event_cmd_list($4);
87		}
88	;
89
90event_list
91	: EVENT
92		{
93			bit_nclear($$, 0, EVENT_MAX - 1);
94			bit_set($$, $1);
95		}
96	| event_list COMMA EVENT
97		{
98			memcpy(&($$), &($1), bitstr_size(EVENT_MAX));
99			bit_set($$, $3);
100		}
101	;
102
103cmd_list
104	: /* empty */
105		{
106			$$  = NULL;
107		}
108	| cmd_list cmd
109		{
110			struct event_cmd * p = $1;
111			if (p) {
112				while (p->next != NULL)
113					p = p->next;
114				p->next = $2;
115				$$ = $1;
116			} else {
117				$$ = $2;
118			}
119		}
120	;
121
122cmd
123	: exec_cmd SEMICOLON	{ $$ = $1; }
124	| reject_cmd SEMICOLON	{ $$ = $1; }
125	;
126
127exec_cmd
128	: EXECCMD string
129		{
130			size_t len = sizeof (struct event_cmd_exec);
131			struct event_cmd_exec *cmd = malloc(len);
132			cmd->evcmd.next = NULL;
133			cmd->evcmd.len = len;
134			cmd->evcmd.name = "exec";
135			cmd->evcmd.op = &event_cmd_exec_ops;
136			cmd->line = $2;
137			$$ = (struct event_cmd *) cmd;
138		}
139	;
140
141reject_cmd
142	: REJECTCMD
143		{
144			size_t len = sizeof (struct event_cmd_reject);
145			struct event_cmd_reject *cmd = malloc(len);
146			cmd->evcmd.next = NULL;
147			cmd->evcmd.len = len;
148			cmd->evcmd.name = "reject";
149			cmd->evcmd.op = &event_cmd_reject_ops;
150			$$ = (struct event_cmd *) cmd;
151		}
152	;
153
154string
155	: STRING	{ $$ = $1; }
156	;
157
158unknown
159	: UNKNOWN
160		{
161			$$ = $1;
162		}
163	;
164%%
165
166