diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 97cc371d0c9d..3c423bedf001 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $NetBSD: display.c,v 1.18 2008/04/10 20:41:42 oster Exp $ */ +/* $NetBSD: display.c,v 1.19 2008/05/25 21:49:33 rmind Exp $ */ /* * Top users/processes display for Unix @@ -47,7 +47,7 @@ #include #ifndef lint -__RCSID("$NetBSD: display.c,v 1.18 2008/04/10 20:41:42 oster Exp $"); +__RCSID("$NetBSD: display.c,v 1.19 2008/05/25 21:49:33 rmind Exp $"); #endif #include "os.h" @@ -935,7 +935,7 @@ clear_message() } } -int +double readline(buffer, size, numeric) char *buffer; @@ -944,9 +944,7 @@ int numeric; { char *ptr = buffer; - int ch; - int cnt = 0; - int maxcnt = 0; + int ch, dotfound = 0, cnt = 0, maxcnt = 0; /* allow room for null terminator */ size -= 1; @@ -990,14 +988,18 @@ int numeric; } } /* check for character validity and buffer overflow */ - else if (cnt == size || (numeric && !isdigit(ch)) || - !isprint(ch)) + else if (cnt == size || (numeric && !isdigit(ch) && + (dotfound || ch != '.')) || !isprint(ch)) { /* not legal */ putchar('\7'); } else { + /* if float - there could be only one dot */ + if (ch == '.') { + dotfound = 1; + } /* echo it and store it in the buffer */ putchar(ch); ptr++; @@ -1018,7 +1020,7 @@ int numeric; /* return either inputted number or string length */ putchar('\r'); - return(cnt == 0 ? -1 : numeric ? atoi(buffer) : cnt); + return(cnt == 0 ? -1 : numeric ? atof(buffer) : cnt); } /* internal support routines */ diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h index c0802a576310..e180b537278b 100644 --- a/usr.bin/top/display.h +++ b/usr.bin/top/display.h @@ -1,4 +1,4 @@ -/* $NetBSD: display.h,v 1.8 2007/05/24 20:04:04 ad Exp $ */ +/* $NetBSD: display.h,v 1.9 2008/05/25 21:49:33 rmind Exp $ */ /* * Top users/processes display for Unix @@ -62,5 +62,5 @@ void display_header __P((int)); void new_message __P((int, const char *, ...)) __attribute__((__format__(__printf__, 2, 3))); void clear_message __P((void)); -int readline __P((char *, int, int)); +double readline __P((char *, int, int)); char *printable __P((char *)); diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index e4e2e64aa558..d3e4bf79fe21 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $NetBSD: top.c,v 1.26 2007/05/24 20:04:04 ad Exp $ */ +/* $NetBSD: top.c,v 1.27 2008/05/25 21:49:33 rmind Exp $ */ const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre"; @@ -49,7 +49,7 @@ const char copyright[] = "Copyright (c) 1984 through 1996, William LeFebvre"; #include #ifndef lint -__RCSID("$NetBSD: top.c,v 1.26 2007/05/24 20:04:04 ad Exp $"); +__RCSID("$NetBSD: top.c,v 1.27 2008/05/25 21:49:33 rmind Exp $"); #endif #include "os.h" @@ -124,7 +124,7 @@ char *argv[]; static char tempbuf2[50]; int old_sigmask; /* only used for BSD-style signals */ int topn = Default_TOPN; - int delay = Default_DELAY; + double delay = Default_DELAY, t; int displays = 0; /* indicates unspecified */ time_t curr_time; char *(*get_userid) __P((int)) = username; @@ -288,7 +288,8 @@ char *argv[]; break; case 's': - if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0)) + delay = atof(optarg); + if (delay < 0.1 || (delay < 0.5 && getuid() != 0)) { fprintf(stderr, "%s: warning: seconds delay should be positive -- using default\n", @@ -640,7 +641,7 @@ Usage: %s [-bIinqSuv] [-d count] [-o field] [-s time] [-U username] [number]\n", set[0].events = POLLIN; /* wait for either input or the end of the delay period */ - if (poll(set, 1, delay * 1000) > 0) + if (poll(set, 1, (int)(delay * 1000)) > 0) { int newval; char *errmsg; @@ -758,11 +759,12 @@ Usage: %s [-bIinqSuv] [-d count] [-o field] [-s time] [-U username] [number]\n", case CMD_delay: /* new seconds delay */ new_message(MT_standout, "Seconds to delay: "); - if ((i = readline(tempbuf1, 8, Yes)) > -1) + if ((t = readline(tempbuf1, 8, Yes)) > -1) { - if ((delay = i) == 0 && getuid() != 0) + delay = t; + if (t < 0.1 || (t < 0.5 && getuid() != 0)) { - delay = 1; + delay = 0.5; } } clear_message();