- 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.
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
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;
}
}
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);
}
/* 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;
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;
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
{
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
/* 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) {
*(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';
#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
* 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
do_mouse();
else
ungetch(i);
- i = get_kbinput(edit, &meta);
+ i = get_kbinput(edit, &meta_key);
#endif
}
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;
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 {
#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 {
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". */
#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);
#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);
* 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;
#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);
}
/* 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 */
switch (kbinput) {
case ERR:
kbinput = tolower(old_kbinput);
- *meta = 1;
+ *meta_key = TRUE;
break;
default:
ungetch(kbinput);
default:
/* Esc [character] == Meta-[character] */
kbinput = tolower(kbinput);
- *meta = 1;
+ *meta_key = TRUE;
}
break;
case NANO_CONTROL_8:
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;
}
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;
}
)
{
int kbinput;
- int meta;
+ int meta_key;
static int x = -1;
/* the cursor position in 'answer' */
int xend;
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
break;
#endif
- return t->val;
+ return t->ctrlval;
}
}
assert(0 <= x && x <= xend && xend == strlen(answer));
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
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));
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;
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;
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;