mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Global: fixes -ffast-math compatibility
Unifies unset double handling using `-DBL_MAX` sentinel Fixes #1894
This commit is contained in:
+2
-2
@@ -113,8 +113,8 @@ static inline void appendInvalidPlaceholder(FFstrbuf* buffer, const char* start,
|
||||
static inline bool formatArgSet(const FFformatarg* arg)
|
||||
{
|
||||
return arg->value != NULL && (
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0.0) || //Also is false for NaN
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_FLOAT && *(float*)arg->value > 0.0) || //Also is false for NaN
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0.0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_FLOAT && *(float*)arg->value > 0.0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_INT && *(int*)arg->value > 0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_STRING && ffStrSet((char*)arg->value)) ||
|
||||
|
||||
@@ -72,9 +72,9 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf
|
||||
ffStrbufAppend(buffer, &options->barBorderLeft);
|
||||
}
|
||||
|
||||
if (percent != percent)
|
||||
if (percent == -DBL_MAX)
|
||||
{
|
||||
// No color config for NaN, use total color for simplification
|
||||
// Use total color for simplification
|
||||
if(!options->pipe && options->barColorTotal.length > 0)
|
||||
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_BLACK "m");
|
||||
|
||||
@@ -187,7 +187,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConf
|
||||
const char* colorYellow = options->percentColorYellow.chars;
|
||||
const char* colorRed = options->percentColorRed.chars;
|
||||
|
||||
if(percent != percent)
|
||||
if(percent == -DBL_MAX)
|
||||
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_BLACK "m");
|
||||
else if(green <= yellow)
|
||||
{
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
void ffTempsAppendNum(double celsius, FFstrbuf* buffer, FFColorRangeConfig config, const FFModuleArgs* module)
|
||||
{
|
||||
if (celsius != celsius) // ignores NaN
|
||||
if (celsius == -DBL_MAX) // ignores invalid value
|
||||
return;
|
||||
|
||||
const FFOptionsDisplay* options = &instance.config.display;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "modules/battery/option.h"
|
||||
|
||||
#define FF_BATTERY_TEMP_UNSET (0/0.0)
|
||||
#define FF_BATTERY_TEMP_UNSET (-DBL_MAX)
|
||||
|
||||
typedef struct FFBatteryResult
|
||||
{
|
||||
|
||||
@@ -96,6 +96,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results)
|
||||
battery->temperature = FF_BATTERY_TEMP_UNSET;
|
||||
battery->cycleCount = 0;
|
||||
battery->timeRemaining = -1;
|
||||
battery->capacity = 0;
|
||||
ffStrbufInit(&battery->manufacturer);
|
||||
ffStrbufInit(&battery->modelName);
|
||||
ffStrbufInit(&battery->status);
|
||||
@@ -124,11 +125,11 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results)
|
||||
{
|
||||
double level = 0, scale = 0;
|
||||
if (ffParsePropLines(start, "level: ", &temp))
|
||||
level = ffStrbufToDouble(&temp);
|
||||
level = ffStrbufToDouble(&temp, -DBL_MAX);
|
||||
ffStrbufClear(&temp);
|
||||
|
||||
if (ffParsePropLines(start, "scale: ", &temp))
|
||||
scale = ffStrbufToDouble(&temp);
|
||||
scale = ffStrbufToDouble(&temp, -DBL_MAX);
|
||||
ffStrbufClear(&temp);
|
||||
|
||||
if (level > 0 && scale > 0)
|
||||
@@ -138,7 +139,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results)
|
||||
if(options->temp)
|
||||
{
|
||||
if (ffParsePropLines(start, "temperature: ", &temp))
|
||||
battery->temperature = ffStrbufToDouble(&temp);
|
||||
battery->temperature = ffStrbufToDouble(&temp, FF_BATTERY_TEMP_UNSET);
|
||||
ffStrbufClear(&temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ static void parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
|
||||
return;
|
||||
|
||||
FFBatteryResult* result = ffListAdd(results);
|
||||
result->capacity = ffStrbufToDouble(&tmpBuffer);
|
||||
result->capacity = ffStrbufToDouble(&tmpBuffer, 0);
|
||||
|
||||
//At this point, we have a battery. Try to get as much values as possible.
|
||||
|
||||
@@ -154,7 +154,11 @@ static void parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
|
||||
if (options->temp)
|
||||
{
|
||||
if (ffReadFileBufferRelative(dfd, "temp", &tmpBuffer))
|
||||
result->temperature = ffStrbufToDouble(&tmpBuffer) / 10;
|
||||
{
|
||||
result->temperature = ffStrbufToDouble(&tmpBuffer, FF_BATTERY_TEMP_UNSET);
|
||||
if (result->temperature != FF_BATTERY_TEMP_UNSET)
|
||||
result->temperature /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ static const char* detectWithCmApi(FFBatteryOptions* options, FFlist* results)
|
||||
|
||||
battery->cycleCount = bi.CycleCount;
|
||||
|
||||
battery->temperature = 0.0/0.0;
|
||||
battery->temperature = FF_BATTERY_TEMP_UNSET;
|
||||
if(options->temp)
|
||||
{
|
||||
bqi.InformationLevel = BatteryTemperature;
|
||||
|
||||
@@ -32,7 +32,7 @@ static const char* detectWithBacklight(FFlist* result)
|
||||
ffStrbufAppendS(&backlightDir, "/brightness");
|
||||
if(ffReadFileBuffer(backlightDir.chars, &buffer))
|
||||
{
|
||||
double actualBrightness = ffStrbufToDouble(&buffer);
|
||||
double actualBrightness = ffStrbufToDouble(&buffer, 0);
|
||||
ffStrbufSubstrBefore(&backlightDir, backlightDirLength);
|
||||
ffStrbufAppendS(&backlightDir, entry->d_name);
|
||||
ffStrbufAppendS(&backlightDir, "/max_brightness");
|
||||
@@ -71,7 +71,7 @@ static const char* detectWithBacklight(FFlist* result)
|
||||
}
|
||||
else
|
||||
ffStrbufInitS(&brightness->name, entry->d_name);
|
||||
brightness->max = ffStrbufToDouble(&buffer);
|
||||
brightness->max = ffStrbufToDouble(&buffer, 0);
|
||||
brightness->min = 0;
|
||||
brightness->current = actualBrightness;
|
||||
brightness->builtin = true;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "modules/cpu/option.h"
|
||||
|
||||
#define FF_CPU_TEMP_UNSET (0/0.0)
|
||||
#define FF_CPU_TEMP_UNSET (-DBL_MAX)
|
||||
|
||||
typedef struct FFCPUCore
|
||||
{
|
||||
|
||||
@@ -28,19 +28,19 @@ static double parseHwmonDir(FFstrbuf* dir, FFstrbuf* buffer)
|
||||
ffStrbufAppendS(dir, "temp1_input");
|
||||
|
||||
if(!ffReadFileBuffer(dir->chars, buffer))
|
||||
return 0.0/0.0;
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
}
|
||||
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
|
||||
double value = ffStrbufToDouble(buffer);// millidegree Celsius
|
||||
double value = ffStrbufToDouble(buffer, FF_CPU_TEMP_UNSET);// millidegree Celsius
|
||||
|
||||
if(value != value)
|
||||
return 0.0/0.0;
|
||||
if(value == FF_CPU_TEMP_UNSET)
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
|
||||
ffStrbufAppendS(dir, "name");
|
||||
if (!ffReadFileBuffer(dir->chars, buffer))
|
||||
return 0.0/0.0;
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
|
||||
ffStrbufTrimRightSpace(buffer);
|
||||
|
||||
@@ -51,14 +51,17 @@ static double parseHwmonDir(FFstrbuf* dir, FFstrbuf* buffer)
|
||||
ffStrbufEqualS(buffer, "coretemp") // Intel
|
||||
) return value / 1000.;
|
||||
|
||||
return 0.0/0.0;
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
}
|
||||
|
||||
static double detectTZTemp(FFstrbuf* buffer)
|
||||
{
|
||||
if (ffReadFileBuffer("/sys/class/thermal/thermal_zone0/temp", buffer))
|
||||
return ffStrbufToDouble(buffer) / 1000.;
|
||||
return 0.0/0.0;
|
||||
{
|
||||
double value = ffStrbufToDouble(buffer, FF_CPU_TEMP_UNSET);// millidegree Celsius
|
||||
return value != FF_CPU_TEMP_UNSET ? value / 1000. : FF_CPU_TEMP_UNSET;
|
||||
}
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
}
|
||||
|
||||
static double detectCPUTemp(void)
|
||||
@@ -72,7 +75,7 @@ static double detectCPUTemp(void)
|
||||
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars);
|
||||
if(dirp == NULL)
|
||||
return 0.0/0.0;
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
@@ -84,7 +87,7 @@ static double detectCPUTemp(void)
|
||||
ffStrbufAppendC(&baseDir, '/');
|
||||
|
||||
double result = parseHwmonDir(&baseDir, &buffer);
|
||||
if (result == result)
|
||||
if (result != FF_CPU_TEMP_UNSET)
|
||||
return result;
|
||||
|
||||
ffStrbufSubstrBefore(&baseDir, baseDirLength);
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include "fastfetch.h"
|
||||
#include "modules/gpu/option.h"
|
||||
|
||||
#define FF_GPU_TEMP_UNSET (0/0.0)
|
||||
#define FF_GPU_TEMP_UNSET (-DBL_MAX)
|
||||
#define FF_GPU_CORE_COUNT_UNSET -1
|
||||
#define FF_GPU_VMEM_SIZE_UNSET ((uint64_t)-1)
|
||||
#define FF_GPU_FREQUENCY_UNSET 0
|
||||
#define FF_GPU_CORE_USAGE_UNSET (0/0.0)
|
||||
#define FF_GPU_CORE_USAGE_UNSET (-DBL_MAX)
|
||||
#define FF_GPU_INDEX_UNSET ((uint32_t)-1)
|
||||
|
||||
extern const char* FF_GPU_VENDOR_NAME_APPLE;
|
||||
|
||||
@@ -411,7 +411,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
FF_DEBUG("Failed to open adapter from LUID");
|
||||
}
|
||||
|
||||
if (options->temp && gpu->temperature != gpu->temperature)
|
||||
if (options->temp && gpu->temperature == FF_GPU_TEMP_UNSET)
|
||||
{
|
||||
FF_DEBUG("Trying to get GPU temperature");
|
||||
D3DKMT_QUERYSTATISTICS queryStatistics = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "modules/physicaldisk/option.h"
|
||||
|
||||
#define FF_PHYSICALDISK_TEMP_UNSET (0/0.0)
|
||||
#define FF_PHYSICALDISK_TEMP_UNSET (-DBL_MAX)
|
||||
|
||||
typedef enum __attribute__((__packed__)) FFPhysicalDiskType
|
||||
{
|
||||
|
||||
@@ -31,13 +31,13 @@ static void parsePowerAdapter(int dfd, FF_MAYBE_UNUSED const char* id, FFlist* r
|
||||
return;
|
||||
|
||||
//input_power_limit must exist and be not empty
|
||||
if (!ffReadFileBufferRelative(dfd, "input_power_limit", &tmpBuffer))
|
||||
if (!ffReadFileBufferRelative(dfd, "input_power_limit", &tmpBuffer) || tmpBuffer.length == 0)
|
||||
return;
|
||||
|
||||
FFPowerAdapterResult* result = ffListAdd(results);
|
||||
ffStrbufInit(&result->name);
|
||||
ffStrbufInit(&result->description);
|
||||
result->watts = (int) (ffStrbufToDouble(&tmpBuffer) / 1e6 + 0.5);
|
||||
result->watts = (int) (ffStrbufToDouble(&tmpBuffer, 0) / 1e6 + 0.5);
|
||||
ffStrbufInit(&result->manufacturer);
|
||||
ffStrbufInit(&result->modelName);
|
||||
ffStrbufInit(&result->serial);
|
||||
|
||||
@@ -44,7 +44,7 @@ static inline void wrapYyjsonFree(yyjson_doc** doc)
|
||||
|
||||
static const char* detectFromWTImpl(FFstrbuf* content, FFstrbuf* name, double* size)
|
||||
{
|
||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonFree))) doc = yyjson_read_opts(content->chars, content->length, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, NULL);
|
||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonFree))) doc = yyjson_read_opts(content->chars, content->length, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS, NULL, NULL);
|
||||
if (!doc)
|
||||
return "Failed to parse WT JSON config file";
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ const char* ffDetectWifi(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -139,9 +139,9 @@ static const char* detectByWdutil(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
@@ -245,9 +245,9 @@ static const char* detectByCoreWlan(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ const char* ffDetectWifi(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ static const char* detectWifiWithNm(FFWifiResult* item, FFstrbuf* buffer)
|
||||
dbus.lib->ffdbus_message_unref(device);
|
||||
}
|
||||
|
||||
if (item->conn.txRate != item->conn.txRate)
|
||||
if (item->conn.txRate == -DBL_MAX)
|
||||
{
|
||||
FF_DEBUG("Getting bitrate from NetworkManager");
|
||||
uint32_t bitrate;
|
||||
@@ -162,7 +162,7 @@ static const char* detectWifiWithNm(FFWifiResult* item, FFstrbuf* buffer)
|
||||
}
|
||||
else if (ffStrEquals(key, "Strength"))
|
||||
{
|
||||
if (item->conn.signalQuality != item->conn.signalQuality)
|
||||
if (item->conn.signalQuality == -DBL_MAX)
|
||||
{
|
||||
FF_DEBUG("Found Strength property");
|
||||
uint32_t strengthPercent;
|
||||
@@ -314,14 +314,14 @@ static const char* detectWifiWithIw(FFWifiResult* item, FFstrbuf* buffer)
|
||||
ffStrbufClear(buffer);
|
||||
if(ffParsePropLines(output.chars, "rx bitrate: ", buffer))
|
||||
{
|
||||
item->conn.rxRate = ffStrbufToDouble(buffer);
|
||||
item->conn.rxRate = ffStrbufToDouble(buffer, -DBL_MAX);
|
||||
FF_DEBUG("RX bitrate: %.2f Mbps", item->conn.rxRate);
|
||||
}
|
||||
|
||||
ffStrbufClear(buffer);
|
||||
if(ffParsePropLines(output.chars, "tx bitrate: ", buffer))
|
||||
{
|
||||
item->conn.txRate = ffStrbufToDouble(buffer);
|
||||
item->conn.txRate = ffStrbufToDouble(buffer, -DBL_MAX);
|
||||
FF_DEBUG("TX bitrate: %.2f Mbps (raw: %s)", item->conn.txRate, buffer->chars);
|
||||
|
||||
if(ffStrbufContainS(buffer, " EHT-MCS "))
|
||||
@@ -548,9 +548,9 @@ const char* ffDetectWifi(FF_MAYBE_UNUSED FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ const char* ffDetectWifi(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ const char* ffDetectWifi(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -80,9 +80,9 @@ const char* ffDetectWifi(FFlist* result)
|
||||
ffStrbufInit(&item->conn.bssid);
|
||||
ffStrbufInit(&item->conn.protocol);
|
||||
ffStrbufInit(&item->conn.security);
|
||||
item->conn.signalQuality = 0.0/0.0;
|
||||
item->conn.rxRate = 0.0/0.0;
|
||||
item->conn.txRate = 0.0/0.0;
|
||||
item->conn.signalQuality = -DBL_MAX;
|
||||
item->conn.rxRate = -DBL_MAX;
|
||||
item->conn.txRate = -DBL_MAX;
|
||||
item->conn.channel = 0;
|
||||
item->conn.frequency = 0;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ static int enumZpoolCallback(zpool_handle_t* zpool, void* param)
|
||||
item->total = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_SIZE, &source);
|
||||
item->used = item->total - data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FREE, &source);
|
||||
uint64_t fragmentation = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FRAGMENTATION, &source);
|
||||
item->fragmentation = fragmentation == UINT64_MAX ? 0.0/0.0 : (double) fragmentation;
|
||||
item->fragmentation = fragmentation == UINT64_MAX ? -DBL_MAX : (double) fragmentation;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
|
||||
ffStrbufAppend(&str, &result->status);
|
||||
}
|
||||
|
||||
if(result->temperature == result->temperature) //FF_BATTERY_TEMP_UNSET
|
||||
if(result->temperature != FF_BATTERY_TEMP_UNSET)
|
||||
{
|
||||
if(str.length > 0)
|
||||
ffStrbufAppendS(&str, " - ");
|
||||
@@ -221,7 +221,10 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc,
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "status", &battery->status);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "technology", &battery->technology);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &battery->serial);
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", battery->temperature);
|
||||
if (battery->temperature != FF_BATTERY_TEMP_UNSET)
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", battery->temperature);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "temperature");
|
||||
yyjson_mut_obj_add_uint(doc, obj, "cycleCount", battery->cycleCount);
|
||||
if (battery->timeRemaining > 0)
|
||||
yyjson_mut_obj_add_int(doc, obj, "timeRemaining", battery->timeRemaining);
|
||||
|
||||
@@ -81,7 +81,7 @@ void ffPrintCPU(FFCPUOptions* options)
|
||||
ffFreqAppendNum(freq, &str);
|
||||
}
|
||||
|
||||
if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET
|
||||
if(cpu.temperature != FF_CPU_TEMP_UNSET)
|
||||
{
|
||||
ffStrbufAppendS(&str, " - ");
|
||||
ffTempsAppendNum(cpu.temperature, &str, options->tempConfig, &options->moduleArgs);
|
||||
@@ -201,7 +201,10 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
yyjson_mut_obj_add_uint(doc, core, "freq", cpu.coreTypes[i].freq);
|
||||
}
|
||||
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", cpu.temperature);
|
||||
if (cpu.temperature != FF_CPU_TEMP_UNSET)
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", cpu.temperature);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "temperature");
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&cpu.name);
|
||||
|
||||
+11
-5
@@ -46,7 +46,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
|
||||
ffFreqAppendNum(gpu->frequency, &output);
|
||||
}
|
||||
|
||||
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
|
||||
if(gpu->temperature != FF_GPU_TEMP_UNSET)
|
||||
{
|
||||
ffStrbufAppendS(&output, " - ");
|
||||
ffTempsAppendNum(gpu->temperature, &output, options->tempConfig, &options->moduleArgs);
|
||||
@@ -126,7 +126,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY coreUsageNum = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY coreUsageBar = ffStrbufCreate();
|
||||
if (gpu->coreUsage == gpu->coreUsage) //FF_GPU_CORE_USAGE_UNSET
|
||||
if (gpu->coreUsage != FF_GPU_CORE_USAGE_UNSET)
|
||||
{
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
ffPercentAppendNum(&coreUsageNum, gpu->coreUsage, options->percent, false, &options->moduleArgs);
|
||||
@@ -338,7 +338,10 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "coreCount");
|
||||
|
||||
yyjson_mut_obj_add_real(doc, obj, "coreUsage", gpu->coreUsage);
|
||||
if (gpu->coreUsage != FF_GPU_CORE_USAGE_UNSET)
|
||||
yyjson_mut_obj_add_real(doc, obj, "coreUsage", gpu->coreUsage);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "coreUsage");
|
||||
|
||||
yyjson_mut_val* memoryObj = yyjson_mut_obj_add_obj(doc, obj, "memory");
|
||||
|
||||
@@ -371,7 +374,7 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "driver", &gpu->driver);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &gpu->name);
|
||||
|
||||
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
|
||||
if(gpu->temperature != FF_GPU_TEMP_UNSET)
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", gpu->temperature);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "temperature");
|
||||
@@ -389,7 +392,10 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "platformApi", &gpu->platformApi);
|
||||
|
||||
yyjson_mut_obj_add_uint(doc, obj, "frequency", gpu->frequency);
|
||||
if (gpu->frequency != FF_GPU_FREQUENCY_UNSET)
|
||||
yyjson_mut_obj_add_uint(doc, obj, "frequency", gpu->frequency);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "frequency");
|
||||
|
||||
yyjson_mut_obj_add_uint(doc, obj, "deviceId", gpu->deviceId);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
|
||||
ffStrbufAppendC(&buffer, ']');
|
||||
}
|
||||
|
||||
if (dev->temperature == dev->temperature) //FF_PHYSICALDISK_TEMP_UNSET
|
||||
if (dev->temperature != FF_PHYSICALDISK_TEMP_UNSET)
|
||||
{
|
||||
if(buffer.length > 0)
|
||||
ffStrbufAppendS(&buffer, " - ");
|
||||
@@ -209,7 +209,10 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "revision", &dev->revision);
|
||||
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", dev->temperature);
|
||||
if (dev->temperature != FF_PHYSICALDISK_TEMP_UNSET)
|
||||
yyjson_mut_obj_add_real(doc, obj, "temperature", dev->temperature);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "temperature");
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFPhysicalDiskResult, dev, result)
|
||||
|
||||
+14
-5
@@ -55,7 +55,7 @@ void ffPrintWifi(FFWifiOptions* options)
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
if(item->conn.ssid.length)
|
||||
{
|
||||
if(item->conn.signalQuality == item->conn.signalQuality)
|
||||
if(item->conn.signalQuality != -DBL_MAX)
|
||||
{
|
||||
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ void ffPrintWifi(FFWifiOptions* options)
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
}
|
||||
|
||||
if(item->conn.signalQuality == item->conn.signalQuality)
|
||||
if(item->conn.signalQuality != -DBL_MAX)
|
||||
{
|
||||
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
ffPercentAppendNum(&buffer, item->conn.signalQuality, options->percent, buffer.length > 0, &options->moduleArgs);
|
||||
@@ -184,9 +184,18 @@ void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut
|
||||
yyjson_mut_obj_add_strbuf(doc, conn, "bssid", &wifi->conn.bssid);
|
||||
yyjson_mut_obj_add_strbuf(doc, conn, "protocol", &wifi->conn.protocol);
|
||||
yyjson_mut_obj_add_strbuf(doc, conn, "security", &wifi->conn.security);
|
||||
yyjson_mut_obj_add_real(doc, conn, "signalQuality", wifi->conn.signalQuality);
|
||||
yyjson_mut_obj_add_real(doc, conn, "rxRate", wifi->conn.rxRate);
|
||||
yyjson_mut_obj_add_real(doc, conn, "txRate", wifi->conn.txRate);
|
||||
if (wifi->conn.signalQuality != -DBL_MAX)
|
||||
yyjson_mut_obj_add_real(doc, conn, "signalQuality", wifi->conn.signalQuality);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, conn, "signalQuality");
|
||||
if (wifi->conn.rxRate != -DBL_MAX)
|
||||
yyjson_mut_obj_add_real(doc, conn, "rxRate", wifi->conn.rxRate);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, conn, "rxRate");
|
||||
if (wifi->conn.txRate != -DBL_MAX)
|
||||
yyjson_mut_obj_add_real(doc, conn, "txRate", wifi->conn.txRate);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, conn, "txRate");
|
||||
yyjson_mut_obj_add_uint(doc, conn, "channel", wifi->conn.channel);
|
||||
yyjson_mut_obj_add_uint(doc, conn, "frequency", wifi->conn.frequency);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,10 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m
|
||||
yyjson_mut_obj_add_uint(doc, obj, "used", zpool->used);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "total", zpool->total);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "version", zpool->version);
|
||||
yyjson_mut_obj_add_real(doc, obj, "fragmentation", zpool->fragmentation);
|
||||
if (zpool->fragmentation != -DBL_MAX)
|
||||
yyjson_mut_obj_add_real(doc, obj, "fragmentation", zpool->fragmentation);
|
||||
else
|
||||
yyjson_mut_obj_add_null(doc, obj, "fragmentation");
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFZpoolResult, zpool, results)
|
||||
|
||||
+2
-2
@@ -521,11 +521,11 @@ void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file)
|
||||
fputc('\n', file);
|
||||
}
|
||||
|
||||
double ffStrbufToDouble(const FFstrbuf* strbuf)
|
||||
double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue)
|
||||
{
|
||||
char* str_end;
|
||||
double result = strtod(strbuf->chars, &str_end);
|
||||
return str_end == strbuf->chars ? 0.0/0.0 : result;
|
||||
return str_end == strbuf->chars ? defaultValue : result;
|
||||
}
|
||||
|
||||
uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue)
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ bool ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c);
|
||||
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file);
|
||||
void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file);
|
||||
|
||||
FF_C_NODISCARD double ffStrbufToDouble(const FFstrbuf* strbuf);
|
||||
FF_C_NODISCARD double ffStrbufToDouble(const FFstrbuf* strbuf, double defaultValue);
|
||||
FF_C_NODISCARD int64_t ffStrbufToSInt(const FFstrbuf* strbuf, int64_t defaultValue);
|
||||
FF_C_NODISCARD uint64_t ffStrbufToUInt(const FFstrbuf* strbuf, uint64_t defaultValue);
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ bool FFWmiRecord::getReal(const wchar_t* key, double* real)
|
||||
case VT_R4: *real = vtProp.fltVal; break;
|
||||
case VT_R8: *real = vtProp.dblVal; break;
|
||||
case VT_BOOL: *real = vtProp.boolVal != VARIANT_FALSE; break;
|
||||
default: *real = NAN; result = false;
|
||||
default: *real = -DBL_MAX; result = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ int main(void)
|
||||
|
||||
//toNumber
|
||||
|
||||
VERIFY(ffStrbufToDouble(&strbuf) == 123456789.0);
|
||||
VERIFY(ffStrbufToDouble(&strbuf, -DBL_MAX) == 123456789.0);
|
||||
VERIFY(ffStrbufToUInt(&strbuf, 999) == 123456789);
|
||||
|
||||
//countC
|
||||
|
||||
Reference in New Issue
Block a user