Changeset 107

Show
Ignore:
Timestamp:
12/24/98 02:13:44 (15 years ago)
Author:
frodo
Message:

Expanded expressions, slightly new syntax

An expression can now refer to the value it has to compute (@), but also to
other values. This is now perfectly valid as an expression:

vid + in_min - in_max * 2 / @

Not that this is very sensible, but you get the idea. Please install the
new example config file, or replace all old 'val' occurences with '@'.

Location:
lm-sensors/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/etc/sensors.conf.eg

    r106 r107  
    4747# two expressions in it: the first describes how the /proc value must 
    4848# be translated to a user value, the second how a user value must be 
    49 # translated to a /proc value. 'val' is the value to operate on. 
     49# translated to a /proc value. '@' is the value to operate on. You may 
     50# refer to other readable features (like '2 * vid'). 
    5051 
    5152# Like for the label statement, there are logical groups here. They are 
     
    7071 
    7172# These would lead to these declarations: 
    72 # compute in3 ((6.8/10)+1)*val ,  val/((6.8/10)+1) 
    73 # compute in4 ((30/10)+1)*val  ,  val/((30/10)+1) 
    74 # compute in5 -(240/60)*val    ,  -val/(240/60) 
    75 # compute in6 -(100/60)*val    ,  -val/(100/60) 
     73# compute in3 ((6.8/10)+1)*@ ,  @/((6.8/10)+1) 
     74# compute in4 ((30/10)+1)*@  ,  @/((30/10)+1) 
     75# compute in5 -(240/60)*@    ,  -@/(240/60) 
     76# compute in6 -(100/60)*@    ,  -@/(100/60) 
    7677 
    7778# On almost any mainboard we have seen, the Winbond compute values lead to 
     
    8485 
    8586# These leads to these declarations: 
    86   compute in3 ((6.8/10)+1)*val ,  val/((6.8/10)+1) 
    87   compute in4 ((28/10)+1)*val  ,  val/((28/10)+1) 
    88   compute in5 -(210/60.4)*val  ,  -val/(210/60.4) 
    89   compute in6 -(90.9/60.4)*val ,  -val/(90.9/60.4) 
     87  compute in3 ((6.8/10)+1)*@ ,  @/((6.8/10)+1) 
     88  compute in4 ((28/10)+1)*@  ,  @/((28/10)+1) 
     89  compute in5 -(210/60.4)*@  ,  -@/(210/60.4) 
     90  compute in6 -(90.9/60.4)*@ ,  -@/(90.9/60.4) 
    9091 
    9192# Set statements set things like limits. Complete expressions can be 
  • lm-sensors/trunk/lib/access.c

    r105 r107  
    188188  if (! expr) 
    189189    *result = val; 
    190   else if ((res = sensors_eval_expr(expr,val,result))) 
     190  else if ((res = sensors_eval_expr(name,expr,val,result))) 
    191191    return res; 
    192192  return 0; 
     
    214214        expr = chip->computes->to_proc; 
    215215  if (expr) 
    216     if ((res = sensors_eval_expr(expr,value,&value))) 
     216    if ((res = sensors_eval_expr(name,expr,value,&value))) 
    217217      return res; 
    218218  if (sensors_write_proc(name,feature,value)) 
  • lm-sensors/trunk/lib/conf-lex.l

    r98 r107  
    171171                  return ','; 
    172172                } 
     173<MIDDLE>"@"     { 
     174                  return '@'; 
     175                } 
    173176 
    174177 /* Quoted string */ 
  • lm-sensors/trunk/lib/conf-parse.y

    r101 r107  
    212212                    $$->kind = sensors_kind_var; 
    213213                  } 
     214                | '@' 
     215                  { $$ = malloc_expr(); 
     216                    $$->kind = sensors_kind_source; 
     217                  } 
    214218                | expression '+' expression 
    215219                  { $$ = malloc_expr();  
  • lm-sensors/trunk/lib/data.c

    r101 r107  
    2424#include "data.h" 
    2525#include "sensors.h" 
     26#include "access.h" 
    2627 
    2728sensors_chip *sensors_config_chips = NULL; 
     
    201202 
    202203 
    203 int sensors_eval_expr(sensors_expr *expr, double val, double *result) 
     204int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, 
     205                      double val, double *result) 
    204206{ 
    205207  double res1,res2; 
    206208  int res; 
     209  sensors_chip_feature *feature; 
    207210 
    208211  if (expr->kind == sensors_kind_val) { 
     
    210213    return 0; 
    211214  } 
     215  if (expr->kind == sensors_kind_source) { 
     216    *result = val; 
     217    return 0; 
     218  } 
    212219  if (expr->kind == sensors_kind_var) { 
    213220    /* We should check the kind of variable here! */ 
    214     *result = val; 
    215     return 0; 
    216   } 
    217   if ((res = sensors_eval_expr(expr->data.subexpr.sub1,val,&res1))) 
     221    if (! (feature = sensors_lookup_feature_name(chipname.prefix, 
     222                                                expr->data.var))) 
     223      return SENSORS_ERR_NO_ENTRY; 
     224    if (! (res = sensors_get_feature(chipname,feature->number,result))) 
     225      return res; 
     226    return 0; 
     227  } 
     228  if ((res = sensors_eval_expr(chipname,expr->data.subexpr.sub1,val,&res1))) 
    218229    return res; 
    219230  if (expr->data.subexpr.sub2 &&  
    220       (res = sensors_eval_expr(expr->data.subexpr.sub2,val,&res2))) 
     231      (res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2))) 
    221232    return res; 
    222233  switch(expr->data.subexpr.op) { 
  • lm-sensors/trunk/lib/data.h

    r99 r107  
    3232 
    3333typedef enum sensors_expr_kind { 
    34   sensors_kind_val, sensors_kind_var, sensors_kind_sub } sensors_expr_kind; 
     34  sensors_kind_val, sensors_kind_source, sensors_kind_var,  
     35  sensors_kind_sub } sensors_expr_kind; 
    3536 
    3637struct sensors_expr; 
     
    127128extern int sensors_parse_i2cbus_name(const char *name, int *res); 
    128129 
    129 extern int sensors_eval_expr(sensors_expr *expr, double val, double *result); 
     130extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, 
     131                             double val, double *result); 
    130132 
    131133 
  • lm-sensors/trunk/lib/init.c

    r101 r107  
    2424#include "proc.h" 
    2525#include "error.h" 
     26#include "access.h" 
    2627 
    2728extern int sensors_yyparse(void);