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 procps-3.1.5 --> procps-3.1.6
watch: new --no-title option
handle SPARC Linux badness handle SPARC Linux badness
rare crash fixed rare crash fixed
compile with gcc 2.91.xx again compile with gcc 2.91.xx again

View File

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

View File

@ -2,7 +2,7 @@
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de> * Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
* Ammended by cblake to only export the function symbol. * Ammended by cblake to only export the function symbol.
* *
* Modified by Albert Cahalan * Modified by Albert Cahalan, ????-2003
* *
* Redistributable under the terms of the * Redistributable under the terms of the
* GNU Library General Public License; see COPYING * 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) #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) __attribute__((constructor));
static void init_Linux_version(void) { static void init_Linux_version(void) {
static struct utsname uts; static struct utsname uts;
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ 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 */ if (uname(&uts) == -1) /* failure implies impending death */
exit(1); exit(1);
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3) 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 watch \- execute a program periodically, showing output fullscreen
.SH SYNOPSIS .SH SYNOPSIS
.B watch .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 .SH DESCRIPTION
.BR watch .BR watch
runs runs
@ -23,7 +23,12 @@ or
flag will highlight the differences between successive updates. The flag will highlight the differences between successive updates. The
.I --cumulative .I --cumulative
option makes highlighting "sticky", presenting a running display of all 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 .PP
.BR watch .BR watch
will run until interrupted. will run until interrupted.

31
watch.c
View File

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