3 * APM (Advanced Power Management) Event Dispatcher
5 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
6 * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
30 * $FreeBSD: src/usr.sbin/apmd/apmdparse.y,v 1.2.2.1 2001/08/13 17:30:30 nsayer Exp $
31 * $DragonFly: src/usr.sbin/apmd/apmdparse.y,v 1.3 2007/11/25 01:28:23 swildner Exp $
35 #include <bitstring.h>
44 extern
int first_time
;
50 bitstr_t bit_decl
(evlist
, EVENT_MAX
);
52 struct event_cmd
* evcmd
;
56 %token BEGINBLOCK ENDBLOCK
57 %token COMMA SEMICOLON
60 %token BATTCHARGE BATTDISCHARGE
61 %token
<str
> BATTTIME BATTPERCENT
62 %token EXECCMD REJECTCMD
64 %token
<str
> STRING UNKNOWN
66 %type
<i
> apm_battery_level
67 %type
<i
> apm_battery_direction
70 %type
<evlist
> event_list
71 %type
<evcmd
> cmd_list
73 %type
<evcmd
> exec_cmd reject_cmd
78 : { first_time
= 1; } config_list
88 | apm_battery_statement
92 : APMEVENT event_list BEGINBLOCK cmd_list ENDBLOCK
94 if
(register_apm_event_handlers
($2, $4) < 0)
96 free_event_cmd_list
($4);
111 apm_battery_direction
121 apm_battery_statement
122 : APMBATT apm_battery_level apm_battery_direction
123 BEGINBLOCK cmd_list ENDBLOCK
125 if
(register_battery_handlers
($2, $3, $5) < 0)
127 free_event_cmd_list
($5);
134 bit_nclear
($$
, 0, EVENT_MAX
- 1);
137 | event_list COMMA EVENT
139 memcpy
(&($$
), &($1), bitstr_size
(EVENT_MAX
));
151 struct event_cmd
* p
= $1;
153 while
(p
->next
!= NULL
)
164 : exec_cmd SEMICOLON
{ $$
= $1; }
165 | reject_cmd SEMICOLON
{ $$
= $1; }
171 size_t len
= sizeof
(struct event_cmd_exec
);
172 struct event_cmd_exec
*cmd
= malloc
(len
);
173 cmd
->evcmd.next
= NULL
;
174 cmd
->evcmd.len
= len
;
175 cmd
->evcmd.name
= "exec";
176 cmd
->evcmd.op
= &event_cmd_exec_ops
;
178 $$
= (struct event_cmd
*) cmd
;
185 size_t len
= sizeof
(struct event_cmd_reject
);
186 struct event_cmd_reject
*cmd
= malloc
(len
);
187 cmd
->evcmd.next
= NULL
;
188 cmd
->evcmd.len
= len
;
189 cmd
->evcmd.name
= "reject";
190 cmd
->evcmd.op
= &event_cmd_reject_ops
;
191 $$
= (struct event_cmd
*) cmd
;
196 : STRING
{ $$
= $1; }