1 /* vi: set sw=4 ts=4: */
3 * Mini watch implementation for busybox
5 * Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de>
6 * Copyrigjt (C) Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 /* BB_AUDIT SUSv3 N/A */
12 /* BB_AUDIT GNU defects -- only option -n is supported. */
17 // watch [-d] [-n seconds]
18 // [--differences[=cumulative]] [--interval=seconds] command
21 // watch [-dt] [-n seconds]
22 // [--differences[=cumulative]] [--interval=seconds] [--no-title] command
24 // (procps 3.x and procps 2.x are forks, not newer/older versions of the same)
26 int watch_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
27 int watch_main(int argc
, char **argv
)
37 opt_complementary
= "-1"; // at least one param please
38 opt
= getopt32(argv
, "+dtn:", &tmp
);
39 //if (opt & 0x1) // -d (ignore)
40 //if (opt & 0x2) // -t
41 if (opt
& 0x4) period
= xatou(tmp
);
45 cmdlen
= 1; // 1 for terminal NUL
47 cmdlen
+= strlen(*p
++) + 1;
48 tmp
= cmd
= xmalloc(cmdlen
);
50 tmp
+= sprintf(tmp
, " %s", *argv
);
53 cmd
++; // skip initial space
56 printf("\033[H\033[J");
57 if (!(opt
& 0x2)) { // no -t
62 get_terminal_width_height(STDIN_FILENO
, &width
, 0);
63 header
= xrealloc(header
, width
--);
64 // '%-*s' pads header with spaces to the full width
65 snprintf(header
, width
, "Every %ds: %-*s", period
, width
, cmd
);
70 strcpy(header
+ width
- len
, thyme
);
74 // TODO: 'real' watch pipes cmd's output to itself
75 // and does not allow it to overflow the screen
76 // (taking into account linewrap!)
80 return 0; // gcc thinks we can reach this :)