config_yacc.y revision 1.1
11.1Sxtraeme/* $NetBSD: config_yacc.y,v 1.1 2007/10/07 04:16:48 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.1Sxtraeme__RCSID("$NetBSD: config_yacc.y,v 1.1 2007/10/07 04:16:48 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.1Sxtraememain : { exit(EXIT_SUCCESS); } 681.1Sxtraeme | device 691.1Sxtraeme | main device 701.1Sxtraeme ; 711.1Sxtraeme 721.1Sxtraemedevice : STRING LBRACE sensors RBRACE 731.1Sxtraeme { config_devblock_add($1, kdict); } 741.1Sxtraeme ; 751.1Sxtraeme 761.1Sxtraemesensors : sensor 771.1Sxtraeme | sensors sensor 781.1Sxtraeme ; 791.1Sxtraeme 801.1Sxtraemesensor : SENSOR LBRACE params RBRACE 811.1Sxtraeme { config_dict_add_prop("index", $1); 821.1Sxtraeme config_dict_mark($1); } 831.1Sxtraeme ; 841.1Sxtraeme 851.1Sxtraemeparams : prop 861.1Sxtraeme | params prop 871.1Sxtraeme ; 881.1Sxtraeme 891.1Sxtraemeprop : SENSOR_PROP EQUAL STRING EOL 901.1Sxtraeme { config_dict_add_prop($1, $3); } 911.1Sxtraeme ; 921.1Sxtraeme 931.1Sxtraeme%% 941.1Sxtraeme 951.1Sxtraemeint 961.1Sxtraemeyyerror(const char *fmt, ...) 971.1Sxtraeme{ 981.1Sxtraeme va_list ap; 991.1Sxtraeme 1001.1Sxtraeme va_start(ap, fmt); 1011.1Sxtraeme fprintf(stderr, "%s: ", getprogname()); 1021.1Sxtraeme vfprintf(stderr, fmt, ap); 1031.1Sxtraeme fprintf(stderr, " in line %d\n", yyline); 1041.1Sxtraeme va_end(ap); 1051.1Sxtraeme 1061.1Sxtraeme exit(EXIT_FAILURE); 1071.1Sxtraeme} 1081.1Sxtraeme 1091.1Sxtraemevoid 1101.1Sxtraemeconfig_parse(FILE *f, prop_dictionary_t d) 1111.1Sxtraeme{ 1121.1Sxtraeme kdict = prop_dictionary_copy(d); 1131.1Sxtraeme yyrestart(f); 1141.1Sxtraeme yyline = 0; 1151.1Sxtraeme yyparse(); 1161.1Sxtraeme} 117