XXIIVV

Stopwatch is a terminal utility countdown.

Why the heck did I even have to write this in the first place.

cc sw.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -o sw
#include <stdio.h>
#include <unistd.h>

int
main()
{
	int h = -1, m = -1, s = -1, t = 0;
	printf("Timeout(HH:MM:SS) | ");
	if(!scanf("%d:%d:%d", &h, &m, &s)) {
		printf("Invalid timestamp\n");
		return 0;
	}
	if(m == -1 && s == -1) {
		s = h;
		h = 0;
		m = 0;
	} else if(s == -1) {
		s = m;
		m = h;
		h = 0;
	}
	t = h * 3600 + m * 60 + s;
	putchar('\n');
	do {
		if(t > 3600)
			printf("\033[A%02d:%02d:%02d\n",
				t / 3600,
				(t / 60) % 60,
				t % 60);
		else if(t > 60)
			printf("\033[A%02d:%02d\n",
				(t / 60) % 60,
				t % 60);
		else
			printf("\033[A%02d\n",
				t);
		sleep(1);
		t--;
	} while(t >= 0);
	printf("Ended.\n");
	return 0;
}
— Submit an edit to stopwatch.c.txt(42 lines)