Skip to content

Commit 97e1b98

Browse files
committed
Global: pack all enums and make flag enums unsigned
1 parent e821a99 commit 97e1b98

File tree

54 files changed

+100
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+100
-73
lines changed

src/common/format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "util/FFstrbuf.h"
44

5-
typedef enum FFformatArgType
5+
typedef enum __attribute__((__packed__)) FFformatArgType
66
{
77
FF_FORMAT_ARG_TYPE_NULL = 0,
88
FF_FORMAT_ARG_TYPE_UINT,

src/common/io/io.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName
8787
}
8888

8989
//Bit flags, combine with |
90-
typedef enum FFPathType
90+
typedef enum __attribute__((__packed__)) FFPathType
9191
{
9292
FF_PATHTYPE_FILE = 1 << 0,
9393
FF_PATHTYPE_DIRECTORY = 1 << 1,
9494
FF_PATHTYPE_ANY = FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY,
95+
FF_PATHTYPE_FORCE_UNSIGNED = UINT8_MAX,
9596
} FFPathType;
9697

9798
static inline bool ffPathExists(const char* path, FFPathType pathType)

src/common/option.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ static inline void ffOptionInitModuleBaseInfo(
4545
baseInfo->generateJsonConfig = (__typeof__(baseInfo->generateJsonConfig)) generateJsonConfig;
4646
}
4747

48-
typedef enum FFModuleKeyType
48+
typedef enum __attribute__((__packed__)) FFModuleKeyType
4949
{
5050
FF_MODULE_KEY_TYPE_NONE = 0,
5151
FF_MODULE_KEY_TYPE_STRING = 1 << 0,
5252
FF_MODULE_KEY_TYPE_ICON = 1 << 1,
5353
FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON,
54+
FF_MODULE_KEY_TYPE_FORCE_UNSIGNED = UINT8_MAX,
5455
} FFModuleKeyType;
5556

5657
typedef struct FFModuleArgs

src/common/percent.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static void appendOutputColor(FFstrbuf* buffer, const FFModuleArgs* module)
1414
ffStrbufAppendF(buffer, "\e[%sm", instance.config.display.colorOutput.chars);
1515
}
1616

17-
void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config, const FFModuleArgs* module)
17+
void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, const FFModuleArgs* module)
1818
{
1919
uint8_t green = config.green, yellow = config.yellow;
2020
assert(green <= 100 && yellow <= 100);
@@ -104,7 +104,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con
104104
}
105105
}
106106

107-
void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses, const FFModuleArgs* module)
107+
void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, bool parentheses, const FFModuleArgs* module)
108108
{
109109
uint8_t green = config.green, yellow = config.yellow;
110110
assert(green <= 100 && yellow <= 100);
@@ -156,7 +156,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig con
156156
ffStrbufAppendC(buffer, ')');
157157
}
158158

159-
bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config)
159+
bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config)
160160
{
161161
if (!ffStrStartsWithIgnCase(subkey, "percent-"))
162162
return false;
@@ -190,7 +190,7 @@ bool ffPercentParseCommandOptions(const char* key, const char* subkey, const cha
190190
return false;
191191
}
192192

193-
bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config)
193+
bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentageModuleConfig* config)
194194
{
195195
if (!ffStrEqualsIgnCase(key, "percent"))
196196
return false;
@@ -228,7 +228,7 @@ bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeCo
228228
return true;
229229
}
230230

231-
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config)
231+
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config)
232232
{
233233
if (config.green == defaultConfig.green && config.yellow == defaultConfig.yellow)
234234
return;

src/common/percent.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44
#include "common/parsing.h"
55
#include "common/option.h"
66

7-
enum FFPercentageTypeFlags
7+
typedef enum __attribute__((__packed__)) FFPercentageTypeFlags
88
{
9+
FF_PERCENTAGE_TYPE_NONE = 0,
910
FF_PERCENTAGE_TYPE_NUM_BIT = 1 << 0,
1011
FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1,
1112
FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2,
1213
FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3,
1314
FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = FF_PERCENTAGE_TYPE_NUM_COLOR_BIT,
14-
};
15+
FF_PERCENTAGE_TYPE_FORCE_UNSIGNED_ = UINT8_MAX,
16+
} FFPercentageTypeFlags;
17+
static_assert(sizeof(FFPercentageTypeFlags) == 1, "");
18+
19+
typedef struct FFPercentageModuleConfig
20+
{
21+
uint8_t green;
22+
uint8_t yellow;
23+
} FFPercentageModuleConfig;
1524

