commit 142a6b4b6a87837af7dfba0e08f75127ca4dbafb
parent 9151f7f9c5ca418a783725508104354110077d24
Author: dwzg <dennis@wtzg.de>
Date: Fri, 24 Apr 2020 00:25:16 +0200
Add function to replace substrings
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/paleofetch.c b/paleofetch.c
@@ -87,6 +87,17 @@ void remove_substring(char *str, const char* substring, size_t len) {
while(*(sub+(++i)) != '\0');
}
+void replace_substring(char *str, const char *sub_str, const char *repl_str, size_t sub_len, size_t repl_len) {
+ char buffer[BUF_SIZE];
+ char *start = strstr(str, sub_str);
+ if (start == NULL) return; // substring not found
+ int start_index = start - str;
+
+ strcpy(buffer, str);
+ strncpy(start, repl_str, repl_len);
+ strcpy(start + repl_len, buffer + start_index + sub_len);
+}
+
char *get_title() {
// reduce the maximum size for these, so that we don't over-fill the title string
char hostname[BUF_SIZE / 3];
@@ -370,6 +381,8 @@ char *get_cpu() {
remove_substring(cpu_model, cpu_remove[i].substring, cpu_remove[i].length);
}
+ 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);