paleofetch

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

commit e178652c3b11740421e85dc26e3a7a89f17e364f
parent f6ae146cd891240813f4d609dfddc1f0d84f81f1
Author: dwzg <dennis@wtzg.de>
Date:   Fri, 24 Apr 2020 09:31:32 +0200

Make substring removing for CPU and GPU configurable

This adds a configurable way to remove substrings from CPU and GPU model names.
I was not able to make it work with the new REPLACE_CONST_STRING macro. It would be nice if you could omit the substring lenght in the config, maybe somebody has a neat idea for this.

Diffstat:
Mconfig.h | 19+++++++++++++++++++
Mpaleofetch.c | 29+++++++++++++++++++----------
2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/config.h b/config.h @@ -23,3 +23,22 @@ { "", get_colors1, false }, \ { "", get_colors2, false }, \ }; + +#define CPU_REMOVE \ +{ \ + /* string length */ \ + { "(R)", 3 }, \ + { "(TM)", 4 }, \ + { "Dual-Core", 9 }, \ + { "Quad-Core", 9 }, \ + { "Six-Core", 8 }, \ + { "Eight-Core", 10 }, \ + { "Core", 4 }, \ + { "CPU", 3 }, \ +}; + +#define GPU_REMOVE \ +{ \ + /* string length */ \ + { "Corporation", 11 }, \ +}; diff --git a/paleofetch.c b/paleofetch.c @@ -16,6 +16,7 @@ #include "config.h" #define BUF_SIZE 150 +#define COUNT(x) (int)(sizeof x / sizeof *x) #define REMOVE_CONST_STRING(A, B) remove_substring((A), (B), sizeof(B) - 1) struct conf { @@ -23,6 +24,14 @@ struct conf { bool cached; } config[] = CONFIG; +typedef struct { + char *substring; + size_t length; +} STRING_REMOVE; + +STRING_REMOVE cpu_remove[] = CPU_REMOVE; +STRING_REMOVE gpu_remove[] = GPU_REMOVE; + Display *display; struct utsname uname_info; struct sysinfo my_sysinfo; @@ -356,14 +365,9 @@ char *get_cpu() { fclose(cpufreq); /* remove unneeded information */ - REMOVE_CONST_STRING(cpu_model, "(R)"); - REMOVE_CONST_STRING(cpu_model, "(TM)"); - REMOVE_CONST_STRING(cpu_model, "Dual-Core"); - REMOVE_CONST_STRING(cpu_model, "Quad-Core"); - REMOVE_CONST_STRING(cpu_model, "Six-Core"); - REMOVE_CONST_STRING(cpu_model, "Eight-Core"); - REMOVE_CONST_STRING(cpu_model, "Core"); - REMOVE_CONST_STRING(cpu_model, "CPU"); + for (int i = 0; i < COUNT(cpu_remove); ++i) { + remove_substring(cpu_model, cpu_remove[i].substring, cpu_remove[i].length); + } char *cpu = malloc(BUF_SIZE); snprintf(cpu, BUF_SIZE, "%s (%d) @ %.1fGHz", cpu_model, num_cores, freq); @@ -406,8 +410,14 @@ char *find_gpu(int index) { if (found == false) *gpu = '\0'; // empty string, so it will not be printed pci_cleanup(pacc); - REMOVE_CONST_STRING(gpu, "Corporation"); + + /* remove unneeded information */ + for (int i = 0; i < COUNT(gpu_remove); ++i) { + remove_substring(gpu, gpu_remove[i].substring, gpu_remove[i].length); + } + truncate_spaces(gpu); + return gpu; } @@ -562,7 +572,6 @@ int main(int argc, char *argv[]) { fclose(cache_file); // We just need the first (and only) line. } -#define COUNT(x) (int)(sizeof x / sizeof *x) int offset = 0; for (int i = 0; i < COUNT(LOGO); i++) {