snore

sleep with feedback
git clone git://git.bitsmanent.org/snore
Log | Files | Refs | README | LICENSE

commit bff84a442a3b45647256d6b6c8f2333568604486
parent 3024349c65b04e8b1377c2605b88100b1ba8a509
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Sat, 29 Apr 2017 19:01:48 +0200

Code style improvement.

Diffstat:
Msnore.c | 24++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/snore.c b/snore.c @@ -48,7 +48,6 @@ time_to_sec(char *s) { calculated = 0.0; string_end = s + strlen(s); - while(s < string_end) { part = strtod(s, &parse_end); if(parse_end == s) { @@ -67,7 +66,6 @@ time_to_sec(char *s) { } calculated += part; } - return calculated; } @@ -91,25 +89,19 @@ time_print(double tm) { int main(int argc, char *argv[]) { - double tm, endtm; + double endtm = 0, tm; int i; if(argc == 2 && !strcmp("-v", argv[1])) die("snore-"VERSION", © 2016 Claudio Alessi, see LICENSE for details\n"); - - if(argc == 1) { - endtm = symbols[LENGTH(symbols) - 1].mult; + for(i = 1; i < argc; ++i) { + tm = time_to_sec(argv[i]); + if(tm < 0) + die("%s: wrong time\n", argv[i]); + endtm += time_to_sec(argv[i]); } - else { - endtm = 0; - for(i = 1; i < argc; ++i) { - tm = time_to_sec(argv[i]); - if(tm < 0) - die("%s: wrong time\n", argv[i]); - endtm += time_to_sec(argv[i]); - } - } - + if(!endtm) + endtm = symbols[LENGTH(symbols) - 1].mult; for(tm = 0; tm < endtm; tm += DELTA) { time_print(tm); /* ascending */ printf(" | ");