svn commit: branches/busybox_scratch/coreutils
aldot at busybox.net
aldot at busybox.net
Sun Aug 20 11:37:04 UTC 2006
Author: aldot
Date: 2006-08-20 04:37:04 -0700 (Sun, 20 Aug 2006)
New Revision: 15843
Log:
- shrink watch and add optional cleanup code:
text data bss dec hex filename
301 0 0 301 12d coreutils/watch.o.orig
293 0 0 293 125 coreutils/watch.o
Modified:
branches/busybox_scratch/coreutils/watch.c
Changeset:
Modified: branches/busybox_scratch/coreutils/watch.c
===================================================================
--- branches/busybox_scratch/coreutils/watch.c 2006-08-20 11:33:09 UTC (rev 15842)
+++ branches/busybox_scratch/coreutils/watch.c 2006-08-20 11:37:04 UTC (rev 15843)
@@ -3,6 +3,7 @@
* Mini watch implementation for busybox
*
* Copyright (C) 2001 by Michael Habermann <mhabermann at gmx.de>
+ * Mar 16, 2003 Manuel Novoa III (mjn3 at codepoet.org)
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
@@ -10,22 +11,12 @@
/* BB_AUDIT SUSv3 N/A */
/* BB_AUDIT GNU defects -- only option -n is supported. */
-/* Mar 16, 2003 Manuel Novoa III (mjn3 at codepoet.org)
- *
- * Removed dependency on date_main(), added proper error checking, and
- * reduced size.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
+#include "busybox.h"
#include <time.h>
#include <assert.h>
-#include <unistd.h>
#include <sys/wait.h>
-#include "busybox.h"
+
int watch_main(int argc, char **argv)
{
int width, len;
@@ -34,19 +25,18 @@
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++));
@@ -59,10 +49,12 @@
thyme = ctime(&t);
len = strlen(thyme);
if (len < width) header[width-len] = 0;
-
- printf("\033[H\033[J%s %s\n", header, thyme);
+ bb_printf("\033[H\033[J%s %s\n", header, thyme);
+
waitpid(bb_xspawn(watched_argv),0,0);
sleep(period);
}
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(header);
}
More information about the busybox-cvs
mailing list