hal: Branch 'master'
Richard Hughes
hughsient at kemper.freedesktop.org
Tue Oct 10 11:57:34 PDT 2006
hald/linux/acpi.c | 2 +-
hald/util.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
New commits:
diff-tree 3f628b804aef5373991cb081e4fd55c0b59d1e62 (from efc17f28a6f5048924189c0b8831702c60c5bf6b)
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Oct 10 19:57:27 2006 +0100
Make sure we get all of a multi-word battery.model value.
me at trinity:~> cat /proc/acpi/battery/BAT*/info | grep 'model number'
model number: DELL Y13385
Now, the current code does:
hal_util_set_string_elem_from_file (d, 'battery.model', path, 'info',
'model number', 0, TRUE);
and hence battery.model = 'DELL'
I need to know the complete model number with the 'Y13385'.I propose
adding GUINTMAX to the elem section of hal_util_grep_string_elem_from_file to
mean 'all of the line' rather than token x of the line.
Obviously, this only applies to string elements.
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 040cb33..3798f67 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -462,7 +462,7 @@ battery_refresh_add (HalDevice *d, const
hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info",
"OEM info", 0, TRUE);
hal_util_set_string_elem_from_file (d, "battery.model", path, "info",
- "model number", 0, TRUE);
+ "model number", G_MAXUINT, TRUE);
hal_util_set_string_elem_from_file (d, "battery.serial", path, "info",
"serial number", 0, TRUE);
hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info",
diff --git a/hald/util.c b/hald/util.c
index 405cc23..b92b3f6 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -564,6 +564,20 @@ hal_util_grep_string_elem_from_file (con
if (((line = hal_util_grep_file (directory, file, linestart, reuse)) == NULL) || (strlen (line) == 0))
goto out;
+ /* this means take all elements, e.g. "DELL Y7637" */
+ if (elem == G_MAXUINT) {
+ /* just a null string ": " we want to discard */
+ if (strlen (line) < 2) {
+ res = NULL;
+ goto out;
+ }
+ /* strip leading spaces, missing out the ":" first char */
+ line = g_strchug (line + 1);
+ strncpy (buf, line, sizeof (buf));
+ res = buf;
+ goto out;
+ }
+
tokens = g_strsplit_set (line, " \t:", 0);
for (i = 0, j = 0; tokens[i] != NULL; i++) {
if (strlen (tokens[i]) == 0)
@@ -579,7 +593,6 @@ hal_util_grep_string_elem_from_file (con
out:
if (tokens != NULL)
g_strfreev (tokens);
-
return res;
}
@@ -626,6 +639,7 @@ out:
* @param linestart Start of line, e.g. "design voltage"
* @param elem Element number after linestart to extract
* excluding whitespace and ':' characters.
+ * If set to G_MAXUINT then all elements are set
* @return TRUE, if, and only if, the value could be
* extracted and the property was set
*/
More information about the hal-commit
mailing list