summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrodo Looijaard <frodol@dds.nl>1998-12-22 01:25:25 +0000
committerFrodo Looijaard <frodol@dds.nl>1998-12-22 01:25:25 +0000
commit849acbe439513229508e73662ce2f498b47e7f88 (patch)
tree3c7d2d3498668cd357d7687fdbdf7c6ea24fd4e2 /lib
parent77ba27fd04de0313024b3159b5ef5d6f09bc6e9d (diff)
downloadlm-sensors-git-849acbe439513229508e73662ce2f498b47e7f88.tar.gz
More libary stuff
The bus translation functions. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@101 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'lib')
-rw-r--r--lib/access.h4
-rw-r--r--lib/conf-parse.y6
-rw-r--r--lib/data.c46
-rw-r--r--lib/error.h3
-rw-r--r--lib/general.c8
-rw-r--r--lib/general.h3
-rw-r--r--lib/init.c4
-rw-r--r--lib/proc.c4
-rw-r--r--lib/proc.h3
-rw-r--r--lib/sensors.h4
10 files changed, 80 insertions, 5 deletions
diff --git a/lib/access.h b/lib/access.h
index 097edf24..baa934ba 100644
--- a/lib/access.h
+++ b/lib/access.h
@@ -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 */
diff --git a/lib/conf-parse.y b/lib/conf-parse.y
index 4122a8c5..2f817d55 100644
--- a/lib/conf-parse.y
+++ b/lib/conf-parse.y
@@ -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
diff --git a/lib/data.c b/lib/data.c
index 9cb92d75..8cd97348 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -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;
+}
diff --git a/lib/error.h b/lib/error.h
index 06eac7cf..e45c8c32 100644
--- a/lib/error.h
+++ b/lib/error.h
@@ -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
diff --git a/lib/general.c b/lib/general.c
index 39c9b4bf..b242a14c 100644
--- a/lib/general.c
+++ b/lib/general.c
@@ -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';
+}
diff --git a/lib/general.h b/lib/general.h
index 4c85e350..4f8a69b7 100644
--- a/lib/general.h
+++ b/lib/general.h
@@ -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 */
diff --git a/lib/init.c b/lib/init.c
index bf3574e7..48b3e91a 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -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;
}
diff --git a/lib/proc.c b/lib/proc.c
index f01c1fb6..9de85b86 100644
--- a/lib/proc.c
+++ b/lib/proc.c
@@ -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);
diff --git a/lib/proc.h b/lib/proc.h
index bbd0f1eb..618357eb 100644
--- a/lib/proc.h
+++ b/lib/proc.h
@@ -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);
diff --git a/lib/sensors.h b/lib/sensors.h
index aa7171bf..944a9927 100644
--- a/lib/sensors.h
+++ b/lib/sensors.h
@@ -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