top: minor refactor in preparation for other filtering

While it's only documented (so far) in commit text and
an occasional email I've tried to maintain some coding
standards primarily for reference/navigation purposes.
They also served, I felt, as useful mental challenges.

Someday I will get around to formerly documenting them
but in the meantime here are the ones for this commit:

. functions are grouped into logical (i hope) sections
. functions & sections are ordered to avoid prototypes
. function names are alphabetical within every section

Thus, given those constraints/objectives, and in order
to prepare for an upcoming Other_Filter feature, a few
things had to be renamed and rearranged. Plus a couple
of other (unrelated) tweaks were made for consistency.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 270e8e7eeb
http://www.freelists.org/post/procps/PATCH-12-top-restore-terminal-state-on-exit,4

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-03-03 00:00:00 -06:00 committed by Jaromir Capik
parent b9976f7056
commit 5e4bade595
3 changed files with 70 additions and 62 deletions

114
top/top.c
View File

@ -1335,7 +1335,7 @@ static const char *user_certify (WIN_t *q, const char *str, char typ) {
* Determine if this proc_t matches the 'u/U' selection criteria
* for a given window -- it's called from only one place, and
* likely inlined even without the directive */
static inline int user_matched (WIN_t *q, const proc_t *p) {
static inline int user_matched (const WIN_t *q, const proc_t *p) {
switch(q->usrseltyp) {
case 0: // uid selection inactive
return 1;
@ -3299,7 +3299,7 @@ static void configs_read (void) {
break;
}
#ifndef USE_X_COLHDR
OFFw(w, NOHICOL_xxx);
OFFw(w, NOHIFND_xxx);
#endif
} // end: for (GROUPSMAX)
@ -3886,56 +3886,12 @@ static void wins_stage_2 (void) {
#endif
} // end: wins_stage_2
/*###### Interactive Input support (do_key helpers) ####################*/
/*###### Interactive Input Tertiary support ############################*/
/*
* These routines exist just to keep the do_key() function
* a reasonably modest size. */
static void file_writerc (void) {
FILE *fp;
int i;
if (Rc_questions) {
show_pmt(N_txt(XTRA_warncfg_txt));
if ('y' != tolower(iokey(1)))
return;
Rc_questions = 0;
}
if (!(fp = fopen(Rc_name, "w"))) {
show_msg(fmtmk(N_fmt(FAIL_rc_open_fmt), Rc_name, strerror(errno)));
return;
}
fprintf(fp, "%s's " RCF_EYECATCHER, Myname);
fprintf(fp, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
, RCF_VERSION_ID
, Rc.mode_altscr, Rc.mode_irixps
// this may be ugly, but it keeps us locale independent...
, (int)Rc.delay_time, (int)((Rc.delay_time - (int)Rc.delay_time) * 1000)
, (int)(Curwin - Winstk));
for (i = 0 ; i < GROUPSMAX; i++) {
fprintf(fp, "%s\tfieldscur=%s\n"
, Winstk[i].rc.winname, Winstk[i].rc.fieldscur);
fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx
, Winstk[i].rc.maxtasks);
fprintf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, Winstk[i].rc.summclr, Winstk[i].rc.msgsclr
, Winstk[i].rc.headclr, Winstk[i].rc.taskclr);
}
// any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress);
if (Inspect.raw)
fputs(Inspect.raw, fp);
fclose(fp);
show_msg(fmtmk(N_fmt(WRITE_rcfile_fmt), Rc_name));
} // end: file_writerc
* This section exists so as to offer some function naming freedom
* while also maintaining the strict alphabetical order protocol
* within each section. */
/*
* This guy is a *Helper* function serving the following two masters:
@ -3972,8 +3928,8 @@ static void find_string (int ch) {
Curwin->findlen = strlen(Curwin->findstr);
found = 0;
#ifndef USE_X_COLHDR
if (Curwin->findstr[0]) SETw(Curwin, NOHICOL_xxx);
else OFFw(Curwin, NOHICOL_xxx);
if (Curwin->findstr[0]) SETw(Curwin, NOHIFND_xxx);
else OFFw(Curwin, NOHIFND_xxx);
#endif
}
if (Curwin->findstr[0]) {
@ -4039,6 +3995,56 @@ signify_that:
} // end: help_view
static void write_rcfile (void) {
FILE *fp;
int i;
if (Rc_questions) {
show_pmt(N_txt(XTRA_warncfg_txt));
if ('y' != tolower(iokey(1)))
return;
Rc_questions = 0;
}
if (!(fp = fopen(Rc_name, "w"))) {
show_msg(fmtmk(N_fmt(FAIL_rc_open_fmt), Rc_name, strerror(errno)));
return;
}
fprintf(fp, "%s's " RCF_EYECATCHER, Myname);
fprintf(fp, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
, RCF_VERSION_ID
, Rc.mode_altscr, Rc.mode_irixps
// this may be ugly, but it keeps us locale independent...
, (int)Rc.delay_time, (int)((Rc.delay_time - (int)Rc.delay_time) * 1000)
, (int)(Curwin - Winstk));
for (i = 0 ; i < GROUPSMAX; i++) {
fprintf(fp, "%s\tfieldscur=%s\n"
, Winstk[i].rc.winname, Winstk[i].rc.fieldscur);
fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx
, Winstk[i].rc.maxtasks);
fprintf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, Winstk[i].rc.summclr, Winstk[i].rc.msgsclr
, Winstk[i].rc.headclr, Winstk[i].rc.taskclr);
}
// any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress);
if (Inspect.raw)
fputs(Inspect.raw, fp);
fclose(fp);
show_msg(fmtmk(N_fmt(WRITE_rcfile_fmt), Rc_name));
} // end: write_rcfile
/*###### Interactive Input Secondary support (do_key helpers) ##########*/
/*
* These routines exist just to keep the do_key() function
* a reasonably modest size. */
static void keys_global (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
@ -4628,7 +4634,7 @@ static void do_key (int ch) {
case 'q': // no return from this guy
bye_bye(NULL);
case 'W': // no need for rebuilds
file_writerc();
write_rcfile();
return;
default: // and now, the real work...
for (i = 0; i < MAXTBL(key_tab); ++i)
@ -4846,7 +4852,7 @@ static const char *task_show (const WIN_t *q, const proc_t *p) {
case X_XON:
case X_XOF:
cp = NULL;
if (!CHKw(q, INFINDS_xxx | NOHICOL_xxx)) {
if (!CHKw(q, INFINDS_xxx | NOHIFND_xxx)) {
/* treat running tasks specially - entire row may get highlighted
so we needn't turn it on and we MUST NOT turn it off */
if (!('R' == p->state && CHKw(q, Show_HIROWS)))

View File

@ -307,7 +307,7 @@ typedef struct CPU_t {
#define INFINDS_xxx 0x010000 // build rows for find_string, not display
#define EQUWINS_xxx 0x000001 // rebalance all wins & tasks (off i,n,u/U)
#ifndef USE_X_COLHDR
#define NOHICOL_xxx 0x100000 // must restrict Show_HICOLS temporarily
#define NOHIFND_xxx 0x100000 // must restrict Show_HICOLS temporarily
#endif
// Default flags if there's no rcfile to provide user customizations
@ -656,7 +656,7 @@ typedef struct WIN_t {
//atic int get_int (const char *prompt);
//atic inline const char *hex_make (KLONG num, int noz);
//atic const char *user_certify (WIN_t *q, const char *str, char typ);
//atic inline int user_matched (WIN_t *q, const proc_t *p);
//atic inline int user_matched (const WIN_t *q, const proc_t *p);
/*------ Basic Formatting support --------------------------------------*/
//atic inline const char *justify_pad (const char *str, int width, int justr);
//atic inline const char *make_chr (const char ch, int width, int justr);
@ -715,11 +715,12 @@ typedef struct WIN_t {
//atic void wins_reflag (int what, int flg);
//atic void wins_stage_1 (void);
//atic void wins_stage_2 (void);
/*------ Interactive Input support (do_key helpers) --------------------*/
//atic void file_writerc (void);
/*------ Interactive Input Tertiary support ----------------------------*/
//atic inline int find_ofs (const WIN_t *q, const char *buf);
//atic void find_string (int ch);
//atic void help_view (void);
//atic void write_rcfile (void);
/*------ Interactive Input Secondary support (do_key helpers) ----------*/
//atic void keys_global (int ch);
//atic void keys_summary (int ch);
//atic void keys_task (int ch);

View File

@ -19,9 +19,6 @@
#include <locale.h>
#include <stdio.h>
#ifdef VALIDATE_NLS
#include <stdlib.h>
#endif
#include <string.h>
#include "../include/nls.h"
@ -29,6 +26,10 @@
#include "top.h"
#include "top_nls.h"
#ifdef VALIDATE_NLS
#include <stdlib.h>
#endif
// Programmer Note(s):
// Preparation ---------------------------------------------
// Unless you have *something* following the gettext macro,