1 /* top.h - Header file: show Linux processes */ 2 /* 3 * Copyright (c) 2002, by: James C. Warner 4 * All rights reserved. 8921 Hilloway Road 5 * Eden Prairie, Minnesota 55347 USA 6 * <warnerjc@worldnet.att.net> 7 * 8 * This file may be used subject to the terms and conditions of the 9 * GNU Library General Public License Version 2, or any later version 10 * at your option, as published by the Free Software Foundation. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Library General Public License for more details. 15 * 16 * For their contributions to this program, the author wishes to thank: 17 * Albert D. Cahalan, <albert@users.sf.net> 18 * Craig Small, <csmall@small.dropbear.id.au> 19 * 20 * Changes by Albert Cahalan, 2002. 21 */ 22 23 #ifndef _Itop 24 #define _Itop 25 26 /* Defines intended to be experimented with ------------------------ */ 27 //#define CASEUP_HEXES /* show any hex values in upper case */ 28 //#define CASEUP_SCALE /* show scaled time/num suffix upper case */ 29 //#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */ 30 //#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */ 31 //#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */ 32 //#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */ 33 34 /* Development/Debugging defines ----------------------------------- */ 35 //#define ATEOJ_REPORT /* report a bunch of stuff, at end-of-job */ 36 //#define PRETEND2_5_X /* pretend we're linux 2.5.x (for IO-wait) */ 37 //#define PRETEND4CPUS /* pretend we're smp with 4 ticsers (sic) */ 38 //#define PRETENDNOCAP /* use a terminal without essential caps */ 39 //#define STDOUT_IOLBF /* disable our own stdout _IOFBF override */ 40 41 #ifdef PRETEND2_5_X 42 #define linux_version_code LINUX_VERSION(2,5,43) 43 #endif 44 45 /*###### Some Miscellaneous constants ##################################*/ 46 47 /* The default delay twix updates */ 48 #define DEF_DELAY 3.0 49 50 /* The length of time a 'message' is displayed */ 51 #define MSG_SLEEP 2 52 53 /* The default value for the 'k' (kill) request */ 54 #define DEF_SIGNAL SIGTERM 55 56 /* Specific process id monitoring support (command line only) */ 57 #define MONPIDMAX 20 58 59 /* Miscellaneous buffer sizes with liberal values 60 -- mostly just to pinpoint source code usage/dependancies */ 61 #define SCREENMAX 512 62 /* the above might seem pretty stingy, until you consider that with every 63 one of top's fields displayed we're talking a 160 byte column header -- 64 so that will provide for all fields plus a 350+ byte command line */ 65 #define WINNAMSIZ 4 66 #define CAPTABMAX 9 67 #define PFLAGSSIZ 32 68 #define CAPBUFSIZ 32 69 #define CLRBUFSIZ 64 70 #define GETBUFSIZ 32 71 #define TNYBUFSIZ 32 72 #define SMLBUFSIZ 256 73 #define OURPATHSZ 1024 74 #define MEDBUFSIZ 1024 75 #define BIGBUFSIZ 2048 76 #define USRNAMSIZ GETBUFSIZ 77 #define ROWBUFSIZ SCREENMAX + CLRBUFSIZ 78 79 80 /*###### Some Miscellaneous Macro definitions ##########################*/ 81 82 /* Yield table size as 'int' */ 83 #define MAXTBL(t) (int)(sizeof(t) / sizeof(t[0])) 84 85 /* Convert some proc stuff into vaules we can actually use */ 86 #define BYTES_2K(n) (unsigned)( (n) >> 10 ) 87 #define PAGES_2B(n) (unsigned)( (n) * Page_size ) 88 #define PAGES_2K(n) BYTES_2K(PAGES_2B(n)) 89 90 /* Used as return arguments in *some* of the sort callbacks */ 91 #define SORT_lt ( Frame_srtflg > 0 ? 1 : -1 ) 92 #define SORT_gt ( Frame_srtflg > 0 ? -1 : 1 ) 93 #define SORT_eq 0 94 95 /* Used to create *most* of the sort callback functions 96 note: some of the callbacks are NOT your father's callbacks, they're 97 highly optimized to save them ol' precious cycles! */ 98 #define SCB_NUM1(f,n) \ 99 static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ 100 if ((*P)->n < (*Q)->n) return SORT_lt; \ 101 if (likely( (*P)->n > (*Q)->n )) return SORT_gt; \ 102 return SORT_eq; } 103 #define SCB_NUM2(f,n1,n2) \ 104 static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ 105 if (((*P)->n1 - (*P)->n2) < ((*Q)->n1 - (*Q)->n2)) return SORT_lt; \ 106 if (likely( ((*P)->n1 - (*P)->n2) > ((*Q)->n1 - (*Q)->n2) )) return SORT_gt; \ 107 return SORT_eq; } 108 #define SCB_NUMx(f,n) \ 109 static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ 110 return Frame_srtflg * ( (*Q)->n - (*P)->n ); } 111 #define SCB_STRx(f,s) \ 112 static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ 113 return Frame_srtflg * strcmp((*Q)->s, (*P)->s); } 114 115 /* The following two macros are used to 'inline' those portions of the 116 * display process requiring formatting, while protecting against any 117 * potential embedded 'millesecond delay' escape sequences. */ 118 /** PUTT - Put to Tty (used in many places) 119 . for temporary, possibly interactive, 'replacement' output 120 . may contain ANY valid terminfo escape sequences 121 . need NOT represent an entire screen row */ 122 #define PUTT(fmt,arg...) do { \ 123 char _str[ROWBUFSIZ]; \ 124 snprintf(_str, sizeof(_str), fmt, ## arg); \ 125 putp(_str); \ 126 } while (0) 127 /** PUFF - Put for Frame (used in only 3 places) 128 . for more permanent frame-oriented 'update' output 129 . may NOT contain cursor motion terminfo escapes 130 . assumed to represent a complete screen ROW 131 . subject to optimization, thus MAY be discarded */ 132 #define PUFF(fmt,arg...) do { \ 133 char _str[ROWBUFSIZ]; \ 134 char *_ptr = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols]; \ 135 int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg); \ 136 if (Batch) putp(_str); \ 137 else { \ 138 if (!memcmp(_ptr, _str, _len)) \ 139 putp("\n"); \ 140 else { \ 141 memcpy(_ptr, _str, _len); \ 142 putp(_ptr); \ 143 } } \ 144 } while (0) 145 146 /*------ Special Macros (debug and/or informative) ---------------------*/ 147 148 /* Orderly end, with any sort of message - see fmtmk */ 149 #define debug_END(s) { \ 150 static void std_err (const char *); \ 151 fputs(Cap_clr_scr, stdout); \ 152 std_err(s); \ 153 } 154 155 /* A poor man's breakpoint, if he's too lazy to learn gdb */ 156 #define its_YOUR_fault { *((char *)0) = '!'; } 157 158 159 /*###### Some Typedef's and Enum's #####################################*/ 160 161 /* This typedef just ensures consistent 'process flags' handling */ 162 typedef unsigned FLG_t; 163 164 /* These typedefs attempt to ensure consistent 'ticks' handling */ 165 typedef unsigned long long TIC_t; 166 typedef long long SIC_t; 167 168 /* Sort support, callback funtion signature */ 169 typedef int (*QFP_t)(const void *, const void *); 170 171 /* This structure consolidates the information that's used 172 in a variety of display roles. */ 173 typedef struct FLD_t { 174 const char keys [4]; // order: New-on New-off Old-on Old-off 175 const char *head; // name for col heads + toggle/reorder fields 176 const char *fmts; // sprintf format string for field display 177 const int width; // field width, if applicable 178 const int scale; // scale_num type, if applicable 179 const QFP_t sort; // sort function 180 const char *desc; // description for toggle/reorder fields 181 const int lflg; // PROC_FILLxxx flag(s) needed by this field 182 } FLD_t; 183 184 /* This structure stores one piece of critical 'history' 185 information from one frame to the next -- we don't calc 186 and save data that goes unused like the old top! */ 187 typedef struct HST_t { 188 int pid; 189 TIC_t tics; 190 } HST_t; 191 192 /* This structure stores a frame's cpu tics used in history 193 calculations. It exists primarily for SMP support but serves 194 all environments. */ 195 typedef struct CPU_t { 196 TIC_t u, n, s, i, w; // as represented in /proc/stat 197 TIC_t u_sav, s_sav, n_sav, i_sav, w_sav; // in the order of our display 198 } CPU_t; 199 200 /* These 2 types support rcfile compatibility */ 201 typedef struct RCW_t { // the 'window' portion of an rcfile 202 FLG_t sortindx; // sort field, represented as a procflag 203 int winflags, // 'view', 'show' and 'sort' mode flags 204 maxtasks, // user requested maximum, 0 equals all 205 summclr, // color num used in summ info 206 msgsclr, // " in msgs/pmts 207 headclr, // " in cols head 208 taskclr; // " in task rows 209 char winname [WINNAMSIZ], // window name, user changeable 210 fieldscur [PFLAGSSIZ]; // fields displayed and ordered 211 } RCW_t; 212 213 typedef struct RCF_t { // the complete rcfile (new style) 214 int mode_altscr; // 'A' - Alt display mode (multi task windows) 215 int mode_irixps; // 'I' - Irix vs. Solaris mode (SMP-only) 216 float delay_time; // 'd' or 's' - How long to sleep twixt updates 217 int win_index; // Curwin, as index 218 RCW_t win [4]; // a 'WIN_t.rc' for each of the 4 windows 219 } RCF_t; 220 221 /* The scaling 'type' used with scale_num() -- this is how 222 the passed number is interpreted should scaling be necessary */ 223 enum scale_num { 224 SK_no, SK_Kb, SK_Mb, SK_Gb 225 }; 226 227 /* Flags for each possible field */ 228 enum pflag { 229 P_PID, P_PPD, P_URR, P_UID, P_URE, P_GRP, P_TTY, 230 P_PRI, P_NCE, 231 P_CPN, P_CPU, P_TME, P_TM2, 232 P_MEM, P_VRT, P_SWP, P_RES, P_COD, P_DAT, P_SHR, 233 P_FLT, P_DRT, 234 P_STA, P_CMD, P_WCH, P_FLG 235 }; 236 237 238 /* ////////////////////////////////////////////////////////////// */ 239 /* Special Section: multiple windows/field groups ---------------*/ 240 /* (kind of a header within a header: constants, macros & types) */ 241 242 #define GROUPSMAX 4 /* the max number of simultaneous windows */ 243 #define GRPNAMSIZ WINNAMSIZ+2 /* window's name + number as in: '#:...' */ 244 245 #define Flags_TOG 1 /* these are used to direct wins_reflag */ 246 #define Flags_SET 2 247 #define Flags_OFF 3 248 249 /* The Persistent 'Mode' flags! 250 These are preserved in the rc file, as a single integer and the 251 letter shown is the corresponding 'command' toggle */ 252 // 'View_' flags affect the summary (minimum), taken from 'Curwin' 253 #define View_CPUSUM 0x8000 /* '1' - show combined cpu stats (vs. each) */ 254 #define View_LOADAV 0x4000 /* 'l' - display load avg and uptime summary */ 255 #define View_STATES 0x2000 /* 't' - display task/cpu(s) states summary */ 256 #define View_MEMORY 0x1000 /* 'm' - display memory summary */ 257 #define View_NOBOLD 0x0001 /* 'B' - disable 'bold' attribute globally */ 258 // 'Show_' & 'Qsrt_' flags are for task display in a visible window 259 #define Show_COLORS 0x0800 /* 'z' - show in color (vs. mono) */ 260 #define Show_HIBOLD 0x0400 /* 'b' - rows and/or cols bold (vs. reverse) */ 261 #define Show_HICOLS 0x0200 /* 'x' - show sort column highlighted */ 262 #define Show_HIROWS 0x0100 /* 'y' - show running tasks highlighted */ 263 #define Show_CMDLIN 0x0080 /* 'c' - show cmdline vs. name */ 264 #define Show_CTIMES 0x0040 /* 'S' - show times as cumulative */ 265 #define Show_IDLEPS 0x0020 /* 'i' - show idle processes (all tasks) */ 266 #define Qsrt_NORMAL 0x0010 /* 'R' - reversed column sort (high to low) */ 267 // these flag(s) have no command as such - they're for internal use 268 #define VISIBLE_tsk 0x0008 /* tasks are showable when in 'Mode_altscr' */ 269 #define NEWFRAM_cwo 0x0004 /* new frame (if anyone cares) - in Curwin */ 270 #define EQUWINS_cwo 0x0002 /* rebalance tasks next frame (off 'i'/ 'n') */ 271 /* ...set in Curwin, but impacts all windows */ 272 273 // Current-window-only flags -- always turned off at end-of-window! 274 #define FLGSOFF_cwo EQUWINS_cwo | NEWFRAM_cwo 275 276 // Default flags if there's no rcfile to provide user customizations 277 #define DEF_WINFLGS ( View_LOADAV | View_STATES | View_CPUSUM | View_MEMORY | \ 278 Show_HIBOLD | Show_HIROWS | Show_IDLEPS | Qsrt_NORMAL | VISIBLE_tsk ) 279 280 // Used to test/manipulate the window flags 281 #define CHKw(q,f) (int)((q)->rc.winflags & (f)) 282 #define TOGw(q,f) (q)->rc.winflags ^= (f) 283 #define SETw(q,f) (q)->rc.winflags |= (f) 284 #define OFFw(q,f) (q)->rc.winflags &= ~(f) 285 #define VIZCHKc (!Rc.mode_altscr || Curwin->rc.winflags & VISIBLE_tsk) \ 286 ? 1 : win_warn() 287 #define VIZTOGc(f) (!Rc.mode_altscr || Curwin->rc.winflags & VISIBLE_tsk) \ 288 ? TOGw(Curwin, f) : win_warn() 289 290 /* This structure stores configurable information for each window. 291 By expending a little effort in its creation and user requested 292 maintainence, the only real additional per frame cost of having 293 windows is an extra sort -- but that's just on ptrs! */ 294 typedef struct WIN_t { 295 struct WIN_t *next, // next window in window stack 296 *prev; // prior window in window stack 297 char *captab [CAPTABMAX]; // captab needed by show_special 298 int winnum, // window's num (array pos + 1) 299 winlines; // task window's rows (volatile) 300 FLG_t procflags [PFLAGSSIZ]; // fieldscur subset, as enum 301 int maxpflgs, // number of procflags (upcase fieldscur) 302 maxcmdln; // max length of a process' command line 303 int len_rownorm, // lengths of the corresponding terminfo 304 len_rowhigh; // strings to avoid repeated strlen calls 305 RCW_t rc; // stuff that gets saved in the rcfile 306 char capclr_sum [CLRBUFSIZ], // terminfo strings built from 307 capclr_msg [CLRBUFSIZ], // above clrs (& rebuilt too), 308 capclr_pmt [CLRBUFSIZ], // but NO recurring costs !!! 309 capclr_hdr [CLRBUFSIZ], // note: sum, msg and pmt strs 310 capclr_rowhigh [CLRBUFSIZ], // are only used when this 311 capclr_rownorm [CLRBUFSIZ]; // window is the 'Curwin'! 312 char cap_bold [CAPBUFSIZ]; // support for View_NOBOLD toggle 313 char grpname [GRPNAMSIZ], // window number:name, printable 314 columnhdr [SCREENMAX], // column headings for procflags 315 colusrnam [USRNAMSIZ]; // if selected by the 'u' command 316 } WIN_t; 317 /* ////////////////////////////////////////////////////////////// */ 318 319 320 /*###### Display Support *Data* ########################################*/ 321 322 /* Configuration files support */ 323 #define SYS_RCFILESPEC "/etc/toprc" 324 #define RCF_EYECATCHER "RCfile for " 325 #define RCF_DEPRECATED "Id:a, " 326 327 /* The default fields displayed and their order, 328 if nothing is specified by the loser, oops user */ 329 #define DEF_FIELDS "AEHIOQTWKNMbcdfgjplrsuvyzX" 330 /* Pre-configured field groupss */ 331 #define JOB_FIELDS "ABcefgjlrstuvyzMKNHIWOPQDX" 332 #define MEM_FIELDS "ANOPQRSTUVbcdefgjlmyzWHIKX" 333 #define USR_FIELDS "ABDECGfhijlopqrstuvyzMKNWX" 334 /* Used by fields_sort, placed here for peace-of-mind */ 335 #define NUL_FIELDS "abcdefghijklmnopqrstuvwxyz" 336 337 338 /* The default values for the local config file */ 339 #define DEF_RCFILE { \ 340 0, 1, DEF_DELAY, 0, { \ 341 { P_CPU, DEF_WINFLGS, 0, \ 342 COLOR_RED, COLOR_RED, COLOR_YELLOW, COLOR_RED, \ 343 "Def", DEF_FIELDS }, \ 344 { P_PID, DEF_WINFLGS, 0, \ 345 COLOR_CYAN, COLOR_CYAN, COLOR_WHITE, COLOR_CYAN, \ 346 "Job", JOB_FIELDS }, \ 347 { P_MEM, DEF_WINFLGS, 0, \ 348 COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLUE, COLOR_MAGENTA, \ 349 "Mem", MEM_FIELDS }, \ 350 { P_URE, DEF_WINFLGS, 0, \ 351 COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \ 352 "Usr", USR_FIELDS } \ 353 } } 354 355 /* These are the possible fscanf formats used in /proc/stat 356 reads during history processing. 357 ( 5th number only for Linux 2.5.41 and above ) */ 358 #define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu" 359 #ifdef PRETEND4CPUS 360 #define CPU_FMTS_MULTI CPU_FMTS_JUST1 361 #else 362 #define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu" 363 #endif 364 365 /* Summary Lines specially formatted string(s) -- 366 see 'show_special' for syntax details + other cautions. */ 367 #define LOADAV_line "%s -%s\n" 368 #define LOADAV_line_alt "%s\06 -%s\n" 369 #define STATES_line1 "Tasks:\03" \ 370 " %3u \02total,\03 %3u \02running,\03 %3u \02sleeping,\03 %3u \02stopped,\03 %3u \02zombie\03\n" 371 #define STATES_line2x4 "%s\03" \ 372 " %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n" 373 #define STATES_line2x5 "%s\03" \ 374 " %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle,\03 %#5.1f%% \02IO-wait\03\n" 375 #ifdef CASEUP_SUMMK 376 #define MEMORY_line1 "Mem: \03" \ 377 " %8uK \02total,\03 %8uK \02used,\03 %8uK \02free,\03 %8uK \02buffers\03\n" 378 #define MEMORY_line2 "Swap:\03" \ 379 " %8uK \02total,\03 %8uK \02used,\03 %8uK \02free,\03 %8uK \02cached\03\n" 380 #else 381 #define MEMORY_line1 "Mem: \03" \ 382 " %8uk \02total,\03 %8uk \02used,\03 %8uk \02free,\03 %8uk \02buffers\03\n" 383 #define MEMORY_line2 "Swap:\03" \ 384 " %8uk \02total,\03 %8uk \02used,\03 %8uk \02free,\03 %8uk \02cached\03\n" 385 #endif 386 387 /* Keyboard Help specially formatted string(s) -- 388 see 'show_special' for syntax details + other cautions. */ 389 #define KEYS_help \ 390 "Help for Interactive Commands\02 - %s\n" \ 391 "Window \01%s\06: \01Cumulative mode \03%s\02. \01System\06: \01Delay \03%.1f secs\02; \01Secure mode \03%s\02.\n" \ 392 "\n" \ 393 " Z\05,\01B\05 Global: '\01Z\02' change color mappings; '\01B\02' disable/enable bold\n" \ 394 " l,t,m Toggle Summaries: '\01l\02' load avg; '\01t\02' task/cpu stats; '\01m\02' mem info\n" \ 395 " 1,I Toggle SMP view: '\0011\02' single/separate states; '\01I\02' Irix/Solaris mode\n" \ 396 "\n" \ 397 " f,o . Fields/Columns: '\01f\02' add or remove; '\01o\02' change display order\n" \ 398 " F or O . Select sort field\n" \ 399 " <,> . Move sort field: '\01<\02' next col left; '\01>\02' next col right\n" \ 400 " R . Toggle normal/reverse sort\n" \ 401 " c,i,S . Toggle: '\01c\02' cmd name/line; '\01i\02' idle tasks; '\01S\02' cumulative time\n" \ 402 " x\05,\01y\05 . Toggle highlights: '\01x\02' sort field; '\01y\02' running tasks\n" \ 403 " z\05,\01b\05 . Toggle: '\01z\02' color/mono; '\01b\02' bold/reverse (only if 'x' or 'y')\n" \ 404 " u . Show specific user only\n" \ 405 " n or # . Set maximum tasks displayed\n" \ 406 "\n" \ 407 "%s" \ 408 " W Write configuration file\n" \ 409 " q Quit\n" \ 410 " ( commands shown with '.' require a \01visible\02 task display \01window\02 ) \n" \ 411 "Press '\01h\02' or '\01?\02' for help with \01Windows\02,\n" \ 412 "any other key to continue " \ 413 "" 414 415 /* This guy goes into the help text (maybe) */ 416 #define KEYS_help_unsecured \ 417 " k,r Manipulate tasks: '\01k\02' kill; '\01r\02' renice\n" \ 418 " d or s Set update interval\n" \ 419 "" 420 421 /* Fields Reorder/Toggle specially formatted string(s) -- 422 see 'show_special' for syntax details + other cautions 423 note: the leading newline below serves really dumb terminals; 424 if there's no 'cursor_home', the screen will be a mess 425 but this part will still be functional. */ 426 #define FIELDS_current \ 427 "\n%sCurrent Fields\02: \01 %s \04 for window \01%s\06\n%s " \ 428 "" 429 430 /* Some extra explanatory text which accompanies the Fields display. 431 note: the newlines cannot actually be used, they just serve as 432 substring delimiters for the 'display_fields' routine. */ 433 #define FIELDS_xtra \ 434 "Flags field:\n" \ 435 " 0x00000001 PF_ALIGNWARN\n" \ 436 " 0x00000002 PF_STARTING\n" \ 437 " 0x00000004 PF_EXITING\n" \ 438 " 0x00000040 PF_FORKNOEXEC\n" \ 439 " 0x00000100 PF_SUPERPRIV\n" \ 440 " 0x00000200 PF_DUMPCORE\n" \ 441 " 0x00000400 PF_SIGNALED\n" \ 442 " 0x00000800 PF_MEMALLOC\n" \ 443 " 0x00002000 PF_FREE_PAGES (2.5)\n" \ 444 " 0x00008000 debug flag (2.5)\n" \ 445 " 0x00024000 special threads (2.5)\n" \ 446 " 0x001D0000 special states (2.5)\n" \ 447 " 0x00100000 PF_USEDFPU (thru 2.4)\n" \ 448 "" 449 /* no room, sacrificed this one: 'Killed for out-of-memory' */ 450 /* " 0x00001000 PF_MEMDIE (2.5)\n" ....................... */ 451 452 /* Sort Select specially formatted string(s) -- 453 see 'show_special' for syntax details + other cautions 454 note: the leading newline below serves really dumb terminals; 455 if there's no 'cursor_home', the screen will be a mess 456 but this part will still be functional. */ 457 #define SORT_fields \ 458 "\n%sCurrent Sort Field\02: \01 %c \04 for window \01%s\06\n%s " \ 459 "" 460 461 /* Some extra explanatory text which accompanies the Sort display. 462 note: the newlines cannot actually be used, they just serve as 463 substring delimiters for the 'display_fields' routine. */ 464 #define SORT_xtra \ 465 "Note1:\n" \ 466 " If a selected sort field can't be\n" \ 467 " shown due to screen width or your\n" \ 468 " field order, the '<' and '>' keys\n" \ 469 " will be unavailable until a field\n" \ 470 " within viewable range is chosen.\n" \ 471 "\n" \ 472 "Note2:\n" \ 473 " Field sorting uses internal values,\n" \ 474 " not those in column display. Thus,\n" \ 475 " the TTY & WCHAN fields will violate\n" \ 476 " strict ASCII collating sequence.\n" \ 477 " (shame on you if WCHAN is chosen)\n" \ 478 "" 479 480 /* Colors Help specially formatted string(s) -- 481 see 'show_special' for syntax details + other cautions. */ 482 #define COLOR_help \ 483 "Help for color mapping\02 - %s\n" \ 484 "current window: \01%s\06\n" \ 485 "\n" \ 486 " color - 04:25:44 up 8 days, 50 min, 7 users, load average:\n" \ 487 " Tasks:\03 64 \02total,\03 2 \03running,\03 62 \02sleeping,\03 0 \02stopped,\03\n" \ 488 " Cpu(s):\03 76.5%% \02user,\03 11.2%% \02system,\03 0.0%% \02nice,\03 12.3%% \02idle\03\n" \ 489 " \01 Nasty Message! \04 -or- \01Input Prompt\05\n" \ 490 " \01 PID TTY PR NI %%CPU TIME+ VIRT SWAP STA Command \06\n" \ 491 " 17284 \10pts/2 \07 8 0 0.0 0:00.75 1380 0 S /bin/bash \10\n" \ 492 " \01 8601 pts/1 7 -10 0.4 0:00.03 916 0 R < color -b \07\n" \ 493 " 11005 \10? \07 9 0 0.0 0:02.50 2852 1008 S amor -ses \10\n" \ 494 " available toggles: \01B\02 =disable bold globally (\01%s\02),\n" \ 495 " \01z\02 =color/mono (\01%s\02), \01b\02 =tasks \"bold\"/reverse (\01%s\02)\n" \ 496 "\n" \ 497 "Select \01target\02 as upper case letter:\n" \ 498 " S\02 = Summary Data,\01 M\02 = Messages/Prompts,\n" \ 499 " H\02 = Column Heads,\01 T\02 = Task Information\n" \ 500 "Select \01color\02 as number:\n" \ 501 " 0\02 = black,\01 1\02 = red, \01 2\02 = green,\01 3\02 = yellow,\n" \ 502 " 4\02 = blue, \01 5\02 = magenta,\01 6\02 = cyan, \01 7\02 = white\n" \ 503 "\n" \ 504 "Selected: \01target\02 \01 %c \04; \01color\02 \01 %d \04\n" \ 505 " press 'q' to abort changes to window '\01%s\02'\n" \ 506 " press 'a' or 'w' to commit & change another, <Enter> to commit and end " \ 507 "" 508 509 /* Windows/Field Group Help specially formatted string(s) -- 510 see 'show_special' for syntax details + other cautions. */ 511 #define WINDOWS_help \ 512 "Help for Windows / Field Groups\02 - \"Current Window\" = \01 %s \06\n" \ 513 "\n" \ 514 ". Use multiple \01windows\02, each with separate config opts (color,fields,sort,etc)\n" \ 515 ". The 'current' window controls the \01Summary Area\02 and responds to your \01Commands\02\n" \ 516 " . that window's \01task display\02 can be turned \01Off\02 & \01On\02, growing/shrinking others\n" \ 517 " . with \01NO\02 task display, some commands will be \01disabled\02 ('i','R','n','c', etc)\n" \ 518 " until a \01different window\02 has been activated, making it the 'current' window\n" \ 519 ". You \01change\02 the 'current' window by: \01 1\02) cycling forward/backward;\01 2\02) choosing\n" \ 520 " a specific field group; or\01 3\02) exiting the color mapping screen\n" \ 521 ". Commands \01available anytime -------------\02\n" \ 522 " A . Alternate display mode toggle, show \01Single\02 / \01Multiple\02 windows\n" \ 523 " G . Choose another field group and make it 'current', or change now\n" \ 524 " by selecting a number from: \01 1\02 =%s;\01 2\02 =%s;\01 3\02 =%s; or\01 4\02 =%s\n" \ 525 ". Commands \01requiring\02 '\01A\02' mode\01 -------------\02\n" \ 526 " g . Change the \01Name\05 of the 'current' window/field group\n" \ 527 " \01*\04 a , w . Cycle through all four windows: '\01a\05' Forward; '\01w\05' Backward\n" \ 528 " \01*\04 - , _ . Show/Hide: '\01-\05' \01Current\02 window; '\01_\05' all \01Visible\02/\01Invisible\02\n" \ 529 " The screen will be divided evenly between task displays. But you can make\n" \ 530 " some \01larger\02 or \01smaller\02, using '\01n\02' and '\01i\02' commands. Then later you could:\n" \ 531 " \01*\04 = , + . Rebalance tasks: '\01=\05' \01Current\02 window; '\01+\05' \01Every\02 window\n" \ 532 " (this also forces the \01current\02 or \01every\02 window to become visible)\n" \ 533 "\n" \ 534 "In '\01A\02' mode, '\01*\04' keys are your \01essential\02 commands. Please try the '\01a\02' and '\01w\02'\n" \ 535 "commands plus the 'G' sub-commands NOW. Press <Enter> to make 'Current' " \ 536 "" 537 538 539 /*###### For Piece of mind #############################################*/ 540 541 /* just sanity check(s)... */ 542 #if USRNAMSIZ < GETBUFSIZ 543 # error "Jeeze, USRNAMSIZ Must NOT be less than GETBUFSIZ !" 544 #endif 545 546 547 /*###### Some Prototypes (ha!) #########################################*/ 548 549 /* These 'prototypes' are here for documentation purposes and in 550 * preparation for a soon-to-occur top.c bust-up! */ 551 /*------ Sort callbacks ------------------------------------------------*/ 552 /* for each possible field, in the form of: */ 553 /*atic int sort_P_XXX (const proc_t **P, const proc_t **Q); */ 554 /* additional specialized sort callback(s) */ 555 /*atic int sort_HST_t (const HST_t *P, const HST_t *Q); */ 556 /*------ Tiny useful routine(s) ----------------------------------------*/ 557 //atic int chin (int ech, char *buf, unsigned cnt); 558 //atic const char *fmtmk (const char *fmts, ...); 559 //atic inline char *scat (char *restrict dst, const char *restrict src); 560 //atic char *strim_0 (char *str); 561 //atic char *strim_1 (char *str); 562 //atic const char *tg2 (int x, int y); 563 /*------ Exit/Interrput routines ---------------------------------------*/ 564 //atic void bye_bye (int eno, const char *str); 565 //atic void end_pgm (int dont_care_sig); 566 //atic void std_err (const char *str); 567 //atic void suspend (int dont_care_sig); 568 /*------ Misc Color/Display support ------------------------------------*/ 569 //atic void capsmk (WIN_t *q); 570 //atic void msg_save (const char *fmts, ...); 571 //atic void show_msg (const char *str); 572 //atic void show_pmt (const char *str); 573 //atic void show_special (int interact, const char *glob); 574 /*------ Small Utility routines ----------------------------------------*/ 575 //atic char *ask4str (const char *prompt); 576 //atic float get_float (const char *prompt); 577 //atic int get_int (const char *prompt); 578 //atic const char *scale_num (unsigned num, const int width, const unsigned type); 579 //atic const char *scale_tics (TIC_t tics, const int width); 580 /*------ Library Alternatives ------------------------------------------*/ 581 //atic void *alloc_c (unsigned numb) MALLOC; 582 //atic void *alloc_r (void *q, unsigned numb) MALLOC; 583 //atic CPU_t *cpus_refresh (CPU_t *cpus); 584 //atic void prochlp (proc_t *this); 585 //atic proc_t **procs_refresh (proc_t **table, int flags); 586 /*------ Field Table/RCfile compatability support ----------------------*/ 587 /*atic FLD_t Fieldstab[] = { ... } */ 588 //atic int ft_cvt_char (const int fr, const int to, int c); 589 //atic inline int ft_get_char (const int fr, int i); 590 //atic int ft_get_idx (const int fr, int c); 591 //atic const FLD_t *ft_get_ptr (const int fr, int c); 592 //atic const FLD_t *ft_idx_to_ptr (const int i); 593 //atic int ft_ptr_to_idx (const FLD_t *p); 594 //atic void rc_bugless (const RCF_t *const rc); 595 //atic int rc_read_new (const char *const buf, RCF_t *rc); 596 //atic int rc_read_old (const char *const buf, RCF_t *rc); 597 //atic void rc_write_new (FILE *fp); 598 //atic void rc_write_old (FILE *fp); 599 //atic const char *rc_write_whatever (void); 600 /*------ Startup routines ----------------------------------------------*/ 601 //atic void before (char *me); 602 //atic void confighlp (char *fields); 603 //atic void configs_read (void); 604 //atic void parse_args (char **args); 605 //atic void whack_terminal (void); 606 /*------ Field Selection/Ordering routines -----------------------------*/ 607 //atic void display_fields (const char *fields, const char *xtra); 608 //atic void fields_reorder (void); 609 //atic void fields_sort (void); 610 //atic void fields_toggle (void); 611 /*------ Windows/Field Groups support ----------------------------------*/ 612 //atic void reframewins (void); 613 //atic void win_names (WIN_t *q, const char *name); 614 //atic void win_select (char ch); 615 //atic int win_warn (void); 616 //atic void winsclrhlp (WIN_t *q, int save); 617 //atic void wins_colors (void); 618 //atic void wins_reflag (int what, int flg); 619 //atic void wins_resize (int dont_care_sig); 620 //atic void windows_stage1 (void); 621 //atic void windows_stage2 (void); 622 /*------ Main Screen routines ------------------------------------------*/ 623 //atic void do_key (unsigned c); 624 //atic void summaryhlp (CPU_t *cpu, const char *pfx); 625 //atic proc_t **summary_show (void); 626 //atic void task_show (const WIN_t *q, const proc_t *p); 627 //atic void window_show (proc_t **ppt, WIN_t *q, int *lscr); 628 /*------ Entry point plus two ------------------------------------------*/ 629 //atic void framehlp (int wix, int max); 630 //atic void frame_make (void); 631 // int main (int dont_care_argc, char **argv); 632 633 #endif /* _Itop */ 634 635