diff options
| author | Burt P <pburt0@gmail.com> | 2019-07-02 20:42:34 -0500 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-07-06 13:08:54 -0700 | 
| commit | 5bd8021f5355b022845f0688a13c0881a56c3b53 (patch) | |
| tree | 5bf17273b626dbfad334c4485e35cd7b3461ce13 | |
| parent | 285664ed7e706d731e20064b40746204db72fbc4 (diff) | |
struct info: add macros as described by lpereira
See:
https://github.com/lpereira/hardinfo/pull/393#issuecomment-507893260
Signed-off-by: Burt P <pburt0@gmail.com>
| -rw-r--r-- | hardinfo/info.c | 24 | ||||
| -rw-r--r-- | includes/info.h | 13 | 
2 files changed, 11 insertions, 26 deletions
diff --git a/hardinfo/info.c b/hardinfo/info.c index 368470b4..b9cd8cb9 100644 --- a/hardinfo/info.c +++ b/hardinfo/info.c @@ -40,7 +40,7 @@ void info_group_add_fieldsv(struct InfoGroup *group, va_list ap)      while (1) {          struct InfoField field = va_arg(ap, struct InfoField); -        if (!field.name) +        if (field.magic == INFO_LAST_MARKER)              break;          g_array_append_val(group->fields, field);      } @@ -72,23 +72,6 @@ struct InfoGroup *info_add_group(struct Info *info, const gchar *group_name, ...      return &g_array_index(info->groups, struct InfoGroup, info->groups->len - 1);  } -struct InfoField info_field(const gchar *name, const gchar *value) -{ -    return (struct InfoField) { -        .name = name, -        .value = value, -    }; -} - -struct InfoField info_field_update(const gchar *name, int update_interval) -{ -    return (struct InfoField) { -        .name = name, -        .value = "...", -        .update_interval = update_interval, -    }; -} -  struct InfoField info_field_printf(const gchar *name, const gchar *format, ...)  {      gchar *value; @@ -105,11 +88,6 @@ struct InfoField info_field_printf(const gchar *name, const gchar *format, ...)      };  } -struct InfoField info_field_last(void) -{ -    return (struct InfoField) {}; -} -  void info_add_computed_group(struct Info *info, const gchar *name, const gchar *value)  {      /* This is a scaffolding method: HardInfo should move away from pre-computing diff --git a/includes/info.h b/includes/info.h index da4c12e4..47e41980 100644 --- a/includes/info.h +++ b/includes/info.h @@ -61,6 +61,7 @@ struct InfoField {      unsigned int flags;      gboolean free_value_on_flatten; +    int magic;  };  struct Info *info_new(void); @@ -71,11 +72,17 @@ void info_add_computed_group(struct Info *info, const gchar *name, const gchar *  void info_group_add_fields(struct InfoGroup *group, ...);  void info_group_add_fieldsv(struct InfoGroup *group, va_list ap); -struct InfoField info_field(const gchar *name, const gchar *value);  struct InfoField info_field_printf(const gchar *name, const gchar *format, ...)      __attribute__((format(printf, 2, 3))); -struct InfoField info_field_update(const gchar *name, int update_interval); -struct InfoField info_field_last(void); + +#define INFO_LAST_MARKER 102 +#define info_field_full(...) (struct InfoField) { \ +    .magic = 3, \ +    __VA_ARGS__ \ +} +#define info_field(n, v) info_field_full(.name = (n), .value = (v)) +#define info_field_update(n, ui) info_field_full(.name = (n), .value = "...", .update_interval = (ui)) +#define info_field_last() (struct InfoField){.magic = INFO_LAST_MARKER}  static inline struct InfoField info_field_with_icon(struct InfoField field, const gchar *icon)  {  | 
