aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2003-12-07 02:15:02 +0000
committerDimitri Sokolyuk <demon@dim13.org>2003-12-07 02:15:02 +0000
commit6cf279df3b2529d23fd24c87bc098c090ecb74e6 (patch)
treef373178a5233008958393e3fcf524fc8ef747190
parente997a6ebe20811b59870b6f75098562e3779ce18 (diff)
cleanup
add `title' function add notice to original `watch' author
-rw-r--r--watch.125
-rw-r--r--watch.c40
2 files changed, 44 insertions, 21 deletions
diff --git a/watch.1 b/watch.1
index 22d628f..15bfc29 100644
--- a/watch.1
+++ b/watch.1
@@ -7,14 +7,17 @@
.Nd execute program periodically, showing output fullscreen
.Sh SYNOPSIS
.Nm watch
-.Op Fl v
-.Op Fl s Ar <seconds>
+.Op Fl vns Ar <seconds>
.Op Ar command
.Sh DESCRIPTION
-The
.Nm
-utility allow you to watch a program as it changes.
-By default it updates it self every 2 seconds.
+runs
+.Ar command
+repeatedly, displaying its output fullscreen.
+This allow you to watch a
+.Ar command
+output as it changes.
+By default it updates output every 2 seconds.
.Pp
The
.Nm
@@ -23,10 +26,12 @@ will end with keyboard interrupt
.Pp
The options are as follows:
.Bl -tag -width Ds
-.It Fl s Ar <seconds>
-Delay in seconds between screen refresh.
.It Fl v
Show version and exit.
+.It Fl n
+Show no title.
+.It Fl s Ar <seconds>
+Delay in seconds between screen refresh.
.El
.Pp
.Sh EXAMPLE
@@ -34,6 +39,8 @@ Show version and exit.
-s 1 ps x
.Pp
.Sh AUTHORS
-The
+The original
.Nm
-utility was written by demon <demon@vhost.dyndns.org> in 2003.
+was written by Tony Rems <rembo@unisoft.com> in 1991,
+with mods and corrections by Francois Pinard.
+It was rewritten by demon <demon@vhost.dyndns.org> in 2003.
diff --git a/watch.c b/watch.c
index 74e31b4..9ea413c 100644
--- a/watch.c
+++ b/watch.c
@@ -1,5 +1,9 @@
/* $Id$ */
-/* watch - execute program periodicaly, showing output fullscreen */
+/*
+ * watch -- execute program repeatedly, displaying output fullscreen
+ * Based on the original 1991 'watch' by Tony Rems <rembo@unisoft.com>
+ * (with mods and corrections by Francois Pinard)
+ */
/*
* Copyright (c) 2003 demon <demon@vhost.dymdns.org>
*
@@ -25,28 +29,30 @@
#include <curses.h>
#define MAXBUF 255
-static char copyright[] = "(c) 2003 demon <demon@vhost.dyndns.org>";
-static char version[] = "0.2";
+static char *copyright = "(c) 2003 demon <demon@vhost.dyndns.org>";
+static char *version = "0.2";
extern char *__progname;
+
time_t tval;
int die_flag;
+int period=2;
+void title();
void usage();
void die();
-int main (int argc, char *argv[]) {
- int period=2;
+int main (int argc, char **argv) {
+ int n_flag=0;
char ch;
char cmd[MAXBUF];
char buf[MAXBUF];
- char curtime[30];
FILE *pipe;
signal(SIGINT, die);
signal(SIGTERM, die);
signal(SIGHUP, die);
- while ((ch = getopt(argc, argv, "s:v")) != -1)
+ while ((ch = getopt(argc, argv, "s:vn")) != -1)
switch (ch) {
case 'v':
(void)fprintf(stderr, "%s %s %s\n", __progname, version, copyright);
@@ -57,6 +63,9 @@ int main (int argc, char *argv[]) {
if(period < 1)
usage();
break;
+ case 'n':
+ n_flag=1;
+ break;
case '?':
default:
usage();
@@ -80,11 +89,9 @@ int main (int argc, char *argv[]) {
if(strlen(cmd)) {
initscr();
while(!die_flag) {
- time(&tval);
- strncpy(curtime, ctime(&tval), sizeof(curtime)-1);
- curtime[strlen(curtime) - 6] = '\0';
move(0,0);
- printw("%s\tEvery %ds: %s\n\n", curtime, period, cmd);
+ if(!n_flag)
+ title(cmd);
pipe = popen(cmd, "r");
while(fgets(buf, sizeof(buf), pipe))
printw("%s",buf);
@@ -100,8 +107,17 @@ int main (int argc, char *argv[]) {
exit(0);
}
+void title(char **cmd) {
+ char curtime[30];
+ time(&tval);
+ strncpy(curtime, ctime(&tval), sizeof(curtime)-1);
+ curtime[strlen(curtime) - 6] = '\0';
+ printw("%s\tEvery %ds: %s", curtime, period, cmd);
+ move(2,0);
+}
+
void usage() {
- (void)fprintf(stderr, "Usage: %s [-s <seconds> | -v ] [command]\n", __progname);
+ (void)fprintf(stderr, "Usage: %s [-s <seconds> ] [ -vn ] [command]\n", __progname);
exit (1);
}