diff options
Diffstat (limited to 'src/config_node.c')
-rw-r--r-- | src/config_node.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/config_node.c b/src/config_node.c new file mode 100644 index 0000000..dcccc00 --- /dev/null +++ b/src/config_node.c @@ -0,0 +1,74 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "config_node.h" + + +struct node* node_new(void (*init_callback)(struct node*)) { + struct node* out = malloc(sizeof(struct node)); + out->data = NULL; + out->next = NULL; + out->display[0] = '\0'; + out->text[0] = '\0'; + out->label[0] = '\0'; + strcpy(out->color, "#eeeeee"); + strcpy(out->label_color, "#eeeeee"); + init_callback(out); + return out; +} + + +struct node* lladd(struct node* list, struct node* next) { + while(list->next) + list = list->next; + list->next = next; + return next; +} + +void llfree(struct node* list) { + struct node* next = list; + while(next) { + next = list->next; + free(list); + } +} + +void _load_node_key(struct node* n, char* key, char* val) { + if(strcmp(key, "color") == 0) + strcpy(n->color, val); + else if(strcmp(key, "label_color") == 0) + strcpy(n->label_color, val); + else if(strcmp(key, "label") == 0) + strcpy(n->label, val); + else if(strcmp(key, "text") == 0) + strcpy(n->text, val); + else if(strcmp(key, "display") == 0) + strcpy(n->display, val); + else + printf("ERROR: Unknown node key %s\n", key); +} + +void node_print(struct node* n) { + printf("{ \"full_text\":\" %s\", \"color\": \"%s\", \"separator\":false },", + n->label, + n->label_color); + printf("{ \"full_text\":\" %s \", \"color\":\"%s\" }", n->text, n->color); + if(n->next) + printf(","); + printf("\n"); + fflush(stdout); +} |