mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
dont use format string if an error occures
This commit is contained in:
+49
-39
@@ -23,12 +23,17 @@ void ffPrintCPU(FFinstance* instance)
|
||||
if(ffPrintCachedValue(instance, &instance->config.cpuKey, "CPU"))
|
||||
return;
|
||||
|
||||
FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
|
||||
if(cpuinfo == NULL)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.cpuKey, "CPU", "fopen(\"/proc/cpuinfo\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
char name[256]; name[0] = '\0';
|
||||
char vendor[256]; vendor[0] = '\0';
|
||||
int physicalCores = 0;
|
||||
|
||||
FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
@@ -48,15 +53,6 @@ void ffPrintCPU(FFinstance* instance)
|
||||
|
||||
fclose(cpuinfo);
|
||||
|
||||
FFstrbuf namePretty;
|
||||
ffStrbufInitA(&namePretty, 64);
|
||||
ffStrbufAppendS(&namePretty, name);
|
||||
ffStrbufRemoveStrings(&namePretty, 11,
|
||||
"(R)", "(r)", "(TM)", "(tm)", " CPU", " FPU", " Processor", " Dual-Core", " Quad-Core", " Six-Core", " Eight-Core"
|
||||
);
|
||||
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
|
||||
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
|
||||
|
||||
double biosLimit = getGhz("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit");
|
||||
double scalingMaxFreq = getGhz("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq");
|
||||
double scalingMinFreq = getGhz("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq");
|
||||
@@ -66,27 +62,47 @@ void ffPrintCPU(FFinstance* instance)
|
||||
int numProcsOnline = get_nprocs();
|
||||
int numProcsAvailable = get_nprocs_conf();
|
||||
|
||||
//The current get_nprocs* returns 1 on failure. It also makes no sense to have a (1) as count
|
||||
int numProcs = numProcsOnline;
|
||||
if(numProcs <= 1)
|
||||
numProcs = numProcsAvailable;
|
||||
if(numProcs <= 1)
|
||||
numProcs = physicalCores;
|
||||
|
||||
double ghz = biosLimit;
|
||||
if(ghz == 0)
|
||||
ghz = scalingMaxFreq;
|
||||
if(ghz == 0)
|
||||
ghz = infoMaxFreq;
|
||||
if(ghz == 0)
|
||||
ghz = scalingMinFreq;
|
||||
if(ghz == 0)
|
||||
ghz = infoMinFreq;
|
||||
|
||||
if(
|
||||
name[0] == '\0' && //This also implies namePretty is not set
|
||||
vendor[0] == '\0' &&
|
||||
numProcs <= 1 &&
|
||||
ghz <= 0
|
||||
) {
|
||||
ffPrintError(instance, &instance->config.cpuKey, "CPU", "No CPU info found in /proc/cpuinfo");
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf namePretty;
|
||||
ffStrbufInitA(&namePretty, 64);
|
||||
ffStrbufAppendS(&namePretty, name);
|
||||
ffStrbufRemoveStrings(&namePretty, 11,
|
||||
"(R)", "(r)", "(TM)", "(tm)", " CPU", " FPU", " Processor", " Dual-Core", " Quad-Core", " Six-Core", " Eight-Core"
|
||||
);
|
||||
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
|
||||
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
|
||||
|
||||
FFstrbuf cpu;
|
||||
ffStrbufInitA(&cpu, 128);
|
||||
|
||||
if(instance->config.cpuFormat.length == 0)
|
||||
{
|
||||
//The current get_nprocs* returns 1 on failure. It also makes no sense to have a (1) as count
|
||||
int numProcs = numProcsOnline;
|
||||
if(numProcs <= 1)
|
||||
numProcs = numProcsAvailable;
|
||||
if(numProcs <= 1)
|
||||
numProcs = physicalCores;
|
||||
|
||||
double ghz = biosLimit;
|
||||
if(ghz == 0)
|
||||
ghz = scalingMaxFreq;
|
||||
if(ghz == 0)
|
||||
ghz = infoMaxFreq;
|
||||
if(ghz == 0)
|
||||
ghz = scalingMinFreq;
|
||||
if(ghz == 0)
|
||||
ghz = infoMinFreq;
|
||||
|
||||
if(namePretty.length > 0)
|
||||
ffStrbufAppend(&cpu, &namePretty);
|
||||
@@ -97,15 +113,8 @@ void ffPrintCPU(FFinstance* instance)
|
||||
ffStrbufAppendS(&cpu, vendor);
|
||||
ffStrbufAppendS(&cpu, " unknown processor");
|
||||
}
|
||||
else if(numProcs > 1 || ghz > 0)
|
||||
ffStrbufAppendS(&cpu, " unknwon processor");
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, &instance->config.cpuKey, "CPU", "No CPU info found in /proc/cpuinfo");
|
||||
ffStrbufDestroy(&cpu);
|
||||
ffStrbufDestroy(&namePretty);
|
||||
return;
|
||||
}
|
||||
ffStrbufAppendS(&cpu, " unknown processor");
|
||||
|
||||
if(numProcs > 1)
|
||||
ffStrbufAppendF(&cpu, " (%i)", numProcs);
|
||||
@@ -115,7 +124,7 @@ void ffPrintCPU(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&cpu, &instance->config.cpuFormat, 11,
|
||||
ffParseFormatString(&cpu, &instance->config.cpuFormat, 13,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, vendor},
|
||||
@@ -123,15 +132,16 @@ void ffPrintCPU(FFinstance* instance)
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &physicalCores},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &numProcs},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &infoMaxFreq},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &infoMinFreq}
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &infoMinFreq},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &ghz}
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.cpuKey, "CPU", &cpu);
|
||||
ffStrbufDestroy(&cpu);
|
||||
|
||||
ffStrbufDestroy(&namePretty);
|
||||
ffStrbufDestroy(&cpu);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user