3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * APM (Advanced Power Management) Event Dispatcher
7 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
8 * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/types.h>
37 #include <bitstring.h>
46 extern int first_time;
52 bitstr_t bit_decl(evlist, EVENT_MAX);
54 struct event_cmd * evcmd;
58 %token BEGINBLOCK ENDBLOCK
59 %token COMMA SEMICOLON
62 %token BATTCHARGE BATTDISCHARGE
63 %token <i> BATTTIME BATTPERCENT
64 %token EXECCMD REJECTCMD
66 %token <str> STRING UNKNOWN
68 %type <i> apm_battery_level
69 %type <i> apm_battery_direction
72 %type <evlist> event_list
73 %type <evcmd> cmd_list
75 %type <evcmd> exec_cmd reject_cmd
80 : { first_time = 1; } config_list
90 | apm_battery_statement
94 : APMEVENT event_list BEGINBLOCK cmd_list ENDBLOCK
96 if (register_apm_event_handlers($2, $4) < 0)
98 free_event_cmd_list($4);
113 apm_battery_direction
123 apm_battery_statement
124 : APMBATT apm_battery_level apm_battery_direction
125 BEGINBLOCK cmd_list ENDBLOCK
127 if (register_battery_handlers($2, $3, $5) < 0)
129 free_event_cmd_list($5);
136 bit_nclear($$, 0, EVENT_MAX - 1);
139 | event_list COMMA EVENT
141 memcpy(&($$), &($1), bitstr_size(EVENT_MAX));
153 struct event_cmd * p = $1;
155 while (p->next != NULL)
166 : exec_cmd SEMICOLON { $$ = $1; }
167 | reject_cmd SEMICOLON { $$ = $1; }
173 size_t len = sizeof (struct event_cmd_exec);
174 struct event_cmd_exec *cmd = malloc(len);
175 cmd->evcmd.next = NULL;
176 cmd->evcmd.len = len;
177 cmd->evcmd.name = "exec";
178 cmd->evcmd.op = &event_cmd_exec_ops;
180 $$ = (struct event_cmd *) cmd;
187 size_t len = sizeof (struct event_cmd_reject);
188 struct event_cmd_reject *cmd = malloc(len);
189 cmd->evcmd.next = NULL;
190 cmd->evcmd.len = len;
191 cmd->evcmd.name = "reject";
192 cmd->evcmd.op = &event_cmd_reject_ops;
193 $$ = (struct event_cmd *) cmd;
198 : STRING { $$ = $1; }