diff options
author | Aaron Ball <nullspoon@oper.io> | 2022-03-18 19:04:47 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2022-03-18 19:04:47 -0600 |
commit | e43c99cedc3af8f372c393167cd1f3381742b76a (patch) | |
tree | fed73a4b3bd2603bd4a86ec4a489aa5e2907e870 | |
parent | c98e6b6adedee9c9576c91ca7c82fcf7d23423bc (diff) | |
download | i3cstat-e43c99cedc3af8f372c393167cd1f3381742b76a.tar.gz i3cstat-e43c99cedc3af8f372c393167cd1f3381742b76a.tar.xz |
Deduplicate config_time, removing config_date
The config_date code is effectively identical to the code for
config_time. The one difference is the format of the date output.
This replaces all of the config_date code, except for the init function,
with referenes to the config_time code to reduce and simplify
maintenance. This also adds the new configurable fmt support to the date
class as well, since it is now just config_time.
-rw-r--r-- | src/config_date.c | 30 | ||||
-rw-r--r-- | src/config_date.h | 6 |
2 files changed, 7 insertions, 29 deletions
diff --git a/src/config_date.c b/src/config_date.c index 0db56ef..7a4753b 100644 --- a/src/config_date.c +++ b/src/config_date.c @@ -16,32 +16,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "config_date.h" +#include "config_time.h" void config_date_init(struct node* n) { - n->data = malloc(sizeof(struct config_date)); + n->data = malloc(sizeof(struct config_time)); n->type = CTYPE_DATE; - n->loadfunc = &config_date_load; - n->loadkey = &load_date_key; -} + n->loadfunc = &config_time_load; + n->loadkey = &load_time_key; -void load_date_key(struct node* n, char* key, char* val) { - if(strcmp(key, "tz") == 0) - strcpy(((struct config_date*) n->data)->tz, val); - else - printf("ERROR: Unknown time key %s\n", key); + strcpy(((struct config_time*) n->data)->fmt, "%F"); } -int config_date_load(struct node* n) { - char buf[256]; - time_t timep; - struct tm* info; - - setenv("TZ", ((struct config_date*)n->data)->tz, 1); - time(&timep); - info = localtime(&timep); - - strftime(buf, 256, "%F", info); - strcpy(n->label, buf); - strcpy(n->color, C_LGREY); - return 0; -} +// All functions are provided by config_time, since date is just a config_time +// with a different date format. diff --git a/src/config_date.h b/src/config_date.h index 41b1069..4a7660e 100644 --- a/src/config_date.h +++ b/src/config_date.h @@ -25,12 +25,6 @@ #include "common.h" #include "config_node.h" -struct config_date { - char tz[64]; -}; - void config_date_init(struct node*); -void load_date_key(struct node*, char*, char*); -int config_date_load(struct node*); #endif |