summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stopwatch.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/stopwatch.c b/stopwatch.c
index 7c5ec76..b978753 100644
--- a/stopwatch.c
+++ b/stopwatch.c
@@ -26,7 +26,7 @@ static int
display_stopwatch(int timerfd)
{
uint64_t overrun = 0;
- uintmax_t total_overrun = 0, h, m, s, d, first_overrun = 0;
+ uintmax_t total_overrun = 0, subtotal_overrun = 0, h, m, s, d, first_overrun = 0;
int paused = 0, have_first = 0;
struct itimerspec old_time, zero_time;
size_t lap = 1;
@@ -63,34 +63,34 @@ display_stopwatch(int timerfd)
} else if (c == '\n') {
if (timerfd_settime(timerfd, 0, &orig_time, NULL))
goto fail;
- d = total_overrun % 10;
- s = total_overrun / 10 % 60;
- m = total_overrun / 10 / 60 % 60;
- h = total_overrun / 10 / 60 / 60;
+ d = subtotal_overrun % 10;
+ s = subtotal_overrun / 10 % 60;
+ m = subtotal_overrun / 10 / 60 % 60;
+ h = subtotal_overrun / 10 / 60 / 60;
if (quadsize)
printf("\033#5");
printf("Lap %2zu: %ju:%02ju:%02ju.%ju", lap, h, m, s, d);
lap++;
if (!have_first) {
have_first = 1;
- first_overrun = total_overrun;
- } else if (total_overrun > first_overrun) {
- total_overrun = total_overrun - first_overrun;
- d = total_overrun % 10;
- s = total_overrun / 10 % 60;
- m = total_overrun / 10 / 60 % 60;
- h = total_overrun / 10 / 60 / 60;
+ first_overrun = subtotal_overrun;
+ } else if (subtotal_overrun > first_overrun) {
+ subtotal_overrun = subtotal_overrun - first_overrun;
+ d = subtotal_overrun % 10;
+ s = subtotal_overrun / 10 % 60;
+ m = subtotal_overrun / 10 / 60 % 60;
+ h = subtotal_overrun / 10 / 60 / 60;
printf(" \033[31m(+%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d);
- } else if (total_overrun < first_overrun) {
- total_overrun = first_overrun - total_overrun;
- d = total_overrun % 10;
- s = total_overrun / 10 % 60;
- m = total_overrun / 10 / 60 % 60;
- h = total_overrun / 10 / 60 / 60;
+ } else if (subtotal_overrun < first_overrun) {
+ subtotal_overrun = first_overrun - subtotal_overrun;
+ d = subtotal_overrun % 10;
+ s = subtotal_overrun / 10 % 60;
+ m = subtotal_overrun / 10 / 60 % 60;
+ h = subtotal_overrun / 10 / 60 / 60;
printf(" \033[34m(-%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d);
}
printf("\033[K\n");
- total_overrun = 0;
+ subtotal_overrun = 0;
}
}
}
@@ -125,6 +125,7 @@ display_stopwatch(int timerfd)
goto fail;
} else {
total_overrun += (uintmax_t)overrun;
+ subtotal_overrun += (uintmax_t)overrun;
}
}