with --ignorercfiles, do not try to find one, because that would lead
to the magic database being searched, which slows down startup a lot.
* src/color.c (color_update): Move some variables to a better place.
+ * src/*: Make 'meta_key' and 'func_key' into global variables, instead
+ of having them declared everywhere and passing them around endlessly.
2014-06-29 Benno Schulenberg <bensberg@justemail.net>
* src/rcfile.c: Fix compilation with --enable-tiny --enable-nanorc.
{
char *retval = NULL;
int kbinput;
- bool meta_key, func_key, old_const_update = ISSET(CONST_UPDATE);
+ bool old_const_update = ISSET(CONST_UPDATE);
char *prev_dir = NULL;
/* The directory we were in, if any, before backing up via
* browsing to "..". */
old_selected = selected;
- kbinput = get_kbinput(edit, &meta_key, &func_key);
+ kbinput = get_kbinput(edit);
#ifndef DISABLE_MOUSE
if (kbinput == KEY_MOUSE) {
}
#endif /* !DISABLE_MOUSE */
- parse_browser_input(&kbinput, &meta_key);
- s = get_shortcut(MBROWSER, &kbinput, &meta_key);
+ parse_browser_input(&kbinput);
+ s = get_shortcut(MBROWSER, &kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
FALSE,
#endif
MGOTODIR, ans,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
NULL,
#endif
/* Convert certain non-shortcut keys into their corresponding shortcut
* sequences, for compatibility with Pico. */
-void parse_browser_input(int *kbinput, bool *meta_key)
+void parse_browser_input(int *kbinput)
{
- if (!*meta_key) {
+ if (!meta_key) {
switch (*kbinput) {
case ' ':
*kbinput = KEY_NPAGE;
{
int i = 0;
char *buf;
- bool meta_key, func_key;
const sc *s;
static char *backupstring = NULL;
/* The search string we'll be using. */
TRUE,
#endif
MWHEREISFILE, backupstring,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
&search_history,
#endif
statusbar(_("Cancelled"));
return -1;
} else {
- s = get_shortcut(MBROWSER, &i, &meta_key);
+ s = get_shortcut(MBROWSER, &i);
if (i == -2 || i == 0) {
#ifdef HAVE_REGEX_H
/* Use last_search if answer is an empty string, or
filestruct *edittop_save = openfile->edittop;
size_t current_x_save = openfile->current_x;
ssize_t current_y_save = openfile->current_y;
- bool edittop_inside = FALSE, meta_key = FALSE, func_key = FALSE;
+ bool edittop_inside = FALSE;
const sc *s;
#ifndef NANO_TINY
bool right_side_up = FALSE, single_line = FALSE;
execute ? MEXTCMD :
#endif
MINSERTFILE, ans,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
NULL,
#endif
ans = mallocstrcpy(ans, answer);
- s = get_shortcut(currmenu, &i, &meta_key);
+ s = get_shortcut(currmenu, &i);
#ifndef NANO_TINY
#ifndef DISABLE_MULTIBUFFER
#ifndef DISABLE_EXTRA
static bool did_credits = FALSE;
#endif
- bool retval = FALSE, meta_key = FALSE, func_key = FALSE;
+ bool retval = FALSE;
const sc *s;
currmenu = MWRITEFILE;
TRUE,
#endif
MWRITEFILE, ans,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
NULL,
#endif
break;
} else {
ans = mallocstrcpy(ans, answer);
- s = get_shortcut(currmenu, &i, &meta_key);
+ s = get_shortcut(currmenu, &i);
#ifndef DISABLE_BROWSER
if (s && s->scfunc == to_files_void) {
* SIGWINCH? */
#endif
+bool meta_key;
+ /* Whether the current keystroke is a Meta key. */
+bool func_key;
+ /* Whether the current keystroke is an extended keypad value. */
+
#ifndef DISABLE_WRAPJUSTIFY
ssize_t fill = 0;
/* The column where we will wrap lines. */
void do_help(void (*refresh_func)(void))
{
int kbinput = ERR;
- bool meta_key, func_key, old_no_help = ISSET(NO_HELP);
+ bool old_no_help = ISSET(NO_HELP);
size_t line = 0;
/* The line number in help_text of the first displayed help
* line. This variable is zero-based. */
old_line = line;
- kbinput = get_kbinput(edit, &meta_key, &func_key);
+ kbinput = get_kbinput(edit);
#ifndef DISABLE_MOUSE
if (kbinput == KEY_MOUSE) {
}
#endif
- parse_help_input(&kbinput, &meta_key);
- s = get_shortcut(MHELP, &kbinput, &meta_key);
+ parse_help_input(&kbinput);
+ s = get_shortcut(MHELP, &kbinput);
if (!s)
continue;
f = sctofunc((sc *) s);
/* Convert certain non-shortcut keys into their corresponding shortcut
* sequences. */
-void parse_help_input(int *kbinput, bool *meta_key)
+void parse_help_input(int *kbinput)
{
- if (!*meta_key) {
+ if (!meta_key) {
switch (*kbinput) {
/* For consistency with the file browser. */
case ' ':
}
/* Read in a character, interpret it as a shortcut or toggle if
- * necessary, and return it. Set meta_key to TRUE if the character is a
- * meta sequence, set func_key to TRUE if the character is a function key.
+ * necessary, and return it.
* If allow_funcs is FALSE, don't actually run any functions associated
* with shortcut keys. */
-int do_input(bool *meta_key, bool *func_key, bool allow_funcs)
+int do_input(bool allow_funcs)
{
int input;
/* The character we read in. */
bool have_shortcut;
/* Read in a character. */
- input = get_kbinput(edit, meta_key, func_key);
+ input = get_kbinput(edit);
#ifndef DISABLE_MOUSE
- if (*func_key && input == KEY_MOUSE) {
+ if (func_key && input == KEY_MOUSE) {
/* We received a mouse click. */
if (do_mouse() == 1)
/* The click was on a shortcut -- read in the character
* that it was converted into. */
- input = get_kbinput(edit, meta_key, func_key);
+ input = get_kbinput(edit);
else
/* The click was invalid or has been handled -- get out. */
return ERR;
#endif
/* Check for a shortcut in the main list. */
- s = get_shortcut(MMAIN, &input, meta_key);
+ s = get_shortcut(MMAIN, &input);
/* If we got a shortcut from the main list, or a "universal"
* edit window shortcut, set have_shortcut to TRUE. */
/* If we got a non-high-bit control key, a meta key sequence, or a
* function key, and it's not a shortcut or toggle, throw it out. */
if (!have_shortcut) {
- if (is_ascii_cntrl_char(input) || *meta_key || *func_key) {
+ if (is_ascii_cntrl_char(input) || meta_key || func_key) {
statusbar(_("Unknown Command"));
beep();
- *meta_key = FALSE;
- *func_key = FALSE;
+ meta_key = FALSE;
+ func_key = FALSE;
input = ERR;
}
}
display_buffer();
while (TRUE) {
- bool meta_key, func_key;
-
/* Make sure the cursor is in the edit window. */
reset_cursor();
wnoutrefresh(edit);
currmenu = MMAIN;
/* Read in and interpret characters. */
- do_input(&meta_key, &func_key, TRUE);
+ do_input(TRUE);
}
/* We should never get here. */
* prompt? */
/* Read in a character, interpret it as a shortcut or toggle if
- * necessary, and return it. Set meta_key to TRUE if the character is a
- * meta sequence, set func_key to TRUE if the character is a function
- * key, set ran_func to TRUE if we ran a function associated with a
+ * necessary, and return it.
+ * Set ran_func to TRUE if we ran a function associated with a
* shortcut key, and set finished to TRUE if we're done after running
* or trying to run a function associated with a shortcut key.
* refresh_func is the function we will call to refresh the edit window. */
-int do_statusbar_input(bool *meta_key, bool *func_key,
- bool *ran_func, bool *finished, void (*refresh_func)(void))
+int do_statusbar_input(bool *ran_func, bool *finished,
+ void (*refresh_func)(void))
{
int input;
/* The character we read in. */
*finished = FALSE;
/* Read in a character. */
- input = get_kbinput(bottomwin, meta_key, func_key);
+ input = get_kbinput(bottomwin);
#ifndef DISABLE_MOUSE
/* If we got a mouse click and it was on a shortcut, read in the
* shortcut character. */
- if (*func_key && input == KEY_MOUSE) {
+ if (func_key && input == KEY_MOUSE) {
if (do_statusbar_mouse() == 1)
- input = get_kbinput(bottomwin, meta_key, func_key);
+ input = get_kbinput(bottomwin);
else {
- *meta_key = FALSE;
- *func_key = FALSE;
+ meta_key = FALSE;
+ func_key = FALSE;
input = ERR;
}
}
#endif
/* Check for a shortcut in the current list. */
- s = get_shortcut(currmenu, &input, meta_key);
+ s = get_shortcut(currmenu, &input);
/* If we got a shortcut from the current list, or a "universal"
* statusbar prompt shortcut, set have_shortcut to TRUE. */
/* If we got a non-high-bit control key, a meta key sequence, or a
* function key, and it's not a shortcut or toggle, throw it out. */
if (!have_shortcut) {
- if (is_ascii_cntrl_char(input) || *meta_key || *func_key) {
+ if (is_ascii_cntrl_char(input) || meta_key || func_key) {
beep();
- *meta_key = FALSE;
- *func_key = FALSE;
+ meta_key = FALSE;
+ func_key = FALSE;
input = ERR;
}
}
bool allow_files,
#endif
const char *curranswer,
- bool *meta_key, bool *func_key,
#ifndef DISABLE_HISTORIES
filestruct **history_list,
#endif
* this case, disable all keys that would change the text if the
* filename isn't blank and we're at the "Write File" prompt. */
while (TRUE) {
- kbinput = do_statusbar_input(meta_key, func_key,
- &ran_func, &finished, refresh_func);
+ kbinput = do_statusbar_input(&ran_func, &finished, refresh_func);
assert(statusbar_x <= strlen(answer));
- s = get_shortcut(currmenu, &kbinput, meta_key);
+ s = get_shortcut(currmenu, &kbinput);
if (s)
if (s->scfunc == do_cancel || s->scfunc == do_enter_void)
bool allow_files,
#endif
int menu, const char *curranswer,
- bool *meta_key, bool *func_key,
#ifndef DISABLE_HISTORIES
filestruct **history_list,
#endif
allow_files,
#endif
curranswer,
- meta_key, func_key,
#ifndef DISABLE_HISTORIES
history_list,
#endif
do {
int kbinput;
- bool meta_key, func_key;
#ifndef DISABLE_MOUSE
int mouse_x, mouse_y;
#endif
currmenu = MYESNO;
- kbinput = get_kbinput(bottomwin, &meta_key, &func_key);
- s = get_shortcut(currmenu, &kbinput, &meta_key);
+ kbinput = get_kbinput(bottomwin);
+ s = get_shortcut(currmenu, &kbinput);
if (s && s->scfunc == do_cancel)
ok = -1;
extern bool jump_buf_main;
#endif
+extern bool meta_key;
+extern bool func_key;
+
#ifndef DISABLE_WRAPJUSTIFY
extern ssize_t fill;
extern ssize_t wrap_at;
char *do_browser(char *path, DIR *dir);
char *do_browse_from(const char *inpath);
void browser_init(const char *path, DIR *dir);
-void parse_browser_input(int *kbinput, bool *meta_key);
+void parse_browser_input(int *kbinput);
void browser_refresh(void);
bool browser_select_filename(const char *needle);
int filesearch_init(void);
#ifndef DISABLE_HELP
void do_help(void (*refresh_func)(void));
void help_init(void);
-void parse_help_input(int *kbinput, bool *meta_key);
+void parse_help_input(int *kbinput);
size_t help_line_len(const char *ptr);
#endif
void do_help_void(void);
void disable_flow_control(void);
void enable_flow_control(void);
void terminal_init(void);
-int do_input(bool *meta_key, bool *func_key, bool allow_funcs);
+int do_input(bool allow_funcs);
#ifndef DISABLE_MOUSE
int do_mouse(void);
#endif
void do_output(char *output, size_t output_len, bool allow_cntrls);
/* All functions in prompt.c. */
-int do_statusbar_input(bool *meta_key, bool *func_key,
- bool *ran_func, bool *finished, void (*refresh_func)(void));
+int do_statusbar_input(bool *ran_func, bool *finished,
+ void (*refresh_func)(void));
#ifndef DISABLE_MOUSE
int do_statusbar_mouse(void);
#endif
bool allow_files,
#endif
const char *curranswer,
- bool *meta_key, bool *func_key,
#ifndef DISABLE_HISTORIES
filestruct **history_list,
#endif
bool allow_files,
#endif
int menu, const char *curranswer,
- bool *meta_key, bool *func_key,
#ifndef DISABLE_HISTORIES
filestruct **history_list,
#endif
void get_key_buffer(WINDOW *win);
size_t get_key_buffer_len(void);
void unget_input(int *input, size_t input_len);
-void unget_kbinput(int kbinput, bool meta_key, bool func_key);
+void unget_kbinput(int kbinput, bool metakey, bool funckey);
int *get_input(WINDOW *win, size_t input_len);
-int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key);
-int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key);
+int get_kbinput(WINDOW *win);
+int parse_kbinput(WINDOW *win);
int get_escape_seq_kbinput(const int *seq, size_t seq_len);
int get_escape_seq_abcd(int kbinput);
int parse_escape_seq_kbinput(WINDOW *win, int kbinput);
#ifndef DISABLE_MOUSE
int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
#endif
-const sc *get_shortcut(int menu, int *kbinput, bool *meta_key);
+const sc *get_shortcut(int menu, int *kbinput);
void blank_line(WINDOW *win, int y, int x, int n);
void blank_titlebar(void);
void blank_topbar(void);
int i = 0;
char *buf;
sc *s;
- bool meta_key = FALSE, func_key = FALSE;
static char *backupstring = NULL;
/* The search string we'll be using. */
TRUE,
#endif
replacing ? MREPLACE : MWHEREIS, backupstring,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
&search_history,
#endif
{
filestruct *edittop_save, *begin;
size_t begin_x, pww_save;
- bool meta_key = FALSE, func_key = FALSE;
ssize_t numreplaced;
int i;
TRUE,
#endif
MREPLACEWITH, last_replace,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
&replace_history,
#endif
void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
bool interactive, bool save_pos, bool allow_update)
{
- bool meta_key = FALSE, func_key = FALSE;
const sc *s;
if (interactive) {
TRUE,
#endif
MGOTOLINE, use_answer ? ans : "",
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
NULL,
#endif
return;
}
- s = get_shortcut(currmenu, &i, &meta_key);
+ s = get_shortcut(currmenu, &i);
if (s && s->scfunc == gototext_void) {
/* Keep answer up on the statusbar. */
bool modified_save = openfile->modified;
int kbinput;
- bool meta_key, func_key;
const sc *s;
/* Move to the beginning of the current line, so that justifying at
/* Now get a keystroke and see if it's unjustify. If not, put back
* the keystroke and return. */
- kbinput = do_input(&meta_key, &func_key, FALSE);
- s = get_shortcut(MMAIN, &kbinput, &meta_key);
+ kbinput = do_input(FALSE);
+ s = get_shortcut(MMAIN, &kbinput);
if (s && s->scfunc == do_uncut_text) {
/* Splice the justify buffer back into the file, but only if we
char *save_search, *save_replace;
size_t match_len, current_x_save = openfile->current_x;
size_t pww_save = openfile->placewewant;
- bool meta_key = FALSE, func_key = FALSE;
filestruct *edittop_save = openfile->edittop;
filestruct *current_save = openfile->current;
/* Save where we are. */
TRUE,
#endif
MSPELL, word,
- &meta_key, &func_key,
#ifndef DISABLE_HISTORIES
NULL,
#endif
while (1) {
ssize_t tmpcol = 1;
int kbinput;
- bool meta_key, func_key;
if (curlint->colno > 0)
tmpcol = curlint->colno;
bottombars(MLINTER);
}
- kbinput = get_kbinput(bottomwin, &meta_key, &func_key);
- s = get_shortcut(currmenu, &kbinput, &meta_key);
+ kbinput = get_kbinput(bottomwin);
+ s = get_shortcut(currmenu, &kbinput);
tmplint = curlint;
if (!s)
}
/* Put back the character stored in kbinput, putting it in byte range
- * beforehand. If meta_key is TRUE, put back the Escape character after
- * putting back kbinput. If func_key is TRUE, put back the function key
+ * beforehand. If metakey is TRUE, put back the Escape character after
+ * putting back kbinput. If funckey is TRUE, put back the function key
* (a value outside byte range) without putting it in byte range. */
-void unget_kbinput(int kbinput, bool meta_key, bool func_key)
+void unget_kbinput(int kbinput, bool metakey, bool funckey)
{
- if (!func_key)
+ if (!funckey)
kbinput = (char)kbinput;
unget_input(&kbinput, 1);
- if (meta_key) {
+ if (metakey) {
kbinput = NANO_CONTROL_3;
unget_input(&kbinput, 1);
}
/* Read in a single character. If it's ignored, swallow it and go on.
* Otherwise, try to translate it from ASCII, meta key sequences, escape
- * sequences, and/or extended keypad values. Set meta_key to TRUE when
- * we get a meta key sequence, and set func_key to TRUE when we get an
- * extended keypad value. Supported extended keypad values consist of
+ * sequences, and/or extended keypad values. Supported extended keypad
+ * values consist of
* [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace,
* the editing keypad (Insert, Delete, Home, End, PageUp, and PageDown),
* the function keypad (F1-F16), and the numeric keypad with NumLock
* off. */
-int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
+int get_kbinput(WINDOW *win)
{
int kbinput;
/* Read in a character and interpret it. Continue doing this until
* we get a recognized value or sequence. */
- while ((kbinput = parse_kbinput(win, meta_key, func_key)) == ERR)
+ while ((kbinput = parse_kbinput(win)) == ERR)
;
/* If we read from the edit window, blank the statusbar if we need
* sequences into their corresponding key values. Set meta_key to TRUE
* when we get a meta key sequence, and set func_key to TRUE when we get
* a function key. */
-int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
+int parse_kbinput(WINDOW *win)
{
static int escapes = 0, byte_digits = 0;
int *kbinput, retval = ERR;
- *meta_key = FALSE;
- *func_key = FALSE;
+ meta_key = FALSE;
+ func_key = FALSE;
/* Read in a character. */
if (nodelay_mode) {
* meta key sequence mode. Set meta_key to
* TRUE, and save the lowercase version of the
* non-escape character as the result. */
- *meta_key = TRUE;
+ meta_key = TRUE;
retval = tolower(*kbinput);
} else
/* One escape followed by a non-escape, and
* escape counter, set meta_key to TRUE, and
* interpret the escape sequence. */
escapes = 0;
- *meta_key = TRUE;
+ meta_key = TRUE;
retval = parse_escape_seq_kbinput(win,
*kbinput);
}
/* If our result is an extended keypad value (i.e. a value
* outside of byte range), set func_key to TRUE. */
if (retval != ERR)
- *func_key = !is_byte(retval);
+ func_key = !is_byte(retval);
}
#ifdef DEBUG
- fprintf(stderr, "parse_kbinput(): kbinput = %d, meta_key = %s, func_key = %s, escapes = %d, byte_digits = %d, retval = %d\n", *kbinput, *meta_key ? "TRUE" : "FALSE", *func_key ? "TRUE" : "FALSE", escapes, byte_digits, retval);
+ fprintf(stderr, "parse_kbinput(): kbinput = %d, meta_key = %s, func_key = %s, escapes = %d, byte_digits = %d, retval = %d\n", *kbinput, meta_key ? "TRUE" : "FALSE", func_key ? "TRUE" : "FALSE", escapes, byte_digits, retval);
#endif
free(kbinput);
* key itself) and meta_key (whether the key is a meta sequence). The
* returned shortcut will be the first in the list that corresponds to
* the given sequence. */
-const sc *get_shortcut(int menu, int *kbinput, bool *meta_key)
+const sc *get_shortcut(int menu, int *kbinput)
{
sc *s;
#ifdef DEBUG
- fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %s -- ", *kbinput, *meta_key ? "TRUE" : "FALSE");
+ fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %s -- ", *kbinput, meta_key ? "TRUE" : "FALSE");
#endif
for (s = sclist; s != NULL; s = s->next) {
if ((menu & s->menu) && *kbinput == s->seq
- && *meta_key == (s->type == META)) {
+ && meta_key == (s->type == META)) {
#ifdef DEBUG
fprintf (stderr, "matched seq \"%s\", and btw meta was %d (menu is %x from %x)\n",
- s->keystr, *meta_key, menu, s->menu);
+ s->keystr, meta_key, menu, s->menu);
#endif
return s;
}
}
#ifdef DEBUG
- fprintf (stderr, "matched nothing, btw meta was %d\n", *meta_key);
+ fprintf (stderr, "matched nothing, btw meta was %d\n", meta_key);
#endif
return NULL;
const subnfunc *getfuncfromkey(WINDOW *win)
{
int kbinput;
- bool func_key = FALSE, meta_key = FALSE;
const sc *s;
- kbinput = parse_kbinput(win, &meta_key, &func_key);
+ kbinput = parse_kbinput(win);
if (kbinput == 0)
return NULL;
- s = get_shortcut(currmenu, &kbinput, &meta_key);
+ s = get_shortcut(currmenu, &kbinput);
if (!s)
return NULL;