summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-04-19 07:35:06 (GMT)
committerErwan Velu <erwan.velu@free.fr>2009-04-19 07:35:06 (GMT)
commit5f036aa1ec3557f444fb8c49f782d31dd53979e7 (patch)
treecb1c84a8235575b150b724685babea026b6e3d45
parentc6293d4dbc3c8b62ac64ca493234942860221983 (diff)
downloadhdt-5f036aa1ec3557f444fb8c49f782d31dd53979e7.zip
hdt-5f036aa1ec3557f444fb8c49f782d31dd53979e7.tar.gz
hdt-5f036aa1ec3557f444fb8c49f782d31dd53979e7.tar.bz2
hdt-5f036aa1ec3557f444fb8c49f782d31dd53979e7.tar.xz
hdt: removing multiple spaces
Impact: Improving visual experience Some hardware reported strings contains multiple spaces. This isn't very nice for managing display. The del_multiple_spaces() function is removing multiple spaces.
-rw-r--r--com32/hdt/hdt-cli-cpu.c2
-rw-r--r--com32/hdt/hdt-common.c33
-rw-r--r--com32/hdt/hdt-common.h1
-rw-r--r--com32/hdt/hdt-menu-processor.c4
4 files changed, 37 insertions, 3 deletions
diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c
index f12201c..ec5e3b6 100644
--- a/com32/hdt/hdt-cli-cpu.c
+++ b/com32/hdt/hdt-cli-cpu.c
@@ -41,7 +41,7 @@ void main_show_cpu(int argc __unused, char **argv __unused,
detect_dmi(hardware);
more_printf("CPU\n");
more_printf(" Manufacturer : %s \n", hardware->cpu.vendor);
- more_printf(" Product : %s \n", hardware->cpu.model);
+ more_printf(" Product : %s \n", del_multi_spaces(hardware->cpu.model));
if ((hardware->cpu.flags.lm == false)
&& (hardware->cpu.flags.smp == false)) {
more_printf(" Features : %d MhZ : x86 32bits\n",
diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c
index cb53f9e..0b073ac 100644
--- a/com32/hdt/hdt-common.c
+++ b/com32/hdt/hdt-common.c
@@ -483,6 +483,39 @@ char *remove_spaces(char *p)
return p;
}
+/* delete multiple spaces, one is enough */
+char *del_multi_spaces(char *p) {
+ /* Saving the original pointer*/
+ char *save=p;
+
+ /* Let's parse the complete string
+ * As we search for a double spacing
+ * we have to be sure then string is
+ * long enough to be processed */
+ while (*p && *p+1) {
+
+ /* If we have two consecutive spaces*/
+ if ((*p == ' ') && (*(p+1) == ' ')) {
+
+ /* Let's copy to the current position
+ * the content from the second space*/
+ strncpy(p,p+1,strlen(p+1));
+
+ /* The string is 1 char smaller*/
+ *(p+strlen(p)-1)='\0';
+
+ /* Don't increment the pointer as we
+ * changed the content of the current position*/
+ continue;
+ }
+
+ /* Nothing as been found, let's see on the next char*/
+ p++;
+ }
+ /* Returning the original pointer*/
+ return save;
+}
+
/* Reset the more_printf counter */
void reset_more_printf() {
display_line_nb=0;
diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h
index 11e1466..558a182 100644
--- a/com32/hdt/hdt-common.h
+++ b/com32/hdt/hdt-common.h
@@ -125,6 +125,7 @@ void reset_more_printf();
const char *find_argument(const char **argv, const char *argument);
char *remove_spaces(char *p);
char *skip_spaces(char *p);
+char *del_multi_spaces(char *p);
int detect_dmi(struct s_hardware *hardware);
void detect_disks(struct s_hardware *hardware);
void detect_pci(struct s_hardware *hardware);
diff --git a/com32/hdt/hdt-menu-processor.c b/com32/hdt/hdt-menu-processor.c
index d71fbe1..a30cf0f 100644
--- a/com32/hdt/hdt-menu-processor.c
+++ b/com32/hdt/hdt-menu-processor.c
@@ -45,9 +45,9 @@ void compute_processor(struct s_my_menu *menu, struct s_hardware *hardware)
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
menu->items_count++;
- snprintf(buffer, sizeof buffer, "Model : %s", hardware->cpu.model);
+ snprintf(buffer, sizeof buffer, "Model : %s", del_multi_spaces(hardware->cpu.model));
snprintf(statbuffer, sizeof statbuffer, "Model: %s",
- hardware->cpu.model);
+ del_multi_spaces(hardware->cpu.model));
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
menu->items_count++;