diff options
| -rw-r--r-- | hardinfo/util.c | 56 | ||||
| -rw-r--r-- | includes/hardinfo.h | 8 | ||||
| -rw-r--r-- | modules/devices/devicetree.c | 57 | 
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("&", vl); +    else +        clean = g_strdup(v); +    g_strfreev(vl); + +    vl = g_strsplit(clean, "<", -1); +    if (g_strv_length(vl) > 1) { +        tmp = g_strjoinv("<", vl); +        g_free(clean); +        clean = tmp; +    } +    g_strfreev(vl); + +    vl = g_strsplit(clean, ">", -1); +    if (g_strv_length(vl) > 1) { +        tmp = g_strjoinv(">", 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("&", vl); -    else -        clean = g_strdup(v); -    g_strfreev(vl); - -    vl = g_strsplit(clean, "<", -1); -    if (g_strv_length(vl) > 1) { -        tmp = g_strjoinv("<", vl); -        g_free(clean); -        clean = tmp; -    } -    g_strfreev(vl); - -    vl = g_strsplit(clean, ">", -1); -    if (g_strv_length(vl) > 1) { -        tmp = g_strjoinv(">", 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"  | 
