Deleted Added
sdiff udiff text old ( 86042 ) new ( 89757 )
full compact
1char *copyright =
2 "Copyright (c) 1984 through 1996, William LeFebvre";
3
4/*
5 * Top users/processes display for Unix
6 * Version 3
7 *
8 * This program may be freely redistributed,
9 * but this entire comment MUST remain intact.
10 *
11 * Copyright (c) 1984, 1989, William LeFebvre, Rice University
12 * Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
13 * Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
14 * Copyright (c) 1996, William LeFebvre, Group sys Consulting
15 *
16 * $FreeBSD: head/contrib/top/top.c 89757 2002-01-24 17:55:40Z dwmalone $
17 */
18
19/*
20 * See the file "Changes" for information on version-to-version changes.
21 */
22
23/*
24 * This file contains "main" and other high-level routines.

--- 28 unchanged lines hidden (view full) ---

53#define Buffersize 2048
54
55/* The buffer that stdio will use */
56char stdoutbuf[Buffersize];
57
58/* build Signal masks */
59#define Smask(s) (1 << ((s) - 1))
60
61/* for getopt: */
62extern int optind;
63extern char *optarg;
64
65/* imported from screen.c */
66extern int overstrike;
67
68/* signal handling routines */

--- 113 unchanged lines hidden (view full) ---

182#ifdef ORDER
183 char *order_name = NULL;
184 int order_index = 0;
185#endif
186#ifndef FD_SET
187 /* FD_SET and friends are not present: fake it */
188 typedef int fd_set;
189#define FD_ZERO(x) (*(x) = 0)
190#define FD_SET(f, x) (*(x) = 1<<f)
191#endif
192 fd_set readfds;
193
194#ifdef ORDER
195 static char command_chars[] = "\f qh?en#sdkriIuto";
196#else
197 static char command_chars[] = "\f qh?en#sdkriIut";
198#endif

--- 16 unchanged lines hidden (view full) ---

215#define CMD_user 14
216#define CMD_selftog 15
217#ifdef ORDER
218#define CMD_order 16
219#endif
220
221 /* set the buffer for stdout */
222#ifdef DEBUG
223 extern FILE *debug;
224 debug = fopen("debug.run", "w");
225 setbuffer(stdout, NULL, 0);
226#else
227 setbuffer(stdout, stdoutbuf, Buffersize);
228#endif
229
230 /* get our name */
231 if (argc > 0)
232 {

--- 32 unchanged lines hidden (view full) ---

265 {
266 ac = argc;
267 av = argv;
268
269 /* this should keep getopt happy... */
270 optind = 1;
271 }
272
273 while ((i = getopt(ac, av, "SIbinquvs:d:U:o:t")) != EOF)
274 {
275 switch(i)
276 {
277 case 'v': /* show version number */
278 fprintf(stderr, "%s: version %s\n",
279 myname, version_string());
280 exit(1);
281 break;
282
283 case 'u': /* toggle uid/username display */
284 do_unames = !do_unames;
285 break;
286
287 case 'U': /* display only username's processes */
288 if ((ps.uid = userid(optarg)) == -1)
289 {
290 fprintf(stderr, "%s: unknown user\n", optarg);

--- 28 unchanged lines hidden (view full) ---

319 }
320 else
321 {
322 displays = i;
323 }
324 break;
325
326 case 's':
327 if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0))
328 {
329 fprintf(stderr,
330 "%s: warning: seconds delay should be positive -- using default\n",
331 myname);
332 delay = Default_DELAY;
333 warnings++;
334 }
335 break;
336
337 case 'q': /* be quick about it */
338 /* only allow this if user is really root */

--- 258 unchanged lines hidden (view full) ---

597 /* update the header area */
598 (*d_header)(header_text);
599
600 if (topn > 0)
601 {
602 /* determine number of processes to actually display */
603 /* this number will be the smallest of: active processes,
604 number user requested, number current screen accomodates */
605 active_procs = system_info.P_ACTIVE;
606 if (active_procs > topn)
607 {
608 active_procs = topn;
609 }
610 if (active_procs > max_topn)
611 {
612 active_procs = max_topn;
613 }

--- 8 unchanged lines hidden (view full) ---

622 {
623 i = 0;
624 }
625
626 /* do end-screen processing */
627 u_endscreen(i);
628
629 /* now, flush the output buffer */
630 if (fflush(stdout) != 0)
631 {
632 new_message(MT_standout, " Write error on stdout");
633 putchar('\r');
634 quit(1);
635 /*NOTREACHED*/
636 }
637
638 /* only do the rest if we have more displays to show */
639 if (displays)
640 {
641 /* switch out for new display on smart terminals */
642 if (smart_terminal)
643 {
644 if (overstrike)

--- 25 unchanged lines hidden (view full) ---

670 }
671 else while (no_command)
672 {
673 /* assume valid command unless told otherwise */
674 no_command = No;
675
676 /* set up arguments for select with timeout */
677 FD_ZERO(&readfds);
678 FD_SET(0, &readfds); /* for standard input */
679 timeout.tv_sec = delay;
680 timeout.tv_usec = 0;
681
682 if (leaveflag) {
683 end_screen();
684 exit(0);
685 }
686

--- 48 unchanged lines hidden (view full) ---

735 char *errmsg;
736
737 /* something to read -- clear the message area first */
738 clear_message();
739
740 /* now read it and convert to command strchr */
741 /* (use "change" as a temporary to hold strchr) */
742 if (read(0, &ch, 1) != 1)
743 {
744 /* read error: either 0 or -1 */
745 new_message(MT_standout, " Read error on stdin");
746 putchar('\r');
747 quit(1);
748 /*NOTREACHED*/
749 }
750 if ((iptr = strchr(command_chars, ch)) == NULL)
751 {
752 if (ch != '\r' && ch != '\n')
753 {
754 /* illegal command */
755 new_message(MT_standout, " Command not understood");
756 }
757 putchar('\r');

--- 89 unchanged lines hidden (view full) ---

847 topn = newval;
848 }
849 break;
850
851 case CMD_delay: /* new seconds delay */
852 new_message(MT_standout, "Seconds to delay: ");
853 if ((i = readline(tempbuf1, 8, Yes)) > -1)
854 {
855 if ((delay = i) == 0 && getuid() != 0)
856 {
857 delay = 1;
858 }
859 }
860 clear_message();
861 break;
862
863 case CMD_displays: /* change display count */
864 new_message(MT_standout,
865 "Displays to show (currently %s): ",
866 displays == -1 ? "infinite" :

--- 121 unchanged lines hidden (view full) ---

988
989 /* flush out stuff that may have been written */
990 fflush(stdout);
991 }
992 }
993 }
994 }
995
996#ifdef DEBUG
997 fclose(debug);
998#endif
999 quit(0);
1000 /*NOTREACHED*/
1001}
1002
1003/*
1004 * reset_display() - reset all the display routine pointers so that entire
1005 * screen will get redrawn.
1006 */

--- 59 unchanged lines hidden ---