mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-08 16:11:26 +00:00
Add a new function to libsensors doing the opposite of
sensors_parse_chip_name(). sensors_snprintf_chip_name() converts a chip name from its internal representation to a human readable string. So far, each user program had to reimplement this function. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4676 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
493d9b27f5
commit
edb42b3c16
7 files changed
+37
-14
No files matched your search
@@ -21,6 +21,7 @@ SVN HEAD
|
||||
Delete sensors_do_all_sets(), unused
|
||||
Pass structures by reference
|
||||
Drop support for dummy type
|
||||
New function sensors_snprintf_chip_name()
|
||||
Makefile: Drop the package and version targets
|
||||
Man page sensors.conf.5: Update the chip statement section
|
||||
Programs doc/*: Delete, obsolete
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ sensors_lookup_feature_name(const sensors_chip_name *chip, const char *feature)
|
||||
/* Check whether the chip name is an 'absolute' name, which can only match
|
||||
one chip, or whether it has wildcards. Returns 0 if it is absolute, 1
|
||||
if there are wildcards. */
|
||||
static int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
{
|
||||
if ((chip->prefix == SENSORS_CHIP_NAME_PREFIX_ANY) ||
|
||||
(chip->bus == SENSORS_CHIP_NAME_BUS_ANY) ||
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
extern const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *chip,
|
||||
int feature);
|
||||
|
||||
/* Check whether the chip name is an 'absolute' name, which can only match
|
||||
one chip, or whether it has wildcards. Returns 0 if it is absolute, 1
|
||||
if there are wildcards. */
|
||||
int sensors_chip_name_has_wildcards(const sensors_chip_name *chip);
|
||||
|
||||
sensors_feature_type sensors_feature_get_type(const char *name, int *nr);
|
||||
|
||||
#endif /* def LIB_SENSORS_ACCESS_H */
|
||||
+20
@@ -20,6 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "access.h"
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "sensors.h"
|
||||
@@ -154,6 +155,25 @@ ERROR:
|
||||
return -SENSORS_ERR_CHIP_NAME;
|
||||
}
|
||||
|
||||
int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
const sensors_chip_name *chip)
|
||||
{
|
||||
if (sensors_chip_name_has_wildcards(chip))
|
||||
return -SENSORS_ERR_WILDCARDS;
|
||||
|
||||
switch (chip->bus) {
|
||||
case SENSORS_CHIP_NAME_BUS_ISA:
|
||||
return snprintf(str, size, "%s-isa-%04x", chip->prefix,
|
||||
chip->addr);
|
||||
case SENSORS_CHIP_NAME_BUS_PCI:
|
||||
return snprintf(str, size, "%s-pci-%04x", chip->prefix,
|
||||
chip->addr);
|
||||
default:
|
||||
return snprintf(str, size, "%s-i2c-%d-%02x", chip->prefix,
|
||||
chip->bus, chip->addr);
|
||||
}
|
||||
}
|
||||
|
||||
int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
@@ -60,6 +60,12 @@ extern void sensors_cleanup(void);
|
||||
extern int sensors_parse_chip_name(const char *orig_name,
|
||||
sensors_chip_name *res);
|
||||
|
||||
/* Print a chip name from its internal representation. Note that chip should
|
||||
not contain wildcard values! Return the number of characters printed on
|
||||
success (same as snprintf), <0 on error. */
|
||||
int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
const sensors_chip_name *chip);
|
||||
|
||||
/* Compare two chips name descriptions, to see whether they could match.
|
||||
Return 0 if it does not match, return 1 if it does match. */
|
||||
extern int sensors_match_chip(const sensors_chip_name *chip1,
|
||||
|
||||
@@ -74,12 +74,8 @@ static const char *
|
||||
chipName
|
||||
(const sensors_chip_name *chip) {
|
||||
static char buffer[256];
|
||||
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
|
||||
sprintf (buffer, "%s-isa-%04x", chip->prefix, chip->addr);
|
||||
else if (chip->bus == SENSORS_CHIP_NAME_BUS_PCI)
|
||||
sprintf (buffer, "%s-pci-%04x", chip->prefix, chip->addr);
|
||||
else
|
||||
sprintf (buffer, "%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr);
|
||||
if (sensors_snprintf_chip_name(buffer, 256, chip) < 0)
|
||||
return NULL;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
+2
-7
@@ -298,13 +298,8 @@ const char *sprintf_chip_name(const sensors_chip_name *name)
|
||||
#define BUF_SIZE 200
|
||||
static char buf[BUF_SIZE];
|
||||
|
||||
if (name->bus == SENSORS_CHIP_NAME_BUS_ISA)
|
||||
snprintf(buf, BUF_SIZE, "%s-isa-%04x", name->prefix, name->addr);
|
||||
else if (name->bus == SENSORS_CHIP_NAME_BUS_PCI)
|
||||
snprintf(buf, BUF_SIZE, "%s-pci-%04x", name->prefix, name->addr);
|
||||
else
|
||||
snprintf(buf, BUF_SIZE, "%s-i2c-%d-%02x", name->prefix, name->bus,
|
||||
name->addr);
|
||||
if (sensors_snprintf_chip_name(buf, BUF_SIZE, name) < 0)
|
||||
return NULL;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user