master ohmu/fastfetch-openbsd / src / common / argType.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#include "common/FFstrbuf.h"
 4
 5// For ffRegReadValue(s)
 6// If length is 0, data will be allocated with malloc() and must be freed by the caller
 7// Otherwise, data must point to a buffer of at least length bytes, and the actual length of the data will be written to length.
 8typedef struct FFArgBuffer {
 9    void* data;
10    uint32_t length;
11} FFArgBuffer;
12
13typedef enum FFArgType: uint8_t {
14    FF_ARG_TYPE_NULL = 0,
15    FF_ARG_TYPE_UINT,
16    FF_ARG_TYPE_UINT64,
17    FF_ARG_TYPE_UINT16,
18    FF_ARG_TYPE_UINT8,
19    FF_ARG_TYPE_INT,
20    FF_ARG_TYPE_STRING,
21    FF_ARG_TYPE_STRBUF,
22    FF_ARG_TYPE_FLOAT,
23    FF_ARG_TYPE_DOUBLE,
24    FF_ARG_TYPE_LIST,
25    FF_ARG_TYPE_BOOL,
26    FF_ARG_TYPE_BUFFER,
27} FFArgType;
28
29#define FF_ARG(variable, var_name) { _Generic((variable),                                   \
30        uint32_t: FF_ARG_TYPE_UINT,                                                         \
31        uint64_t: FF_ARG_TYPE_UINT64,                                                       \
32        uint16_t: FF_ARG_TYPE_UINT16,                                                       \
33        uint8_t: FF_ARG_TYPE_UINT8,                                                         \
34        int32_t: FF_ARG_TYPE_INT,                                                           \
35        char*: FF_ARG_TYPE_STRING,                                                          \
36        const char*: FF_ARG_TYPE_STRING,                                                    \
37        FFstrbuf: FF_ARG_TYPE_STRBUF,                                                       \
38        float: FF_ARG_TYPE_FLOAT,                                                           \
39        double: FF_ARG_TYPE_DOUBLE,                                                         \
40        FFlist: FF_ARG_TYPE_LIST,                                                           \
41        bool: FF_ARG_TYPE_BOOL,                                                             \
42        FFArgBuffer: FF_ARG_TYPE_BUFFER),                                                   \
43    _Generic((variable), char*: (variable), const char*: (variable), default: &(variable)), \
44    (var_name) }