top: even more miscellaneous accumulated modifications

This commit just addresses the following minor issues:

. eliminate the leading tab character upon error exits
. standardized single key input as 'keyin', not 'chin'
. symbolic keys changed to guarantee no negative value
. placed most 'case' statement labels on a unique line
. standardized lvalue/rvalue convention in while loops
. fixed prototype declaration in the 'debug_END' macro

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-01-11 00:00:00 -06:00 committed by Craig Small
parent 7060f9ab3a
commit 5856919e83
2 changed files with 60 additions and 48 deletions

@ -503,10 +503,10 @@ static void error_exit (const char *str) NORETURN;
static void error_exit (const char *str) { static void error_exit (const char *str) {
static char buf[MEDBUFSIZ]; static char buf[MEDBUFSIZ];
/* we'll use our own buffer so callers can still use fmtmk() and, yes the /* we'll use our own buffer so callers can still use fmtmk() and, after
leading tab is not the standard convention, but the standard is wrong twelve long years, 2013 was the year we finally eliminated the leading
-- OUR msg won't get lost in screen clutter, like so many others! */ tab character -- now our message can get lost in screen clutter too! */
snprintf(buf, sizeof(buf), "\t%s: %s\n", Myname, str); snprintf(buf, sizeof(buf), "%s: %s\n", Myname, str);
bye_bye(buf); bye_bye(buf);
} // end: error_exit } // end: error_exit
@ -1062,7 +1062,8 @@ static char *linein (const char *prompt) {
} }
putp(fmtmk("%s%s%s", tg2(beg, Msg_row), Cap_clr_eol, buf)); putp(fmtmk("%s%s%s", tg2(beg, Msg_row), Cap_clr_eol, buf));
putp(tg2(beg+pos, Msg_row)); putp(tg2(beg+pos, Msg_row));
} while (key && kbd_ENTER != key && kbd_ESC != key); fflush(stdout);
} while (key && key != kbd_ENTER && key != kbd_ESC);
return buf; return buf;
#undef sqzSTR #undef sqzSTR
@ -1941,7 +1942,7 @@ static void fields_utility (void) {
default: // keep gcc happy default: // keep gcc happy
break; break;
} }
} while (key && 'q' != key && kbd_ESC != key); } while (key && key != 'q' && key != kbd_ESC);
#undef unSCRL #undef unSCRL
#undef swapEM #undef swapEM
#undef spewFI #undef spewFI
@ -2750,10 +2751,13 @@ static int insp_view_choice (proc_t *obj) {
lest repeated <Enter> keys produce immediate re-selection in caller */ lest repeated <Enter> keys produce immediate re-selection in caller */
tcflush(STDIN_FILENO, TCIFLUSH); tcflush(STDIN_FILENO, TCIFLUSH);
switch (key = keyin(0)) { key = keyin(0);
switch (key) {
case kbd_ENTER: // must force new keyin() case kbd_ENTER: // must force new keyin()
key = -1; // fall through ! key = -1; // fall through !
case kbd_ESC: case 'q': case 0: case kbd_ESC:
case 'q':
case 0:
putp(Cap_clr_scr); putp(Cap_clr_scr);
return key; return key;
case kbd_LEFT: case kbd_LEFT:
@ -2768,20 +2772,27 @@ static int insp_view_choice (proc_t *obj) {
case kbd_DOWN: case kbd_DOWN:
++curlin; ++curlin;
break; break;
case kbd_PGUP: case 'b': case kbd_PGUP:
case 'b':
curlin -= maxLN -1; // keep 1 line for reference curlin -= maxLN -1; // keep 1 line for reference
break; break;
case kbd_PGDN: case kbd_SPACE: case kbd_PGDN:
case kbd_SPACE:
curlin += maxLN -1; // ditto curlin += maxLN -1; // ditto
break; break;
case kbd_HOME: case 'g': case kbd_HOME:
case 'g':
curcol = curlin = 0; curcol = curlin = 0;
break; break;
case kbd_END: case 'G': case kbd_END:
case 'G':
curcol = 0; curcol = 0;
curlin = Insp_nl - maxLN; curlin = Insp_nl - maxLN;
break; break;
case 'L': case '&': case '/': case 'n': case 'L':
case '&':
case '/':
case 'n':
putp(Cap_curs_norm); putp(Cap_curs_norm);
insp_find_str(key, &curcol, &curlin); insp_find_str(key, &curcol, &curlin);
break; break;
@ -2870,7 +2881,7 @@ static void inspection_utility (int pid) {
key = -1; key = -1;
break; break;
} }
} while (key && 'q' != key && kbd_ESC != key); } while (key && key != 'q' && key != kbd_ESC);
#undef mkSEL #undef mkSEL
} // end: inspection_utility } // end: inspection_utility
@ -3453,14 +3464,14 @@ static void win_names (WIN_t *q, const char *name) {
/* /*
* Display a window/field group (ie. make it "current"). */ * Display a window/field group (ie. make it "current"). */
static WIN_t *win_select (char ch) { static WIN_t *win_select (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy WIN_t *w = Curwin; // avoid gcc bloat with a local copy
/* if there's no ch, it means we're supporting the external interface, /* if there's no ch, it means we're supporting the external interface,
so we must try to get our own darn ch by begging the user... */ so we must try to get our own darn ch by begging the user... */
if (!ch) { if (!ch) {
show_pmt(N_txt(CHOOSE_group_txt)); show_pmt(N_txt(CHOOSE_group_txt));
if (1 > chin(0, (char *)&ch, 1)) return w; if (1 > (ch = keyin(0))) return w;
} }
switch (ch) { switch (ch) {
case 'a': // we don't carry 'a' / 'w' in our case 'a': // we don't carry 'a' / 'w' in our
@ -3523,7 +3534,8 @@ static void wins_colors (void) {
#define kbdAPPLY kbd_ENTER #define kbdAPPLY kbd_ENTER
WIN_t *w = Curwin; // avoid gcc bloat with a local copy WIN_t *w = Curwin; // avoid gcc bloat with a local copy
int clr = w->rc.taskclr, *pclr = &w->rc.taskclr; int clr = w->rc.taskclr, *pclr = &w->rc.taskclr;
char ch, tgt = 'T'; char tgt = 'T';
int key;
if (0 >= max_colors) { if (0 >= max_colors) {
show_msg(N_txt(COLORS_nomap_txt)); show_msg(N_txt(COLORS_nomap_txt));
@ -3542,31 +3554,32 @@ static void wins_colors (void) {
, CHKw(w, Show_COLORS) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt) , CHKw(w, Show_COLORS) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, CHKw(w, Show_HIBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt) , CHKw(w, Show_HIBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, tgt, clr, w->grpname)); , tgt, clr, w->grpname));
if (1 > chin(0, &ch, 1)) break;
switch (ch) { key = keyin(0);
switch (key) {
case 'S': case 'S':
pclr = &w->rc.summclr; pclr = &w->rc.summclr;
clr = *pclr; clr = *pclr;
tgt = ch; tgt = key;
break; break;
case 'M': case 'M':
pclr = &w->rc.msgsclr; pclr = &w->rc.msgsclr;
clr = *pclr; clr = *pclr;
tgt = ch; tgt = key;
break; break;
case 'H': case 'H':
pclr = &w->rc.headclr; pclr = &w->rc.headclr;
clr = *pclr; clr = *pclr;
tgt = ch; tgt = key;
break; break;
case 'T': case 'T':
pclr = &w->rc.taskclr; pclr = &w->rc.taskclr;
clr = *pclr; clr = *pclr;
tgt = ch; tgt = key;
break; break;
case '0': case '1': case '2': case '3': case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7': case '4': case '5': case '6': case '7':
clr = ch - '0'; clr = key - '0';
*pclr = clr; *pclr = clr;
break; break;
case 'B': case 'B':
@ -3580,7 +3593,7 @@ static void wins_colors (void) {
break; break;
case 'a': case 'a':
case 'w': case 'w':
wins_clrhlp((w = win_select(ch)), 1); wins_clrhlp((w = win_select(key)), 1);
clr = w->rc.taskclr, pclr = &w->rc.taskclr; clr = w->rc.taskclr, pclr = &w->rc.taskclr;
tgt = 'T'; tgt = 'T';
break; break;
@ -3588,9 +3601,10 @@ static void wins_colors (void) {
break; break;
} }
capsmk(w); capsmk(w);
} while (kbdAPPLY != ch && kbdABORT != ch); } while (key && key != kbdAPPLY && key != kbdABORT);
if (key == kbdABORT) wins_clrhlp(w, 0);
if (kbdABORT == ch) wins_clrhlp(w, 0);
putp(Cap_curs_norm); putp(Cap_curs_norm);
#undef kbdABORT #undef kbdABORT
#undef kbdAPPLY #undef kbdAPPLY
@ -3793,7 +3807,7 @@ static void find_string (int ch) {
static void help_view (void) { static void help_view (void) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy WIN_t *w = Curwin; // avoid gcc bloat with a local copy
char ch; int ch;
putp(Cap_clr_scr); putp(Cap_clr_scr);
putp(Cap_curs_huge); putp(Cap_curs_huge);
@ -3806,17 +3820,16 @@ static void help_view (void) {
, Secure_mode ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt) , Secure_mode ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, Secure_mode ? "" : N_unq(KEYS_helpext_fmt))); , Secure_mode ? "" : N_unq(KEYS_helpext_fmt)));
if (0 < chin(0, &ch, 1) ch = keyin(0);
&& ('?' == ch || 'h' == ch || 'H' == ch)) { if (ch == '?' || ch == 'h' || ch == 'H') {
do { do {
putp(Cap_clr_scr); putp(Cap_clr_scr);
show_special(1, fmtmk(N_unq(WINDOWS_help_fmt) show_special(1, fmtmk(N_unq(WINDOWS_help_fmt)
, w->grpname , w->grpname
, Winstk[0].rc.winname, Winstk[1].rc.winname , Winstk[0].rc.winname, Winstk[1].rc.winname
, Winstk[2].rc.winname, Winstk[3].rc.winname)); , Winstk[2].rc.winname, Winstk[3].rc.winname));
if (1 > chin(0, &ch, 1)) break; if (0 < (ch = keyin(0))) w = win_select(ch);
w = win_select(ch); } while (ch && ch != kbd_ENTER && ch != kbd_ESC);
} while (kbd_ENTER != ch && kbd_ESC != ch);
} }
putp(Cap_curs_norm); putp(Cap_curs_norm);
@ -3824,7 +3837,6 @@ static void help_view (void) {
static void keys_global (int ch) { static void keys_global (int ch) {
// standardized error message(s)
WIN_t *w = Curwin; // avoid gcc bloat with a local copy WIN_t *w = Curwin; // avoid gcc bloat with a local copy
switch (ch) { switch (ch) {

@ -137,20 +137,20 @@ char *strcasestr(const char *haystack, const char *needle);
#define COLPLUSCH '+' #define COLPLUSCH '+'
// support for keyboard stuff (cursor motion keystrokes, mostly) // support for keyboard stuff (cursor motion keystrokes, mostly)
#define kbd_ENTER '\n'
#define kbd_ESC '\033' #define kbd_ESC '\033'
#define kbd_SPACE ' ' #define kbd_SPACE ' '
#define kbd_UP '\x81' #define kbd_UP 0x01
#define kbd_DOWN '\x82' #define kbd_DOWN 0x02
#define kbd_RIGHT '\x83' #define kbd_RIGHT 0x03
#define kbd_LEFT '\x84' #define kbd_LEFT 0x04
#define kbd_PGUP '\x85' #define kbd_PGUP 0x05
#define kbd_PGDN '\x86' #define kbd_PGDN 0x06
#define kbd_END '\x87' #define kbd_END 0x07
#define kbd_HOME '\x88' #define kbd_HOME 0x08
#define kbd_BKSP '\x89' #define kbd_BKSP 0x09
#define kbd_INS '\x8a' #define kbd_ENTER 0x0a // this is also the real ^J
#define kbd_DEL '\x8b' #define kbd_INS 0x0b
#define kbd_DEL 0x0c
/* Special value in Pseudo_row to force an additional procs refresh /* Special value in Pseudo_row to force an additional procs refresh
-- used at startup and for task/thread mode transitions */ -- used at startup and for task/thread mode transitions */
@ -518,7 +518,7 @@ typedef struct WIN_t {
/* Orderly end, with any sort of message - see fmtmk */ /* Orderly end, with any sort of message - see fmtmk */
#define debug_END(s) { \ #define debug_END(s) { \
static void error_exit (const char *); \ void error_exit (const char *); \
fputs(Cap_clr_scr, stdout); \ fputs(Cap_clr_scr, stdout); \
error_exit(s); \ error_exit(s); \
} }
@ -686,7 +686,7 @@ typedef struct WIN_t {
//atic void whack_terminal (void); //atic void whack_terminal (void);
/*------ Windows/Field Groups support ----------------------------------*/ /*------ Windows/Field Groups support ----------------------------------*/
//atic void win_names (WIN_t *q, const char *name); //atic void win_names (WIN_t *q, const char *name);
//atic WIN_t *win_select (char ch); //atic WIN_t *win_select (int ch);
//atic int win_warn (int what); //atic int win_warn (int what);
//atic void wins_clrhlp (WIN_t *q, int save); //atic void wins_clrhlp (WIN_t *q, int save);
//atic void wins_colors (void); //atic void wins_colors (void);