From 5aadbcfe7f06d99f639d9be4e7e7ff6e5f3ca5ab Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 22 Aug 2004 01:55:03 +0000 Subject: cleanup --- Makefile | 1 + watch.c | 98 +++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index 4a9e34d..73e21e4 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ PROG= watch BINDIR= /usr/local/bin MAN= watch.1 DPADD= ${LIBCURSES} +CFLAGS+= -W -Wall LDADD= -lcurses . include diff --git a/watch.c b/watch.c index 49d2748..4492416 100644 --- a/watch.c +++ b/watch.c @@ -1,9 +1,4 @@ /* $Id$ */ -/* - * watch -- execute program repeatedly, displaying output fullscreen - * Based on the original 1991 'watch' by Tony Rems - * (with mods and corrections by Francois Pinard) - */ /* * Copyright (c) 2003, 2004 demon * @@ -19,6 +14,21 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* + * watch -- execute program repeatedly, displaying output fullscreen + * Based on the original 1991 'watch' by Tony Rems + * (with mods and corrections by Francois Pinard) + */ + +static const char copyright[] = +"@(#) Copyright (c) 2003, 2004 demon \n"; +static const char rcsid[] = +"$Id$"; +static const char version[] = "0.5"; + +#if defined(__linux__) +#define __dead __volatile +#endif #include #include @@ -34,25 +44,22 @@ #include #include -static char buffer[_POSIX_MAX_INPUT]; -static char *copyright = "(c) 2003, 2004 demon "; -static char *version = "0.5"; -extern char *__progname; - -unsigned int period = 2; -unsigned short die_flag = 0; -unsigned short n_flag = 0; -unsigned short color_flag = 0; +static int readargs(char **); +static void display(); +static int title(void); +static void resize(); +static void settimer(int); +static void die(); +static __dead void usage(void); -static int lines, cols; +extern char *__progname; +char buffer[_POSIX_MAX_INPUT]; -int readargs(char **); -void display(); -int title(); -void resize(); -void settimer(int); -void die(); -void usage(); +int period = 2; +int die_flag = 0; +int n_flag = 0; +int color_flag = 0; +int lines, cols; int main(int argc, char **argv) @@ -63,8 +70,8 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, "+s:vn")) != -1) switch (ch) { case 'v': - (void) fprintf(stderr, "watch %s %s\n", - version, copyright); + (void) fprintf(stderr, "%s %s %s", + __progname, version, copyright + 5); exit(1); break; case 's': @@ -92,7 +99,6 @@ main(int argc, char **argv) initscr(); lines = LINES; cols = COLS; - signal(SIGWINCH, resize); hold_curs = curs_set(0); if (has_colors()) @@ -100,7 +106,9 @@ main(int argc, char **argv) signal(SIGALRM, display); settimer(period); - display(); + raise(SIGALRM); + + signal(SIGWINCH, resize); while (die_flag == 0) pause(); @@ -110,7 +118,7 @@ main(int argc, char **argv) exit(0); } -int +static int readargs(char **argv) { int alen, blen; @@ -135,13 +143,13 @@ readargs(char **argv) return 0; } -void +static void display() { - char ch; - FILE *pipe; int char_count = 0; int line_count = 0; + char ch; + FILE *pipe; clear(); @@ -152,7 +160,7 @@ display() pipe = popen(buffer, "r"); while ((ch = fgetc(pipe)) != EOF) { - if ((ch == '\0') || (ch == '\n')) { + if (ch == '\0' || ch == '\n') { line_count++; char_count = 0; } @@ -168,18 +176,20 @@ display() refresh(); } -int -title() +static int +title(void) { - char title[_POSIX_MAX_INPUT]; int tlen, tlen2; + char title[_POSIX_MAX_INPUT]; + time_t tval; + struct tm *tm; - time_t tval = time(NULL); - struct tm *tm = localtime(&tval); - - if (cols + 1 >= _POSIX_MAX_INPUT) + if (cols + 1 >= _POSIX_MAX_INPUT || cols - 12 < 0) return -1; + tval = time(NULL); + tm = localtime(&tval); + snprintf(title, cols, " Every %ds : %s", period, buffer); tlen = strlen(title); @@ -208,7 +218,7 @@ title() return 0; } -void +static void resize() { int save_errno = errno; @@ -223,7 +233,7 @@ resize() errno = save_errno; } -void +static void settimer(int wait) { int save_errno = errno; @@ -236,16 +246,16 @@ settimer(int wait) errno = save_errno; } -void +static void die() { die_flag = 1; } -void -usage() +static __dead void +usage(void) { - (void) fprintf(stderr, "Usage: %s [-v] [-n] [-s ] command\n", + (void) fprintf(stderr, "usage: %s [-v] [-n] [-s ] command\n", __progname); exit(1); } -- cgit v1.2.3