Updated top.ch to Jims Wd code

This commit is contained in:
csmall 2002-06-26 23:56:49 +00:00
parent 15ca5a130d
commit 8875fa0010
2 changed files with 41 additions and 64 deletions

74
top.c
View File

@ -1,6 +1,6 @@
/* top.c - Source file: show Linux processes */ /* top.c - Source file: show Linux processes */
/* /*
* Copyright (c) June, 2002 - James C. Warner * Copyright (c) 2002, by: James C. Warner
* All rights reserved. 8921 Hilloway Road * All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA * Eden Prairie, Minnesota 55347 USA
* <warnerjc@worldnet.att.net> * <warnerjc@worldnet.att.net>
@ -1304,7 +1304,7 @@ static void win_colsheads (WIN_t *q)
/* now we can build the true run-time columns header and format the /* now we can build the true run-time columns header and format the
command column heading if P_CMD is really being displayed -- command column heading if P_CMD is really being displayed --
show_a_task is aware of the addition of winnum to the header */ show_a_task is aware of the addition of winnum to the header */
sprintf(q->columnhdr, "%s", Show_altscr ? fmtmk("%d", mkWNO(q)) : ""); sprintf(q->columnhdr, "%s", Show_altscr ? fmtmk("%d", q->winnum) : "");
for (i = 0; i < q->maxpflgs; i++) { for (i = 0; i < q->maxpflgs; i++) {
/* are we gonna' need the kernel symbol table? */ /* are we gonna' need the kernel symbol table? */
if (P_WCHAN == q->procflags[i]) needpsdb = 1; if (P_WCHAN == q->procflags[i]) needpsdb = 1;
@ -1339,7 +1339,7 @@ static void win_names (WIN_t *q, const char *name)
internal, they can be trusted -- it's those darn users that we internal, they can be trusted -- it's those darn users that we
worry 'bout... */ worry 'bout... */
sprintf(q->winname, "%.*s", WINNAMSIZ -1, name); sprintf(q->winname, "%.*s", WINNAMSIZ -1, name);
sprintf(q->grpname, "%d:%.*s", mkWNO(q), WINNAMSIZ -1, name); sprintf(q->grpname, "%d:%.*s", q->winnum, WINNAMSIZ -1, name);
} }
@ -1357,22 +1357,14 @@ static void win_select (int ch)
} }
switch (ch) { switch (ch) {
case 'a': /* we don't carry 'a' / 'w' in our */ case 'a': /* we don't carry 'a' / 'w' in our */
Curwin = Curwin->next; /* user prompt - those case labels */ Curwin = Curwin->next; /* pmt - they're here for a good */
break; /* are just here for a good friend */ break; /* friend of ours -- wins_colors. */
case 'w': /* of ours, wins_colors (however, */ case 'w': /* (however, those lettrs work via */
Curwin = Curwin->prev; /* those letters work via the pmt */ Curwin = Curwin->prev; /* the pmt too but gee, end-loser */
break; /* too -- but really the end-loser */ break; /* should just press the darn key) */
case '1': /* should just press the darn key */ case '1': case '2':
Curwin = Winstk[Def_WINDOW]; /* in the first place) */ case '3': case '4':
break; Curwin = Winstk[ch - '1'];
case '2':
Curwin = Winstk[Job_WINDOW];
break;
case '3':
Curwin = Winstk[Mem_WINDOW];
break;
case '4':
Curwin = Winstk[Usr_WINDOW];
break; break;
} }
} }
@ -1422,8 +1414,7 @@ static void win_sortset (WIN_t *q, const int which)
static int win_warn (void) static int win_warn (void)
{ {
show_msg(fmtmk("\aCommand disabled, activate window #%d with '-' or '_'" show_msg(fmtmk("\aCommand disabled, activate window #%d with '-' or '_'"
, mkWNO(Curwin))); , Curwin->winnum));
/* we gotta' return false 'cause we're somewhat well known within /* we gotta' return false 'cause we're somewhat well known within
macro society, by way of that sassy little tertiary operator... */ macro society, by way of that sassy little tertiary operator... */
return 0; return 0;
@ -1534,13 +1525,13 @@ static void wins_reflag (int what, int flg)
w = Curwin; w = Curwin;
do { do {
switch (what) { switch (what) {
case Flgs_TOG: case Flags_TOG:
TOGw(w, flg); TOGw(w, flg);
break; break;
case Flgs_SET: case Flags_SET: /* Ummmm, i can't find anybody */
SETw(w, flg); SETw(w, flg); /* who uses Flags_set -- maybe */
break; break; /* ol' gcc will opt it away... */
case Flgs_OFF: case Flags_OFF:
OFFw(w, flg); OFFw(w, flg);
break; break;
} }
@ -1616,7 +1607,7 @@ static void windows_stage1 (void)
for (i = 0; i < GROUPSMAX; i++) { for (i = 0; i < GROUPSMAX; i++) {
Winstk[i] = w; Winstk[i] = w;
w->winnum = i; w->winnum = i + 1;
strcpy(w->winname, wtab[i].name); strcpy(w->winname, wtab[i].name);
strcpy(w->fieldscur, wtab[i].flds); strcpy(w->fieldscur, wtab[i].flds);
w->sorttype = wtab[i].sort; w->sorttype = wtab[i].sort;
@ -1636,8 +1627,8 @@ static void windows_stage1 (void)
++w; ++w;
} }
/* fixup the circular chains... */ /* fixup the circular chains... */
Winstk[Usr_WINDOW]->next = Winstk[0]; Winstk[3]->next = Winstk[0];
Winstk[0]->prev = Winstk[Usr_WINDOW]; Winstk[0]->prev = Winstk[3];
Curwin = Winstk[0]; Curwin = Winstk[0];
Show_altscr = 0; Show_altscr = 0;
} }
@ -2120,9 +2111,6 @@ static void show_a_task (WIN_t *q, proc_t *task)
* Process keyboard input during the main loop */ * Process keyboard input during the main loop */
static void do_key (unsigned c) static void do_key (unsigned c)
{ {
#ifndef QUIT_NORMALQ
#define kbdESCAPE 27
#endif
#define kbdCTRL_L 12 #define kbdCTRL_L 12
/* standardized 'secure mode' errors */ /* standardized 'secure mode' errors */
const char *err_secure = "\aCan't %s in secure mode"; const char *err_secure = "\aCan't %s in secure mode";
@ -2140,7 +2128,7 @@ static void do_key (unsigned c)
case '_': /* 'Dash' upper case ----------------------- */ case '_': /* 'Dash' upper case ----------------------- */
if (Show_altscr) /* switcharoo, all viz & inviz ............. */ if (Show_altscr) /* switcharoo, all viz & inviz ............. */
wins_reflag(Flgs_TOG, VISIBLE_tsk); wins_reflag(Flags_TOG, VISIBLE_tsk);
break; break;
case '=': /* 'Equals' lower case --------------------- */ case '=': /* 'Equals' lower case --------------------- */
@ -2395,10 +2383,10 @@ static void do_key (unsigned c)
putp(Cap_clr_scr); putp(Cap_clr_scr);
show_special(fmtmk(WINDOWS_help show_special(fmtmk(WINDOWS_help
, Myname, Curwin->grpname , Myname, Curwin->grpname
, Winstk[Def_WINDOW]->winname , Winstk[0]->winname
, Winstk[Job_WINDOW]->winname , Winstk[1]->winname
, Winstk[Mem_WINDOW]->winname , Winstk[2]->winname
, Winstk[Usr_WINDOW]->winname)); , Winstk[3]->winname));
chin(0, &ch, 1); chin(0, &ch, 1);
win_select(ch); win_select(ch);
} while ('\n' != ch); } while ('\n' != ch);
@ -2435,7 +2423,7 @@ static void do_key (unsigned c)
#ifdef QUIT_NORMALQ #ifdef QUIT_NORMALQ
case 'q': case 'q':
#else #else
case kbdESCAPE: case 'Q':
#endif #endif
stop(0); stop(0);
@ -2443,9 +2431,6 @@ static void do_key (unsigned c)
show_msg("\aUnknown command - try 'h' for help"); show_msg("\aUnknown command - try 'h' for help");
} }
#ifndef QUIT_NORMALQ
#undef kbdESCAPE
#endif
#undef kbdCTRL_L #undef kbdCTRL_L
} }
@ -2628,7 +2613,8 @@ static void so_lets_see_em (void)
Max_lines = (Screen_rows - Msg_row) - 1; Max_lines = (Screen_rows - Msg_row) - 1;
if (CHKw(Curwin, EQUWINS_cwo)) if (CHKw(Curwin, EQUWINS_cwo))
wins_reflag(Flgs_OFF, EQUWINS_cwo); wins_reflag(Flags_OFF, EQUWINS_cwo);
/* sure hope each window's columns header begins with a newline... */ /* sure hope each window's columns header begins with a newline... */
putp(tg2(0, Msg_row)); putp(tg2(0, Msg_row));
@ -2743,8 +2729,8 @@ int main (int dont_care_argc, char **argv)
\---------------------------------------------------------------------/ \---------------------------------------------------------------------/
Sheeesh, didn't that dufus know the return statement can't be executed, Sheeesh, didn't that dufus know the return statement can't be executed,
or a signal & stop() will do-us-in? Oh Lordy, I is DROWNING in morons; or we end via that stop() function? Oh Lordy, I is DROWNING in morons;
they done REACHED clear up to my OUTER braces. We's all DOOMED, I say! they done REACHED clear up to my OUTER braces! We's surely DOOMED now!
/---------------------------------------------------------------------\ /---------------------------------------------------------------------\
*/ */
return 0; return 0;

