commit f3738fe164927883ff7ba7bc8b89a42519b121ab
parent 04a08fe6a5b3083ab60b9d3d9bcd5ff2257d6d0e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 21 Aug 2022 09:12:35 +0200
tweaks: don't use a pointer when the value itself is all that is needed
Diffstat:
9 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -510,7 +510,7 @@ char *browse(char *path)
continue;
}
#endif
- function = interpret(&kbinput);
+ function = interpret(kbinput);
if (function == full_refresh) {
full_refresh();
diff --git a/src/files.c b/src/files.c
@@ -1213,7 +1213,7 @@ void insert_a_file_or(bool execute)
ssize_t was_current_lineno = openfile->current->lineno;
size_t was_current_x = openfile->current_x;
#if !defined(NANO_TINY) || defined(ENABLE_BROWSER) || defined(ENABLE_MULTIBUFFER)
- functionptrtype function = func_from_key(&response);
+ functionptrtype function = func_from_key(response);
#endif
given = mallocstrcpy(given, answer);
@@ -2141,7 +2141,7 @@ int write_it_out(bool exiting, bool withprompt)
return 0;
}
- function = func_from_key(&response);
+ function = func_from_key(response);
/* Upon request, abandon the buffer. */
if (function == discard_buffer) {
diff --git a/src/global.c b/src/global.c
@@ -448,28 +448,28 @@ size_t shown_entries_for(int menu)
}
/* Return the first shortcut in the current menu that matches the given input. */
-const keystruct *get_shortcut(int *keycode)
+const keystruct *get_shortcut(const int keycode)
{
/* Plain characters and upper control codes cannot be shortcuts. */
- if (!meta_key && 0x20 <= *keycode && *keycode <= 0xFF)
+ if (!meta_key && 0x20 <= keycode && keycode <= 0xFF)
return NULL;
/* Lower control codes with Meta cannot be shortcuts either. */
- if (meta_key && *keycode < 0x20)
+ if (meta_key && keycode < 0x20)
return NULL;
#ifndef NANO_TINY
/* During a paste at a prompt, ignore all command keycodes. */
- if (bracketed_paste && *keycode != BRACKETED_PASTE_MARKER)
+ if (bracketed_paste && keycode != BRACKETED_PASTE_MARKER)
return NULL;
#endif
#ifdef ENABLE_NANORC
- if (*keycode == PLANTED_COMMAND)
+ if (keycode == PLANTED_COMMAND)
return planted_shortcut;
#endif
for (keystruct *sc = sclist; sc != NULL; sc = sc->next) {
- if ((sc->menus & currmenu) && *keycode == sc->keycode)
+ if ((sc->menus & currmenu) && keycode == sc->keycode)
return sc;
}
@@ -477,7 +477,7 @@ const keystruct *get_shortcut(int *keycode)
}
/* Return a pointer to the function that is bound to the given key. */
-functionptrtype func_from_key(int *keycode)
+functionptrtype func_from_key(const int keycode)
{
const keystruct *sc = get_shortcut(keycode);
@@ -488,15 +488,15 @@ functionptrtype func_from_key(int *keycode)
/* Return the function that is bound to the given key in the file browser or
* the help viewer. Accept also certain plain characters, for compatibility
* with Pico or to mimic 'less' and similar text viewers. */
-functionptrtype interpret(int *keycode)
+functionptrtype interpret(const int keycode)
{
if (!meta_key) {
- if (*keycode == 'N')
+ if (keycode == 'N')
return do_findprevious;
- if (*keycode == 'n')
+ if (keycode == 'n')
return do_findnext;
- switch (tolower(*keycode)) {
+ switch (tolower(keycode)) {
case 'b':
case '-':
return do_page_up;
diff --git a/src/help.c b/src/help.c
@@ -475,7 +475,7 @@ void show_help(void)
continue;
}
#endif
- function = interpret(&kbinput);
+ function = interpret(kbinput);
if (function == full_refresh) {
full_refresh();
diff --git a/src/nano.c b/src/nano.c
@@ -1567,7 +1567,7 @@ void process_a_keystroke(void)
#endif
/* Check for a shortcut in the main list. */
- shortcut = get_shortcut(&input);
+ shortcut = get_shortcut(input);
function = (shortcut ? shortcut->func : NULL);
/* If not a command, discard anything that is not a normal character byte. */
diff --git a/src/prompt.c b/src/prompt.c
@@ -458,7 +458,7 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
#endif
/* Check for a shortcut in the current list. */
- shortcut = get_shortcut(&input);
+ shortcut = get_shortcut(input);
function = (shortcut ? shortcut->func : NULL);
if (function == do_cancel || function == do_enter)
@@ -728,7 +728,7 @@ int ask_user(bool withall, const char *question)
choice = NO;
else if (withall && strchr("Aa", kbinput) != NULL)
choice = ALL;
- else if (func_from_key(&kbinput) == do_cancel)
+ else if (func_from_key(kbinput) == do_cancel)
choice = CANCEL;
/* Interpret ^N and ^Q as "No", to allow exiting in anger. */
else if (kbinput == '\x0E' || kbinput == '\x11')
@@ -754,10 +754,10 @@ int ask_user(bool withall, const char *question)
}
}
#endif
- else if (func_from_key(&kbinput) == full_refresh)
+ else if (func_from_key(kbinput) == full_refresh)
full_refresh();
#ifndef NANO_TINY
- else if (func_from_key(&kbinput) == do_toggle) {
+ else if (func_from_key(kbinput) == do_toggle) {
TOGGLE(NO_HELP);
window_init();
titlebar(NULL);
diff --git a/src/prototypes.h b/src/prototypes.h
@@ -321,10 +321,10 @@ char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *list
/* Some functions in global.c. */
const keystruct *first_sc_for(int menu, void (*function)(void));
size_t shown_entries_for(int menu);
-const keystruct *get_shortcut(int *keycode);
-functionptrtype func_from_key(int *keycode);
+const keystruct *get_shortcut(const int keycode);
+functionptrtype func_from_key(const int keycode);
#if defined(ENABLE_BROWSER) || defined(ENABLE_HELP)
-functionptrtype interpret(int *keycode);
+functionptrtype interpret(const int keycode);
#endif
int keycode_from_string(const char *keystring);
void shortcut_init(void);
diff --git a/src/search.c b/src/search.c
@@ -138,7 +138,7 @@ void search_init(bool replacing, bool retain_answer)
retain_answer = TRUE;
- function = func_from_key(&response);
+ function = func_from_key(response);
/* If we're here, one of the five toggles was pressed, or
* a shortcut was executed. */
@@ -284,7 +284,7 @@ int findnextstr(const char *needle, bool whole_word_only, int modus,
} else
meta_key = FALSE;
- if (func_from_key(&input) == do_cancel) {
+ if (func_from_key(input) == do_cancel) {
#ifndef NANO_TINY
if (the_window_resized)
regenerate_screen();
@@ -773,7 +773,7 @@ void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer,
return;
}
- if (func_from_key(&response) == flip_goto) {
+ if (func_from_key(response) == flip_goto) {
UNSET(BACKWARDS_SEARCH);
/* Switch to searching but retain what the user typed so far. */
search_init(FALSE, TRUE);
diff --git a/src/text.c b/src/text.c
@@ -2856,7 +2856,7 @@ void do_linter(void)
if (kbinput == KEY_WINCH)
continue;
#endif
- function = func_from_key(&kbinput);
+ function = func_from_key(kbinput);
tmplint = curlint;
if (function == do_cancel || function == do_enter) {