From d986e7ec25d7b7b651590ca2e3423c677fe89ae4 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:27:38 -0500 Subject: [PATCH] simplify functions that ought to be one-liners --- progs/timerlib.c | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/progs/timerlib.c b/progs/timerlib.c index 3e8e39c..92c48d2 100644 --- a/progs/timerlib.c +++ b/progs/timerlib.c @@ -6,17 +6,9 @@ struct timer { 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); -} +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) { @@ -26,34 +18,18 @@ int timerstate(int (*f)(struct timer *t), struct timer *t) { return 0; } -int timerstop(struct timer *t) { - return timerstate(t->c, t); -} - -int timerpause(struct timer *t) { - return timerstate(t->p, t); -} +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; -} +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);