diff --git a/lupan-clock/stdout-clock.c b/lupan-clock/stdout-clock.c index dd34ae4..13f36e2 100644 --- a/lupan-clock/stdout-clock.c +++ b/lupan-clock/stdout-clock.c @@ -1,27 +1,40 @@ #include #include +#include #include #include #include -void show(struct tm *tm) +void show(char *prefix, struct tm *tm) { char s[6]; strftime(s, sizeof(s), "%H:%M", tm); - printf("%s\n", s); + printf("%s%s\n", prefix, s); fflush(stdout); } -int main() { - int h, m, init = 60; +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(tm); + show(prefix, tm); h = tm->tm_hour; m = tm->tm_min; init = (init > 0) ? init - 1 : 0;