rename a few variables and make a few cosmetic cleanups

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1699 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2004-03-19 21:46:34 +00:00
parent 7947544460
commit 1576d537a6
7 changed files with 80 additions and 68 deletions

View File

@ -42,6 +42,8 @@ CVS code -
- Remove the last editbot references, to avoid any potential
segfaults related to them. Also remove fix_editbot(), as it's
no longer needed. (David Benbennick)
- Rename several variables to make their use clearer and to
avoid conflicts. (DLR)
- files.c:
do_insertfile()
- Wrap one reference to NANO_EXTCMD_KEY in a NANO_SMALL #ifdef.
@ -219,6 +221,9 @@ CVS code -
get_escape_seq_abcd()
- A resurrected version of the old abcd() function, readded in
order to simplify get_escape_seq_kbinput(). (DLR)
get_mouse_kbinput()
- Interpret shortcut key values slightly more stringently when
ungetch()ing them. (DLR)
get_page_start()
- For consistency, tweak so that scrolling always occurs when we
try to move onto the "$" at the end of the line, as opposed to

View File

@ -2567,7 +2567,7 @@ char *do_browser(const char *inpath)
struct stat st;
char *foo, *retval = NULL;
static char *path = NULL;
int numents = 0, i = 0, j = 0, kbinput = -1, meta, longest = 0;
int numents = 0, i = 0, j = 0, kbinput = ERR, meta_key, longest = 0;
int abort = 0, col = 0, selected = 0, editline = 0, width = 0;
int filecols = 0, lineno = 0;
char **filelist = (char **)NULL;
@ -2881,7 +2881,7 @@ char *do_browser(const char *inpath)
}
}
wrefresh(edit);
} while ((kbinput = get_kbinput(edit, &meta)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
} while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
curs_set(1);
blank_edit();
titlebar(NULL);

View File

@ -171,11 +171,12 @@ int length_of_list(const shortcut *s)
}
/* Initialize a struct *without* our lovely braces =( */
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
void sc_init_one(shortcut **shortcutage, int ctrlval, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int meta, int func_key, int misc, int view, int (*func) (void))
int metaval, int funcval, int miscval, int view, int
(*func)(void))
{
shortcut *s;
@ -189,14 +190,14 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc,
s = s->next;
}
s->val = key;
s->ctrlval = ctrlval;
s->desc = desc;
#ifndef DISABLE_HELP
s->help = help;
#endif
s->metaval = meta;
s->func_key = func_key;
s->misc = misc;
s->metaval = metaval;
s->funcval = funcval;
s->miscval = miscval;
s->viewok = view;
s->func = func;
s->next = NULL;
@ -741,7 +742,7 @@ void shortcut_init(int unjustify)
NANO_NO_KEY, VIEW, do_last_line);
#ifndef NANO_SMALL
sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, _("History"),
sc_init_one(&replace_list_2, NANO_HISTORY_KEY, _("History"),
IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY,
NANO_NO_KEY, VIEW, 0);
#endif

View File

