config_yacc.y revision 1.3
11.3Sxtraeme/* $NetBSD: config_yacc.y,v 1.3 2007/11/16 08:01:38 xtraeme Exp $ */ 21.1Sxtraeme 31.1Sxtraeme/*- 41.1Sxtraeme * Copyright (c) 2007 Juan Romero Pardines. 51.1Sxtraeme * All rights reserved. 61.1Sxtraeme * 71.1Sxtraeme * Redistribution and use in source and binary forms, with or without 81.1Sxtraeme * modification, are permitted provided that the following conditions 91.1Sxtraeme * are met: 101.1Sxtraeme * 1. Redistributions of source code must retain the above copyright 111.1Sxtraeme * notice, this list of conditions and the following disclaimer. 121.1Sxtraeme * 2. Redistributions in binary form must reproduce the above copyright 131.1Sxtraeme * notice, this list of conditions and the following disclaimer in the 141.1Sxtraeme * documentation and/or other materials provided with the distribution. 151.1Sxtraeme * 161.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.1Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.1Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.1Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.1Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 211.1Sxtraeme * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221.1Sxtraeme * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231.1Sxtraeme * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241.1Sxtraeme * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 251.1Sxtraeme * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261.1Sxtraeme */ 271.1Sxtraeme 281.1Sxtraeme%{ 291.1Sxtraeme 301.1Sxtraeme#include <sys/cdefs.h> 311.1Sxtraeme#ifndef lint 321.3Sxtraeme__RCSID("$NetBSD: config_yacc.y,v 1.3 2007/11/16 08:01:38 xtraeme Exp $"); 331.1Sxtraeme#endif /* not lint */ 341.1Sxtraeme 351.1Sxtraeme#include <stdio.h> 361.1Sxtraeme#include <string.h> 371.1Sxtraeme#include <stdarg.h> 381.1Sxtraeme#include <err.h> 391.1Sxtraeme#include <errno.h> 401.1Sxtraeme#include <stdbool.h> 411.1Sxtraeme 421.1Sxtraeme#include <prop/proplib.h> 431.1Sxtraeme 441.1Sxtraeme#include "envstat.h" 451.1Sxtraeme 461.1Sxtraemeint yylex(void); 471.1Sxtraemeint yyparse(void); 481.1Sxtraemeint yyerror(const char *, ...); 491.1Sxtraemevoid yyrestart(FILE *); 501.1Sxtraeme 511.1Sxtraemeint yyline; 521.1Sxtraemechar *yytext; 531.1Sxtraemestatic prop_dictionary_t kdict; 541.1Sxtraeme 551.1Sxtraeme%} 561.1Sxtraeme 571.1Sxtraeme%token EOL EQUAL LBRACE RBRACE 581.1Sxtraeme%token STRING NUMBER SENSOR 591.3Sxtraeme%token SENSOR_PROP DEVICE_PROP 601.3Sxtraeme%token <string> SENSOR STRING SENSOR_PROP DEVICE_PROP 611.1Sxtraeme%union { 621.1Sxtraeme char *string; 631.1Sxtraeme} 641.1Sxtraeme 651.1Sxtraeme%% 661.1Sxtraeme 671.2Sxtraememain : devices 681.2Sxtraeme | { exit(EXIT_SUCCESS); } 691.2Sxtraeme ; 701.2Sxtraeme 711.2Sxtraemedevices : device 721.2Sxtraeme | devices device 731.1Sxtraeme ; 741.1Sxtraeme 751.3Sxtraemedevice : STRING LBRACE props RBRACE 761.1Sxtraeme { config_devblock_add($1, kdict); } 771.1Sxtraeme ; 781.1Sxtraeme 791.3Sxtraemeprops : sensor 801.3Sxtraeme | props sensor 811.3Sxtraeme | devprop 821.3Sxtraeme | props devprop 831.1Sxtraeme ; 841.1Sxtraeme 851.1Sxtraemesensor : SENSOR LBRACE params RBRACE 861.1Sxtraeme { config_dict_add_prop("index", $1); 871.3Sxtraeme config_dict_mark(); } 881.1Sxtraeme ; 891.1Sxtraeme 901.1Sxtraemeparams : prop 911.1Sxtraeme | params prop 921.1Sxtraeme ; 931.1Sxtraeme 941.1Sxtraemeprop : SENSOR_PROP EQUAL STRING EOL 951.1Sxtraeme { config_dict_add_prop($1, $3); } 961.1Sxtraeme ; 971.1Sxtraeme 981.3Sxtraemedevprop : DEVICE_PROP EQUAL STRING EOL 991.3Sxtraeme { config_dict_adddev_prop($1, $3, yyline); } 1001.3Sxtraeme ; 1011.3Sxtraeme 1021.3Sxtraeme 1031.1Sxtraeme%% 1041.1Sxtraeme 1051.1Sxtraemeint 1061.1Sxtraemeyyerror(const char *fmt, ...) 1071.1Sxtraeme{ 1081.1Sxtraeme va_list ap; 1091.1Sxtraeme 1101.1Sxtraeme va_start(ap, fmt); 1111.1Sxtraeme fprintf(stderr, "%s: ", getprogname()); 1121.1Sxtraeme vfprintf(stderr, fmt, ap); 1131.1Sxtraeme fprintf(stderr, " in line %d\n", yyline); 1141.1Sxtraeme va_end(ap); 1151.1Sxtraeme 1161.1Sxtraeme exit(EXIT_FAILURE); 1171.1Sxtraeme} 1181.1Sxtraeme 1191.1Sxtraemevoid 1201.1Sxtraemeconfig_parse(FILE *f, prop_dictionary_t d) 1211.1Sxtraeme{ 1221.1Sxtraeme kdict = prop_dictionary_copy(d); 1231.1Sxtraeme yyrestart(f); 1241.3Sxtraeme yyline = 1; 1251.1Sxtraeme yyparse(); 1261.1Sxtraeme} 127