This commit is contained in:
albert 2003-02-09 07:27:16 +00:00
parent 3d111f943c
commit b8e27a1ecf
5 changed files with 31 additions and 17 deletions

1
NEWS
View File

@ -1,5 +1,6 @@
procps-3.1.5 --> procps-3.1.6
watch: new --no-title option
handle SPARC Linux badness
rare crash fixed
compile with gcc 2.91.xx again

View File

@ -1,5 +1,7 @@
_3_1_5 {
global:
__cyg_profile_func_enter; __cyg_profile_func_exit; main;
readproc; readproctab; ps_readproc; look_up_our_self; escape_command;
escape_str; escape_strlist;
openproc; closeproc;

View File

@ -2,7 +2,7 @@
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
* Ammended by cblake to only export the function symbol.
*
* Modified by Albert Cahalan
* Modified by Albert Cahalan, ????-2003
*
* Redistributable under the terms of the
* GNU Library General Public License; see COPYING
@ -31,14 +31,13 @@ void display_version(void) {
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
int linux_version_code = 0;
int linux_version_code;
static void init_Linux_version(void) __attribute__((constructor));
static void init_Linux_version(void) {
static struct utsname uts;
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
if (linux_version_code) return;
if (uname(&uts) == -1) /* failure implies impending death */
exit(1);
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)

View File

@ -3,7 +3,7 @@
watch \- execute a program periodically, showing output fullscreen
.SH SYNOPSIS
.B watch
.I [\-dhv] [\-n <seconds>] [\-\-differences[=cumulative]] [\-\-help] [\-\-interval=<seconds>] [\-\-version] <command>
.I [\-dhvt] [\-n <seconds>] [\-\-differences[=cumulative]] [\-\-help] [\-\-interval=<seconds>] [\-\-no\-title] [\-\-version] <command>
.SH DESCRIPTION
.BR watch
runs
@ -23,7 +23,12 @@ or
flag will highlight the differences between successive updates. The
.I --cumulative
option makes highlighting "sticky", presenting a running display of all
positions that have ever changed.
positions that have ever changed. The
.I -t
or
.I --no-title
option turns off the header showing the interval, command, and current
time at the top of the display, as well as the following blank line.
.PP
.BR watch
will run until interrupted.

31
watch.c
View File

@ -29,12 +29,13 @@ static struct option longopts[] = {
{"differences", optional_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"interval", required_argument, 0, 'n'},
{"no-title", no_argument, 0, 't'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static char usage[] =
"Usage: %s [-dhnv] [--differences[=cumulative]] [--help] [--interval=<n>] [--version] <command>\n";
"Usage: %s [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command>\n";
static char *progname;
@ -42,6 +43,7 @@ static int curses_started = 0;
static int height = 24, width = 80;
static int screen_size_changed = 0;
static int first_screen = 1;
static int show_title = 2; // number of lines used, 2 or 0
#define min(x,y) ((x) > (y) ? (y) : (x))
@ -101,7 +103,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
progname = argv[0];
while ((optc = getopt_long(argc, argv, "+d::hn:v", longopts, (int *) 0))
while ((optc = getopt_long(argc, argv, "+d::hn:vt", longopts, (int *) 0))
!= EOF) {
switch (optc) {
case 'd':
@ -112,6 +114,9 @@ main(int argc, char *argv[])
case 'h':
option_help = 1;
break;
case 't':
show_title = 0;
break;
case 'n':
{
char *str;
@ -201,22 +206,24 @@ main(int argc, char *argv[])
first_screen = 1;
}
/* left justify interval and command, right justify time, clipping all
to fit window width */
asprintf(&header, "Every %ds: %.*s",
interval, min(width - 1, command_length), command);
mvaddstr(0, 0, header);
if (strlen(header) > (size_t) (width - tsl - 1))
mvaddstr(0, width - tsl - 4, "... ");
mvaddstr(0, width - tsl + 1, ts);
free(header);
if (show_title) {
// left justify interval and command,
// right justify time, clipping all to fit window width
asprintf(&header, "Every %ds: %.*s",
interval, min(width - 1, command_length), command);
mvaddstr(0, 0, header);
if (strlen(header) > (size_t) (width - tsl - 1))
mvaddstr(0, width - tsl - 4, "... ");
mvaddstr(0, width - tsl + 1, ts);
free(header);
}
if (!(p = popen(command, "r"))) {
perror("popen");
do_exit(2);
}
for (y = 2; y < height; y++) {
for (y = show_title; y < height; y++) {
int eolseen = 0, tabpending = 0;
for (x = 0; x < width; x++) {
int c = ' ';