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