Deleted Added
full compact
top.c (86042) top.c (89757)
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
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, 1990, 1992, William LeFebvre, Northwestern 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
13 *
15 *
14 * $FreeBSD: head/contrib/top/top.c 86042 2001-11-04 21:15:52Z dwmalone $
16 * $FreeBSD: head/contrib/top/top.c 89757 2002-01-24 17:55:40Z dwmalone $
15 */
16
17/*
18 * See the file "Changes" for information on version-to-version changes.
19 */
20
21/*
22 * This file contains "main" and other high-level routines.

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

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

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

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

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

216#define CMD_user 14
217#define CMD_selftog 15
218#ifdef ORDER
219#define CMD_order 16
220#endif
221
222 /* set the buffer for stdout */
223#ifdef DEBUG
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");
224 setbuffer(stdout, NULL, 0);
225#else
226 setbuffer(stdout, stdoutbuf, Buffersize);
227#endif
228
229 /* get our name */
230 if (argc > 0)
231 {

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

264 {
265 ac = argc;
266 av = argv;
267
268 /* this should keep getopt happy... */
269 optind = 1;
270 }
271
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
272 while ((i = getopt(ac, av, "SIbinqus:d:U:o:t")) != EOF)
273 while ((i = getopt(ac, av, "SIbinquvs:d:U:o:t")) != EOF)
273 {
274 switch(i)
275 {
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
276 case 'u': /* toggle uid/username display */
277 do_unames = !do_unames;
278 break;
279
280 case 'U': /* display only username's processes */
281 if ((ps.uid = userid(optarg)) == -1)
282 {
283 fprintf(stderr, "%s: unknown user\n", optarg);

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

312 }
313 else
314 {
315 displays = i;
316 }
317 break;
318
319 case 's':
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':
320 if ((delay = atoi(optarg)) < 0)
327 if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0))
321 {
322 fprintf(stderr,
328 {
329 fprintf(stderr,
323 "%s: warning: seconds delay should be non-negative -- using default\n",
330 "%s: warning: seconds delay should be positive -- using default\n",
324 myname);
325 delay = Default_DELAY;
326 warnings++;
327 }
328 break;
329
330 case 'q': /* be quick about it */
331 /* only allow this if user is really root */

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

590 /* update the header area */
591 (*d_header)(header_text);
592
593 if (topn > 0)
594 {
595 /* determine number of processes to actually display */
596 /* this number will be the smallest of: active processes,
597 number user requested, number current screen accomodates */
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 */
598 active_procs = system_info.p_active;
605 active_procs = system_info.P_ACTIVE;
599 if (active_procs > topn)
600 {
601 active_procs = topn;
602 }
603 if (active_procs > max_topn)
604 {
605 active_procs = max_topn;
606 }

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

615 {
616 i = 0;
617 }
618
619 /* do end-screen processing */
620 u_endscreen(i);
621
622 /* now, flush the output buffer */
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 */
623 fflush(stdout);
630 if (fflush(stdout) != 0)
631 {
632 new_message(MT_standout, " Write error on stdout");
633 putchar('\r');
634 quit(1);
635 /*NOTREACHED*/
636 }
624
625 /* only do the rest if we have more displays to show */
626 if (displays)
627 {
628 /* switch out for new display on smart terminals */
629 if (smart_terminal)
630 {
631 if (overstrike)

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

657 }
658 else while (no_command)
659 {
660 /* assume valid command unless told otherwise */
661 no_command = No;
662
663 /* set up arguments for select with timeout */
664 FD_ZERO(&readfds);
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);
665 FD_SET(1, &readfds); /* for standard input */
678 FD_SET(0, &readfds); /* for standard input */
666 timeout.tv_sec = delay;
667 timeout.tv_usec = 0;
668
669 if (leaveflag) {
670 end_screen();
671 exit(0);
672 }
673

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

722 char *errmsg;
723
724 /* something to read -- clear the message area first */
725 clear_message();
726
727 /* now read it and convert to command strchr */
728 /* (use "change" as a temporary to hold strchr) */
729 if (read(0, &ch, 1) != 1)
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)
730 quit(0);
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 }
731 if ((iptr = strchr(command_chars, ch)) == NULL)
732 {
733 if (ch != '\r' && ch != '\n')
734 {
735 /* illegal command */
736 new_message(MT_standout, " Command not understood");
737 }
738 putchar('\r');

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

828 topn = newval;
829 }
830 break;
831
832 case CMD_delay: /* new seconds delay */
833 new_message(MT_standout, "Seconds to delay: ");
834 if ((i = readline(tempbuf1, 8, Yes)) > -1)
835 {
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 {
836 delay = i;
855 if ((delay = i) == 0 && getuid() != 0)
856 {
857 delay = 1;
858 }
837 }
838 clear_message();
839 break;
840
841 case CMD_displays: /* change display count */
842 new_message(MT_standout,
843 "Displays to show (currently %s): ",
844 displays == -1 ? "infinite" :

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

966
967 /* flush out stuff that may have been written */
968 fflush(stdout);
969 }
970 }
971 }
972 }
973
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
974 quit(0);
975 /*NOTREACHED*/
976}
977
978/*
979 * reset_display() - reset all the display routine pointers so that entire
980 * screen will get redrawn.
981 */

--- 59 unchanged lines hidden ---
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 ---