1 /* vi: set sw=4 ts=4: */
3 * Mini watch implementation for busybox
5 * Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 /* BB_AUDIT SUSv3 N/A */
11 /* BB_AUDIT GNU defects -- only option -n is supported. */
13 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
15 * Removed dependency on date_main(), added proper error checking, and
29 int watch_main(int argc, char **argv)
33 char **watched_argv, *header;
35 if (argc < 2) bb_show_usage();
37 get_terminal_width_height(1, &width, 0);
38 header = xzalloc(width--);
40 /* don't use getopt, because it permutes the arguments */
42 if ((argc > 3) && !strcmp(*argv, "-n")) {
43 period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX);
50 len = snprintf(header, width, "Every %ds:", period);
51 while (*argv && len<width)
52 snprintf(header+len, width-len, " %s", *(argv++));
61 if (len < width) header[width-len] = 0;
63 printf("\033[H\033[J%s %s\n", header, thyme);
65 waitpid(bb_xspawn(watched_argv),0,0);