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 /hardinfo | |
parent | ed11c87c2cc56fe40f6d4503cf0cc56e7ed841f7 (diff) |
DMI: allow specifying type for dmi_chassis_type_str()
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'hardinfo')
-rw-r--r-- | hardinfo/dmi_util.c | 74 |
1 files changed, 38 insertions, 36 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; } |