config_yacc.y revision 1.2
11.2Sxtraeme/* $NetBSD: config_yacc.y,v 1.2 2007/10/07 13:46:22 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.2Sxtraeme__RCSID("$NetBSD: config_yacc.y,v 1.2 2007/10/07 13:46:22 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.1Sxtraeme%token SENSOR_PROP 601.1Sxtraeme%token <string> SENSOR STRING SENSOR_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.1Sxtraemedevice : STRING LBRACE sensors RBRACE 761.1Sxtraeme { config_devblock_add($1, kdict); } 771.1Sxtraeme ; 781.1Sxtraeme 791.1Sxtraemesensors : sensor 801.1Sxtraeme | sensors sensor 811.1Sxtraeme ; 821.1Sxtraeme 831.1Sxtraemesensor : SENSOR LBRACE params RBRACE 841.1Sxtraeme { config_dict_add_prop("index", $1); 851.1Sxtraeme config_dict_mark($1); } 861.1Sxtraeme ; 871.1Sxtraeme 881.1Sxtraemeparams : prop 891.1Sxtraeme | params prop 901.1Sxtraeme ; 911.1Sxtraeme 921.1Sxtraemeprop : SENSOR_PROP EQUAL STRING EOL 931.1Sxtraeme { config_dict_add_prop($1, $3); } 941.1Sxtraeme ; 951.1Sxtraeme 961.1Sxtraeme%% 971.1Sxtraeme 981.1Sxtraemeint 991.1Sxtraemeyyerror(const char *fmt, ...) 1001.1Sxtraeme{ 1011.1Sxtraeme va_list ap; 1021.1Sxtraeme 1031.1Sxtraeme va_start(ap, fmt); 1041.1Sxtraeme fprintf(stderr, "%s: ", getprogname()); 1051.1Sxtraeme vfprintf(stderr, fmt, ap); 1061.1Sxtraeme fprintf(stderr, " in line %d\n", yyline); 1071.1Sxtraeme va_end(ap); 1081.1Sxtraeme 1091.1Sxtraeme exit(EXIT_FAILURE); 1101.1Sxtraeme} 1111.1Sxtraeme 1121.1Sxtraemevoid 1131.1Sxtraemeconfig_parse(FILE *f, prop_dictionary_t d) 1141.1Sxtraeme{ 1151.1Sxtraeme kdict = prop_dictionary_copy(d); 1161.1Sxtraeme yyrestart(f); 1171.1Sxtraeme yyline = 0; 1181.1Sxtraeme yyparse(); 1191.1Sxtraeme} 120