display.c (237656) | display.c (300395) |
---|---|
1/* 2 * Top users/processes display for Unix 3 * Version 3 4 * 5 * This program may be freely redistributed, 6 * but this entire comment MUST remain intact. 7 * 8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University 9 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University 10 * | 1/* 2 * Top users/processes display for Unix 3 * Version 3 4 * 5 * This program may be freely redistributed, 6 * but this entire comment MUST remain intact. 7 * 8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University 9 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University 10 * |
11 * $FreeBSD: head/contrib/top/display.c 237656 2012-06-27 18:08:48Z jhb $ | 11 * $FreeBSD: head/contrib/top/display.c 300395 2016-05-22 04:17:00Z ngie $ |
12 */ 13 14/* 15 * This file contains the routines that display information on the screen. 16 * Each section of the screen has two routines: one for initially writing 17 * all constant and dynamic text, and one for only updating the text that 18 * changes. The prefix "i_" is used on all the "initial" routines and the 19 * prefix "u_" is used for all the "updating" routines. --- 4 unchanged lines hidden (view full) --- 24 * have minimal (or nonexistant) terminal capabilities. 25 * 26 * The routines are called in this order: *_loadave, i_timeofday, 27 * *_procstates, *_cpustates, *_memory, *_message, *_header, 28 * *_process, u_endscreen. 29 */ 30 31#include "os.h" | 12 */ 13 14/* 15 * This file contains the routines that display information on the screen. 16 * Each section of the screen has two routines: one for initially writing 17 * all constant and dynamic text, and one for only updating the text that 18 * changes. The prefix "i_" is used on all the "initial" routines and the 19 * prefix "u_" is used for all the "updating" routines. --- 4 unchanged lines hidden (view full) --- 24 * have minimal (or nonexistant) terminal capabilities. 25 * 26 * The routines are called in this order: *_loadave, i_timeofday, 27 * *_procstates, *_cpustates, *_memory, *_message, *_header, 28 * *_process, u_endscreen. 29 */ 30 31#include "os.h" |
32 33#include <sys/time.h> 34 |
|
32#include <ctype.h> 33#include <time.h> | 35#include <ctype.h> 36#include <time.h> |
34#include <sys/time.h> | 37#include <unistd.h> |
35 36#include "screen.h" /* interface to screen package */ 37#include "layout.h" /* defines for screen position layout */ 38#include "display.h" 39#include "top.h" 40#include "top.local.h" 41#include "boolean.h" 42#include "machine.h" /* we should eliminate this!!! */ --- 8 unchanged lines hidden (view full) --- 51 52static int lmpid = 0; 53static int last_hi = 0; /* used in u_process and u_endscreen */ 54static int lastline = 0; 55static int display_width = MAX_COLS; 56 57#define lineindex(l) ((l)*display_width) 58 | 38 39#include "screen.h" /* interface to screen package */ 40#include "layout.h" /* defines for screen position layout */ 41#include "display.h" 42#include "top.h" 43#include "top.local.h" 44#include "boolean.h" 45#include "machine.h" /* we should eliminate this!!! */ --- 8 unchanged lines hidden (view full) --- 54 55static int lmpid = 0; 56static int last_hi = 0; /* used in u_process and u_endscreen */ 57static int lastline = 0; 58static int display_width = MAX_COLS; 59 60#define lineindex(l) ((l)*display_width) 61 |
59char *printable(); | |
60 61/* things initialized by display_init and used thruout */ 62 63/* buffer of proc information lines for display updating */ 64char *screenbuf = NULL; 65 66static char **procstate_names; 67static char **cpustate_names; --- 166 unchanged lines hidden (view full) --- 234 } 235 } 236 } 237 238 /* return number of lines available */ 239 return(lines); 240} 241 | 62 63/* things initialized by display_init and used thruout */ 64 65/* buffer of proc information lines for display updating */ 66char *screenbuf = NULL; 67 68static char **procstate_names; 69static char **cpustate_names; --- 166 unchanged lines hidden (view full) --- 236 } 237 } 238 } 239 240 /* return number of lines available */ 241 return(lines); 242} 243 |
244void |
|
242i_loadave(mpid, avenrun) 243 244int mpid; 245double *avenrun; 246 247{ 248 register int i; 249 --- 12 unchanged lines hidden (view full) --- 262 { 263 printf("%c %5.2f", 264 i == 0 ? ':' : ',', 265 avenrun[i]); 266 } 267 lmpid = mpid; 268} 269 | 245i_loadave(mpid, avenrun) 246 247int mpid; 248double *avenrun; 249 250{ 251 register int i; 252 --- 12 unchanged lines hidden (view full) --- 265 { 266 printf("%c %5.2f", 267 i == 0 ? ':' : ',', 268 avenrun[i]); 269 } 270 lmpid = mpid; 271} 272 |
273void |
|
270u_loadave(mpid, avenrun) 271 272int mpid; 273double *avenrun; 274 275{ 276 register int i; 277 --- 23 unchanged lines hidden (view full) --- 301 for (i = 0; i < 3; i++) 302 { 303 printf("%s%5.2f", 304 i == 0 ? "" : ", ", 305 avenrun[i]); 306 } 307} 308 | 274u_loadave(mpid, avenrun) 275 276int mpid; 277double *avenrun; 278 279{ 280 register int i; 281 --- 23 unchanged lines hidden (view full) --- 305 for (i = 0; i < 3; i++) 306 { 307 printf("%s%5.2f", 308 i == 0 ? "" : ", ", 309 avenrun[i]); 310 } 311} 312 |
313void |
|
309i_timeofday(tod) 310 311time_t *tod; 312 313{ 314 /* 315 * Display the current time. 316 * "ctime" always returns a string that looks like this: --- 29 unchanged lines hidden (view full) --- 346 347/* 348 * *_procstates(total, brkdn, names) - print the process summary line 349 * 350 * Assumptions: cursor is at the beginning of the line on entry 351 * lastline is valid 352 */ 353 | 314i_timeofday(tod) 315 316time_t *tod; 317 318{ 319 /* 320 * Display the current time. 321 * "ctime" always returns a string that looks like this: --- 29 unchanged lines hidden (view full) --- 351 352/* 353 * *_procstates(total, brkdn, names) - print the process summary line 354 * 355 * Assumptions: cursor is at the beginning of the line on entry 356 * lastline is valid 357 */ 358 |
359void |
|
354i_procstates(total, brkdn) 355 356int total; 357int *brkdn; 358 359{ 360 register int i; 361 --- 11 unchanged lines hidden (view full) --- 373 /* format and print the process state summary */ 374 summary_format(procstates_buffer, brkdn, procstate_names); 375 fputs(procstates_buffer, stdout); 376 377 /* save the numbers for next time */ 378 memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); 379} 380 | 360i_procstates(total, brkdn) 361 362int total; 363int *brkdn; 364 365{ 366 register int i; 367 --- 11 unchanged lines hidden (view full) --- 379 /* format and print the process state summary */ 380 summary_format(procstates_buffer, brkdn, procstate_names); 381 fputs(procstates_buffer, stdout); 382 383 /* save the numbers for next time */ 384 memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); 385} 386 |
387void |
|
381u_procstates(total, brkdn) 382 383int total; 384int *brkdn; 385 386{ 387 static char new[MAX_COLS]; 388 register int i; --- 66 unchanged lines hidden (view full) --- 455 } 456 457 /* set cpustates_column accordingly then return result */ 458 cpustates_column = strlen(use); 459 return(use); 460} 461#endif 462 | 388u_procstates(total, brkdn) 389 390int total; 391int *brkdn; 392 393{ 394 static char new[MAX_COLS]; 395 register int i; --- 66 unchanged lines hidden (view full) --- 462 } 463 464 /* set cpustates_column accordingly then return result */ 465 cpustates_column = strlen(use); 466 return(use); 467} 468#endif 469 |
470void |
|
463i_cpustates(states) 464 | 471i_cpustates(states) 472 |
465register int *states; | 473int *states; |
466 467{ 468 register int i = 0; 469 register int value; 470 register char **names; 471 register char *thisname; 472 int cpu; 473 --- 26 unchanged lines hidden (view full) --- 500 } 501 } 502} 503 504 /* copy over values into "last" array */ 505 memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); 506} 507 | 474 475{ 476 register int i = 0; 477 register int value; 478 register char **names; 479 register char *thisname; 480 int cpu; 481 --- 26 unchanged lines hidden (view full) --- 508 } 509 } 510} 511 512 /* copy over values into "last" array */ 513 memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); 514} 515 |
516void |
|
508u_cpustates(states) 509 | 517u_cpustates(states) 518 |
510register int *states; | 519int *states; |
511 512{ 513 register int value; 514 register char **names; 515 register char *thisname; 516 register int *lp; 517 register int *colp; 518 int cpu; --- 33 unchanged lines hidden (view full) --- 552 /* increment and move on */ 553 lp++; 554 states++; 555 colp++; 556 } 557} 558} 559 | 520 521{ 522 register int value; 523 register char **names; 524 register char *thisname; 525 register int *lp; 526 register int *colp; 527 int cpu; --- 33 unchanged lines hidden (view full) --- 561 /* increment and move on */ 562 lp++; 563 states++; 564 colp++; 565 } 566} 567} 568 |
569void |
|
560z_cpustates() 561 562{ 563 register int i = 0; 564 register char **names; 565 register char *thisname; 566 register int *lp; 567 int cpu, value; --- 33 unchanged lines hidden (view full) --- 601 * *_memory(stats) - print "Memory: " followed by the memory summary string 602 * 603 * Assumptions: cursor is on "lastline" 604 * for i_memory ONLY: cursor is on the previous line 605 */ 606 607char memory_buffer[MAX_COLS]; 608 | 570z_cpustates() 571 572{ 573 register int i = 0; 574 register char **names; 575 register char *thisname; 576 register int *lp; 577 int cpu, value; --- 33 unchanged lines hidden (view full) --- 611 * *_memory(stats) - print "Memory: " followed by the memory summary string 612 * 613 * Assumptions: cursor is on "lastline" 614 * for i_memory ONLY: cursor is on the previous line 615 */ 616 617char memory_buffer[MAX_COLS]; 618 |
619void |
|
609i_memory(stats) 610 611int *stats; 612 613{ 614 fputs("\nMem: ", stdout); 615 lastline++; 616 617 /* format and print the memory summary */ 618 summary_format(memory_buffer, stats, memory_names); 619 fputs(memory_buffer, stdout); 620} 621 | 620i_memory(stats) 621 622int *stats; 623 624{ 625 fputs("\nMem: ", stdout); 626 lastline++; 627 628 /* format and print the memory summary */ 629 summary_format(memory_buffer, stats, memory_names); 630 fputs(memory_buffer, stdout); 631} 632 |
633void |
|
622u_memory(stats) 623 624int *stats; 625 626{ 627 static char new[MAX_COLS]; 628 629 /* format the new line */ --- 4 unchanged lines hidden (view full) --- 634/* 635 * *_arc(stats) - print "ARC: " followed by the ARC summary string 636 * 637 * Assumptions: cursor is on "lastline" 638 * for i_arc ONLY: cursor is on the previous line 639 */ 640char arc_buffer[MAX_COLS]; 641 | 634u_memory(stats) 635 636int *stats; 637 638{ 639 static char new[MAX_COLS]; 640 641 /* format the new line */ --- 4 unchanged lines hidden (view full) --- 646/* 647 * *_arc(stats) - print "ARC: " followed by the ARC summary string 648 * 649 * Assumptions: cursor is on "lastline" 650 * for i_arc ONLY: cursor is on the previous line 651 */ 652char arc_buffer[MAX_COLS]; 653 |
654void |
|
642i_arc(stats) 643 644int *stats; 645 646{ 647 if (arc_names == NULL) | 655i_arc(stats) 656 657int *stats; 658 659{ 660 if (arc_names == NULL) |
648 return (0); | 661 return; |
649 650 fputs("\nARC: ", stdout); 651 lastline++; 652 653 /* format and print the memory summary */ 654 summary_format(arc_buffer, stats, arc_names); 655 fputs(arc_buffer, stdout); 656} 657 | 662 663 fputs("\nARC: ", stdout); 664 lastline++; 665 666 /* format and print the memory summary */ 667 summary_format(arc_buffer, stats, arc_names); 668 fputs(arc_buffer, stdout); 669} 670 |
671void |
|
658u_arc(stats) 659 660int *stats; 661 662{ 663 static char new[MAX_COLS]; 664 665 if (arc_names == NULL) | 672u_arc(stats) 673 674int *stats; 675 676{ 677 static char new[MAX_COLS]; 678 679 if (arc_names == NULL) |
666 return (0); | 680 return; |
667 668 /* format the new line */ 669 summary_format(new, stats, arc_names); 670 line_update(arc_buffer, new, x_arc, y_arc); 671} 672 673 674/* 675 * *_swap(stats) - print "Swap: " followed by the swap summary string 676 * 677 * Assumptions: cursor is on "lastline" 678 * for i_swap ONLY: cursor is on the previous line 679 */ 680 681char swap_buffer[MAX_COLS]; 682 | 681 682 /* format the new line */ 683 summary_format(new, stats, arc_names); 684 line_update(arc_buffer, new, x_arc, y_arc); 685} 686 687 688/* 689 * *_swap(stats) - print "Swap: " followed by the swap summary string 690 * 691 * Assumptions: cursor is on "lastline" 692 * for i_swap ONLY: cursor is on the previous line 693 */ 694 695char swap_buffer[MAX_COLS]; 696 |
697void |
|
683i_swap(stats) 684 685int *stats; 686 687{ 688 fputs("\nSwap: ", stdout); 689 lastline++; 690 691 /* format and print the swap summary */ 692 summary_format(swap_buffer, stats, swap_names); 693 fputs(swap_buffer, stdout); 694} 695 | 698i_swap(stats) 699 700int *stats; 701 702{ 703 fputs("\nSwap: ", stdout); 704 lastline++; 705 706 /* format and print the swap summary */ 707 summary_format(swap_buffer, stats, swap_names); 708 fputs(swap_buffer, stdout); 709} 710 |
711void |
|
696u_swap(stats) 697 698int *stats; 699 700{ 701 static char new[MAX_COLS]; 702 703 /* format the new line */ --- 15 unchanged lines hidden (view full) --- 719 * respect to screen updates). 720 */ 721 722static char next_msg[MAX_COLS + 5]; 723static int msglen = 0; 724/* Invariant: msglen is always the length of the message currently displayed 725 on the screen (even when next_msg doesn't contain that message). */ 726 | 712u_swap(stats) 713 714int *stats; 715 716{ 717 static char new[MAX_COLS]; 718 719 /* format the new line */ --- 15 unchanged lines hidden (view full) --- 735 * respect to screen updates). 736 */ 737 738static char next_msg[MAX_COLS + 5]; 739static int msglen = 0; 740/* Invariant: msglen is always the length of the message currently displayed 741 on the screen (even when next_msg doesn't contain that message). */ 742 |
743void |
|
727i_message() 728 729{ 730 while (lastline < y_message) 731 { 732 fputc('\n', stdout); 733 lastline++; 734 } --- 5 unchanged lines hidden (view full) --- 740 } 741 else if (msglen > 0) 742 { 743 (void) clear_eol(msglen); 744 msglen = 0; 745 } 746} 747 | 744i_message() 745 746{ 747 while (lastline < y_message) 748 { 749 fputc('\n', stdout); 750 lastline++; 751 } --- 5 unchanged lines hidden (view full) --- 757 } 758 else if (msglen > 0) 759 { 760 (void) clear_eol(msglen); 761 msglen = 0; 762 } 763} 764 |
765void |
|
748u_message() 749 750{ 751 i_message(); 752} 753 754static int header_length; 755 --- 25 unchanged lines hidden (view full) --- 781} 782 783/* 784 * *_header(text) - print the header for the process area 785 * 786 * Assumptions: cursor is on the previous line and lastline is consistent 787 */ 788 | 766u_message() 767 768{ 769 i_message(); 770} 771 772static int header_length; 773 --- 25 unchanged lines hidden (view full) --- 799} 800 801/* 802 * *_header(text) - print the header for the process area 803 * 804 * Assumptions: cursor is on the previous line and lastline is consistent 805 */ 806 |
807void |
|
789i_header(text) 790 791char *text; 792 793{ 794 char *s; 795 796 s = trim_header(text); --- 9 unchanged lines hidden (view full) --- 806 else if (header_status == ERASE) 807 { 808 header_status = OFF; 809 } 810 free(s); 811} 812 813/*ARGSUSED*/ | 808i_header(text) 809 810char *text; 811 812{ 813 char *s; 814 815 s = trim_header(text); --- 9 unchanged lines hidden (view full) --- 825 else if (header_status == ERASE) 826 { 827 header_status = OFF; 828 } 829 free(s); 830} 831 832/*ARGSUSED*/ |
833void |
|
814u_header(text) 815 | 834u_header(text) 835 |
816char *text; /* ignored */ | 836char *text __unused; /* ignored */ |
817 818{ 819 820 if (header_status == ERASE) 821 { 822 putchar('\n'); 823 lastline++; 824 clear_eol(header_length); 825 header_status = OFF; 826 } 827} 828 829/* 830 * *_process(line, thisline) - print one process line 831 * 832 * Assumptions: lastline is consistent 833 */ 834 | 837 838{ 839 840 if (header_status == ERASE) 841 { 842 putchar('\n'); 843 lastline++; 844 clear_eol(header_length); 845 header_status = OFF; 846 } 847} 848 849/* 850 * *_process(line, thisline) - print one process line 851 * 852 * Assumptions: lastline is consistent 853 */ 854 |
855void |
|
835i_process(line, thisline) 836 837int line; 838char *thisline; 839 840{ 841 register char *p; 842 register char *base; --- 14 unchanged lines hidden (view full) --- 857 /* copy it in to our buffer */ 858 base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; 859 p = strecpy(base, thisline); 860 861 /* zero fill the rest of it */ 862 memzero(p, display_width - (p - base)); 863} 864 | 856i_process(line, thisline) 857 858int line; 859char *thisline; 860 861{ 862 register char *p; 863 register char *base; --- 14 unchanged lines hidden (view full) --- 878 /* copy it in to our buffer */ 879 base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; 880 p = strecpy(base, thisline); 881 882 /* zero fill the rest of it */ 883 memzero(p, display_width - (p - base)); 884} 885 |
886void |
|
865u_process(line, newline) 866 867int line; 868char *newline; 869 870{ 871 register char *optr; 872 register int screen_line = line + Header_lines; --- 31 unchanged lines hidden (view full) --- 904 memzero(optr, display_width - (optr - bufferline)); 905 } 906 else 907 { 908 line_update(bufferline, newline, 0, line + Header_lines); 909 } 910} 911 | 887u_process(line, newline) 888 889int line; 890char *newline; 891 892{ 893 register char *optr; 894 register int screen_line = line + Header_lines; --- 31 unchanged lines hidden (view full) --- 926 memzero(optr, display_width - (optr - bufferline)); 927 } 928 else 929 { 930 line_update(bufferline, newline, 0, line + Header_lines); 931 } 932} 933 |
934void |
|
912u_endscreen(hi) 913 | 935u_endscreen(hi) 936 |
914register int hi; | 937int hi; |
915 916{ 917 register int screen_line = hi + Header_lines; 918 register int i; 919 920 if (smart_terminal) 921 { 922 if (hi < last_hi) --- 41 unchanged lines hidden (view full) --- 964 } 965 else 966 { 967 /* separate this display from the next with some vertical room */ 968 fputs("\n\n", stdout); 969 } 970} 971 | 938 939{ 940 register int screen_line = hi + Header_lines; 941 register int i; 942 943 if (smart_terminal) 944 { 945 if (hi < last_hi) --- 41 unchanged lines hidden (view full) --- 987 } 988 else 989 { 990 /* separate this display from the next with some vertical room */ 991 fputs("\n\n", stdout); 992 } 993} 994 |
995void |
|
972display_header(t) 973 974int t; 975 976{ 977 if (t) 978 { 979 header_status = ON; 980 } 981 else if (header_status == ON) 982 { 983 header_status = ERASE; 984 } 985} 986 987/*VARARGS2*/ | 996display_header(t) 997 998int t; 999 1000{ 1001 if (t) 1002 { 1003 header_status = ON; 1004 } 1005 else if (header_status == ON) 1006 { 1007 header_status = ERASE; 1008 } 1009} 1010 1011/*VARARGS2*/ |
1012void |
|
988new_message(type, msgfmt, a1, a2, a3) 989 990int type; 991char *msgfmt; 992caddr_t a1, a2, a3; 993 994{ 995 register int i; --- 24 unchanged lines hidden (view full) --- 1020 { 1021 type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout); 1022 msglen = strlen(next_msg); 1023 next_msg[0] = '\0'; 1024 } 1025 } 1026} 1027 | 1013new_message(type, msgfmt, a1, a2, a3) 1014 1015int type; 1016char *msgfmt; 1017caddr_t a1, a2, a3; 1018 1019{ 1020 register int i; --- 24 unchanged lines hidden (view full) --- 1045 { 1046 type & MT_standout ? standout(next_msg) : fputs(next_msg, stdout); 1047 msglen = strlen(next_msg); 1048 next_msg[0] = '\0'; 1049 } 1050 } 1051} 1052 |
1053void |
|
1028clear_message() 1029 1030{ 1031 if (clear_eol(msglen) == 1) 1032 { 1033 putchar('\r'); 1034 } 1035} 1036 | 1054clear_message() 1055 1056{ 1057 if (clear_eol(msglen) == 1) 1058 { 1059 putchar('\r'); 1060 } 1061} 1062 |
1063int |
|
1037readline(buffer, size, numeric) 1038 1039char *buffer; 1040int size; 1041int numeric; 1042 1043{ 1044 register char *ptr = buffer; --- 286 unchanged lines hidden (view full) --- 1331 { 1332 *ptr = '?'; 1333 } 1334 ptr++; 1335 } 1336 return(str); 1337} 1338 | 1064readline(buffer, size, numeric) 1065 1066char *buffer; 1067int size; 1068int numeric; 1069 1070{ 1071 register char *ptr = buffer; --- 286 unchanged lines hidden (view full) --- 1358 { 1359 *ptr = '?'; 1360 } 1361 ptr++; 1362 } 1363 return(str); 1364} 1365 |
1366void |
|
1339i_uptime(bt, tod) 1340 1341struct timeval* bt; 1342time_t *tod; 1343 1344{ 1345 time_t uptime; 1346 int days, hrs, mins, secs; --- 25 unchanged lines hidden --- | 1367i_uptime(bt, tod) 1368 1369struct timeval* bt; 1370time_t *tod; 1371 1372{ 1373 time_t uptime; 1374 int days, hrs, mins, secs; --- 25 unchanged lines hidden --- |