From a7449c3f5ef66c8149c71fe3d16e5e5997ef354b Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:34:53 -0500 Subject: [PATCH] merge timerlib.c and timer.c into one file --- c/timer.c | 43 ++++++++++++++++++++++++++++++++++++++++++- c/timerlib.c | 42 ------------------------------------------ 2 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 c/timerlib.c diff --git a/c/timer.c b/c/timer.c index eab8457..b2c45e5 100644 --- a/c/timer.c +++ b/c/timer.c @@ -4,7 +4,48 @@ #include #include -#include "timerlib.c" +struct timer { + int s; /* seconds */ + int d; /* data storage */ + void (*u)(struct timer *t); /* update function */ + int (*c)(struct timer *t); /* stop check function */ + int (*p)(struct timer *t); /* pause check function */ +}; + +void timerdec(struct timer *t) { if (t->s != 0) t->s--; } +void timerinc(struct timer *t) { t->s++; } +void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } + +int timerstate(int (*f)(struct timer *t), struct timer *t) { + if(f != NULL) { + if(f(t)) return 1; + else return 0; + } + return 0; +} + +int timerstop(struct timer *t) { return timerstate(t->c, t); } +int timerpause(struct timer *t) { return timerstate(t->p, t); } + +int timerzero(struct timer *t) { + if(t->s == 0) return 1; + return 0; +} + +int seconds(int t) { return t % 60; } +int minutes(int t) { return (t / 60) % 60; } +int minute(int t) { return t / 60; } +int hours(int t) { return (t / 60) / 60; } + +struct timer *timerinit(void) { + struct timer *t = malloc(sizeof *t); + t->s = 0; + t->d = 0; + t->u = NULL; + t->c = NULL; + t->p = NULL; + return t; +} struct settings { int e:1; /* use escape (v assumed) */ diff --git a/c/timerlib.c b/c/timerlib.c deleted file mode 100644 index 92c48d2..0000000 --- a/c/timerlib.c +++ /dev/null @@ -1,42 +0,0 @@ -struct timer { - int s; /* seconds */ - int d; /* data storage */ - void (*u)(struct timer *t); /* update function */ - int (*c)(struct timer *t); /* stop check function */ - int (*p)(struct timer *t); /* pause check function */ -}; - -void timerdec(struct timer *t) { if (t->s != 0) t->s--; } -void timerinc(struct timer *t) { t->s++; } -void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } - -int timerstate(int (*f)(struct timer *t), struct timer *t) { - if(f != NULL) { - if(f(t)) return 1; - else return 0; - } - return 0; -} - -int timerstop(struct timer *t) { return timerstate(t->c, t); } -int timerpause(struct timer *t) { return timerstate(t->p, t); } - -int timerzero(struct timer *t) { - if(t->s == 0) return 1; - return 0; -} - -int seconds(int t) { return t % 60; } -int minutes(int t) { return (t / 60) % 60; } -int minute(int t) { return t / 60; } -int hours(int t) { return (t / 60) / 60; } - -struct timer *timerinit(void) { - struct timer *t = malloc(sizeof *t); - t->s = 0; - t->d = 0; - t->u = NULL; - t->c = NULL; - t->p = NULL; - return t; -}