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-20 00:00:00 -05:00 committed by Craig Small
parent 8398b7d9b0
commit 016f10cb93
2 changed files with 72 additions and 70 deletions

137
top/top.c
View File

@ -1317,74 +1317,6 @@ static inline const char *hex_make (long num, int noz) {
} // 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,
* and/or update the window's 'u/U' selection stuff. */
@ -3060,6 +2992,75 @@ signify_that:
#undef INSP_RLEN
#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 ##############################################*/
/*

View File

@ -579,8 +579,6 @@ typedef struct WIN_t {
//atic float get_float (const char *prompt);
//atic int get_int (const char *prompt);
//atic inline const char *hex_make (long 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);
/*------ Basic Formatting support --------------------------------------*/
//atic inline const char *justify_pad (const char *str, int width, int justr);
@ -619,6 +617,9 @@ typedef struct WIN_t {
//atic void insp_show_pgs (int col, int row, int max);
//atic int insp_view_choice (struct pids_stack *obj);
//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 ----------------------------------------------*/
//atic void before (char *me);
//atic int config_cvt (WIN_t *q);