top: add a flexible 'Inspect' capability

This commit introduces an extremely powerful, flexible
brand new capability.  Now, users can pause the normal
iterative display and inspect the contents of any file
or output from any script, command, or even pipelines.

It's invoked via the 'Y' interactive command which, in
turn, is supported with simple user supplied additions
as new entries in the top personal configuration file.

A separate new 'Inspect' window supports scrolling and
searching, similar to the main top display.  Except it
extends existing 'L'/'&' (locate/locate-next) commands
so that an out-of-view match automatically adjusts the
horizontal position bringing such data into view.  And
it provides for multiple successive same line matches.

Also, the basic 'more/less' navigation keys are active
in this new 'Inspect' window, to ease user transition.

There are no program changes required when entries are
added to or deleted from the rcfile.  And there are no
known limits to the complexity of a script, command or
pipeline, other than the unidirectional nature imposed
by the 'popen' function call which top cannot violate.

Since it's impossible to predict exactly what contents
will be generated, top treats all output as raw binary
data.  Any control characters display in '^C' notation
while all other unprintable characters show as '<AB>'.

The biggest problem encountered was with the find/next
capability since that strstr guy was really diminished
given the possibility that numerous 'strings' could be
encountered *within* many of top's raw, binary 'rows'.

Oh, and another problem was in maintaining the perfect
left & right text justification of this commit message
along with all of the commit summaries.  Some of those
summaries (like this very one) are of course, slightly
shorter, to make room for the 'man document' addition.

Enjoy!

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2012-11-25 00:00:05 -05:00
committed by Craig Small
parent 9e99c84c48
commit 081fe506f3
4 changed files with 668 additions and 18 deletions

View File

@ -32,6 +32,9 @@
//#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */
//#define CPU_ZEROTICS /* tolerate few tics when cpu off vs. idle */
//#define EQUCOLHDRYES /* yes, do equalize column header lengths */
//#define INSP_OFFDEMO /* disable demo screens, issue msg instead */
//#define INSP_SAVEBUF /* preserve 'Insp_buf' contents in a file */
//#define INSP_SLIDE_1 /* when scrolling left/right don't move 8 */
//#define OFF_HST_HASH /* use BOTH qsort+bsrch vs. hashing scheme */
//#define OFF_STDIOLBF /* disable our own stdout _IOFBF override */
//#define PERCENTBOOST /* enable extended precision for % fields */
@ -120,6 +123,8 @@ char *strcasestr(const char *haystack, const char *needle);
many termcap/color transitions - these definitions ensure we have room */
#define ROWMINSIZ ( SCREENMAX + 4 * (CAPBUFSIZ + CLRBUFSIZ) )
#define ROWMAXSIZ ( SCREENMAX + 16 * (CAPBUFSIZ + CLRBUFSIZ) )
// minimum size guarantee for dynamically acquired 'readfile' buffer
#define READMINSZ 2048
// space between task fields/columns
#define COLPADSTR " "
@ -598,12 +603,13 @@ typedef struct WIN_t {
//atic inline void show_scroll (void);
//atic void show_special (int interact, const char *glob);
//atic void updt_scroll_msg (void);
/*------ Low Level Memory/Keyboard support -----------------------------*/
/*------ Low Level Memory/Keyboard/File I/O support --------------------*/
//atic void *alloc_c (size_t num);
//atic void *alloc_r (void *ptr, size_t num);
//atic int chin (int ech, char *buf, unsigned cnt);
//atic int keyin (int init);
//atic char *linein (const char *prompt);
//atic int readfile (FILE *fp, char **baddr, unsigned *bsize, unsigned *bread);
/*------ Small Utility routines ----------------------------------------*/
//atic float get_float (const char *prompt);
//atic int get_int (const char *prompt);
@ -638,6 +644,17 @@ typedef struct WIN_t {
//atic void procs_hlp (proc_t *p);
//atic void procs_refresh (void);
//atic void sysinfo_refresh (int forced);
/*------ Inspect Other Output ------------------------------------------*/
//atic void insp_cnt_nl (void);
#ifndef INSP_OFFDEMO
//atic void insp_do_demo (char *fmts, int pid);
#endif
//atic void insp_do_file (char *fmts, int pid);
//atic void insp_do_pipe (char *fmts, int pid);
//atic void insp_find (int ch, int *col, int *row);
//atic inline void insp_show_pg (int col, int row, int max);
//atic int insp_view_this (char *hdr);
//atic void inspection_utility (int pid);
/*------ Startup routines ----------------------------------------------*/
//atic void before (char *me);
//atic int config_cvt (WIN_t *q);