Merge commit 'refs/merge-requests/1' of git://gitorious.org/procps/procps
This commit is contained in:
commit
35d6960b5a
6
watch.1
6
watch.1
@ -11,6 +11,7 @@ runs
|
|||||||
repeatedly, displaying its output and errors (the first screenfull). This
|
repeatedly, displaying its output and errors (the first screenfull). This
|
||||||
allows you to watch the program output change over time. By default, the
|
allows you to watch the program output change over time. By default, the
|
||||||
program is run every 2 seconds.
|
program is run every 2 seconds.
|
||||||
|
By default,
|
||||||
.B watch
|
.B watch
|
||||||
will run until interrupted.
|
will run until interrupted.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
@ -46,6 +47,11 @@ Beep if command has a non-zero exit.
|
|||||||
\fB\-e\fR, \fB\-\-errexit\fR
|
\fB\-e\fR, \fB\-\-errexit\fR
|
||||||
Freeze updates on command error, and exit after a key press.
|
Freeze updates on command error, and exit after a key press.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-g\fR, \fB\-\-chgexit\fR
|
||||||
|
Exit when the output of
|
||||||
|
.I command
|
||||||
|
changes.
|
||||||
|
.TP
|
||||||
\fB\-c\fR, \fB\-\-color\fR
|
\fB\-c\fR, \fB\-\-color\fR
|
||||||
Interpret ANSI color sequences.
|
Interpret ANSI color sequences.
|
||||||
.TP
|
.TP
|
||||||
|
25
watch.c
25
watch.c
@ -70,6 +70,7 @@ static void __attribute__ ((__noreturn__))
|
|||||||
" -d, --differences[=<permanent>]\n"
|
" -d, --differences[=<permanent>]\n"
|
||||||
" highlight changes between updates\n"
|
" highlight changes between updates\n"
|
||||||
" -e, --errexit exit if command has a non-zero exit\n"
|
" -e, --errexit exit if command has a non-zero exit\n"
|
||||||
|
" -g, --chgexit exit when output from command changes\n"
|
||||||
" -n, --interval <secs> seconds to wait between updates\n"
|
" -n, --interval <secs> seconds to wait between updates\n"
|
||||||
" -p, --precise attempt run command in precise intervals\n"
|
" -p, --precise attempt run command in precise intervals\n"
|
||||||
" -t, --no-title turn off header\n"
|
" -t, --no-title turn off header\n"
|
||||||
@ -278,7 +279,7 @@ int main(int argc, char *argv[])
|
|||||||
option_exec = 0,
|
option_exec = 0,
|
||||||
option_beep = 0,
|
option_beep = 0,
|
||||||
option_color = 0,
|
option_color = 0,
|
||||||
option_errexit = 0, option_help = 0, option_version = 0;
|
option_errexit = 0, option_chgexit = 0, option_help = 0, option_version = 0;
|
||||||
double interval = 2;
|
double interval = 2;
|
||||||
char *command;
|
char *command;
|
||||||
char **command_argv;
|
char **command_argv;
|
||||||
@ -293,6 +294,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
int status;
|
int status;
|
||||||
|
int exit_early = 0;
|
||||||
pid_t child;
|
pid_t child;
|
||||||
|
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
@ -302,6 +304,7 @@ int main(int argc, char *argv[])
|
|||||||
{"interval", required_argument, 0, 'n'},
|
{"interval", required_argument, 0, 'n'},
|
||||||
{"beep", no_argument, 0, 'b'},
|
{"beep", no_argument, 0, 'b'},
|
||||||
{"errexit", no_argument, 0, 'e'},
|
{"errexit", no_argument, 0, 'e'},
|
||||||
|
{"chgexit", no_argument, 0, 'g'},
|
||||||
{"exec", no_argument, 0, 'x'},
|
{"exec", no_argument, 0, 'x'},
|
||||||
{"precise", no_argument, 0, 'p'},
|
{"precise", no_argument, 0, 'p'},
|
||||||
{"no-title", no_argument, 0, 't'},
|
{"no-title", no_argument, 0, 't'},
|
||||||
@ -315,7 +318,7 @@ int main(int argc, char *argv[])
|
|||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
|
|
||||||
while ((optc =
|
while ((optc =
|
||||||
getopt_long(argc, argv, "+bced::hn:pvtx", longopts, (int *)0))
|
getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0))
|
||||||
!= EOF) {
|
!= EOF) {
|
||||||
switch (optc) {
|
switch (optc) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@ -332,6 +335,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'e':
|
case 'e':
|
||||||
option_errexit = 1;
|
option_errexit = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'g':
|
||||||
|
option_chgexit = 1;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
show_title = 0;
|
show_title = 0;
|
||||||
break;
|
break;
|
||||||
@ -426,7 +432,7 @@ int main(int argc, char *argv[])
|
|||||||
if (precise_timekeeping)
|
if (precise_timekeeping)
|
||||||
next_loop = get_time_usec();
|
next_loop = get_time_usec();
|
||||||
|
|
||||||
for (;;) {
|
do {
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
char *ts = ctime(&t);
|
char *ts = ctime(&t);
|
||||||
int tsl = strlen(ts);
|
int tsl = strlen(ts);
|
||||||
@ -637,6 +643,17 @@ int main(int argc, char *argv[])
|
|||||||
tabpending = 0;
|
tabpending = 0;
|
||||||
}
|
}
|
||||||
move(y, x);
|
move(y, x);
|
||||||
|
if (!exit_early && option_chgexit) {
|
||||||
|
#ifdef WITH_WATCH8BIT
|
||||||
|
cchar_t oldc;
|
||||||
|
in_wch(&oldc);
|
||||||
|
exit_early = (wchar_t) c != oldc.chars[0];
|
||||||
|
#else
|
||||||
|
chtype oldch = inch();
|
||||||
|
unsigned char oldc = oldch & A_CHARTEXT;
|
||||||
|
exit_early = (unsigned char) c != oldc;
|
||||||
|
#endif /* WITH_WATCH8BIT */
|
||||||
|
}
|
||||||
if (option_differences) {
|
if (option_differences) {
|
||||||
#ifdef WITH_WATCH8BIT
|
#ifdef WITH_WATCH8BIT
|
||||||
cchar_t oldc;
|
cchar_t oldc;
|
||||||
@ -706,7 +723,7 @@ int main(int argc, char *argv[])
|
|||||||
usleep(next_loop - cur_time);
|
usleep(next_loop - cur_time);
|
||||||
} else
|
} else
|
||||||
usleep(interval * 1000000);
|
usleep(interval * 1000000);
|
||||||
}
|
} while (!exit_early);
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user