31
top.h
View File

@ -1,6 +1,6 @@
/* top.h - Header file: show Linux processes */ /* top.h - Header file: show Linux processes */
/* /*
* Copyright (c) June, 2002 - James C. Warner * Copyright (c) 2002, by: James C. Warner
* All rights reserved. 8921 Hilloway Road * All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA * Eden Prairie, Minnesota 55347 USA
* <warnerjc@worldnet.att.net> * <warnerjc@worldnet.att.net>
@ -27,7 +27,7 @@
//#define CASEUP_HEXES /* show any hex values in upper case */ //#define CASEUP_HEXES /* show any hex values in upper case */
//#define CASEUP_SCALE /* show scaled times & memory upper case */ //#define CASEUP_SCALE /* show scaled times & memory upper case */
//#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */ //#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */
//#define QUIT_NORMALQ /* use 'q' to quit, not new default <Esc> */ //#define QUIT_NORMALQ /* use 'q' to quit, not new default 'Q' */
//#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */ //#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */
//#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */ //#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */
//#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */ //#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */
@ -41,7 +41,7 @@
/*###### Some Miscellaneous constants ##################################*/ /*###### Some Miscellaneous constants ##################################*/
/* The default delay twix updates */ /* The default delay twix updates */
#define DEF_DELAY 2.0 #define DEF_DELAY 3.0
/* The length of time a 'message' is displayed */ /* The length of time a 'message' is displayed */
#define MSG_SLEEP 2 #define MSG_SLEEP 2
@ -168,14 +168,9 @@ enum pflag {
#define GRPNAMSIZ 6 /* window's name + number as in: '#:...' */ #define GRPNAMSIZ 6 /* window's name + number as in: '#:...' */
#define CAPTABMAX 9 /* a window's captab used by show_special */ #define CAPTABMAX 9 /* a window's captab used by show_special */
#define Def_WINDOW 0 /* these represent the pre-allocated */ #define Flags_TOG 1 /* these are used to direct wins_reflag */
#define Job_WINDOW 1 /* WIN_t's relative position in the */ #define Flags_SET 2
#define Mem_WINDOW 2 /* window stack pointer array... */ #define Flags_OFF 3
#define Usr_WINDOW 3
#define Flgs_TOG 1 /* these are used to direct wins_reflag */
#define Flgs_SET 2
#define Flgs_OFF 3
/* The Persistent 'Mode' flags! /* The Persistent 'Mode' flags!
All of these are preserved in the rc file, as a single integer. All of these are preserved in the rc file, as a single integer.
@ -221,10 +216,6 @@ enum pflag {
#define VIZTOGc(f) (!Show_altscr || Curwin->winflags & VISIBLE_tsk) \ #define VIZTOGc(f) (!Show_altscr || Curwin->winflags & VISIBLE_tsk) \
? TOGw(Curwin, f) : win_warn() ? TOGw(Curwin, f) : win_warn()
/* Just create a printable window number -- represented here since
we can't decide which to prefer (relative 0 or 1) */
#define mkWNO(q) q->winnum + 1
/* This structure stores configurable information for each window. /* This structure stores configurable information for each window.
By expending a little effort in its creation and user requested By expending a little effort in its creation and user requested
maintainence, the only real additional per frame cost of having maintainence, the only real additional per frame cost of having
@ -233,7 +224,7 @@ enum pflag {
typedef struct win { typedef struct win {
struct win *next, /* next window in window stack */ struct win *next, /* next window in window stack */
*prev; /* prior window in window stack */ *prev; /* prior window in window stack */
int winnum, /* this window's num/array pos */ int winnum, /* window's num (array pos + 1) */
winlines; /* task window's rows (volatile) */ winlines; /* task window's rows (volatile) */
int winflags; /* 'view', 'show' and 'sort' mode flags */ int winflags; /* 'view', 'show' and 'sort' mode flags */
char grpname [GRPNAMSIZ], /* window number:name, printable */ char grpname [GRPNAMSIZ], /* window number:name, printable */
@ -267,7 +258,7 @@ typedef struct win {
/*###### Display Support *Data* ########################################*/ /*###### Display Support *Data* ########################################*/
/* An rcfile 'footprint' used to invalidate existing */ /* An rcfile 'footprint' used to invalidate existing */
#define RCF_FILEID 'c' #define RCF_FILEID 'd'
/* The default fields displayed and their order, /* The default fields displayed and their order,
if nothing is specified by the loser, oops user */ if nothing is specified by the loser, oops user */
@ -341,9 +332,9 @@ typedef struct win {
/* Keyboard Help specially formatted string(s) -- /* Keyboard Help specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */ see 'show_special' for syntax details + other cautions. */
#ifdef QUIT_NORMALQ #ifdef QUIT_NORMALQ
#define HELP_STOPkey " q " #define HELP_QUITkey " q "
#else #else
#define HELP_STOPkey " <Esc> " #define HELP_QUITkey " Q "
#endif #endif
#define KEYS_help \ #define KEYS_help \
"%s's - \01Help for Interactive Commands\02 - %s\n" \ "%s's - \01Help for Interactive Commands\02 - %s\n" \
@ -364,7 +355,7 @@ typedef struct win {
" u . Show specific user only\n" \ " u . Show specific user only\n" \
" # or n . Set maximum tasks displayed\n" \ " # or n . Set maximum tasks displayed\n" \
" W Write configuration file\n" \ " W Write configuration file\n" \
HELP_STOPkey "Quit\n" \ HELP_QUITkey "Quit\n" \
" ( commands shown with '.' require a \01visible\02 task display \01window\02 ) \n" \ " ( commands shown with '.' require a \01visible\02 task display \01window\02 ) \n" \
"Press '\01h\02' or '\01?\02' for help with \01Windows\02,\n" \ "Press '\01h\02' or '\01?\02' for help with \01Windows\02,\n" \
"any other key to continue " \ "any other key to continue " \