commit 00613632ad7c4546a1783f8b83212fb976a178d4
parent 142a6b4b6a87837af7dfba0e08f75127ca4dbafb
Author: dwzg <dennis@wtzg.de>
Date: Fri, 24 Apr 2020 21:05:07 +0200
Add configurable way to replace strings of CPU and GPU model
Diffstat:
3 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/config.h b/config.h
@@ -24,7 +24,7 @@
{ "", get_colors2, false }, \
};
-#define CPU_REMOVE \
+#define CPU_CONFIG \
{ \
REMOVE("(R)"), \
REMOVE("(TM)"), \
@@ -36,7 +36,7 @@
REMOVE("CPU"), \
};
-#define GPU_REMOVE \
+#define GPU_CONFIG \
{ \
REMOVE("Corporation"), \
};
diff --git a/paleofetch.c b/paleofetch.c
@@ -34,11 +34,13 @@ struct conf {
typedef struct {
char *substring;
+ char *repl_str;
size_t length;
+ size_t repl_len;
} STRING_REMOVE;
-STRING_REMOVE cpu_remove[] = CPU_REMOVE;
-STRING_REMOVE gpu_remove[] = GPU_REMOVE;
+STRING_REMOVE cpu_config[] = CPU_CONFIG;
+STRING_REMOVE gpu_config[] = GPU_CONFIG;
Display *display;
struct utsname uname_info;
@@ -377,12 +379,14 @@ char *get_cpu() {
fclose(cpufreq);
/* remove unneeded information */
- for (int i = 0; i < COUNT(cpu_remove); ++i) {
- remove_substring(cpu_model, cpu_remove[i].substring, cpu_remove[i].length);
+ for (int i = 0; i < COUNT(cpu_config); ++i) {
+ if (cpu_config[i].repl_str == NULL) {
+ remove_substring(cpu_model, cpu_config[i].substring, cpu_config[i].length);
+ } else {
+ replace_substring(cpu_model, cpu_config[i].substring, cpu_config[i].repl_str, cpu_config[i].length, cpu_config[i].repl_len);
+ }
}
- replace_substring(cpu_model, "Core2", "Core 2", 5, 6);
-
char *cpu = malloc(BUF_SIZE);
snprintf(cpu, BUF_SIZE, "%s (%d) @ %.1fGHz", cpu_model, num_cores, freq);
free(cpu_model);
@@ -426,8 +430,12 @@ char *find_gpu(int index) {
pci_cleanup(pacc);
/* remove unneeded information */
- for (int i = 0; i < COUNT(gpu_remove); ++i) {
- remove_substring(gpu, gpu_remove[i].substring, gpu_remove[i].length);
+ for (int i = 0; i < COUNT(gpu_config); ++i) {
+ if (gpu_config[i].repl_str == NULL) {
+ remove_substring(gpu, gpu_config[i].substring, gpu_config[i].length);
+ } else {
+ replace_substring(gpu, gpu_config[i].substring, gpu_config[i].repl_str, gpu_config[i].length, gpu_config[i].repl_len);
+ }
}
truncate_spaces(gpu);
diff --git a/paleofetch.h b/paleofetch.h
@@ -20,4 +20,5 @@ char *get_title(),
*spacer();
#define SPACER {"", spacer, false},
-#define REMOVE(A) { (A), sizeof(A) - 1}
+#define REMOVE(A) { (A), NULL, sizeof(A) - 1 , 0 }
+#define REPLACE(A, B) { (A), (B), sizeof(A) - 1, sizeof(B) - 1 }