Index: contrib/top/commands.h =================================================================== --- contrib/top/commands.h +++ contrib/top/commands.h @@ -0,0 +1,11 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + + + +void show_errors(void); +int error_count(void); +void show_help(void); + + +#endif /* COMMANDS_H */ Index: contrib/top/commands.c =================================================================== --- contrib/top/commands.c +++ contrib/top/commands.c @@ -19,16 +19,21 @@ */ #include "os.h" -#include -#include -#include + #include #include +#include +#include +#include +#include + +#include "commands.h" #include "sigdesc.h" /* generated automatically */ #include "top.h" #include "boolean.h" #include "utils.h" +#include "machine.h" extern int errno; @@ -39,6 +44,8 @@ int err_compar(); char *err_string(); +int str_adderr(char *str, int len, int err); +int str_addarg(char *str, int len, char *arg, int first); /* * show_help() - display the help screen; invoked in response to @@ -45,6 +52,7 @@ * either 'h' or '?'. */ +void show_help() { @@ -123,6 +131,7 @@ return(*str == '\0' ? NULL : str); } +int scanint(str, intp) char *str; @@ -262,6 +271,7 @@ * the string "str". */ +int str_adderr(str, len, err) char *str; @@ -289,6 +299,7 @@ * is set (indicating that a comma should NOT be added to the front). */ +int str_addarg(str, len, arg, first) char *str; @@ -321,6 +332,7 @@ * for sorting errors. */ +int err_compar(p1, p2) register struct errs *p1, *p2; @@ -339,6 +351,7 @@ * error_count() - return the number of errors currently logged. */ +int error_count() { @@ -349,6 +362,7 @@ * show_errors() - display on stdout the current log of errors. */ +void show_errors() { Index: contrib/top/display.h =================================================================== --- contrib/top/display.h +++ contrib/top/display.h @@ -5,3 +5,37 @@ #define MT_standout 1 #define MT_delayed 2 +#include "machine.h" + +int display_updatecpus(struct statics *statics); +void clear_message(void); +int display_resize(void); +void i_header(char *text); +char *printable(char * string); +char *cpustates_tag(void); +void display_header(int t); +int display_init(struct statics *statics); +void i_arc(int *stats); +void i_cpustates(register int *states); +void i_loadave(int mpid, double *avenrun); +void i_memory(int *stats); +void i_message(void); +void i_process(int line, char *thisline); +void i_procstates(int total, int *brkdn); +void i_swap(int *stats); +void i_timeofday(time_t *tod); +void i_uptime(struct timeval *bt, time_t *tod); +void new_message(); +int readline(char *buffer, int size, int numeric); +char *trim_header(char *text); +void u_arc(int *stats); +void u_cpustates(register int *states); +void u_endscreen(register int hi); +void u_header(char *text); +void u_loadave(int mpid, double *avenrun); +void u_memory(int *stats); +void u_message(void); +void u_process(int line, char *newline); +void u_procstates(int total, int *brkdn); +void u_swap(int *stats); +void z_cpustates(void); Index: contrib/top/display.c =================================================================== --- contrib/top/display.c +++ contrib/top/display.c @@ -29,9 +29,12 @@ */ #include "os.h" + +#include + #include #include -#include +#include #include "screen.h" /* interface to screen package */ #include "layout.h" /* defines for screen position layout */ @@ -56,7 +59,6 @@ #define lineindex(l) ((l)*display_width) -char *printable(); /* things initialized by display_init and used thruout */ @@ -115,6 +117,7 @@ int y_cpustates = 2; int Header_lines = 7; + int display_resize() { @@ -239,6 +242,7 @@ return(lines); } +void i_loadave(mpid, avenrun) int mpid; @@ -267,6 +271,7 @@ lmpid = mpid; } +void u_loadave(mpid, avenrun) int mpid; @@ -306,6 +311,7 @@ } } +void i_timeofday(tod) time_t *tod; @@ -351,6 +357,7 @@ * lastline is valid */ +void i_procstates(total, brkdn) int total; @@ -378,6 +385,7 @@ memcpy(lprocstates, brkdn, num_procstates * sizeof(int)); } +void u_procstates(total, brkdn) int total; @@ -460,6 +468,7 @@ } #endif +void i_cpustates(states) register int *states; @@ -505,6 +514,7 @@ memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus); } +void u_cpustates(states) register int *states; @@ -557,6 +567,7 @@ } } +void z_cpustates() { @@ -606,6 +617,7 @@ char memory_buffer[MAX_COLS]; +void i_memory(stats) int *stats; @@ -619,6 +631,7 @@ fputs(memory_buffer, stdout); } +void u_memory(stats) int *stats; @@ -639,6 +652,7 @@ */ char arc_buffer[MAX_COLS]; +void i_arc(stats) int *stats; @@ -645,7 +659,7 @@ { if (arc_names == NULL) - return (0); + return; fputs("\nARC: ", stdout); lastline++; @@ -655,6 +669,7 @@ fputs(arc_buffer, stdout); } +void u_arc(stats) int *stats; @@ -663,7 +678,7 @@ static char new[MAX_COLS]; if (arc_names == NULL) - return (0); + return; /* format the new line */ summary_format(new, stats, arc_names); @@ -680,6 +695,7 @@ char swap_buffer[MAX_COLS]; +void i_swap(stats) int *stats; @@ -693,6 +709,7 @@ fputs(swap_buffer, stdout); } +void u_swap(stats) int *stats; @@ -724,6 +741,7 @@ /* Invariant: msglen is always the length of the message currently displayed on the screen (even when next_msg doesn't contain that message). */ +void i_message() { @@ -745,6 +763,7 @@ } } +void u_message() { @@ -786,6 +805,7 @@ * Assumptions: cursor is on the previous line and lastline is consistent */ +void i_header(text) char *text; @@ -811,6 +831,7 @@ } /*ARGSUSED*/ +void u_header(text) char *text; /* ignored */ @@ -832,6 +853,7 @@ * Assumptions: lastline is consistent */ +void i_process(line, thisline) int line; @@ -862,6 +884,7 @@ memzero(p, display_width - (p - base)); } +void u_process(line, newline) int line; @@ -909,6 +932,7 @@ } } +void u_endscreen(hi) register int hi; @@ -969,6 +993,7 @@ } } +void display_header(t) int t; @@ -985,6 +1010,7 @@ } /*VARARGS2*/ +void new_message(type, msgfmt, a1, a2, a3) int type; @@ -1025,6 +1051,7 @@ } } +void clear_message() { @@ -1034,6 +1061,7 @@ } } +int readline(buffer, size, numeric) char *buffer; @@ -1336,6 +1364,7 @@ return(str); } +void i_uptime(bt, tod) struct timeval* bt; Index: contrib/top/machine.h =================================================================== --- contrib/top/machine.h +++ contrib/top/machine.h @@ -7,7 +7,11 @@ * module. It is NOT machine dependent and should not need to be changed * for any specific machine. */ +#ifndef MACHINE_H +#define MACHINE_H +#include "top.h" + /* * the statics struct is filled in by machine_init */ @@ -74,8 +78,14 @@ /* routines defined by the machine dependent module */ -char *format_header(); -char *format_next_process(); +char *format_header(); +char *format_next_process(); +void toggle_pcpustats(void); +void get_system_info(struct system_info *si); +int machine_init(struct statics *statics, char do_unames); +int proc_owner(int pid); /* non-int routines typically used by the machine dependent module */ -char *printable(); +char *printable(); + +#endif /* MACHINE_H */ Index: contrib/top/screen.h =================================================================== --- contrib/top/screen.h +++ contrib/top/screen.h @@ -28,4 +28,14 @@ extern int screen_width; /* a function that puts a single character on stdout */ -int putstdout(); +void putstdout(char ch); +int clear_eol(int len); +void standout(char *msg); +void clear(void); +void go_home(void); +void reinit_screen(void); +void get_screensize(void); +void init_termcap(int interactive); +void end_screen(void); +void init_screen(void); + Index: contrib/top/screen.c =================================================================== --- contrib/top/screen.c +++ contrib/top/screen.c @@ -50,7 +50,6 @@ extern char *myname; -int putstdout(); int overstrike; int screen_length; @@ -236,6 +235,7 @@ #endif } +void init_screen() { @@ -326,6 +326,7 @@ } } +void end_screen() { @@ -356,6 +357,7 @@ } } +void reinit_screen() { @@ -383,6 +385,7 @@ } } +void get_screensize() { @@ -428,6 +431,7 @@ lower_left[sizeof(lower_left) - 1] = '\0'; } +void standout(msg) char *msg; @@ -445,6 +449,7 @@ } } +void clear() { @@ -454,6 +459,7 @@ } } +int clear_eol(len) int len; @@ -478,6 +484,7 @@ return(-1); } +void go_home() { @@ -489,6 +496,7 @@ /* This has to be defined as a subroutine for tputs (instead of a macro) */ +void putstdout(ch) char ch; Index: contrib/top/top.h =================================================================== --- contrib/top/top.h +++ contrib/top/top.h @@ -7,6 +7,9 @@ * General (global) definitions */ +#ifndef TOP_H +#define TOP_H + /* Current major version number */ #define VERSION 3 @@ -47,3 +50,5 @@ extern enum displaymodes displaymode; extern int pcpu_stats; + +#endif /* TOP_H */ Index: contrib/top/top.c =================================================================== --- contrib/top/top.c +++ contrib/top/top.c @@ -34,15 +34,19 @@ */ #include "os.h" -#include -#include -#include -#include + #include #include + +#include +#include #include +#include +#include +#include /* includes specific to top */ +#include "commands.h" #include "display.h" /* interface to display package */ #include "screen.h" /* interface to screen package */ #include "top.h" @@ -50,6 +54,7 @@ #include "boolean.h" #include "machine.h" #include "utils.h" +#include "username.h" /* Size of the stdio buffer given to stdout */ #define Buffersize 2048 @@ -114,38 +119,21 @@ char *username(); char *itoa7(); -/* display routines that need to be predeclared */ -int i_loadave(); -int u_loadave(); -int i_procstates(); -int u_procstates(); -int i_cpustates(); -int u_cpustates(); -int i_memory(); -int u_memory(); -int i_arc(); -int u_arc(); -int i_swap(); -int u_swap(); -int i_message(); -int u_message(); -int i_header(); -int u_header(); -int i_process(); -int u_process(); - /* pointers to display routines */ -int (*d_loadave)() = i_loadave; -int (*d_procstates)() = i_procstates; -int (*d_cpustates)() = i_cpustates; -int (*d_memory)() = i_memory; -int (*d_arc)() = i_arc; -int (*d_swap)() = i_swap; -int (*d_message)() = i_message; -int (*d_header)() = i_header; -int (*d_process)() = i_process; +void (*d_loadave)() = i_loadave; +void (*d_procstates)() = i_procstates; +void (*d_cpustates)() = i_cpustates; +void (*d_memory)() = i_memory; +void (*d_arc)() = i_arc; +void (*d_swap)() = i_swap; +void (*d_message)() = i_message; +void (*d_header)() = i_header; +void (*d_process)() = i_process; +void reset_display(void); + +int main(argc, argv) int argc; @@ -1178,6 +1166,7 @@ * screen will get redrawn. */ +void reset_display() { Index: contrib/top/username.h =================================================================== --- contrib/top/username.h +++ contrib/top/username.h @@ -0,0 +1,11 @@ +#ifndef USERNAME_H +#define USERNAME_H + + +int enter_user(register int uid, register char *name, int wecare); +int get_user(register int uid); +void init_hash(void); +char *username(register int uid); +int userid(char *username); + +#endif /* USERNAME_H */ Index: contrib/top/username.c =================================================================== --- contrib/top/username.c +++ contrib/top/username.c @@ -32,11 +32,15 @@ #include #include + +#include #include -#include +#include +#include #include "top.local.h" #include "utils.h" +#include "username.h" struct hash_el { int uid; @@ -55,6 +59,8 @@ /* We depend on that for hash_table and YOUR compiler had BETTER do it! */ struct hash_el hash_table[Table_size]; + +void init_hash() { Index: contrib/top/utils.h =================================================================== --- contrib/top/utils.h +++ contrib/top/utils.h @@ -22,3 +22,5 @@ char *format_time(); char *format_k(); char *format_k2(unsigned long long); +int string_index(char *string, char **array); + Index: contrib/top/version.c =================================================================== --- contrib/top/version.c +++ contrib/top/version.c @@ -9,6 +9,9 @@ * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University */ +#include +#include + #include "top.h" #include "patchlevel.h"