diff options
author | Burt P <pburt0@gmail.com> | 2017-08-16 18:42:43 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2017-08-27 08:21:05 -0700 |
commit | 0c9c83526b1d740d0c71e527a5f5b0af1a8de35e (patch) | |
tree | 2287085a19852687fe187f05efd27644b3fd5c40 | |
parent | ed11c87c2cc56fe40f6d4503cf0cc56e7ed841f7 (diff) |
DMI: allow specifying type for dmi_chassis_type_str()
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | hardinfo/dmi_util.c | 74 | ||||
-rw-r--r-- | includes/dmi_util.h | 6 | ||||
-rw-r--r-- | modules/computer.c | 2 | ||||
-rw-r--r-- | modules/devices/dmi.c | 2 |
4 files changed, 45 insertions, 39 deletions
diff --git a/hardinfo/dmi_util.c b/hardinfo/dmi_util.c index cacca715..f87e3546 100644 --- a/hardinfo/dmi_util.c +++ b/hardinfo/dmi_util.c @@ -107,44 +107,46 @@ dmi_str_done: return ret; } -char *dmi_chassis_type_str(int with_val) { - gchar *chassis = dmi_get_str("chassis-type"); - if (chassis != NULL) { - static const char *types[] = { - N_("Invalid chassis type (0)"), - N_("Unknown chassis type"), /* 1 is "Other", but not helpful in HardInfo */ - N_("Unknown chassis type"), - N_("Desktop"), - N_("Low-profile Desktop"), - N_("Pizza Box"), - N_("Mini Tower"), - N_("Tower"), - N_("Portable"), - N_("Laptop"), - N_("Notebook"), - N_("Handheld"), - N_("Docking Station"), - N_("All-in-one"), - N_("Subnotebook"), - N_("Space-saving"), - N_("Lunch Box"), - N_("Main Server Chassis"), - N_("Expansion Chassis"), - N_("Sub Chassis"), - N_("Bus Expansion Chassis"), - N_("Peripheral Chassis"), - N_("RAID Chassis"), - N_("Rack Mount Chassis"), - N_("Sealed-case PC"), - }; - int chassis_type = atoi(chassis); +char *dmi_chassis_type_str(int chassis_type, int with_val) { + static const char *types[] = { + N_("Invalid chassis type (0)"), + N_("Unknown chassis type"), /* 1 is "Other", but not helpful in HardInfo */ + N_("Unknown chassis type"), + N_("Desktop"), + N_("Low-profile Desktop"), + N_("Pizza Box"), + N_("Mini Tower"), + N_("Tower"), + N_("Portable"), + N_("Laptop"), + N_("Notebook"), + N_("Handheld"), + N_("Docking Station"), + N_("All-in-one"), + N_("Subnotebook"), + N_("Space-saving"), + N_("Lunch Box"), + N_("Main Server Chassis"), + N_("Expansion Chassis"), + N_("Sub Chassis"), + N_("Bus Expansion Chassis"), + N_("Peripheral Chassis"), + N_("RAID Chassis"), + N_("Rack Mount Chassis"), + N_("Sealed-case PC"), + }; + + if (chassis_type <= 0) { + gchar *chassis = dmi_get_str("chassis-type"); + chassis_type = atoi(chassis); g_free(chassis); + } - if (chassis_type >= 0 && chassis_type < G_N_ELEMENTS(types)) - if (with_val) - return g_strdup_printf("[%d] %s", chassis_type, _(types[chassis_type])); - else - return g_strdup(_(types[chassis_type])); + if (chassis_type >= 0 && chassis_type < G_N_ELEMENTS(types)) { + if (with_val) + return g_strdup_printf("[%d] %s", chassis_type, _(types[chassis_type])); + else + return g_strdup(_(types[chassis_type])); } return NULL; } diff --git a/includes/dmi_util.h b/includes/dmi_util.h index b92d4ff2..965bee91 100644 --- a/includes/dmi_util.h +++ b/includes/dmi_util.h @@ -3,6 +3,10 @@ const char *dmi_sysfs_root(void); char *dmi_get_str(const char *id_str); -char *dmi_chassis_type_str(int with_val); + +/* if chassis_type is <=0 it will be fetched from DMI. + * with_val = true, will return a string like "[3] Desktop" instead of just + * "Desktop". */ +char *dmi_chassis_type_str(int chassis_type, int with_val); #endif diff --git a/modules/computer.c b/modules/computer.c index 5f346733..388c305a 100644 --- a/modules/computer.c +++ b/modules/computer.c @@ -307,7 +307,7 @@ static gchar *detect_machine_type(void) GDir *dir; gchar *chassis; - chassis = dmi_chassis_type_str(0); + chassis = dmi_chassis_type_str(-1, 0); if (chassis != NULL) return chassis; diff --git a/modules/devices/dmi.c b/modules/devices/dmi.c index a3620959..3f3f6800 100644 --- a/modules/devices/dmi.c +++ b/modules/devices/dmi.c @@ -85,7 +85,7 @@ gboolean dmi_get_info() dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, _(info->name) ); } else if (group && info->id_str) { if (strcmp(info->id_str, "chassis-type") == 0) - value = dmi_chassis_type_str(1); + value = dmi_chassis_type_str(-1, 1); else value = dmi_get_str(info->id_str); |