summaryrefslogtreecommitdiffhomepage
path: root/coreutils/watch.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-08-28 23:31:54 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-08-28 23:31:54 +0000
commit73561cc75ac31e63bcab4b4ebfaf738e4ca225e6 (patch)
tree2a57564b8917a983365c765d4daa83032d9f0a17 /coreutils/watch.c
parent6ce8dae1d5a201156a83201de6c49cdcc4c8df3e (diff)
- pull from busybox_scratch: r15829:15850
Various fixes, cleanups and shrinkage: saves 952 Bytes: text data bss dec hex filename 1087742 15853 790632 1894227 1ce753 ../busybox/busybox.old 1086790 15853 790632 1893275 1ce39b busybox via: # scripts/bloat-o-meter ../busybox/busybox_unstripped.old busybox_unstripped function old new delta ipcrm_main 756 822 +66 getval - 61 +61 maybe_set_utc - 40 +40 udhcpc_main 2896 2912 +16 md5_hash_block 428 437 +9 opt 8 16 +8 qgravechar 106 110 +4 make_bitmap 292 295 +3 inflate_unzip 2056 2059 +3 add_partition 1412 1414 +2 __parsespent 156 158 +2 qrealloc 41 42 +1 format - 1 +1 catv_main 313 314 +1 watch_main 293 292 -1 varunset 81 80 -1 part 1 - -1 check_if_skip 837 836 -1 start_stop_daemon_main 840 837 -3 create_lost_and_found 175 172 -3 supress_non_delimited_lines 4 - -4 static.l 4 - -4 static.c 5 1 -4 bsd_sum_file 237 233 -4 eval2 338 332 -6 arithmetic_common 166 158 -8 cmpfunc 22 5 -17 cksum_main 294 275 -19 cmp_main 465 439 -26 dd_main 1535 1508 -27 rmmod_main 376 333 -43 cut_file 727 644 -83 ipcs_main 3809 3721 -88 cut_main 722 614 -108 date_main 1443 1263 -180 remove_ids 222 - -222 ------------------------------------------------------------------------------ (add/remove: 3/4 grow/shrink: 11/18 up/down: 217/-853) Total: -636 bytes
Diffstat (limited to 'coreutils/watch.c')
-rw-r--r--coreutils/watch.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/coreutils/watch.c b/coreutils/watch.c
index c8b16b908..7b9c6698a 100644
--- a/coreutils/watch.c
+++ b/coreutils/watch.c
@@ -3,6 +3,7 @@
* Mini watch implementation for busybox
*
* Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de>
+ * Copyrigjt (C) Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
@@ -10,14 +11,9 @@
/* BB_AUDIT SUSv3 N/A */
/* BB_AUDIT GNU defects -- only option -n is supported. */
-/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
- *
- * Removed dependency on date_main(), added proper error checking, and
- * reduced size.
- */
-
#include "busybox.h"
+
int watch_main(int argc, char **argv)
{
int width, len;
@@ -26,19 +22,18 @@ int watch_main(int argc, char **argv)
if (argc < 2) bb_show_usage();
- get_terminal_width_height(1, &width, 0);
+ get_terminal_width_height(STDOUT_FILENO, &width, 0);
header = xzalloc(width--);
/* don't use getopt, because it permutes the arguments */
++argv;
- if ((argc > 3) && !strcmp(*argv, "-n")) {
+ if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') {
period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX);
argv += 2;
}
watched_argv = argv;
/* create header */
-
len = snprintf(header, width, "Every %ds:", period);
while (*argv && len<width)
snprintf(header+len, width-len, " %s", *(argv++));
@@ -50,11 +45,13 @@ int watch_main(int argc, char **argv)
time(&t);
thyme = ctime(&t);
len = strlen(thyme);
- if (len < width) header[width-len] = 0;
-
- printf("\033[H\033[J%s %s\n", header, thyme);
+ if (len < width)
+ header[width-len] = 0;
+ bb_printf("\033[H\033[J%s %s\n", header, thyme);
waitpid(xspawn(watched_argv),0,0);
sleep(period);
}
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(header);
}