check if showErrors in ffPrintError

This commit is contained in:
Linus Dierheimer
2021-02-20 19:08:23 +01:00
parent 626badd3c8
commit 5d32a782a2
11 changed files with 24 additions and 42 deletions
+6 -12
View File
@@ -7,16 +7,14 @@ void ffPrintBattery(FFstate* state)
FILE* fullFile = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
if(fullFile == NULL)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_full\", \"r\") == NULL");
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_full\", \"r\") == NULL");
return;
}
uint32_t full;
scanned = fscanf(fullFile, "%u", &full);
if(scanned != 1)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fscanf(fullFile, \"%u\", &full) != 1");
ffPrintError(state, "Battery", "fscanf(fullFile, \"%u\", &full) != 1");
return;
}
fclose(fullFile);
@@ -24,16 +22,14 @@ void ffPrintBattery(FFstate* state)
FILE* nowFile = fopen("/sys/class/power_supply/BAT0/charge_now", "r");
if(nowFile == NULL)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_now\", \"r\") == NULL");
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_now\", \"r\") == NULL");
return;
}
uint32_t now;
scanned = fscanf(nowFile, "%u", &now);
if(scanned != 1)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fscanf(nowFile, \"%u\", &now) != 1");
ffPrintError(state, "Battery", "fscanf(nowFile, \"%u\", &now) != 1");
return;
}
fclose(nowFile);
@@ -41,16 +37,14 @@ void ffPrintBattery(FFstate* state)
FILE* statusFile = fopen("/sys/class/power_supply/BAT0/status", "r");
if(statusFile == NULL)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/status\", \"r\") == NULL");
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/status\", \"r\") == NULL");
return;
}
char status[256];
scanned = fscanf(statusFile, "%s", status);
if(scanned != 1)
{
if(state->showErrors)
ffPrintError(state, "Battery", "fscanf(statusFile, \"%u\", &status) != 1");
ffPrintError(state, "Battery", "fscanf(statusFile, \"%u\", &status) != 1");
return;
}
fclose(statusFile);
+3 -6
View File
@@ -8,24 +8,21 @@ void ffPrintCPU(FFstate* state)
ffParsePropFile("/proc/cpuinfo", "model name%*s %[^\n]", name);
if(name[0] == '\0')
{
if(state->showErrors)
ffPrintError(state, "CPU", "\"model name%*s %[^\\n]\" not found in \"/proc/cpuinfo\"");
ffPrintError(state, "CPU", "\"model name%*s %[^\\n]\" not found in \"/proc/cpuinfo\"");
return;
}
FILE* frequencyFile = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
if(frequencyFile == NULL)
{
if(state->showErrors)
ffPrintError(state, "CPU", "fopen(\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq\", \"r\") == NULL");
ffPrintError(state, "CPU", "fopen(\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq\", \"r\") == NULL");
return;
}
uint32_t frequency;
int scanned = fscanf(frequencyFile, "%u", &frequency);
if(scanned != 1)
{
if(state->showErrors)
ffPrintError(state, "CPU", "fscanf(frequencyFile, \"%s\", frequency) != 1");
ffPrintError(state, "CPU", "fscanf(frequencyFile, \"%s\", frequency) != 1");
return;
}
fclose(frequencyFile);
+1 -2
View File
@@ -21,8 +21,7 @@ void ffPrintDesktopEnvironment(FFstate* state)
const char* currentDesktop = getenv("XDG_CURRENT_DESKTOP");
if(currentDesktop == NULL)
{
if(state->showErrors)
ffPrintError(state, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
ffPrintError(state, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
return;
}
+1 -2
View File
@@ -8,8 +8,7 @@ void ffPrintDisk(FFstate* state)
int ret = statvfs("/", &fs);
if(ret != 0)
{
if(state->showErrors)
ffPrintError(state, "Disk (/)", "statvfs(\"/\", &fs) != 0");
ffPrintError(state, "Disk (/)", "statvfs(\"/\", &fs) != 0");
return;
}
+3
View File
@@ -92,6 +92,9 @@ void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4)
void ffPrintError(FFstate* state, const char* key, const char* message)
{
if(!state->showErrors)
return;
ffPrintLogoAndKey(state, key);
printf(FASTFETCH_TEXT_MODIFIER_ERROR"%s\n"FASTFETCH_TEXT_MODIFIER_RESET, message);
}
+2 -4
View File
@@ -5,15 +5,13 @@ void ffPrintHost(FFstate* state)
FILE* nameFile = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
if(nameFile == NULL)
{
if(state->showErrors)
ffPrintError(state, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
ffPrintError(state, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
return;
}
char name[256];
if(fscanf(nameFile, "%[^\n]", name) != 1)
{
if(state->showErrors)
ffPrintError(state, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
ffPrintError(state, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
return;
}
fclose(nameFile);
+1 -2
View File
@@ -6,8 +6,7 @@ void ffPrintLocale(FFstate* state)
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", locale);
if(locale[0] == '\0')
{
if(state->showErrors)
ffPrintError(state, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
ffPrintError(state, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
return;
}
+1 -2
View File
@@ -5,8 +5,7 @@ void ffPrintMemory(FFstate* state)
{
FILE* meminfo = fopen("/proc/meminfo", "r");
if(meminfo == NULL) {
if(state->showErrors)
ffPrintError(state, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
ffPrintError(state, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
return;
}
+1 -2
View File
@@ -6,8 +6,7 @@ void ffPrintOS(FFstate* state)
ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name);
if(name[0] == '\0')
{
if(state->showErrors)
ffPrintError(state, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
ffPrintError(state, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
return;
}
+1 -2
View File
@@ -7,8 +7,7 @@ void ffPrintShell(FFstate* state)
char* shellPath = getenv("SHELL");
if(shellPath == NULL)
{
if(state->showErrors)
ffPrintError(state, "Shell", "getenv(\"SHELL\") == NULL");
ffPrintError(state, "Shell", "getenv(\"SHELL\") == NULL");
return;
}
+4 -8
View File
@@ -10,12 +10,9 @@ void printTerminalName(FFstate* state, const char* pid)
FILE* stat = fopen(file, "r");
if(stat == NULL)
{
if(state->showErrors)
{
char error[256];
sprintf(error, "fopen(\"%s\", \"r\") == NULL", file);
ffPrintError(state, "Terminal", error);
}
char error[256];
sprintf(error, "fopen(\"%s\", \"r\") == NULL", file);
ffPrintError(state, "Terminal", error);
return;
}
@@ -23,8 +20,7 @@ void printTerminalName(FFstate* state, const char* pid)
char ppid[256];
if(fscanf(stat, "%*s (%[^)])%*s%s", name, ppid) != 2)
{
if(state->showErrors)
ffPrintError(state, "Terminal", "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
ffPrintError(state, "Terminal", "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
return;
}