top: reposition some of that 'other filtering' support

When we get around to saving that 'Other Filter' stuff
in the rcfile, we'll need access to the Fieldstab plus
the justify_pad() function. So this commit repositions
two 'osel' functions in anticipation of adding 1 more.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-06-17 00:00:00 -05:00 committed by Craig Small
parent 2b7779fdeb
commit 1fe5a5415f
2 changed files with 72 additions and 70 deletions

137
top/top.c
View File

@ -1496,74 +1496,6 @@ static inline const char *hex_make (KLONG num, int noz) {
} // end: hex_make } // end: hex_make
/*
* This sructure is hung from a WIN_t when other filtering is active */
struct osel_s {
struct osel_s *nxt; // the next criteria or NULL.
int (*rel)(const char *, const char *); // relational strings compare
char *(*sel)(const char *, const char *); // for selection str compares
char *raw; // raw user input (dup check)
char *val; // value included or excluded
int ops; // filter delimiter/operation
int inc; // include == 1, exclude == 0
int enu; // field (procflag) to filter
};
/*
* A function to turn off entire other filtering in the given window */
static void osel_clear (WIN_t *q) {
struct osel_s *osel = q->osel_1st;
while (osel) {
struct osel_s *nxt = osel->nxt;
free(osel->val);
free(osel->raw);
free(osel);
osel = nxt;
}
q->osel_tot = 0;
q->osel_1st = NULL;
free (q->osel_prt);
q->osel_prt = NULL;
#ifndef USE_X_COLHDR
OFFw(Curwin, NOHISEL_xxx);
#endif
} // end: osel_clear
/*
* Determine if there are matching values or relationships among the
* other criteria in this passed window -- it's called from only one
* place, and likely inlined even without the directive */
static inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str) {
struct osel_s *osel = q->osel_1st;
while (osel) {
if (osel->enu == enu) {
int r;
switch (osel->ops) {
case '<': // '<' needs the r < 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r >= 0 && osel->inc) || (r < 0 && !osel->inc)) return 0;
break;
case '>': // '>' needs the r > 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r <= 0 && osel->inc) || (r > 0 && !osel->inc)) return 0;
break;
default:
{ char *p = osel->sel(str, osel->val);
if ((!p && osel->inc) || (p && !osel->inc)) return 0;
}
break;
}
}
osel = osel->nxt;
}
return 1;
} // end: osel_matched
/* /*
* Validate the passed string as a user name or number, * Validate the passed string as a user name or number,
* and/or update the window's 'u/U' selection stuff. */ * and/or update the window's 'u/U' selection stuff. */
@ -3537,6 +3469,75 @@ signify_that:
#undef INSP_RLEN #undef INSP_RLEN
#undef INSP_BUSY #undef INSP_BUSY
/*###### Other Filtering ###############################################*/
/*
* This sructure is hung from a WIN_t when other filtering is active */
struct osel_s {
struct osel_s *nxt; // the next criteria or NULL.
int (*rel)(const char *, const char *); // relational strings compare
char *(*sel)(const char *, const char *); // for selection str compares
char *raw; // raw user input (dup check)
char *val; // value included or excluded
int ops; // filter delimiter/operation
int inc; // include == 1, exclude == 0
int enu; // field (procflag) to filter
};
/*
* A function to turn off entire other filtering in the given window */
static void osel_clear (WIN_t *q) {
struct osel_s *osel = q->osel_1st;
while (osel) {
struct osel_s *nxt = osel->nxt;
free(osel->val);
free(osel->raw);
free(osel);
osel = nxt;
}
q->osel_tot = 0;
q->osel_1st = NULL;
free (q->osel_prt);
q->osel_prt = NULL;
#ifndef USE_X_COLHDR
OFFw(Curwin, NOHISEL_xxx);
#endif
} // end: osel_clear
/*
* Determine if there are matching values or relationships among the
* other criteria in this passed window -- it's called from only one
* place, and likely inlined even without the directive */
static inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str) {
struct osel_s *osel = q->osel_1st;
while (osel) {
if (osel->enu == enu) {
int r;
switch (osel->ops) {
case '<': // '<' needs the r < 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r >= 0 && osel->inc) || (r < 0 && !osel->inc)) return 0;
break;
case '>': // '>' needs the r > 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r <= 0 && osel->inc) || (r > 0 && !osel->inc)) return 0;
break;
default:
{ char *p = osel->sel(str, osel->val);
if ((!p && osel->inc) || (p && !osel->inc)) return 0;
}
break;
}
}
osel = osel->nxt;
}
return 1;
} // end: osel_matched
/*###### Startup routines ##############################################*/ /*###### Startup routines ##############################################*/
/* /*

View File

@ -710,8 +710,6 @@ typedef struct WIN_t {
//atic float get_float (const char *prompt); //atic float get_float (const char *prompt);
//atic int get_int (const char *prompt); //atic int get_int (const char *prompt);
//atic inline const char *hex_make (KLONG num, int noz); //atic inline const char *hex_make (KLONG num, int noz);
//atic void osel_clear (WIN_t *q);
//atic inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str);
//atic const char *user_certify (WIN_t *q, const char *str, char typ); //atic const char *user_certify (WIN_t *q, const char *str, char typ);
//atic inline int user_matched (const WIN_t *q, const proc_t *p); //atic inline int user_matched (const WIN_t *q, const proc_t *p);
/*------ Basic Formatting support --------------------------------------*/ /*------ Basic Formatting support --------------------------------------*/
@ -758,6 +756,9 @@ typedef struct WIN_t {
//atic void insp_show_pgs (int col, int row, int max); //atic void insp_show_pgs (int col, int row, int max);
//atic int insp_view_choice (proc_t *obj); //atic int insp_view_choice (proc_t *obj);
//atic void inspection_utility (int pid); //atic void inspection_utility (int pid);
/*------ Other Filtering ------------------------------------------------*/
//atic void osel_clear (WIN_t *q);
//atic inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str);
/*------ Startup routines ----------------------------------------------*/ /*------ Startup routines ----------------------------------------------*/
//atic void before (char *me); //atic void before (char *me);
//atic int config_cvt (WIN_t *q); //atic int config_cvt (WIN_t *q);