1625
// if (green <= yellow)
1726
// [0, green]: print green
@@ -23,12 +32,12 @@ enum FFPercentageTypeFlags
2332
// [yellow, green): print yellow
2433
// [0, yellow): print red
2534

26-
void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config, const FFModuleArgs* module);
27-
void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses, const FFModuleArgs* module);
35+
void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, const FFModuleArgs* module);
36+
void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, bool parentheses, const FFModuleArgs* module);
2837

2938
typedef struct yyjson_val yyjson_val;
3039
typedef struct yyjson_mut_doc yyjson_mut_doc;
3140
typedef struct yyjson_mut_val yyjson_mut_val;
32-
bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config);
33-
bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config);
34-
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config);
41+
bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config);
42+
bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentageModuleConfig* config);
43+
void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config);

src/common/printing.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include "fastfetch.h"
44
#include "common/format.h"
55

6-
typedef enum FFPrintType {
6+
typedef enum __attribute__((__packed__)) FFPrintType {
77
FF_PRINT_TYPE_DEFAULT = 0,
88
FF_PRINT_TYPE_NO_CUSTOM_KEY = 1 << 0, // key has been formatted outside
99
FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR = 1 << 1,
1010
FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH = 1 << 2,
1111
FF_PRINT_TYPE_NO_CUSTOM_OUTPUT_FORMAT = 1 << 3, // reserved
12+
FF_PRINT_TYPE_FORCE_UNSIGNED = UINT8_MAX,
1213
} FFPrintType;
1314

1415
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType);

src/common/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "fastfetch.h"
44

5-
typedef enum FFvarianttype
5+
typedef enum __attribute__((__packed__)) FFvarianttype
66
{
77
FF_VARIANT_TYPE_STRING,
88
FF_VARIANT_TYPE_BOOL,

src/detection/cpucache/cpucache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "fastfetch.h"
44

5-
typedef enum FFCPUCacheType
5+
typedef enum __attribute__((__packed__)) FFCPUCacheType
66
{
77
FF_CPU_CACHE_TYPE_UNIFIED = 0,
88
FF_CPU_CACHE_TYPE_INSTRUCTION = 1,

src/detection/displayserver/displayserver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
#define FF_WM_PROTOCOL_X11 "X11"
4343
#define FF_WM_PROTOCOL_WAYLAND "Wayland"
4444

45-
typedef enum FFDisplayType {
45+
typedef enum __attribute__((__packed__)) FFDisplayType {
4646
FF_DISPLAY_TYPE_UNKNOWN,
4747
FF_DISPLAY_TYPE_BUILTIN,
4848
FF_DISPLAY_TYPE_EXTERNAL,
4949
} FFDisplayType;
5050

51-
typedef enum FFDisplayHdrStatus
51+
typedef enum __attribute__((__packed__)) FFDisplayHdrStatus
5252
{
5353
FF_DISPLAY_HDR_STATUS_UNKNOWN,
5454
FF_DISPLAY_HDR_STATUS_UNSUPPORTED,

src/detection/displayserver/linux/wayland/wayland.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "../displayserver_linux.h"
1111

12-
typedef enum WaylandProtocolType
12+
typedef enum __attribute__((__packed__)) WaylandProtocolType
1313
{
1414
FF_WAYLAND_PROTOCOL_TYPE_NONE,
1515
FF_WAYLAND_PROTOCOL_TYPE_GLOBAL,

0 commit comments

Comments
 (0)