mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.99][X86] Add function to abbreviate Intel CPU names from CPUID
This commit is contained in:
@@ -116,6 +116,52 @@ char* get_str_cpu_name_internal() {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void abbreviate_intel_cpu_name(char** name) {
|
||||||
|
char* old_name = *name;
|
||||||
|
char* new_name = ecalloc(strlen(old_name) + 1, sizeof(char));
|
||||||
|
|
||||||
|
char* old_name_ptr = old_name;
|
||||||
|
char* new_name_ptr = new_name;
|
||||||
|
char* aux_ptr = NULL;
|
||||||
|
|
||||||
|
// 1. Remove "(R)"
|
||||||
|
if(strncmp(old_name_ptr, "Intel(R)", 8) != 0) return;
|
||||||
|
strcpy(new_name_ptr, "Intel");
|
||||||
|
new_name_ptr += 5;
|
||||||
|
old_name_ptr += 8;
|
||||||
|
|
||||||
|
// 2. Remove "(R)" or "(TM)"
|
||||||
|
aux_ptr = strstr(old_name_ptr, "(");
|
||||||
|
if(aux_ptr == NULL) return;
|
||||||
|
strncpy(new_name_ptr, old_name_ptr, aux_ptr-old_name_ptr);
|
||||||
|
|
||||||
|
new_name_ptr += aux_ptr-old_name_ptr;
|
||||||
|
strcpy(new_name_ptr, " ");
|
||||||
|
new_name_ptr++;
|
||||||
|
old_name_ptr = strstr(aux_ptr, ")");
|
||||||
|
if(old_name_ptr == NULL) return;
|
||||||
|
old_name_ptr += 2;
|
||||||
|
|
||||||
|
// 3. Skip "CPU" (if exists)
|
||||||
|
if(strncmp(old_name_ptr, "CPU", 3) == 0) {
|
||||||
|
aux_ptr = strstr(old_name_ptr, " ");
|
||||||
|
if(aux_ptr == NULL) return;
|
||||||
|
old_name_ptr = aux_ptr + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Copy the CPU name
|
||||||
|
aux_ptr = strstr(old_name_ptr, "CPU");
|
||||||
|
if(aux_ptr == NULL) {
|
||||||
|
// Name contains no "CPU" at the end, so ends with @
|
||||||
|
aux_ptr = strstr(old_name_ptr, "@");
|
||||||
|
if(aux_ptr == NULL) return;
|
||||||
|
}
|
||||||
|
strncpy(new_name_ptr, old_name_ptr, (aux_ptr-1)-old_name_ptr);
|
||||||
|
|
||||||
|
free(old_name);
|
||||||
|
*name = new_name;
|
||||||
|
}
|
||||||
|
|
||||||
struct uarch* get_cpu_uarch(struct cpuInfo* cpu) {
|
struct uarch* get_cpu_uarch(struct cpuInfo* cpu) {
|
||||||
uint32_t eax = 0x00000001;
|
uint32_t eax = 0x00000001;
|
||||||
uint32_t ebx = 0;
|
uint32_t ebx = 0;
|
||||||
@@ -314,6 +360,7 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
|
|
||||||
if (cpu->maxExtendedLevels >= 0x80000004){
|
if (cpu->maxExtendedLevels >= 0x80000004){
|
||||||
cpu->cpu_name = get_str_cpu_name_internal();
|
cpu->cpu_name = get_str_cpu_name_internal();
|
||||||
|
if(cpu->cpu_vendor == CPU_VENDOR_INTEL) abbreviate_intel_cpu_name(&cpu->cpu_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cpu->cpu_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
cpu->cpu_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
||||||
|
|||||||
Reference in New Issue
Block a user