| 1 |
%{ |
|---|
| 2 |
/* |
|---|
| 3 |
conf-parse.y - Part of libsensors, a Linux library for reading sensor data. |
|---|
| 4 |
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 5 |
|
|---|
| 6 |
This program is free software; you can redistribute it and/or modify |
|---|
| 7 |
it under the terms of the GNU General Public License as published by |
|---|
| 8 |
the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 |
(at your option) any later version. |
|---|
| 10 |
|
|---|
| 11 |
This program is distributed in the hope that it will be useful, |
|---|
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
GNU General Public License for more details. |
|---|
| 15 |
|
|---|
| 16 |
You should have received a copy of the GNU General Public License |
|---|
| 17 |
along with this program; if not, write to the Free Software |
|---|
| 18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 |
*/ |
|---|
| 20 |
|
|---|
| 21 |
#define YYERROR_VERBOSE |
|---|
| 22 |
|
|---|
| 23 |
#include <stdio.h> |
|---|
| 24 |
#include <string.h> |
|---|
| 25 |
#include <stdlib.h> |
|---|
| 26 |
|
|---|
| 27 |
#include "data.h" |
|---|
| 28 |
#include "general.h" |
|---|
| 29 |
#include "error.h" |
|---|
| 30 |
#include "conf.h" |
|---|
| 31 |
#include "access.h" |
|---|
| 32 |
|
|---|
| 33 |
/* These two functions are defined in conf-lex.l */ |
|---|
| 34 |
extern int sensors_yylex(void); |
|---|
| 35 |
extern char sensors_lex_error[]; |
|---|
| 36 |
extern int sensors_yylineno; |
|---|
| 37 |
|
|---|
| 38 |
static void sensors_yyerror(const char *err); |
|---|
| 39 |
static sensors_expr *malloc_expr(void); |
|---|
| 40 |
|
|---|
| 41 |
static sensors_chip *current_chip = NULL; |
|---|
| 42 |
|
|---|
| 43 |
#define bus_add_el(el) sensors_add_array_el(el,\ |
|---|
| 44 |
&sensors_config_busses,\ |
|---|
| 45 |
&sensors_config_busses_count,\ |
|---|
| 46 |
&sensors_config_busses_max,\ |
|---|
| 47 |
sizeof(sensors_bus)) |
|---|
| 48 |
#define label_add_el(el) sensors_add_array_el(el,\ |
|---|
| 49 |
¤t_chip->labels,\ |
|---|
| 50 |
¤t_chip->labels_count,\ |
|---|
| 51 |
¤t_chip->labels_max,\ |
|---|
| 52 |
sizeof(sensors_label)); |
|---|
| 53 |
#define set_add_el(el) sensors_add_array_el(el,\ |
|---|
| 54 |
¤t_chip->sets,\ |
|---|
| 55 |
¤t_chip->sets_count,\ |
|---|
| 56 |
¤t_chip->sets_max,\ |
|---|
| 57 |
sizeof(sensors_set)); |
|---|
| 58 |
#define compute_add_el(el) sensors_add_array_el(el,\ |
|---|
| 59 |
¤t_chip->computes,\ |
|---|
| 60 |
¤t_chip->computes_count,\ |
|---|
| 61 |
¤t_chip->computes_max,\ |
|---|
| 62 |
sizeof(sensors_compute)); |
|---|
| 63 |
#define ignore_add_el(el) sensors_add_array_el(el,\ |
|---|
| 64 |
¤t_chip->ignores,\ |
|---|
| 65 |
¤t_chip->ignores_count,\ |
|---|
| 66 |
¤t_chip->ignores_max,\ |
|---|
| 67 |
sizeof(sensors_ignore)); |
|---|
| 68 |
#define chip_add_el(el) sensors_add_array_el(el,\ |
|---|
| 69 |
&sensors_config_chips,\ |
|---|
| 70 |
&sensors_config_chips_count,\ |
|---|
| 71 |
&sensors_config_chips_max,\ |
|---|
| 72 |
sizeof(sensors_chip)); |
|---|
| 73 |
|
|---|
| 74 |
#define fits_add_el(el,list) sensors_add_array_el(el,\ |
|---|
| 75 |
&(list).fits,\ |
|---|
| 76 |
&(list).fits_count,\ |
|---|
| 77 |
&(list).fits_max, \ |
|---|
| 78 |
sizeof(sensors_chip_name)); |
|---|
| 79 |
|
|---|
| 80 |
/* YYERROR can only be called in rules, not in other functions, so this must |
|---|
| 81 |
be a macro */ |
|---|
| 82 |
#define check_current_chip()\ |
|---|
| 83 |
do { if (! current_chip) {\ |
|---|
| 84 |
sensors_yyerror("Label, Set or Compute statement before first chip statement");\ |
|---|
| 85 |
YYERROR;\ |
|---|
| 86 |
}\ |
|---|
| 87 |
} while (0) |
|---|
| 88 |
|
|---|
| 89 |
%} |
|---|
| 90 |
|
|---|
| 91 |
%union { |
|---|
| 92 |
double value; |
|---|
| 93 |
char *name; |
|---|
| 94 |
void *nothing; |
|---|
| 95 |
sensors_chip_name_list chips; |
|---|
| 96 |
sensors_expr *expr; |
|---|
| 97 |
int bus; |
|---|
| 98 |
sensors_chip_name chip; |
|---|
| 99 |
int line; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
%left <nothing> '-' '+' |
|---|
| 103 |
%left <nothing> '*' '/' |
|---|
| 104 |
%left <nothing> NEG |
|---|
| 105 |
%right <nothing> '^' '`' |
|---|
| 106 |
|
|---|
| 107 |
%token <nothing> ',' |
|---|
| 108 |
%token <nothing> EOL |
|---|
| 109 |
%token <line> BUS |
|---|
| 110 |
%token <line> LABEL |
|---|
| 111 |
%token <line> SET |
|---|
| 112 |
%token <line> CHIP |
|---|
| 113 |
%token <line> COMPUTE |
|---|
| 114 |
%token <line> IGNORE |
|---|
| 115 |
%token <value> FLOAT |
|---|
| 116 |
%token <name> NAME |
|---|
| 117 |
%token <nothing> ERROR |
|---|
| 118 |
|
|---|
| 119 |
%type <chips> chip_name_list |
|---|
| 120 |
%type <expr> expression |
|---|
| 121 |
%type <bus> i2cbus_name |
|---|
| 122 |
%type <name> adapter_name |
|---|
| 123 |
%type <name> algorithm_name |
|---|
| 124 |
%type <name> function_name |
|---|
| 125 |
%type <name> string |
|---|
| 126 |
%type <chip> chip_name |
|---|
| 127 |
|
|---|
| 128 |
%start input |
|---|
| 129 |
|
|---|
| 130 |
%% |
|---|
| 131 |
|
|---|
| 132 |
input: /* empty */ |
|---|
| 133 |
| input line |
|---|
| 134 |
; |
|---|
| 135 |
|
|---|
| 136 |
line: bus_statement EOL |
|---|
| 137 |
| busalgo_statement EOL |
|---|
| 138 |
| label_statement EOL |
|---|
| 139 |
| set_statement EOL |
|---|
| 140 |
| chip_statement EOL |
|---|
| 141 |
| compute_statement EOL |
|---|
| 142 |
| ignore_statement EOL |
|---|
| 143 |
| error EOL |
|---|
| 144 |
; |
|---|
| 145 |
|
|---|
| 146 |
bus_statement: BUS i2cbus_name adapter_name |
|---|
| 147 |
{ sensors_bus new_el; |
|---|
| 148 |
new_el.lineno = $1; |
|---|
| 149 |
new_el.number = $2; |
|---|
| 150 |
new_el.adapter = $3; |
|---|
| 151 |
bus_add_el(&new_el); |
|---|
| 152 |
} |
|---|
| 153 |
; |
|---|
| 154 |
|
|---|
| 155 |
/* for compatibility, deprecated */ |
|---|
| 156 |
busalgo_statement: BUS i2cbus_name adapter_name algorithm_name |
|---|
| 157 |
{ sensors_bus new_el; |
|---|
| 158 |
new_el.lineno = $1; |
|---|
| 159 |
new_el.number = $2; |
|---|
| 160 |
new_el.adapter = $3; |
|---|
| 161 |
free($4); |
|---|
| 162 |
bus_add_el(&new_el); |
|---|
| 163 |
} |
|---|
| 164 |
; |
|---|
| 165 |
|
|---|
| 166 |
label_statement: LABEL function_name string |
|---|
| 167 |
{ sensors_label new_el; |
|---|
| 168 |
check_current_chip(); |
|---|
| 169 |
new_el.lineno = $1; |
|---|
| 170 |
new_el.name = $2; |
|---|
| 171 |
new_el.value = $3; |
|---|
| 172 |
label_add_el(&new_el); |
|---|
| 173 |
} |
|---|
| 174 |
; |
|---|
| 175 |
|
|---|
| 176 |
set_statement: SET function_name expression |
|---|
| 177 |
{ sensors_set new_el; |
|---|
| 178 |
check_current_chip(); |
|---|
| 179 |
new_el.lineno = $1; |
|---|
| 180 |
new_el.name = $2; |
|---|
| 181 |
new_el.value = $3; |
|---|
| 182 |
set_add_el(&new_el); |
|---|
| 183 |
} |
|---|
| 184 |
; |
|---|
| 185 |
|
|---|
| 186 |
compute_statement: COMPUTE function_name expression ',' expression |
|---|
| 187 |
{ sensors_compute new_el; |
|---|
| 188 |
check_current_chip(); |
|---|
| 189 |
new_el.lineno = $1; |
|---|
| 190 |
new_el.name = $2; |
|---|
| 191 |
new_el.from_proc = $3; |
|---|
| 192 |
new_el.to_proc = $5; |
|---|
| 193 |
compute_add_el(&new_el); |
|---|
| 194 |
} |
|---|
| 195 |
; |
|---|
| 196 |
|
|---|
| 197 |
ignore_statement: IGNORE function_name |
|---|
| 198 |
{ sensors_ignore new_el; |
|---|
| 199 |
check_current_chip(); |
|---|
| 200 |
new_el.lineno = $1; |
|---|
| 201 |
new_el.name = $2; |
|---|
| 202 |
ignore_add_el(&new_el); |
|---|
| 203 |
} |
|---|
| 204 |
; |
|---|
| 205 |
|
|---|
| 206 |
chip_statement: CHIP chip_name_list |
|---|
| 207 |
{ sensors_chip new_el; |
|---|
| 208 |
new_el.lineno = $1; |
|---|
| 209 |
new_el.labels = NULL; |
|---|
| 210 |
new_el.sets = NULL; |
|---|
| 211 |
new_el.computes = NULL; |
|---|
| 212 |
new_el.ignores = NULL; |
|---|
| 213 |
new_el.labels_count = new_el.labels_max = 0; |
|---|
| 214 |
new_el.sets_count = new_el.sets_max = 0; |
|---|
| 215 |
new_el.computes_count = new_el.computes_max = 0; |
|---|
| 216 |
new_el.ignores_count = new_el.ignores_max = 0; |
|---|
| 217 |
new_el.chips = $2; |
|---|
| 218 |
chip_add_el(&new_el); |
|---|
| 219 |
current_chip = sensors_config_chips + |
|---|
| 220 |
sensors_config_chips_count - 1; |
|---|
| 221 |
} |
|---|
| 222 |
; |
|---|
| 223 |
|
|---|
| 224 |
chip_name_list: chip_name |
|---|
| 225 |
{ |
|---|
| 226 |
$$.fits = NULL; |
|---|
| 227 |
$$.fits_count = $$.fits_max = 0; |
|---|
| 228 |
fits_add_el(&$1,$$); |
|---|
| 229 |
} |
|---|
| 230 |
| chip_name_list chip_name |
|---|
| 231 |
{ $$ = $1; |
|---|
| 232 |
fits_add_el(&$2,$$); |
|---|
| 233 |
} |
|---|
| 234 |
; |
|---|
| 235 |
|
|---|
| 236 |
expression: FLOAT |
|---|
| 237 |
{ $$ = malloc_expr(); |
|---|
| 238 |
$$->data.val = $1; |
|---|
| 239 |
$$->kind = sensors_kind_val; |
|---|
| 240 |
} |
|---|
| 241 |
| NAME |
|---|
| 242 |
{ $$ = malloc_expr(); |
|---|
| 243 |
$$->data.var = $1; |
|---|
| 244 |
$$->kind = sensors_kind_var; |
|---|
| 245 |
} |
|---|
| 246 |
| '@' |
|---|
| 247 |
{ $$ = malloc_expr(); |
|---|
| 248 |
$$->kind = sensors_kind_source; |
|---|
| 249 |
} |
|---|
| 250 |
| expression '+' expression |
|---|
| 251 |
{ $$ = malloc_expr(); |
|---|
| 252 |
$$->kind = sensors_kind_sub; |
|---|
| 253 |
$$->data.subexpr.op = sensors_add; |
|---|
| 254 |
$$->data.subexpr.sub1 = $1; |
|---|
| 255 |
$$->data.subexpr.sub2 = $3; |
|---|
| 256 |
} |
|---|
| 257 |
| expression '-' expression |
|---|
| 258 |
{ $$ = malloc_expr(); |
|---|
| 259 |
$$->kind = sensors_kind_sub; |
|---|
| 260 |
$$->data.subexpr.op = sensors_sub; |
|---|
| 261 |
$$->data.subexpr.sub1 = $1; |
|---|
| 262 |
$$->data.subexpr.sub2 = $3; |
|---|
| 263 |
} |
|---|
| 264 |
| expression '*' expression |
|---|
| 265 |
{ $$ = malloc_expr(); |
|---|
| 266 |
$$->kind = sensors_kind_sub; |
|---|
| 267 |
$$->data.subexpr.op = sensors_multiply; |
|---|
| 268 |
$$->data.subexpr.sub1 = $1; |
|---|
| 269 |
$$->data.subexpr.sub2 = $3; |
|---|
| 270 |
} |
|---|
| 271 |
| expression '/' expression |
|---|
| 272 |
{ $$ = malloc_expr(); |
|---|
| 273 |
$$->kind = sensors_kind_sub; |
|---|
| 274 |
$$->data.subexpr.op = sensors_divide; |
|---|
| 275 |
$$->data.subexpr.sub1 = $1; |
|---|
| 276 |
$$->data.subexpr.sub2 = $3; |
|---|
| 277 |
} |
|---|
| 278 |
| '-' expression %prec NEG |
|---|
| 279 |
{ $$ = malloc_expr(); |
|---|
| 280 |
$$->kind = sensors_kind_sub; |
|---|
| 281 |
$$->data.subexpr.op = sensors_negate; |
|---|
| 282 |
$$->data.subexpr.sub1 = $2; |
|---|
| 283 |
$$->data.subexpr.sub2 = NULL; |
|---|
| 284 |
} |
|---|
| 285 |
| '(' expression ')' |
|---|
| 286 |
{ $$ = $2; } |
|---|
| 287 |
| '^' expression |
|---|
| 288 |
{ $$ = malloc_expr(); |
|---|
| 289 |
$$->kind = sensors_kind_sub; |
|---|
| 290 |
$$->data.subexpr.op = sensors_exp; |
|---|
| 291 |
$$->data.subexpr.sub1 = $2; |
|---|
| 292 |
$$->data.subexpr.sub2 = NULL; |
|---|
| 293 |
} |
|---|
| 294 |
| '`' expression |
|---|
| 295 |
{ $$ = malloc_expr(); |
|---|
| 296 |
$$->kind = sensors_kind_sub; |
|---|
| 297 |
$$->data.subexpr.op = sensors_log; |
|---|
| 298 |
$$->data.subexpr.sub1 = $2; |
|---|
| 299 |
$$->data.subexpr.sub2 = NULL; |
|---|
| 300 |
} |
|---|
| 301 |
; |
|---|
| 302 |
|
|---|
| 303 |
i2cbus_name: NAME |
|---|
| 304 |
{ int res = sensors_parse_i2cbus_name($1,&$$); |
|---|
| 305 |
free($1); |
|---|
| 306 |
if (res) { |
|---|
| 307 |
sensors_yyerror("Parse error in i2c bus name"); |
|---|
| 308 |
YYERROR; |
|---|
| 309 |
} |
|---|
| 310 |
} |
|---|
| 311 |
; |
|---|
| 312 |
|
|---|
| 313 |
adapter_name: NAME |
|---|
| 314 |
{ sensors_strip_of_spaces($1); |
|---|
| 315 |
$$ = $1; } |
|---|
| 316 |
; |
|---|
| 317 |
|
|---|
| 318 |
algorithm_name: NAME |
|---|
| 319 |
{ sensors_strip_of_spaces($1); |
|---|
| 320 |
$$ = $1; } |
|---|
| 321 |
; |
|---|
| 322 |
|
|---|
| 323 |
function_name: NAME |
|---|
| 324 |
{ $$ = $1; } |
|---|
| 325 |
; |
|---|
| 326 |
|
|---|
| 327 |
string: NAME |
|---|
| 328 |
{ $$ = $1; } |
|---|
| 329 |
; |
|---|
| 330 |
|
|---|
| 331 |
chip_name: NAME |
|---|
| 332 |
{ int res = sensors_parse_chip_name($1,&$$); |
|---|
| 333 |
free($1); |
|---|
| 334 |
if (res) { |
|---|
| 335 |
sensors_yyerror("Parse error in chip name"); |
|---|
| 336 |
YYERROR; |
|---|
| 337 |
} |
|---|
| 338 |
} |
|---|
| 339 |
; |
|---|
| 340 |
|
|---|
| 341 |
%% |
|---|
| 342 |
|
|---|
| 343 |
void sensors_yyerror(const char *err) |
|---|
| 344 |
{ |
|---|
| 345 |
if (sensors_lex_error[0]) { |
|---|
| 346 |
sensors_parse_error(sensors_lex_error,sensors_yylineno); |
|---|
| 347 |
sensors_lex_error[0] = '\0'; |
|---|
| 348 |
} else |
|---|
| 349 |
sensors_parse_error(err,sensors_yylineno); |
|---|
| 350 |
} |
|---|
| 351 |
|
|---|
| 352 |
sensors_expr *malloc_expr(void) |
|---|
| 353 |
{ |
|---|
| 354 |
sensors_expr *res = malloc(sizeof(sensors_expr)); |
|---|
| 355 |
if (! res) |
|---|
| 356 |
sensors_fatal_error("malloc_expr","Allocating a new expression"); |
|---|
| 357 |
return res; |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|