commit 874085430dd9e3d1a9fdb2316f00eed42114f375
parent 457b8794d482c399c2eab25756add03e788836f4
Author: sam-barr <samfbarr@outlook.com>
Date: Fri, 24 Apr 2020 13:43:54 -0500
Merge pull request #39 from dwzg/substring_remove_config
Make substring removing for CPU and GPU configurable
Diffstat:
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/config.h b/config.h
@@ -23,3 +23,20 @@
{ "", get_colors1, false }, \
{ "", get_colors2, false }, \
};
+
+#define CPU_REMOVE \
+{ \
+ REMOVE("(R)"), \
+ REMOVE("(TM)"), \
+ REMOVE("Dual-Core"), \
+ REMOVE("Quad-Core"), \
+ REMOVE("Six-Core"), \
+ REMOVE("Eight-Core"), \
+ REMOVE("Core"), \
+ REMOVE("CPU"), \
+};
+
+#define GPU_REMOVE \
+{ \
+ REMOVE("Corporation"), \
+};
diff --git a/paleofetch.c b/paleofetch.c
@@ -16,13 +16,21 @@
#include "config.h"
#define BUF_SIZE 150
-#define REMOVE_CONST_STRING(A, B) remove_substring((A), (B), sizeof(B) - 1)
+#define COUNT(x) (int)(sizeof x / sizeof *x)
struct conf {
char *label, *(*function)();
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 +364,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 +409,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 +571,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++) {
diff --git a/paleofetch.h b/paleofetch.h
@@ -20,3 +20,4 @@ char *get_title(),
*spacer();
#define SPACER {"", spacer, false},
+#define REMOVE(A) { (A), sizeof(A) }