aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-08-08 20:52:19 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2017-08-14 01:56:47 -0700
commit90103feadf0fcbe866e82cc6f424b0662f5f5474 (patch)
tree326d2a5ac00b87c49570bd069c9b644e567c59c7
parentb7086345dc5402ceda5e079fdb9f848f00216e40 (diff)
Move hardinfo_clean_label() and hardinfo_clean_value() to util.c
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r--hardinfo/util.c56
-rw-r--r--includes/hardinfo.h8
-rw-r--r--modules/devices/devicetree.c57
3 files changed, 65 insertions, 56 deletions
diff --git a/hardinfo/util.c b/hardinfo/util.c
index 60e43ab1..6ddf56ad 100644
--- a/hardinfo/util.c
+++ b/hardinfo/util.c
@@ -1323,3 +1323,59 @@ gboolean g_strv_contains(const gchar * const * strv, const gchar *str) {
return 0;
}
#endif
+
+/* Hardinfo labels that have # are truncated and/or hidden.
+ * Labels can't have $ because that is the delimiter in
+ * moreinfo. */
+gchar *hardinfo_clean_label(const gchar *v, int replacing) {
+ gchar *clean, *p;
+
+ p = clean = g_strdup(v);
+ while (*p != 0) {
+ switch(*p) {
+ case '#': case '$':
+ *p = '_';
+ break;
+ default:
+ break;
+ }
+ p++;
+ }
+ if (replacing)
+ g_free((gpointer)v);
+ return clean;
+}
+
+/* hardinfo uses the values as {ht,x}ml, apparently */
+gchar *hardinfo_clean_value(const gchar *v, int replacing) {
+ gchar *clean, *tmp;
+ gchar **vl;
+ if (v == NULL) return NULL;
+
+ vl = g_strsplit(v, "&", -1);
+ if (g_strv_length(vl) > 1)
+ clean = g_strjoinv("&amp;", vl);
+ else
+ clean = g_strdup(v);
+ g_strfreev(vl);
+
+ vl = g_strsplit(clean, "<", -1);
+ if (g_strv_length(vl) > 1) {
+ tmp = g_strjoinv("&lt;", vl);
+ g_free(clean);
+ clean = tmp;
+ }
+ g_strfreev(vl);
+
+ vl = g_strsplit(clean, ">", -1);
+ if (g_strv_length(vl) > 1) {
+ tmp = g_strjoinv("&gt;", vl);
+ g_free(clean);
+ clean = tmp;
+ }
+ g_strfreev(vl);
+
+ if (replacing)
+ g_free((gpointer)v);
+ return clean;
+}
diff --git a/includes/hardinfo.h b/includes/hardinfo.h
index 243f850f..8d5f70f1 100644
--- a/includes/hardinfo.h
+++ b/includes/hardinfo.h
@@ -169,4 +169,12 @@ gchar *moreinfo_lookup(gchar *key);
gboolean g_strv_contains(const gchar * const * strv, const gchar *str);
#endif
+/* Hardinfo labels that have # are truncated and/or hidden.
+ * Labels can't have $ because that is the delimiter in
+ * moreinfo.
+ * replacing = true will free v */
+gchar *hardinfo_clean_label(const gchar *v, int replacing);
+/* hardinfo uses the values as {ht,x}ml, apparently */
+gchar *hardinfo_clean_value(const gchar *v, int replacing);
+
#endif /* __HARDINFO_H__ */
diff --git a/modules/devices/devicetree.c b/modules/devices/devicetree.c
index bae4850e..6fce066a 100644
--- a/modules/devices/devicetree.c
+++ b/modules/devices/devicetree.c
@@ -24,66 +24,11 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdint.h>
+#include "hardinfo.h"
#include "devices.h"
#include "cpu_util.h"
#include "dt_util.h"
-/* Hardinfo labels that have # are truncated and/or hidden.
- * Labels can't have $ because that is the delimiter in
- * moreinfo. */
-gchar *hardinfo_clean_label(const gchar *v, int replacing) {
- gchar *clean, *p;
-
- p = clean = g_strdup(v);
- while (*p != 0) {
- switch(*p) {
- case '#': case '$':
- *p = '_';
- break;
- default:
- break;
- }
- p++;
- }
- if (replacing)
- g_free((gpointer)v);
- return clean;
-}
-
-/* hardinfo uses the values as {ht,x}ml, apparently */
-gchar *hardinfo_clean_value(const gchar *v, int replacing) {
- gchar *clean, *tmp;
- gchar **vl;
- if (v == NULL) return NULL;
-
- vl = g_strsplit(v, "&", -1);
- if (g_strv_length(vl) > 1)
- clean = g_strjoinv("&amp;", vl);
- else
- clean = g_strdup(v);
- g_strfreev(vl);
-
- vl = g_strsplit(clean, "<", -1);
- if (g_strv_length(vl) > 1) {
- tmp = g_strjoinv("&lt;", vl);
- g_free(clean);
- clean = tmp;
- }
- g_strfreev(vl);
-
- vl = g_strsplit(clean, ">", -1);
- if (g_strv_length(vl) > 1) {
- tmp = g_strjoinv("&gt;", vl);
- g_free(clean);
- clean = tmp;
- }
- g_strfreev(vl);
-
- if (replacing)
- g_free((gpointer)v);
- return clean;
-}
-
#include "devicetree/rpi_data.c"
#include "devicetree/pmac_data.c"