@ -262,10 +262,10 @@ void help_init(void)
{
size_t allocsize = 1; /* space needed for help_text */
char *ptr = NULL;
const shortcut *s;
#ifndef NANO_SMALL
const toggle *t;
#endif
const shortcut *s;
/* First set up the initial help text for the current function */
if (currshortcut == whereis_list || currshortcut == replace_list
@ -405,18 +405,18 @@ void help_init(void)
/* true if the character in s->metaval is shown in first column */
int meta_shortcut = 0;
if (s->val != NANO_NO_KEY) {
if (s->ctrlval != NANO_NO_KEY) {
#ifndef NANO_SMALL
if (s->val == NANO_HISTORY_KEY)
if (s->ctrlval == NANO_HISTORY_KEY)
ptr += sprintf(ptr, "%.2s", _("Up"));
else
#endif
if (s->val == NANO_CONTROL_SPACE)
if (s->ctrlval == NANO_CONTROL_SPACE)
ptr += sprintf(ptr, "^%.5s", _("Space"));
else if (s->val == NANO_CONTROL_8)
else if (s->ctrlval == NANO_CONTROL_8)
ptr += sprintf(ptr, "^?");
else
ptr += sprintf(ptr, "^%c", s->val + 64);
ptr += sprintf(ptr, "^%c", s->ctrlval + 64);
}
#ifndef NANO_SMALL
else if (s->metaval != NANO_NO_KEY) {
@ -430,15 +430,15 @@ void help_init(void)
*(ptr++) = '\t';
if (s->func_key != NANO_NO_KEY)
ptr += sprintf(ptr, "(F%d)", s->func_key - KEY_F0);
if (s->funcval != NANO_NO_KEY)
ptr += sprintf(ptr, "(F%d)", s->funcval - KEY_F0);
*(ptr++) = '\t';
if (!meta_shortcut && s->metaval != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->metaval));
else if (meta_shortcut && s->misc != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->misc));
else if (meta_shortcut && s->miscval != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->miscval));
*(ptr++) = '\t';
@ -448,12 +448,13 @@ void help_init(void)
#ifndef NANO_SMALL
/* And the toggles... */
if (currshortcut == main_list)
if (currshortcut == main_list) {
for (t = toggles; t != NULL; t = t->next) {
assert(t->desc != NULL);
ptr += sprintf(ptr, "M-%c\t\t\t%s %s\n", toupper(t->val), t->desc,
_("enable/disable"));
}
}
#endif /* !NANO_SMALL */
/* If all went well, we didn't overwrite the allocated space for
@ -2641,8 +2642,8 @@ int do_justify(void)
* keystroke and return. */
{
int meta;
i = get_kbinput(edit, &meta);
int meta_key;
i = get_kbinput(edit, &meta_key);
#ifndef DISABLE_MOUSE
/* If it was a mouse click, parse it with do_mouse() and it
* might become the unjustify key. Else give it back to the
@ -2651,7 +2652,7 @@ int do_justify(void)
do_mouse();
else
ungetch(i);
i = get_kbinput(edit, &meta);
i = get_kbinput(edit, &meta_key);
#endif
}
@ -3030,7 +3031,7 @@ int main(int argc, char *argv[])
const shortcut *s;
int keyhandled = 0; /* Have we handled the keystroke yet? */
int kbinput; /* Input from keyboard */
int meta;
int meta_key;
#ifndef NANO_SMALL
const toggle *t;
@ -3518,15 +3519,15 @@ int main(int argc, char *argv[])
currshortcut = main_list;
#endif
kbinput = get_kbinput(edit, &meta);
kbinput = get_kbinput(edit, &meta_key);
#ifdef DEBUG
fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput);
#endif
if (meta == 1) {
/* Check for the metaval and misc defs... */
if (meta_key == 1) {
/* Check for the metaval and miscval defs... */
for (s = main_list; s != NULL; s = s->next)
if ((s->metaval != NANO_NO_KEY && kbinput == s->metaval) ||
(s->misc != NANO_NO_KEY && kbinput == s->misc)) {
(s->miscval != NANO_NO_KEY && kbinput == s->miscval)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else {
@ -3561,8 +3562,8 @@ int main(int argc, char *argv[])
#else
for (s = main_list; s != NULL && !keyhandled; s = s->next) {
#endif
if ((s->val != NANO_NO_KEY && kbinput == s->val) ||
(s->func_key != NANO_NO_KEY && kbinput == s->func_key)) {
if ((s->ctrlval != NANO_NO_KEY && kbinput == s->ctrlval) ||
(s->funcval != NANO_NO_KEY && kbinput == s->funcval)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else {

View File

@ -187,11 +187,11 @@ typedef struct openfilestruct {
typedef struct shortcut {
/* Key values that aren't used should be set to NANO_NO_KEY. */
int val; /* Special sentinel key or control key we want
int ctrlval; /* Special sentinel key or control key we want
* bound. */
int metaval; /* Meta key we want bound. */
int func_key; /* Function key we want bound. */
int misc; /* Other Meta key we want bound. */
int metaval; /* Meta key we want bound. */
int funcval; /* Function key we want bound. */
int miscval; /* Other Meta key we want bound. */
int viewok; /* Is this function legal in view mode? */
int (*func) (void); /* Function to call when we catch this key. */
const char *desc; /* Description, e.g. "Page Up". */

View File

@ -218,7 +218,8 @@ void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int meta, int func_key, int misc, int view, int (*func) (void));
int metaval, int funcval, int miscval, int view, int
(*func)(void));
#ifndef NANO_SMALL
void toggle_init_one(int val, const char *desc, int flag);
void toggle_init(void);
@ -450,11 +451,11 @@ int check_wildcard_match(const char *text, const char *pattern);
#endif
/* Public functions in winio.c */
int get_kbinput(WINDOW *win, int *meta);
int get_kbinput(WINDOW *win, int *meta_key);
int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
allow_ascii);
int get_ignored_kbinput(WINDOW *win);
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta);
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta_key);
int get_ascii_kbinput(WINDOW *win, int kbinput);
int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, int
escape_seq_len);

View File

@ -44,7 +44,7 @@ static int statblank = 0; /* Number of keystrokes left after
* consist of [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter,
* Backspace, Insert, Delete, Home, End, PageUp, PageDown, and F1-F14.
* Assume nodelay(win) is FALSE. */
int get_kbinput(WINDOW *win, int *meta)
int get_kbinput(WINDOW *win, int *meta_key)
{
int kbinput, retval;
@ -53,7 +53,7 @@ int get_kbinput(WINDOW *win, int *meta)
#endif
kbinput = get_ignored_kbinput(win);
retval = get_accepted_kbinput(win, kbinput, meta);
retval = get_accepted_kbinput(win, kbinput, meta_key);
#ifndef NANO_SMALL
allow_pending_sigwinch(FALSE);
@ -151,11 +151,11 @@ int get_ignored_kbinput(WINDOW *win)
}
/* Translate acceptable ASCII, extended keypad values, and/or escape
* sequences. Set meta to 1 if we get a Meta sequence. Assume
* sequences. Set meta_key to 1 if we get a Meta sequence. Assume
* nodelay(win) is FALSE. */
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta_key)
{
*meta = 0;
*meta_key = FALSE;
switch (kbinput) {
case NANO_CONTROL_3: /* Escape */
@ -199,7 +199,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
switch (kbinput) {
case ERR:
kbinput = tolower(old_kbinput);
*meta = 1;
*meta_key = TRUE;
break;
default:
ungetch(kbinput);
@ -214,7 +214,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
default:
/* Esc [character] == Meta-[character] */
kbinput = tolower(kbinput);
*meta = 1;
*meta_key = TRUE;
}
break;
case NANO_CONTROL_8:
@ -272,7 +272,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
break;
}
#ifdef DEBUG
fprintf(stderr, "get_accepted_kbinput(): kbinput = %d, meta = %d\n", kbinput, *meta);
fprintf(stderr, "get_accepted_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, *meta_key);
#endif
return kbinput;
}
@ -833,13 +833,16 @@ int get_mouseinput(int *mouse_x, int *mouse_y, int allow_shortcuts)
for (; j > 0; j--)
s = s->next;
/* And ungetch() the equivalent keystroke. */
ungetch(s->val);
/* If it's not a control character, assume it's a Meta key
* sequence, in which case we need to ungetch() Escape too. */
if (!is_cntrl_char(s->val))
ungetch(NANO_CONTROL_3);
/* And ungetch() the equivalent control key. If it's a Meta key
* sequence, we need to ungetch() Escape too. Assume that the
* shortcut has an equivalent control key, meta key sequence, or
* both. */
if (s->ctrlval != NANO_NO_KEY)
ungetch(s->ctrlval);
else {
ungetch(s->metaval);
ungetch(NANO_CONTROL_3);
}
return 1;
}
@ -1078,7 +1081,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
)
{
int kbinput;
int meta;
int meta_key;
static int x = -1;
/* the cursor position in 'answer' */
int xend;
@ -1129,16 +1132,17 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
input */
wrefresh(edit);
while ((kbinput = get_kbinput(bottomwin, &meta)) != NANO_ENTER_KEY) {
while ((kbinput = get_kbinput(bottomwin, &meta_key)) != NANO_ENTER_KEY) {
for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG
fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput);
#endif
if (kbinput == t->func_key)
kbinput = t->val;
/* Temporary hack to interpret NANO_HELP_FKEY correctly. */
if (kbinput == t->funcval)
kbinput = t->ctrlval;
if (kbinput == t->val && is_cntrl_char(kbinput)) {
if (kbinput == t->ctrlval && is_cntrl_char(kbinput)) {
#ifndef DISABLE_HELP
/* Have to do this here, it would be too late to do it
@ -1154,7 +1158,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
break;
#endif
return t->val;
return t->ctrlval;
}
}
assert(0 <= x && x <= xend && xend == strlen(answer));
@ -1325,7 +1329,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput,
kbinput);
#endif
if (meta == 1 && (kbinput == t->metaval || kbinput == t->misc))
if (meta_key == TRUE && (kbinput == t->metaval || kbinput == t->miscval))
/* We hit a Meta key. Do like above. We don't
* just ungetch() the letter and let it get
* caught above cause that screws the
@ -1446,18 +1450,18 @@ void bottombars(const shortcut *s)
wmove(bottomwin, 1 + j, i * (COLS / numcols));
/* Yucky sentinel values we can't handle a better way */
if (s->val != NANO_NO_KEY) {
if (s->ctrlval != NANO_NO_KEY) {
#ifndef NANO_SMALL
if (s->val == NANO_HISTORY_KEY)
if (s->ctrlval == NANO_HISTORY_KEY)
strncpy(keystr, _("Up"), 8);
else
#endif
if (s->val == NANO_CONTROL_SPACE)
if (s->ctrlval == NANO_CONTROL_SPACE)
strcpy(keystr, "^ ");
else if (s->val == NANO_CONTROL_8)
else if (s->ctrlval == NANO_CONTROL_8)
strcpy(keystr, "^?");
else
sprintf(keystr, "^%c", s->val + 64);
sprintf(keystr, "^%c", s->ctrlval + 64);
} else if (s->metaval != NANO_NO_KEY)
sprintf(keystr, "M-%c", toupper(s->metaval));
@ -2143,12 +2147,12 @@ int do_yesno(int all, const char *msg)
do {
int kbinput;
int meta;
int meta_key;
#ifndef DISABLE_MOUSE
int mouse_x, mouse_y;
#endif
kbinput = get_kbinput(edit, &meta);
kbinput = get_kbinput(edit, &meta_key);
if (kbinput == NANO_CANCEL_KEY)
ok = -1;
@ -2355,7 +2359,7 @@ int line_len(const char *ptr)
int do_help(void)
{
#ifndef DISABLE_HELP
int i, page = 0, kbinput = -1, meta, no_more = 0;
int i, page = 0, kbinput = ERR, meta_key, no_more = 0;
int no_help_flag = 0;
const shortcut *oldshortcut;
@ -2431,7 +2435,7 @@ int do_help(void)
no_more = 1;
continue;
}
} while ((kbinput = get_kbinput(edit, &meta)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
} while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
currshortcut = oldshortcut;