1d50a71bdSMitsuru IWASAKI %{ 2d50a71bdSMitsuru IWASAKI /*- 3d50a71bdSMitsuru IWASAKI * APM (Advanced Power Management) Event Dispatcher 4d50a71bdSMitsuru IWASAKI * 5d50a71bdSMitsuru IWASAKI * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 6d50a71bdSMitsuru IWASAKI * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp> 7d50a71bdSMitsuru IWASAKI * All rights reserved. 8d50a71bdSMitsuru IWASAKI * 9d50a71bdSMitsuru IWASAKI * Redistribution and use in source and binary forms, with or without 10d50a71bdSMitsuru IWASAKI * modification, are permitted provided that the following conditions 11d50a71bdSMitsuru IWASAKI * are met: 12d50a71bdSMitsuru IWASAKI * 1. Redistributions of source code must retain the above copyright 13d50a71bdSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer. 14d50a71bdSMitsuru IWASAKI * 2. Redistributions in binary form must reproduce the above copyright 15d50a71bdSMitsuru IWASAKI * notice, this list of conditions and the following disclaimer in the 16d50a71bdSMitsuru IWASAKI * documentation and/or other materials provided with the distribution. 17d50a71bdSMitsuru IWASAKI * 18d50a71bdSMitsuru IWASAKI * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19d50a71bdSMitsuru IWASAKI * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20d50a71bdSMitsuru IWASAKI * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21d50a71bdSMitsuru IWASAKI * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22d50a71bdSMitsuru IWASAKI * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23d50a71bdSMitsuru IWASAKI * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24d50a71bdSMitsuru IWASAKI * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25d50a71bdSMitsuru IWASAKI * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26d50a71bdSMitsuru IWASAKI * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27d50a71bdSMitsuru IWASAKI * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28d50a71bdSMitsuru IWASAKI * SUCH DAMAGE. 29d50a71bdSMitsuru IWASAKI * 3097d92980SPeter Wemm * $FreeBSD$ 31d50a71bdSMitsuru IWASAKI */ 32d50a71bdSMitsuru IWASAKI 33*00774f35SPeter Wemm #include <sys/types.h> 34d50a71bdSMitsuru IWASAKI #include <string.h> 35d50a71bdSMitsuru IWASAKI #include <syslog.h> 36d50a71bdSMitsuru IWASAKI #include <bitstring.h> 37d50a71bdSMitsuru IWASAKI #include "apmd.h" 38d50a71bdSMitsuru IWASAKI #include "y.tab.h" 39d50a71bdSMitsuru IWASAKI 40d50a71bdSMitsuru IWASAKI int lineno; 41d50a71bdSMitsuru IWASAKI int first_time; 42d50a71bdSMitsuru IWASAKI %} 43d50a71bdSMitsuru IWASAKI 44a7880d59SJung-uk Kim /* We don't need it, avoid the warning. */ 45a7880d59SJung-uk Kim %option nounput 46a7880d59SJung-uk Kim %option noinput 47a7880d59SJung-uk Kim 48d50a71bdSMitsuru IWASAKI %s TOP 49d50a71bdSMitsuru IWASAKI 50d50a71bdSMitsuru IWASAKI %% 51d50a71bdSMitsuru IWASAKI 52d50a71bdSMitsuru IWASAKI %{ 53d50a71bdSMitsuru IWASAKI if (first_time) { 54d50a71bdSMitsuru IWASAKI BEGIN TOP; 55d50a71bdSMitsuru IWASAKI lineno = 1; 56d50a71bdSMitsuru IWASAKI first_time = 0; 57d50a71bdSMitsuru IWASAKI } 58d50a71bdSMitsuru IWASAKI %} 59d50a71bdSMitsuru IWASAKI 60d50a71bdSMitsuru IWASAKI <TOP>[ \t]+ ; 61d50a71bdSMitsuru IWASAKI <TOP>\n lineno++; 62d50a71bdSMitsuru IWASAKI <TOP>, { return COMMA; } 63d50a71bdSMitsuru IWASAKI <TOP>; { return SEMICOLON; } 64d50a71bdSMitsuru IWASAKI <TOP>#.*$ ; 65d50a71bdSMitsuru IWASAKI 66d50a71bdSMitsuru IWASAKI <TOP>apm_event { return APMEVENT; } 67d50a71bdSMitsuru IWASAKI 68d50a71bdSMitsuru IWASAKI <TOP>NOEVENT { yylval.ev = EVENT_NOEVENT; return EVENT; } 69d50a71bdSMitsuru IWASAKI <TOP>STANDBYREQ { yylval.ev = EVENT_STANDBYREQ; return EVENT; } 70d50a71bdSMitsuru IWASAKI <TOP>SUSPENDREQ { yylval.ev = EVENT_SUSPENDREQ; return EVENT; } 71d50a71bdSMitsuru IWASAKI <TOP>NORMRESUME { yylval.ev = EVENT_NORMRESUME; return EVENT; } 72d50a71bdSMitsuru IWASAKI <TOP>CRITRESUME { yylval.ev = EVENT_CRITRESUME; return EVENT; } 73d50a71bdSMitsuru IWASAKI <TOP>BATTERYLOW { yylval.ev = EVENT_BATTERYLOW; return EVENT; } 74d50a71bdSMitsuru IWASAKI <TOP>POWERSTATECHANGE { yylval.ev = EVENT_POWERSTATECHANGE; return EVENT; } 75d50a71bdSMitsuru IWASAKI <TOP>UPDATETIME { yylval.ev = EVENT_UPDATETIME; return EVENT; } 76d50a71bdSMitsuru IWASAKI <TOP>CRITSUSPEND { yylval.ev = EVENT_CRITSUSPEND; return EVENT; } 77d50a71bdSMitsuru IWASAKI <TOP>USERSTANDBYREQ { yylval.ev = EVENT_USERSTANDBYREQ; return EVENT; } 78d50a71bdSMitsuru IWASAKI <TOP>USERSUSPENDREQ { yylval.ev = EVENT_USERSUSPENDREQ; return EVENT; } 79d50a71bdSMitsuru IWASAKI <TOP>STANDBYRESUME { yylval.ev = EVENT_STANDBYRESUME; return EVENT; } 80d50a71bdSMitsuru IWASAKI <TOP>CAPABILITIESCHANGE { yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; } 81d50a71bdSMitsuru IWASAKI 82719b9dc1SNick Sayer <TOP>apm_battery { return APMBATT; } 83719b9dc1SNick Sayer 84719b9dc1SNick Sayer <TOP>charging { return BATTCHARGE; } 85719b9dc1SNick Sayer <TOP>discharging { return BATTDISCHARGE; } 86719b9dc1SNick Sayer <TOP>[0-9]+% { 87719b9dc1SNick Sayer yylval.i = atoi(yytext); 88719b9dc1SNick Sayer return BATTPERCENT; 89719b9dc1SNick Sayer } 90719b9dc1SNick Sayer <TOP>[0-9]+[Mm] { 91719b9dc1SNick Sayer yylval.i = -atoi(yytext); 92719b9dc1SNick Sayer return BATTTIME; 93719b9dc1SNick Sayer } 94719b9dc1SNick Sayer 95d50a71bdSMitsuru IWASAKI <TOP>exec { return EXECCMD; } 96d50a71bdSMitsuru IWASAKI <TOP>reject { return REJECTCMD; } 97d50a71bdSMitsuru IWASAKI 98d50a71bdSMitsuru IWASAKI <TOP>\{ { return BEGINBLOCK; } 99d50a71bdSMitsuru IWASAKI <TOP>\} { return ENDBLOCK; } 100d50a71bdSMitsuru IWASAKI <TOP>\"[^"]+\" { 101d50a71bdSMitsuru IWASAKI int len = strlen(yytext) - 2; 102d50a71bdSMitsuru IWASAKI if ((yylval.str = (char *) malloc(len + 1)) == NULL) 103d50a71bdSMitsuru IWASAKI goto out; 104d50a71bdSMitsuru IWASAKI memcpy(yylval.str, yytext + 1, len); 105d50a71bdSMitsuru IWASAKI yylval.str[len] = '\0'; 106d50a71bdSMitsuru IWASAKI out: 107d50a71bdSMitsuru IWASAKI return STRING; 108d50a71bdSMitsuru IWASAKI } 109d50a71bdSMitsuru IWASAKI 110d50a71bdSMitsuru IWASAKI <TOP>[^"{},;#\n\t ]+ { yylval.str = strdup(yytext); return UNKNOWN; } 111d50a71bdSMitsuru IWASAKI %% 112d50a71bdSMitsuru IWASAKI 113d50a71bdSMitsuru IWASAKI void 114d50a71bdSMitsuru IWASAKI yyerror(const char *s) 115d50a71bdSMitsuru IWASAKI { 116d50a71bdSMitsuru IWASAKI syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s); 117d50a71bdSMitsuru IWASAKI } 118