Changeset 119
- Timestamp:
- 12/25/98 22:51:59 (14 years ago)
- Location:
- lm-sensors/trunk/lib
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/lib/Module.mk
r99 r119 43 43 LIBSHOBJECTS := $(LIBCSOURCES:.c=.lo) $(LIBOTHEROBJECTS:.o=.lo) 44 44 LIBSTOBJECTS := $(LIBCSOURCES:.c=.ao) $(LIBOTHEROBJECTS:.o=.ao) 45 LIBEXTRACLEAN := $(MODULE_DIR)/conf _parse.h45 LIBEXTRACLEAN := $(MODULE_DIR)/conf-parse.h 46 46 47 47 LIBHEADERFILES := $(MODULE_DIR)/error.h $(MODULE_DIR)/sensors.h -
lm-sensors/trunk/lib/access.c
r110 r119 280 280 return NULL; 281 281 } 282 283 int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, 284 double val, double *result) 285 { 286 double res1,res2; 287 int res; 288 sensors_chip_feature *feature; 289 290 if (expr->kind == sensors_kind_val) { 291 *result = expr->data.val; 292 return 0; 293 } 294 if (expr->kind == sensors_kind_source) { 295 *result = val; 296 return 0; 297 } 298 if (expr->kind == sensors_kind_var) { 299 if (! (feature = sensors_lookup_feature_name(chipname.prefix, 300 expr->data.var))) 301 return SENSORS_ERR_NO_ENTRY; 302 if (! (res = sensors_get_feature(chipname,feature->number,result))) 303 return res; 304 return 0; 305 } 306 if ((res = sensors_eval_expr(chipname,expr->data.subexpr.sub1,val,&res1))) 307 return res; 308 if (expr->data.subexpr.sub2 && 309 (res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2))) 310 return res; 311 switch(expr->data.subexpr.op) { 312 case sensors_add: 313 *result = res1 + res2; 314 return 0; 315 case sensors_sub: 316 *result = res1 - res2; 317 return 0; 318 case sensors_multiply: 319 *result = res1 * res2; 320 return 0; 321 case sensors_divide: 322 if (res2 == 0.0) 323 return -SENSORS_ERR_DIV_ZERO; 324 *result = res1 / res2; 325 return 0; 326 case sensors_negate: 327 *result = -res1; 328 return 0; 329 } 330 return 0; 331 } 332 282 333 -
lm-sensors/trunk/lib/access.h
r110 r119 23 23 #include "sensors.h" 24 24 #include "data.h" 25 26 typedef struct sensors_chip_feature {27 int number;28 const char *name;29 int logical_mapping;30 int compute_mapping;31 int mode;32 int sysctl;33 int offset;34 int scaling;35 } sensors_chip_feature;36 37 typedef struct sensors_chip_features {38 const char *prefix;39 struct sensors_chip_feature *feature;40 } sensors_chip_features;41 42 extern sensors_chip_features sensors_chip_features_list[];43 25 44 26 /* Returns, one by one, a pointer to all sensor_chip structs of the … … 68 50 extern int sensors_substitute_busses(void); 69 51 52 53 /* Parse an i2c bus name into its components. Returns 0 on succes, a value from 54 error.h on failure. */ 55 extern int sensors_parse_i2cbus_name(const char *name, int *res); 56 57 /* Evaluate an expression */ 58 extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, 59 double val, double *result); 60 61 70 62 #endif /* def LIB_SENSORS_ACCESS_H */ -
lm-sensors/trunk/lib/chips.c
r116 r119 19 19 20 20 #include "chips.h" 21 #include " access.h"21 #include "data.h" 22 22 #include "sensors.h" 23 23 #include "src/sensors.h" -
lm-sensors/trunk/lib/conf-parse.y
r107 r119 28 28 #include "general.h" 29 29 #include "error.h" 30 #include "conf.h" 30 31 31 32 /* These two functions are defined in conf-lex.l */ -
lm-sensors/trunk/lib/data.c
r107 r119 24 24 #include "data.h" 25 25 #include "sensors.h" 26 #include "access.h"27 26 28 27 sensors_chip *sensors_config_chips = NULL; … … 202 201 203 202 204 int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,205 double val, double *result)206 {207 double res1,res2;208 int res;209 sensors_chip_feature *feature;210 211 if (expr->kind == sensors_kind_val) {212 *result = expr->data.val;213 return 0;214 }215 if (expr->kind == sensors_kind_source) {216 *result = val;217 return 0;218 }219 if (expr->kind == sensors_kind_var) {220 /* We should check the kind of variable here! */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)))229 return res;230 if (expr->data.subexpr.sub2 &&231 (res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2)))232 return res;233 switch(expr->data.subexpr.op) {234 case sensors_add:235 *result = res1 + res2;236 return 0;237 case sensors_sub:238 *result = res1 - res2;239 return 0;240 case sensors_multiply:241 *result = res1 * res2;242 return 0;243 case sensors_divide:244 if (res2 == 0.0)245 return -SENSORS_ERR_DIV_ZERO;246 *result = res1 / res2;247 return 0;248 case sensors_negate:249 *result = -res1;250 return 0;251 }252 return 0;253 }254 255 203 int sensors_substitute_chip(sensors_chip_name *name,int lineno) 256 204 { … … 274 222 } 275 223 276 /* Well, if we did not find anything, j -sensors_proc_bus_count; so if224 /* Well, if we did not find anything, j = sensors_proc_bus_count; so if 277 225 we set this chip's bus number to j, it will never be matched. Good. */ 278 226 name->bus = j; -
lm-sensors/trunk/lib/data.h
r107 r119 27 27 data. */ 28 28 29 /* Kinds of expression operators recognized */ 29 30 typedef enum sensors_operation { 30 31 sensors_add, sensors_sub, sensors_multiply, sensors_divide, 31 32 sensors_negate } sensors_operation; 32 33 34 /* An expression can have several forms */ 33 35 typedef enum sensors_expr_kind { 34 36 sensors_kind_val, sensors_kind_source, sensors_kind_var, 35 37 sensors_kind_sub } sensors_expr_kind; 36 38 39 /* An expression. It is either a floating point value, a variable name, 40 an operation on subexpressions, or the special value 'sub' } */ 37 41 struct sensors_expr; 38 42 … … 51 55 } data; 52 56 } sensors_expr; 53 54 57 58 /* Config file label declaration: a feature name, combined with the label 59 value */ 55 60 typedef struct sensors_label { 56 61 char *name; … … 59 64 } sensors_label; 60 65 66 /* Config file set declaration: a feature name, combined with an expression */ 61 67 typedef struct sensors_set { 62 68 char *name; … … 65 71 } sensors_set; 66 72 73 /* Config file compute declaration: a feature name, combined with two 74 expressions */ 67 75 typedef struct sensors_compute { 68 76 char *name; … … 72 80 } sensors_compute; 73 81 82 /* A list of chip names, used to represent a config file chips declaration */ 74 83 typedef struct sensors_chip_name_list { 75 84 sensors_chip_name *fits; … … 78 87 } sensors_chip_name_list; 79 88 89 /* A config file chip block */ 80 90 typedef struct sensors_chip { 81 91 sensors_chip_name_list chips; … … 92 102 } sensors_chip; 93 103 94 typedef enum sensors_bus_type {sensors_i2c, sensors_isa, 95 sensors_smbus } sensors_bus_type; 96 104 /* Config file bus declaration: the i2c bus number, combined with adapter 105 and algorithm names */ 97 106 typedef struct sensors_bus { 98 107 int number; … … 102 111 } sensors_bus; 103 112 113 /* /proc/sys/dev/sensors/chips line representation */ 104 114 typedef struct sensors_proc_chips_entry { 105 115 int sysctl; … … 107 117 } sensors_proc_chips_entry; 108 118 119 /* Internal data about a single chip feature. 120 name is the string name used to refer to this feature (both in config 121 files and through user functions); 122 number is the internal feature number, used in many functions to refer 123 to this feature 124 logical_mapping is either SENSORS_NO_MAPPING is this is feature is the 125 main element of category; or it is the number of a feature with which 126 this feature is logically grouped (a group could be fan, fan_max and 127 fan_div) 128 compute_mapping is like logical_mapping, only it refers to another 129 feature whose compute line will be inherited (a group could be fan and 130 fan_max, but not fan_div) 131 mode is SENSORS_MODE_NO_RW, SENSORS_MODE_R, SENSORS_MODE_W or 132 SENSORS_MODE_RW, for unaccessible, readable, writable, and both readable 133 and writable. 134 sysctl is the SYSCTL id of the file the value can be found in; 135 offset is the (byte) offset of the place this feature can be found; 136 Divide the read value by 10**scaling to get the real value */ 137 typedef struct sensors_chip_feature { 138 int number; 139 const char *name; 140 int logical_mapping; 141 int compute_mapping; 142 int mode; 143 int sysctl; 144 int offset; 145 int scaling; 146 } sensors_chip_feature; 147 148 /* Internal data about all features of a type of chip */ 149 typedef struct sensors_chip_features { 150 const char *prefix; 151 struct sensors_chip_feature *feature; 152 } sensors_chip_features; 109 153 110 154 extern sensors_chip *sensors_config_chips; … … 124 168 extern int sensors_proc_bus_max; 125 169 126 /* Parse an i2c bus name into its components. Returns 0 on succes, a value from 127 error.h on failure. */ 128 extern int sensors_parse_i2cbus_name(const char *name, int *res); 129 130 extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr, 131 double val, double *result); 132 170 extern sensors_chip_features sensors_chip_features_list[]; 133 171 134 172 #endif /* def LIB_SENSORS_DATA_H */ -
lm-sensors/trunk/lib/error.h
r101 r119 44 44 memory left) is detected. Give it a new value, and your own function 45 45 is called instead of the default (which prints to stderr and ends 46 the program). */46 the program). Never let it return! */ 47 47 extern void (*sensors_fatal_error) (const char *proc, const char *err); 48 48 -
lm-sensors/trunk/lib/init.c
r107 r119 25 25 #include "error.h" 26 26 #include "access.h" 27 28 extern int sensors_yyparse(void); 29 extern FILE *sensors_yyin; 27 #include "conf.h" 30 28 31 29 static void free_proc_chips_entry(sensors_proc_chips_entry entry);
