diff --git a/lib/conf-parse.y b/lib/conf-parse.y index 1799617a..9e75606b 100644 --- a/lib/conf-parse.y +++ b/lib/conf-parse.y @@ -29,6 +29,7 @@ #include "error.h" #include "conf.h" #include "access.h" +#include "init.h" static void sensors_yyerror(const char *err); static sensors_expr *malloc_expr(void); @@ -72,15 +73,6 @@ static sensors_chip *current_chip = NULL; &(list).fits_max, \ sizeof(sensors_chip_name)); -/* YYERROR can only be called in rules, not in other functions, so this must - be a macro */ -#define check_current_chip()\ - do { if (! current_chip) {\ - sensors_yyerror("Label, Set or Compute statement before first chip statement");\ - YYERROR;\ - }\ - } while (0) - %} %union { @@ -160,7 +152,12 @@ busalgo_statement: BUS i2cbus_name adapter_name algorithm_name label_statement: LABEL function_name string { sensors_label new_el; - check_current_chip(); + if (!current_chip) { + sensors_yyerror("Label statement before first chip statement"); + free($2); + free($3); + YYERROR; + } new_el.lineno = $1; new_el.name = $2; new_el.value = $3; @@ -170,7 +167,12 @@ label_statement: LABEL function_name string set_statement: SET function_name expression { sensors_set new_el; - check_current_chip(); + if (!current_chip) { + sensors_yyerror("Set statement before first chip statement"); + free($2); + free_expr($3); + YYERROR; + } new_el.lineno = $1; new_el.name = $2; new_el.value = $3; @@ -180,7 +182,13 @@ set_statement: SET function_name expression compute_statement: COMPUTE function_name expression ',' expression { sensors_compute new_el; - check_current_chip(); + if (!current_chip) { + sensors_yyerror("Compute statement before first chip statement"); + free($2); + free_expr($3); + free_expr($5); + YYERROR; + } new_el.lineno = $1; new_el.name = $2; new_el.from_proc = $3; @@ -191,7 +199,11 @@ compute_statement: COMPUTE function_name expression ',' expression ignore_statement: IGNORE function_name { sensors_ignore new_el; - check_current_chip(); + if (!current_chip) { + sensors_yyerror("Ignore statement before first chip statement"); + free($2); + YYERROR; + } new_el.lineno = $1; new_el.name = $2; ignore_add_el(&new_el); diff --git a/lib/init.c b/lib/init.c index 088a2781..c7d9734c 100644 --- a/lib/init.c +++ b/lib/init.c @@ -27,6 +27,7 @@ #include "conf.h" #include "sysfs.h" #include "scanner.h" +#include "init.h" static void free_proc_chips_entry(sensors_proc_chips_entry entry); static void free_chip_name(sensors_chip_name name); @@ -36,7 +37,6 @@ static void free_label(sensors_label label); static void free_set(sensors_set set); static void free_compute(sensors_compute compute); static void free_ignore(sensors_ignore ignore); -static void free_expr(sensors_expr *expr); int sensors_init(FILE *input) { diff --git a/lib/init.h b/lib/init.h new file mode 100644 index 00000000..c413e392 --- /dev/null +++ b/lib/init.h @@ -0,0 +1,27 @@ +/* + init.h - Part of libsensors, a Linux library for reading sensor data. + Copyright (C) 2007 Jean Delvare + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef LIB_SENSORS_INIT_H +#define LIB_SENSORS_INIT_H + +#include "data.h" + +void free_expr(sensors_expr *expr); + +#endif /* def LIB_SENSORS_INIT_H */