1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
$NetBSD: patch-aa,v 1.4 2008/02/22 02:14:53 tnn Exp $
--- watch.c.orig 2008-02-22 03:05:28.000000000 +0100
+++ watch.c
@@ -13,7 +13,13 @@
#define VERSION "0.2.0"
#include <ctype.h>
+#if defined(HAVE_NBCOMPAT_H)
+#include <nbcompat/config.h>
+#include <nbcompat/cdefs.h>
+#include <nbcompat/getopt.h>
+#else
#include <getopt.h>
+#endif
#include <signal.h>
#include <ncurses.h>
#include <stdio.h>
@@ -142,6 +148,7 @@ main(int argc, char *argv[])
option_differences_cumulative = 0,
option_help = 0, option_version = 0;
float interval = 2;
+ struct timespec tsinterval;
char *command;
int command_length = 0; /* not including final \0 */
@@ -199,6 +206,9 @@ main(int argc, char *argv[])
if (optind >= argc)
do_usage();
+ tsinterval.tv_sec = interval;
+ tsinterval.tv_nsec = (interval - tsinterval.tv_sec) * 1000000000L;
+
command = strdup(argv[optind++]);
command_length = strlen(command);
for (; optind < argc; optind++) {
@@ -246,10 +256,16 @@ main(int argc, char *argv[])
}
if (show_title) {
+#if defined(__sun)
+ header = malloc(width + 1);
+ if (!header) { perror("malloc"); do_exit(2); }
+ snprintf(header, width + 1, "Every %.1fs: %s", interval, command);
+#else
// left justify interval and command,
// right justify time, clipping all to fit window width
asprintf(&header, "Every %.1fs: %.*s",
interval, min(width - 1, command_length), command);
+#endif
mvaddstr(0, 0, header);
if (strlen(header) > (size_t) (width - tsl - 1))
mvaddstr(0, width - tsl - 4, "... ");
@@ -313,7 +329,7 @@ main(int argc, char *argv[])
first_screen = 0;
refresh();
- usleep(interval * 1000000);
+ nanosleep(&tsinterval, NULL);
}
endwin();
|