paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e5c505a856928365c293b85d036329a9dfdc5f8f
parent 04a05ef0361fe4aa4ccb6ed6d857668d41a5ce65
Author: sam-barr <samfbarr@outlook.com>
Date:   Wed, 22 Apr 2020 20:12:41 -0500

added truncate_spaces function

Diffstat:
Mpaleofetch.c | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/paleofetch.c b/paleofetch.c @@ -44,17 +44,37 @@ struct sysinfo my_sysinfo; int title_length; int status; +void halt_and_catch_fire(const char *message) { + if(status != 0) { + printf("%s\n", message); + exit(status); + } +} + +/* + * Replaces the first newline character with null terminator + */ void remove_newline(char *s) { while (*s != '\0' && *s != '\n') s++; *s = '\0'; } -void halt_and_catch_fire(const char *message) { - if(status != 0) { - printf("%s\n", message); - exit(status); +/* + * Cleans up repeated spaces in a string + */ +void truncate_spaces(char *str) { + int src = 0, dst = 0; + + while(*(str + dst) != '\0') { + *(str + src) = *(str + dst); + if(*(str + (dst++)) == ' ') + while(*(str + dst) == ' ') dst++; + + src++; } + + *(str +src) = '\0'; } /* @@ -289,6 +309,7 @@ char *get_cpu() { remove_substring(cpu, "(TM)", 4); remove_substring(cpu, "Core", 4); remove_substring(cpu, "CPU", 3); + truncate_spaces(cpu); return cpu; } @@ -316,6 +337,7 @@ char *get_gpu() { } remove_substring(gpu, "Corporation", 11); + truncate_spaces(gpu); pci_cleanup(pacc); return gpu;