More libary stuff

The bus translation functions.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@101 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard committed 1998-12-22 01:25:25 +00:00
1 parent 77ba27fd04
commit 849acbe439
10 files changed
+80 -5

No files matched your search

+4
View File
@@ -70,4 +70,8 @@ extern sensors_chip_feature *sensors_lookup_feature_nr(const char *prefix,
extern sensors_chip_feature *sensors_lookup_feature_name(const char *prefix,
const char *feature);
/* Substitute configuration bus numbers with real-world /proc bus numbers
in the chips lists */
extern int sensors_substitute_busses(void);
#endif /* def LIB_SENSORS_ACCESS_H */
+4 -2
View File
@@ -261,11 +261,13 @@ i2cbus_name: NAME
;
adapter_name: NAME
{ $$ = $1; }
{ sensors_strip_of_spaces($1);
$$ = $1; }
;
algorithm_name: NAME
{ $$ = $1; }
{ sensors_strip_of_spaces($1);
$$ = $1; }
;
function_name: NAME
+46
View File
@@ -32,6 +32,7 @@ sensors_bus *sensors_config_busses = NULL;
int sensors_config_busses_count = 0;
int sensors_config_busses_max = 0;
static int sensors_substitute_chip(sensors_chip_name *name,int lineno);
/* Wow, this must be one of the ugliest functions I have ever written.
The idea is that it parses a chip name. These are valid names:
@@ -239,5 +240,50 @@ int sensors_eval_expr(sensors_expr *expr, double val, double *result)
}
return 0;
}
int sensors_substitute_chip(sensors_chip_name *name,int lineno)
{
int i,j;
for (i = 0; i < sensors_config_busses_count; i++)
if (sensors_config_busses[i].number == name->bus)
break;
if (i == sensors_config_busses_count) {
sensors_parse_error("Undeclared i2c bus referenced",lineno);
name->bus = sensors_proc_bus_count;
return -SENSORS_ERR_BUS_NAME;
}
for (j = 0; j < sensors_proc_bus_count; j++) {
if (!strcmp(sensors_config_busses[i].adapter,
sensors_proc_bus[j].adapter) &&
!strcmp(sensors_config_busses[i].algorithm,
sensors_proc_bus[j].algorithm))
break;
}
/* Well, if we did not find anything, j - sensors_proc_bus_count; so if
we set this chip's bus number to j, it will never be matched. Good. */
name->bus = j;
return 0;
}
int sensors_substitute_busses(void)
{
int err,i,j,lineno;
sensors_chip_name_list *chips;
int res=0;
for(i = 0; i < sensors_config_chips_count; i++) {
lineno = sensors_config_chips[i].lineno;
chips = &sensors_config_chips[i].chips;
for(j = 0; j < chips->fits_count; j++)
if ((chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ISA) &&
(chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY) &&
(chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY_I2C))
if ((err = sensors_substitute_chip(chips->fits+j, lineno)))
res = err;
}
return res;
}
+2 -1
View File
@@ -36,7 +36,8 @@ extern const char *sensors_strerror(int errnum);
/* This function is called when a parse error is detected. Give it a new
value, and your own function is called instead of the default (which
prints to stderr). */
prints to stderr). This function may terminate the program, but it
usually outputs an error and returns. */
extern void (*sensors_parse_error) (const char *err, int lineno);
/* This function is called when an immediately fatal error (like no
+8
View File
@@ -74,3 +74,11 @@ void sensors_add_array_els(const void *els, int nr_els, void **list,
memcpy(((char *)*list) + *num_el * el_size, els, el_size * nr_els);
*num_el += nr_els;
}
/* Strip a string of all terminating spaces */
void sensors_strip_of_spaces(char *name)
{
int i;
for (i = strlen(name)-1; (i>=0) && (name[i] == ' '); i--);
name[i+1] = '\0';
}
+3
View File
@@ -33,4 +33,7 @@ extern void sensors_add_array_el(const void *el, void **list, int *num_el,
extern void sensors_add_array_els(const void *els, int nr_els, void **list,
int *num_el, int *max_el, int el_size);
/* Strip a string of all terminating spaces */
extern void sensors_strip_of_spaces(char *name);
#endif /* LIB_SENSORS_GENERAL */
+3 -1
View File
@@ -46,7 +46,9 @@ int sensors_init(FILE *input)
return res;
sensors_yyin = input;
if ((res = sensors_yyparse()))
return SENSORS_ERR_PARSE;
return -SENSORS_ERR_PARSE;
if ((res = sensors_substitute_busses()));
return res;
return 0;
}
+4
View File
@@ -95,6 +95,8 @@ int sensors_read_proc_bus(void)
if (!f)
return -SENSORS_ERR_PROC;
while (fgets(line,255,f)) {
if (strlen(line) > 0)
line[strlen(line)-1] = '\0';
if (! (border = rindex(line,'\t')))
goto ERROR;
if (! (entry.algorithm = strdup(border+1)))
@@ -112,6 +114,8 @@ int sensors_read_proc_bus(void)
goto ERROR;
if (sensors_parse_i2cbus_name(line,&entry.number))
goto ERROR;
sensors_strip_of_spaces(entry.algorithm);
sensors_strip_of_spaces(entry.adapter);
add_bus(&entry);
}
fclose(f);
+3
View File
@@ -23,6 +23,9 @@
/* Read /proc/sys/dev/sensors/chips */
extern int sensors_read_proc_chips(void);
/* Read /proc/bus/i2c */
extern int sensors_read_proc_bus(void);
/* Read a value out of a /proc file */
extern int sensors_read_proc(sensors_chip_name name, int feature,
double *value);
+3 -1
View File
@@ -36,7 +36,9 @@ typedef struct sensors_chip_name {
int addr;
} sensors_chip_name;
/* (Re)load the configuration file and the detected chips list. */
/* (Re)load the configuration file and the detected chips list. If this
returns a value unequal to zero, you are in trouble; you can not
assume anything will be initialized properly. */
extern int sensors_init(FILE *input);
/* Strictly optional clean-up function: You can't access anything after