#include #include #include #include #include #include void show(char *prefix, struct tm *tm) { char s[6]; strftime(s, sizeof(s), "%H:%M", tm); printf("%s%s\n", prefix, s); fflush(stdout); } int main(int argc, char **argv) { int h, m, init = 60, opt; time_t t; struct tm *tm; char *prefix = ""; while ((opt = getopt(argc, argv, "p:")) != -1) { switch (opt) { case 'p': prefix = optarg; break; default: fprintf(stderr, "Usage: %s [-p PREFIX]\n", argv[0]); exit(EXIT_FAILURE); } } while (1) { t = time(NULL); tm = localtime(&t); if (tm->tm_hour != h || tm->tm_min != m || init > 0) { show(prefix, tm); h = tm->tm_hour; m = tm->tm_min; init = (init > 0) ? init - 1 : 0; } sleep(1); } return 1; }