summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/top/boolean.h35
-rw-r--r--usr.bin/top/commands.c10
-rw-r--r--usr.bin/top/display.c13
-rw-r--r--usr.bin/top/screen.c24
-rw-r--r--usr.bin/top/top.c82
5 files changed, 63 insertions, 101 deletions
diff --git a/usr.bin/top/boolean.h b/usr.bin/top/boolean.h
deleted file mode 100644
index d46b24b2aba..00000000000
--- a/usr.bin/top/boolean.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $OpenBSD: boolean.h,v 1.2 2002/07/15 17:20:36 deraadt Exp $ */
-
-/*
- * Top users/processes display for Unix
- * Version 3
- *
- * Copyright (c) 1984, 1989, William LeFebvre, Rice University
- * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS EMPLOYER BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* My favorite names for boolean values */
-#define No 0
-#define Yes 1
-#define Maybe 2 /* tri-state boolean, actually */
-
diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c
index b63f2c3b193..8cf2ec8370d 100644
--- a/usr.bin/top/commands.c
+++ b/usr.bin/top/commands.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commands.c,v 1.32 2017/03/15 04:24:14 deraadt Exp $ */
+/* $OpenBSD: commands.c,v 1.33 2019/10/08 07:26:59 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -46,10 +46,10 @@
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <stdbool.h>
#include "top.h"
-#include "boolean.h"
#include "utils.h"
#include "machine.h"
@@ -158,7 +158,7 @@ static char *err_listem =
static char *
err_string(void)
{
- int cnt = 0, first = Yes, currerr = -1;
+ int cnt = 0, first = true, currerr = -1;
static char string[STRMAX];
struct errs *errp;
@@ -186,13 +186,13 @@ err_string(void)
(void) strlcat(string, "; ", sizeof string);
}
currerr = errp->err;
- first = Yes;
+ first = true;
}
if (str_addarg(string, sizeof string, errp->arg, first) >=
sizeof string)
return (err_listem);
- first = No;
+ first = false;
}
/* add final message */
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 97ba3977ab8..eabae12008c 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.59 2019/07/03 03:24:02 deraadt Exp $ */
+/* $OpenBSD: display.c,v 1.60 2019/10/08 07:26:59 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -57,12 +57,12 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stdbool.h>
#include "screen.h" /* interface to screen package */
#include "layout.h" /* defines for screen position layout */
#include "display.h"
#include "top.h"
-#include "boolean.h"
#include "machine.h" /* we should eliminate this!!! */
#include "utils.h"
@@ -104,7 +104,7 @@ extern int ncpuonline;
extern int combine_cpus;
extern struct process_select ps;
-int header_status = Yes;
+int header_status = true;
static int
empty(void)
@@ -309,10 +309,7 @@ i_procstates(int total, int *states, int threads)
move(1, 0);
clrtoeol();
/* write current number of procs and remember the value */
- if (threads == Yes)
- printwp("%d threads: ", total);
- else
- printwp("%d processes: ", total);
+ printwp("%d %s: ", total, threads ? "threads" : "processes");
/* format and print the process state summary */
summary_format(procstates_buffer, sizeof(procstates_buffer),
@@ -518,7 +515,7 @@ i_message(void)
void
i_header(char *text)
{
- if (header_status == Yes && (screen_length > y_header
+ if (header_status && (screen_length > y_header
|| !smart_terminal)) {
if (!smart_terminal) {
putn();
diff --git a/usr.bin/top/screen.c b/usr.bin/top/screen.c
index b65989ddbb0..8d0a8ffcd02 100644
--- a/usr.bin/top/screen.c
+++ b/usr.bin/top/screen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen.c,v 1.21 2017/03/15 04:24:14 deraadt Exp $ */
+/* $OpenBSD: screen.c,v 1.22 2019/10/08 07:26:59 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -46,17 +46,17 @@
#include <stdlib.h>
#include <term.h>
#include <unistd.h>
+#include <stdbool.h>
#include "top.h"
#include "screen.h"
#include "layout.h"
-#include "boolean.h"
int screen_length, screen_width;
char ch_erase, ch_kill, smart_terminal;
static struct termios old_settings, new_settings;
-static char is_a_terminal = No;
+static char is_a_terminal = false;
void
init_termcap(int interactive)
@@ -70,11 +70,11 @@ init_termcap(int interactive)
if (!interactive) {
/* pretend we have a dumb terminal */
- smart_terminal = No;
+ smart_terminal = false;
return;
}
/* assume we have a smart terminal until proven otherwise */
- smart_terminal = Yes;
+ smart_terminal = true;
/* get the terminal name */
term_name = getenv("TERM");
@@ -82,7 +82,7 @@ init_termcap(int interactive)
/* if there is no TERM, assume it's a dumb terminal */
/* patch courtesy of Sam Horrocks at telegraph.ics.uci.edu */
if (term_name == NULL) {
- smart_terminal = No;
+ smart_terminal = false;
return;
}
@@ -94,13 +94,13 @@ init_termcap(int interactive)
warnx("no termcap entry for a `%s' terminal", term_name);
/* pretend it's dumb and proceed */
- smart_terminal = No;
+ smart_terminal = false;
return;
}
/* "hardcopy" immediately indicates a very stupid terminal */
if (tgetflag("hc")) {
- smart_terminal = No;
+ smart_terminal = false;
return;
}
@@ -118,7 +118,7 @@ init_termcap(int interactive)
/* get necessary capabilities */
if (tgetstr("cl", NULL) == NULL || tgetstr("cm", NULL) == NULL) {
- smart_terminal = No;
+ smart_terminal = false;
return;
}
@@ -131,7 +131,7 @@ init_termcap(int interactive)
/* if stdout is not a terminal, pretend we are a dumb terminal */
if (tcgetattr(STDOUT_FILENO, &old_settings) == -1)
- smart_terminal = No;
+ smart_terminal = false;
}
void
@@ -152,7 +152,7 @@ init_screen(void)
ch_erase = old_settings.c_cc[VERASE];
ch_kill = old_settings.c_cc[VKILL];
- is_a_terminal = Yes;
+ is_a_terminal = true;
#if 0
/* send the termcap initialization string */
putcap(terminal_init);
@@ -160,7 +160,7 @@ init_screen(void)
}
if (!is_a_terminal) {
/* not a terminal at all---consider it dumb */
- smart_terminal = No;
+ smart_terminal = false;
}
if (smart_terminal)
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index e1d10f2edd4..66e6e618a3b 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.99 2019/10/06 15:08:54 kn Exp $ */
+/* $OpenBSD: top.c,v 1.100 2019/10/08 07:26:59 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -40,13 +40,13 @@
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
+#include <stdbool.h>
/* includes specific to top */
#include "display.h" /* interface to display package */
#include "screen.h" /* interface to screen package */
#include "top.h"
#include "top.local.h"
-#include "boolean.h"
#include "machine.h"
#include "utils.h"
@@ -77,21 +77,21 @@ int order_index;
int rev_order;
int displays = 0; /* indicates unspecified */
-char do_unames = Yes;
+int do_unames = true;
struct process_select ps;
-char interactive = Maybe;
+int interactive = -1; /* indicates undefined */
double delay = Default_DELAY;
char *order_name = NULL;
int topn = Default_TOPN;
-int no_command = Yes;
-int old_system = No;
-int old_threads = No;
-int show_args = No;
+int no_command = true;
+int old_system = false;
+int old_threads = false;
+int show_args = false;
pid_t hlpid = (pid_t)-1;
int combine_cpus = 0;
#if Default_TOPN == Infinity
-char topn_specified = No;
+int topn_specified = false;
#endif
struct system_info system_info;
@@ -189,13 +189,13 @@ filterpid(char buf[], int hl)
if (errstr != NULL || !find_pid(pid))
return -1;
- if (hl == Yes)
+ if (hl)
hlpid = (pid_t)pid;
else {
- if (ps.system == No)
- old_system = No;
+ if (!ps.system)
+ old_system = false;
ps.pid = (pid_t)pid;
- ps.system = Yes;
+ ps.system = true;
}
return 0;
@@ -213,7 +213,7 @@ parseargs(int ac, char **av)
combine_cpus = 1;
break;
case 'C':
- show_args = Yes;
+ show_args = true;
break;
case 'u': /* toggle uid/username display */
do_unames = !do_unames;
@@ -226,7 +226,7 @@ parseargs(int ac, char **av)
break;
case 'p': /* display only process id */
- if (filterpid(optarg, No) == -1)
+ if (filterpid(optarg, false) == -1)
new_message(MT_delayed, "%s: unknown pid",
optarg);
break;
@@ -237,8 +237,8 @@ parseargs(int ac, char **av)
break;
case 'H': /* show threads */
- ps.threads = Yes;
- old_threads = Yes;
+ ps.threads = true;
+ old_threads = true;
break;
case 'I': /* show idle processes */
@@ -246,19 +246,19 @@ parseargs(int ac, char **av)
break;
case 'i': /* go interactive regardless */
- interactive = Yes;
+ interactive = true;
break;
case 'n': /* batch, or non-interactive */
case 'b':
- interactive = No;
+ interactive = false;
break;
case 'd': /* number of displays to show */
if ((i = atoiwi(optarg)) != Invalid && i != 0) {
displays = i;
if (displays == 1)
- interactive = No;
+ interactive = false;
break;
}
new_message(MT_delayed,
@@ -322,7 +322,7 @@ parseargs(int ac, char **av)
}
#if Default_TOPN == Infinity
else
- topn_specified = Yes;
+ topn_specified = true;
#endif
}
}
@@ -346,8 +346,8 @@ main(int argc, char *argv[])
#endif
/* initialize some selection options */
- ps.idle = Yes;
- ps.system = No;
+ ps.idle = true;
+ ps.system = false;
ps.uid = (uid_t)-1;
ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1;
@@ -435,7 +435,7 @@ main(int argc, char *argv[])
display_header(topn > 0);
/* determine interactive state */
- if (interactive == Maybe)
+ if (interactive == -1)
interactive = smart_terminal;
/* if # of displays not specified, fill it in */
@@ -580,7 +580,7 @@ restart:
/* only do the rest if we have more displays to show */
if (displays) {
/* switch out for new display on smart terminals */
- no_command = Yes;
+ no_command = true;
if (!interactive) {
/* set up alarm */
(void) signal(SIGALRM, onalrm);
@@ -624,7 +624,7 @@ rundisplay(void)
* assume valid command unless told
* otherwise
*/
- no_command = No;
+ no_command = false;
/*
* set up arguments for select with
@@ -693,7 +693,7 @@ rundisplay(void)
/* illegal command */
new_message(MT_standout, " Command not understood");
putr();
- no_command = Yes;
+ no_command = true;
fflush(stdout);
return (0);
}
@@ -733,7 +733,7 @@ rundisplay(void)
new_message(MT_standout,
" Currently no errors to report.");
putr();
- no_command = Yes;
+ no_command = true;
} else {
clear();
show_errors();
@@ -760,16 +760,16 @@ rundisplay(void)
if ((i > topn || i == Infinity)
&& topn == 0) {
/* redraw the header */
- display_header(Yes);
+ display_header(true);
} else if (i == 0)
- display_header(No);
+ display_header(false);
topn = i;
} else {
new_message(MT_standout,
"Processes should be a "
"non-negative number");
putr();
- no_command = Yes;
+ no_command = true;
}
} else
clear_message();
@@ -788,7 +788,7 @@ rundisplay(void)
new_message(MT_standout,
"Delay should be a non-negative number");
putr();
- no_command = Yes;
+ no_command = true;
}
} else
@@ -810,7 +810,7 @@ rundisplay(void)
new_message(MT_standout,
"Displays should be a non-negative number");
putr();
- no_command = Yes;
+ no_command = true;
}
} else
clear_message();
@@ -822,7 +822,7 @@ rundisplay(void)
if ((errmsg = kill_procs(tempbuf)) != NULL) {
new_message(MT_standout, "%s", errmsg);
putr();
- no_command = Yes;
+ no_command = true;
}
} else
clear_message();
@@ -834,7 +834,7 @@ rundisplay(void)
if ((errmsg = renice_procs(tempbuf)) != NULL) {
new_message(MT_standout, "%s", errmsg);
putr();
- no_command = Yes;
+ no_command = true;
}
} else
clear_message();
@@ -862,7 +862,7 @@ rundisplay(void)
" %s: unknown user",
tempbuf[0] == '-' ? tempbuf + 1 :
tempbuf);
- no_command = Yes;
+ no_command = true;
}
putr();
} else
@@ -886,7 +886,7 @@ rundisplay(void)
" %s: unrecognized sorting order",
tempbuf[0] == '-' ? tempbuf + 1 :
tempbuf);
- no_command = Yes;
+ no_command = true;
} else
order_index = i;
putr();
@@ -904,7 +904,7 @@ rundisplay(void)
} else if (filterpid(tempbuf, 0) == -1) {
new_message(MT_standout,
" %s: unknown pid", tempbuf);
- no_command = Yes;
+ no_command = true;
}
putr();
} else
@@ -912,7 +912,7 @@ rundisplay(void)
break;
case CMD_command:
- show_args = (show_args == No) ? Yes : No;
+ show_args = !show_args;
break;
case CMD_threads:
@@ -944,10 +944,10 @@ rundisplay(void)
if (tempbuf[0] == '+' &&
tempbuf[1] == '\0') {
hlpid = (pid_t)-1;
- } else if (filterpid(tempbuf, Yes) == -1) {
+ } else if (filterpid(tempbuf, true) == -1) {
new_message(MT_standout,
" %s: unknown pid", tempbuf);
- no_command = Yes;
+ no_command = true;
}
putr();
} else