aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comet.conf5
-rw-r--r--src/comet.c4
-rw-r--r--src/config.c70
-rw-r--r--src/config.h33
4 files changed, 28 insertions, 84 deletions
diff --git a/comet.conf b/comet.conf
index bece0c9..7f07c8a 100644
--- a/comet.conf
+++ b/comet.conf
@@ -52,3 +52,8 @@
; ; only group
; spacing = 10
; children = label2 another blockus
+
+[block.cpu]
+ type = cpu
+ interval = 1
+ text = "CPU: ${percentage}"
diff --git a/src/comet.c b/src/comet.c
index 53be0b2..dda183b 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -26,7 +26,7 @@
static sig_atomic_t running = true;
-void signal_quit(int status)
+static void signal_quit(int status)
{
running = false;
}
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
FILE *config_file = fopen(config_path, "rb");
if (config_file != NULL) {
- log_debug("Reading config '%s'", config_path);
+ log_info("Reading config '%s'", config_path);
config_read(&config, config_file);
}
diff --git a/src/config.c b/src/config.c
index 4451341..bb9c1d2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -8,25 +8,11 @@
#include "any_log.h"
#include "config.h"
#include "util.h"
+#include "block.h"
#define ANY_INI_IMPLEMENT
#include "any_ini.h"
-typedef enum {
- CONFIG_STRING,
- CONFIG_INT,
- CONFIG_UINT,
- CONFIG_DOUBLE,
- CONFIG_BOOL,
- CONFIG_COLOR,
-} config_type_t;
-
-typedef struct {
- const char *key;
- config_type_t type;
- size_t offset;
-} config_entry_t;
-
static const config_entry_t bar_entries[] = {
{ "width", CONFIG_UINT, offsetof(config_t, width) },
{ "height", CONFIG_UINT, offsetof(config_t, height) },
@@ -172,7 +158,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
bool nullable = entries[i].type == CONFIG_STRING;
if ((value == NULL || *value == '\0') && !nullable) {
- log_value_error("Empty config entry",
+ log_value_error("Invalid empty entry",
"s:section", section,
"s:key", key,
"s:expected_type", types[entries[i].type],
@@ -231,7 +217,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
log_panic("Unreachable");
}
- log_value_error("Invalid config entry",
+ log_value_error("Invalid entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -242,7 +228,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
}
}
- log_value_warn("Unknown config entry",
+ log_value_warn("Unknown entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -278,19 +264,12 @@ void config_read(config_t *config, FILE *file)
const config_entry_t *entries = NULL;
void *result = NULL;
- config_section_t **section_ptr = NULL;
- size_t *section_size = NULL;
- char *section_label = NULL;
-
if (section != NULL) {
if (!strncmp(section, "block.", 6)) {
- section_ptr = &config->blocks;
- section_size = &config->n_blocks;
- section_label = strcopy(section + 6);
+ // TODO
+
} else if (!strncmp(section, "action.", 7)) {
- section_ptr = &config->actions;
- section_size = &config->n_actions;
- section_label = strcopy(section + 7);
+ // TODO
} else if (!strcmp(section, "bar")) {
entries = bar_entries;
result = config;
@@ -298,24 +277,11 @@ void config_read(config_t *config, FILE *file)
log_warn("Unknown section '%s'", section);
}
- if (section_ptr != NULL) {
- if (*section_label == '\0') {
- ++errors;
- log_value_error("Sections must have a non-empty label",
- "s:section", section,
- "i:line", ini.line);
- }
-
- *section_ptr = realloc(*section_ptr, ++(*section_size) * sizeof(config_section_t));
- assert(*section_ptr != NULL);
- (*section_ptr)[*section_size - 1].label = section_label;
- }
-
char *key;
while ((key = any_ini_stream_next_key(&ini)) != NULL) {
char *value = any_ini_stream_next_value(&ini);
- log_value_trace("Reading config entry",
+ log_value_trace("Reading entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -340,29 +306,11 @@ void config_resolve(config_t *config, block_t *block)
int errors = 1;
if (errors > 0)
- log_panic("Failed to resolve config");
+ log_panic("Config could not be resolved");
}
void config_free(config_t *config)
{
- for (int i = 0; i < config->n_blocks; i++) {
- for (int j = 0; j < config->blocks[i].n_pairs; j++)
- pair_free(&config->blocks[i].pairs[j]);
-
- free(config->blocks[i].pairs);
- free(config->blocks[i].label);
- }
-
- for (int i = 0; i < config->n_actions; i++) {
- for (int j = 0; j < config->actions[i].n_pairs; j++)
- pair_free(&config->actions[i].pairs[j]);
-
- free(config->actions[i].pairs);
- free(config->actions[i].label);
- }
-
- free(config->blocks);
- free(config->actions);
free(config->font);
free(config->monitor);
}
diff --git a/src/config.h b/src/config.h
index c24c968..70c828c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -6,31 +6,22 @@
#include "block.h"
-//typedef struct {
-// char *label;
-// char *type;
-// int x_padding, y_padding;
-// color_t color;
-// char *text;
-// color_t text_color;
-// int line_width;
-// color_t line_color;
-// bool hidden;
-// double interval;
-// int min_width, max_width;
-//} config_block_t;
+typedef enum {
+ CONFIG_STRING,
+ CONFIG_INT,
+ CONFIG_UINT,
+ CONFIG_DOUBLE,
+ CONFIG_BOOL,
+ CONFIG_COLOR,
+} config_type_t;
typedef struct {
- char *label;
- size_t n_pairs;
- pair_t *pairs;
-} config_section_t;
+ const char *key;
+ config_type_t type;
+ size_t offset;
+} config_entry_t;
typedef struct {
- size_t n_blocks;
- config_section_t *blocks;
- size_t n_actions;
- config_section_t *actions;
char *font;
char *monitor;
uint32_t height;