From a7e11495bdb8e4b63a6304395219532313f2b5d1 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 13 Dec 2019 18:54:53 +0100 Subject: [PATCH] tweaks: move three functions to the file where they are used Also move the corresponding two arrays. --- src/global.c | 306 --------------------------------------------------- src/proto.h | 5 - src/rcfile.c | 302 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 302 insertions(+), 311 deletions(-) diff --git a/src/global.c b/src/global.c index b1e44873..444cb818 100644 --- a/src/global.c +++ b/src/global.c @@ -248,20 +248,6 @@ char *homedir = NULL; char *statedir = NULL; /* The directory for nano's history files. */ -#ifdef ENABLE_NANORC -#define NUMBER_OF_MENUS 16 -char *menunames[NUMBER_OF_MENUS] = { "main", "search", "replace", "replacewith", - "yesno", "gotoline", "writeout", "insert", - "extcmd", "help", "spell", "linter", - "browser", "whereisfile", "gotodir", - "all" }; -int menusymbols[NUMBER_OF_MENUS] = { MMAIN, MWHEREIS, MREPLACE, MREPLACEWITH, - MYESNO, MGOTOLINE, MWRITEFILE, MINSERTFILE, - MEXTCMD, MHELP, MSPELL, MLINTER, - MBROWSER, MWHEREISFILE, MGOTODIR, - MMOST|MBROWSER|MHELP|MYESNO }; -#endif - #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES) char *startup_problem = NULL; /* An error message (if any) about nanorc files or history files. */ @@ -1450,295 +1436,3 @@ const char *flagtostr(int flag) } } #endif /* !NANO_TINY */ - -#ifdef ENABLE_NANORC -/* Interpret a function string given in the rc file, and return a - * shortcut record with the corresponding function filled in. */ -keystruct *strtosc(const char *input) -{ - keystruct *s = nmalloc(sizeof(keystruct)); - -#ifndef NANO_TINY - s->toggle = 0; -#endif - -#ifdef ENABLE_HELP - if (!strcasecmp(input, "help")) - s->func = do_help_void; - else -#endif - if (!strcasecmp(input, "cancel")) - s->func = do_cancel; - else if (!strcasecmp(input, "exit")) - s->func = do_exit; - else if (!strcasecmp(input, "discardbuffer")) - s->func = discard_buffer; - else if (!strcasecmp(input, "writeout")) - s->func = do_writeout_void; - else if (!strcasecmp(input, "savefile")) - s->func = do_savefile; - else if (!strcasecmp(input, "insert")) - s->func = do_insertfile_void; - else if (!strcasecmp(input, "whereis")) - s->func = do_search_forward; - else if (!strcasecmp(input, "wherewas")) - s->func = do_search_backward; - else if (!strcasecmp(input, "findprevious")) - s->func = do_findprevious; - else if (!strcasecmp(input, "findnext")) - s->func = do_findnext; - else if (!strcasecmp(input, "replace")) - s->func = do_replace; - else if (!strcasecmp(input, "cut")) - s->func = cut_text; - else if (!strcasecmp(input, "paste")) - s->func = paste_text; -#ifndef NANO_TINY - else if (!strcasecmp(input, "cutrestoffile")) - s->func = cut_till_eof; - else if (!strcasecmp(input, "copy")) - s->func = copy_text; - else if (!strcasecmp(input, "zap")) - s->func = zap_text; - else if (!strcasecmp(input, "mark")) - s->func = do_mark; -#endif -#ifdef ENABLE_SPELLER - else if (!strcasecmp(input, "tospell") || - !strcasecmp(input, "speller")) - s->func = do_spell; -#endif -#ifdef ENABLE_COLOR - else if (!strcasecmp(input, "linter")) - s->func = do_linter; -#ifdef ENABLE_SPELLER - else if (!strcasecmp(input, "formatter")) - s->func = do_formatter; -#endif -#endif - else if (!strcasecmp(input, "curpos")) - s->func = do_cursorpos_void; - else if (!strcasecmp(input, "gotoline")) - s->func = do_gotolinecolumn_void; -#ifdef ENABLE_JUSTIFY - else if (!strcasecmp(input, "justify")) - s->func = do_justify_void; - else if (!strcasecmp(input, "fulljustify")) - s->func = do_full_justify; - else if (!strcasecmp(input, "beginpara")) - s->func = do_para_begin_void; - else if (!strcasecmp(input, "endpara")) - s->func = do_para_end_void; -#endif -#ifdef ENABLE_COMMENT - else if (!strcasecmp(input, "comment")) - s->func = do_comment; -#endif -#ifdef ENABLE_WORDCOMPLETION - else if (!strcasecmp(input, "complete")) - s->func = complete_a_word; -#endif -#ifndef NANO_TINY - else if (!strcasecmp(input, "indent")) - s->func = do_indent; - else if (!strcasecmp(input, "unindent")) - s->func = do_unindent; - else if (!strcasecmp(input, "chopwordleft") || - !strcasecmp(input, "cutwordleft")) /* Deprecated; remove in 2021. */ - s->func = chop_previous_word; - else if (!strcasecmp(input, "chopwordright") || - !strcasecmp(input, "cutwordright")) /* Deprecated; remove in 2021. */ - s->func = chop_next_word; - else if (!strcasecmp(input, "findbracket")) - s->func = do_find_bracket; - else if (!strcasecmp(input, "wordcount")) - s->func = do_wordlinechar_count; - else if (!strcasecmp(input, "recordmacro")) - s->func = record_macro; - else if (!strcasecmp(input, "runmacro")) - s->func = run_macro; - else if (!strcasecmp(input, "undo")) - s->func = do_undo; - else if (!strcasecmp(input, "redo")) - s->func = do_redo; -#endif - else if (!strcasecmp(input, "left") || - !strcasecmp(input, "back")) - s->func = do_left; - else if (!strcasecmp(input, "right") || - !strcasecmp(input, "forward")) - s->func = do_right; - else if (!strcasecmp(input, "up") || - !strcasecmp(input, "prevline")) - s->func = do_up; - else if (!strcasecmp(input, "down") || - !strcasecmp(input, "nextline")) - s->func = do_down; -#if !defined(NANO_TINY) || defined(ENABLE_HELP) - else if (!strcasecmp(input, "scrollup")) - s->func = do_scroll_up; - else if (!strcasecmp(input, "scrolldown")) - s->func = do_scroll_down; -#endif - else if (!strcasecmp(input, "prevword")) - s->func = do_prev_word_void; - else if (!strcasecmp(input, "nextword")) - s->func = do_next_word_void; - else if (!strcasecmp(input, "home")) - s->func = do_home; - else if (!strcasecmp(input, "end")) - s->func = do_end; - else if (!strcasecmp(input, "prevblock")) - s->func = do_prev_block; - else if (!strcasecmp(input, "nextblock")) - s->func = do_next_block; - else if (!strcasecmp(input, "pageup") || - !strcasecmp(input, "prevpage")) - s->func = do_page_up; - else if (!strcasecmp(input, "pagedown") || - !strcasecmp(input, "nextpage")) - s->func = do_page_down; - else if (!strcasecmp(input, "firstline")) - s->func = to_first_line; - else if (!strcasecmp(input, "lastline")) - s->func = to_last_line; -#ifdef ENABLE_MULTIBUFFER - else if (!strcasecmp(input, "prevbuf")) - s->func = switch_to_prev_buffer; - else if (!strcasecmp(input, "nextbuf")) - s->func = switch_to_next_buffer; -#endif - else if (!strcasecmp(input, "verbatim")) - s->func = do_verbatim_input; - else if (!strcasecmp(input, "tab")) - s->func = do_tab; - else if (!strcasecmp(input, "enter")) - s->func = do_enter; - else if (!strcasecmp(input, "delete")) - s->func = do_delete; - else if (!strcasecmp(input, "backspace")) - s->func = do_backspace; - else if (!strcasecmp(input, "refresh")) - s->func = total_refresh; - else if (!strcasecmp(input, "suspend")) - s->func = do_suspend_void; - else if (!strcasecmp(input, "casesens")) - s->func = case_sens_void; - else if (!strcasecmp(input, "regexp")) - s->func = regexp_void; - else if (!strcasecmp(input, "backwards")) - s->func = backwards_void; - else if (!strcasecmp(input, "flipreplace")) - s->func = flip_replace; - else if (!strcasecmp(input, "flipgoto")) - s->func = flip_goto; -#ifdef ENABLE_HISTORIES - else if (!strcasecmp(input, "older")) - s->func = get_history_older_void; - else if (!strcasecmp(input, "newer")) - s->func = get_history_newer_void; -#endif -#ifndef NANO_TINY - else if (!strcasecmp(input, "dosformat")) - s->func = dos_format_void; - else if (!strcasecmp(input, "macformat")) - s->func = mac_format_void; - else if (!strcasecmp(input, "append")) - s->func = append_void; - else if (!strcasecmp(input, "prepend")) - s->func = prepend_void; - else if (!strcasecmp(input, "backup")) - s->func = backup_file_void; - else if (!strcasecmp(input, "flipexecute")) - s->func = flip_execute; - else if (!strcasecmp(input, "flippipe")) - s->func = flip_pipe; - else if (!strcasecmp(input, "flipconvert")) - s->func = flip_convert; -#endif -#ifdef ENABLE_MULTIBUFFER - else if (!strcasecmp(input, "flipnewbuffer")) - s->func = flip_newbuffer; -#endif -#ifdef ENABLE_BROWSER - else if (!strcasecmp(input, "tofiles") || - !strcasecmp(input, "browser")) - s->func = to_files_void; - else if (!strcasecmp(input, "gotodir")) - s->func = goto_dir_void; - else if (!strcasecmp(input, "firstfile")) - s->func = to_first_file; - else if (!strcasecmp(input, "lastfile")) - s->func = to_last_file; -#endif - else { -#ifndef NANO_TINY - s->func = do_toggle_void; - if (!strcasecmp(input, "nohelp")) - s->toggle = NO_HELP; - else if (!strcasecmp(input, "constantshow")) - s->toggle = CONSTANT_SHOW; - else if (!strcasecmp(input, "softwrap")) - s->toggle = SOFTWRAP; -#ifdef ENABLE_LINENUMBERS - else if (!strcasecmp(input, "linenumbers")) - s->toggle = LINE_NUMBERS; -#endif - else if (!strcasecmp(input, "whitespacedisplay")) - s->toggle = WHITESPACE_DISPLAY; -#ifdef ENABLE_COLOR - else if (!strcasecmp(input, "nosyntax")) - s->toggle = NO_COLOR_SYNTAX; -#endif - else if (!strcasecmp(input, "smarthome")) - s->toggle = SMART_HOME; - else if (!strcasecmp(input, "autoindent")) - s->toggle = AUTOINDENT; - else if (!strcasecmp(input, "cutfromcursor")) - s->toggle = CUT_FROM_CURSOR; -#ifdef ENABLE_WRAPPING - else if (!strcasecmp(input, "nowrap")) - s->toggle = BREAK_LONG_LINES; -#endif - else if (!strcasecmp(input, "tabstospaces")) - s->toggle = TABS_TO_SPACES; -#ifdef ENABLE_MOUSE - else if (!strcasecmp(input, "mouse")) - s->toggle = USE_MOUSE; -#endif - else if (!strcasecmp(input, "suspendenable")) - s->toggle = SUSPEND; - else -#endif /* !NANO_TINY */ - { - free(s); - return NULL; - } - } - return s; -} - -/* Return the symbol that corresponds to the given menu name. */ -int name_to_menu(const char *name) -{ - int index = -1; - - while (++index < NUMBER_OF_MENUS) - if (strcasecmp(name, menunames[index]) == 0) - return menusymbols[index]; - - return -1; -} - -/* Return the name that corresponds to the given menu symbol. */ -char *menu_to_name(int menu) -{ - int index = -1; - - while (++index < NUMBER_OF_MENUS) - if (menusymbols[index] == menu) - return menunames[index]; - - return "boooo"; -} -#endif /* ENABLE_NANORC */ diff --git a/src/proto.h b/src/proto.h index 8e5b4ec0..babffa12 100644 --- a/src/proto.h +++ b/src/proto.h @@ -328,11 +328,6 @@ int keycode_from_string(const char *keystring); void assign_keyinfo(keystruct *s, const char *keystring, const int keycode); void shortcut_init(void); const char *flagtostr(int flag); -#ifdef ENABLE_NANORC -keystruct *strtosc(const char *input); -int name_to_menu(const char *name); -char *menu_to_name(int menu); -#endif /* All functions in help.c. */ #ifdef ENABLE_HELP diff --git a/src/rcfile.c b/src/rcfile.c index 5efacabc..3dc31637 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -146,6 +146,18 @@ static bool seen_color_command = FALSE; static colortype *lastcolor = NULL; /* The end of the color list for the current syntax. */ #endif + +#define NUMBER_OF_MENUS 16 +char *menunames[NUMBER_OF_MENUS] = { "main", "search", "replace", "replacewith", + "yesno", "gotoline", "writeout", "insert", + "extcmd", "help", "spell", "linter", + "browser", "whereisfile", "gotodir", + "all" }; +int menusymbols[NUMBER_OF_MENUS] = { MMAIN, MWHEREIS, MREPLACE, MREPLACEWITH, + MYESNO, MGOTOLINE, MWRITEFILE, MINSERTFILE, + MEXTCMD, MHELP, MSPELL, MLINTER, + MBROWSER, MWHEREISFILE, MGOTODIR, + MMOST|MBROWSER|MHELP|MYESNO }; #endif /* ENABLE_NANORC */ #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES) @@ -200,6 +212,296 @@ void jot_error(const char *msg, ...) #endif /* ENABLE_NANORC || ENABLE_HISTORIES */ #ifdef ENABLE_NANORC +/* Interpret a function string given in the rc file, and return a + * shortcut record with the corresponding function filled in. */ +keystruct *strtosc(const char *input) +{ + keystruct *s = nmalloc(sizeof(keystruct)); + +#ifndef NANO_TINY + s->toggle = 0; +#endif + +#ifdef ENABLE_HELP + if (!strcasecmp(input, "help")) + s->func = do_help_void; + else +#endif + if (!strcasecmp(input, "cancel")) + s->func = do_cancel; + else if (!strcasecmp(input, "exit")) + s->func = do_exit; + else if (!strcasecmp(input, "discardbuffer")) + s->func = discard_buffer; + else if (!strcasecmp(input, "writeout")) + s->func = do_writeout_void; + else if (!strcasecmp(input, "savefile")) + s->func = do_savefile; + else if (!strcasecmp(input, "insert")) + s->func = do_insertfile_void; + else if (!strcasecmp(input, "whereis")) + s->func = do_search_forward; + else if (!strcasecmp(input, "wherewas")) + s->func = do_search_backward; + else if (!strcasecmp(input, "findprevious")) + s->func = do_findprevious; + else if (!strcasecmp(input, "findnext")) + s->func = do_findnext; + else if (!strcasecmp(input, "replace")) + s->func = do_replace; + else if (!strcasecmp(input, "cut")) + s->func = cut_text; + else if (!strcasecmp(input, "paste")) + s->func = paste_text; +#ifndef NANO_TINY + else if (!strcasecmp(input, "cutrestoffile")) + s->func = cut_till_eof; + else if (!strcasecmp(input, "copy")) + s->func = copy_text; + else if (!strcasecmp(input, "zap")) + s->func = zap_text; + else if (!strcasecmp(input, "mark")) + s->func = do_mark; +#endif +#ifdef ENABLE_SPELLER + else if (!strcasecmp(input, "tospell") || + !strcasecmp(input, "speller")) + s->func = do_spell; +#endif +#ifdef ENABLE_COLOR + else if (!strcasecmp(input, "linter")) + s->func = do_linter; +#ifdef ENABLE_SPELLER + else if (!strcasecmp(input, "formatter")) + s->func = do_formatter; +#endif +#endif + else if (!strcasecmp(input, "curpos")) + s->func = do_cursorpos_void; + else if (!strcasecmp(input, "gotoline")) + s->func = do_gotolinecolumn_void; +#ifdef ENABLE_JUSTIFY + else if (!strcasecmp(input, "justify")) + s->func = do_justify_void; + else if (!strcasecmp(input, "fulljustify")) + s->func = do_full_justify; + else if (!strcasecmp(input, "beginpara")) + s->func = do_para_begin_void; + else if (!strcasecmp(input, "endpara")) + s->func = do_para_end_void; +#endif +#ifdef ENABLE_COMMENT + else if (!strcasecmp(input, "comment")) + s->func = do_comment; +#endif +#ifdef ENABLE_WORDCOMPLETION + else if (!strcasecmp(input, "complete")) + s->func = complete_a_word; +#endif +#ifndef NANO_TINY + else if (!strcasecmp(input, "indent")) + s->func = do_indent; + else if (!strcasecmp(input, "unindent")) + s->func = do_unindent; + else if (!strcasecmp(input, "chopwordleft") || + !strcasecmp(input, "cutwordleft")) /* Deprecated; remove in 2021. */ + s->func = chop_previous_word; + else if (!strcasecmp(input, "chopwordright") || + !strcasecmp(input, "cutwordright")) /* Deprecated; remove in 2021. */ + s->func = chop_next_word; + else if (!strcasecmp(input, "findbracket")) + s->func = do_find_bracket; + else if (!strcasecmp(input, "wordcount")) + s->func = do_wordlinechar_count; + else if (!strcasecmp(input, "recordmacro")) + s->func = record_macro; + else if (!strcasecmp(input, "runmacro")) + s->func = run_macro; + else if (!strcasecmp(input, "undo")) + s->func = do_undo; + else if (!strcasecmp(input, "redo")) + s->func = do_redo; +#endif + else if (!strcasecmp(input, "left") || + !strcasecmp(input, "back")) + s->func = do_left; + else if (!strcasecmp(input, "right") || + !strcasecmp(input, "forward")) + s->func = do_right; + else if (!strcasecmp(input, "up") || + !strcasecmp(input, "prevline")) + s->func = do_up; + else if (!strcasecmp(input, "down") || + !strcasecmp(input, "nextline")) + s->func = do_down; +#if !defined(NANO_TINY) || defined(ENABLE_HELP) + else if (!strcasecmp(input, "scrollup")) + s->func = do_scroll_up; + else if (!strcasecmp(input, "scrolldown")) + s->func = do_scroll_down; +#endif + else if (!strcasecmp(input, "prevword")) + s->func = do_prev_word_void; + else if (!strcasecmp(input, "nextword")) + s->func = do_next_word_void; + else if (!strcasecmp(input, "home")) + s->func = do_home; + else if (!strcasecmp(input, "end")) + s->func = do_end; + else if (!strcasecmp(input, "prevblock")) + s->func = do_prev_block; + else if (!strcasecmp(input, "nextblock")) + s->func = do_next_block; + else if (!strcasecmp(input, "pageup") || + !strcasecmp(input, "prevpage")) + s->func = do_page_up; + else if (!strcasecmp(input, "pagedown") || + !strcasecmp(input, "nextpage")) + s->func = do_page_down; + else if (!strcasecmp(input, "firstline")) + s->func = to_first_line; + else if (!strcasecmp(input, "lastline")) + s->func = to_last_line; +#ifdef ENABLE_MULTIBUFFER + else if (!strcasecmp(input, "prevbuf")) + s->func = switch_to_prev_buffer; + else if (!strcasecmp(input, "nextbuf")) + s->func = switch_to_next_buffer; +#endif + else if (!strcasecmp(input, "verbatim")) + s->func = do_verbatim_input; + else if (!strcasecmp(input, "tab")) + s->func = do_tab; + else if (!strcasecmp(input, "enter")) + s->func = do_enter; + else if (!strcasecmp(input, "delete")) + s->func = do_delete; + else if (!strcasecmp(input, "backspace")) + s->func = do_backspace; + else if (!strcasecmp(input, "refresh")) + s->func = total_refresh; + else if (!strcasecmp(input, "suspend")) + s->func = do_suspend_void; + else if (!strcasecmp(input, "casesens")) + s->func = case_sens_void; + else if (!strcasecmp(input, "regexp")) + s->func = regexp_void; + else if (!strcasecmp(input, "backwards")) + s->func = backwards_void; + else if (!strcasecmp(input, "flipreplace")) + s->func = flip_replace; + else if (!strcasecmp(input, "flipgoto")) + s->func = flip_goto; +#ifdef ENABLE_HISTORIES + else if (!strcasecmp(input, "older")) + s->func = get_history_older_void; + else if (!strcasecmp(input, "newer")) + s->func = get_history_newer_void; +#endif +#ifndef NANO_TINY + else if (!strcasecmp(input, "dosformat")) + s->func = dos_format_void; + else if (!strcasecmp(input, "macformat")) + s->func = mac_format_void; + else if (!strcasecmp(input, "append")) + s->func = append_void; + else if (!strcasecmp(input, "prepend")) + s->func = prepend_void; + else if (!strcasecmp(input, "backup")) + s->func = backup_file_void; + else if (!strcasecmp(input, "flipexecute")) + s->func = flip_execute; + else if (!strcasecmp(input, "flippipe")) + s->func = flip_pipe; + else if (!strcasecmp(input, "flipconvert")) + s->func = flip_convert; +#endif +#ifdef ENABLE_MULTIBUFFER + else if (!strcasecmp(input, "flipnewbuffer")) + s->func = flip_newbuffer; +#endif +#ifdef ENABLE_BROWSER + else if (!strcasecmp(input, "tofiles") || + !strcasecmp(input, "browser")) + s->func = to_files_void; + else if (!strcasecmp(input, "gotodir")) + s->func = goto_dir_void; + else if (!strcasecmp(input, "firstfile")) + s->func = to_first_file; + else if (!strcasecmp(input, "lastfile")) + s->func = to_last_file; +#endif + else { +#ifndef NANO_TINY + s->func = do_toggle_void; + if (!strcasecmp(input, "nohelp")) + s->toggle = NO_HELP; + else if (!strcasecmp(input, "constantshow")) + s->toggle = CONSTANT_SHOW; + else if (!strcasecmp(input, "softwrap")) + s->toggle = SOFTWRAP; +#ifdef ENABLE_LINENUMBERS + else if (!strcasecmp(input, "linenumbers")) + s->toggle = LINE_NUMBERS; +#endif + else if (!strcasecmp(input, "whitespacedisplay")) + s->toggle = WHITESPACE_DISPLAY; +#ifdef ENABLE_COLOR + else if (!strcasecmp(input, "nosyntax")) + s->toggle = NO_COLOR_SYNTAX; +#endif + else if (!strcasecmp(input, "smarthome")) + s->toggle = SMART_HOME; + else if (!strcasecmp(input, "autoindent")) + s->toggle = AUTOINDENT; + else if (!strcasecmp(input, "cutfromcursor")) + s->toggle = CUT_FROM_CURSOR; +#ifdef ENABLE_WRAPPING + else if (!strcasecmp(input, "nowrap")) + s->toggle = BREAK_LONG_LINES; +#endif + else if (!strcasecmp(input, "tabstospaces")) + s->toggle = TABS_TO_SPACES; +#ifdef ENABLE_MOUSE + else if (!strcasecmp(input, "mouse")) + s->toggle = USE_MOUSE; +#endif + else if (!strcasecmp(input, "suspendenable")) + s->toggle = SUSPEND; + else +#endif /* !NANO_TINY */ + { + free(s); + return NULL; + } + } + return s; +} + +/* Return the symbol that corresponds to the given menu name. */ +int name_to_menu(const char *name) +{ + int index = -1; + + while (++index < NUMBER_OF_MENUS) + if (strcasecmp(name, menunames[index]) == 0) + return menusymbols[index]; + + return -1; +} + +/* Return the name that corresponds to the given menu symbol. */ +char *menu_to_name(int menu) +{ + int index = -1; + + while (++index < NUMBER_OF_MENUS) + if (menusymbols[index] == menu) + return menunames[index]; + + return "boooo"; +} + /* Parse the next word from the string, null-terminate it, and return * a pointer to the first character after the null terminator. The * returned pointer will point to '\0' if we hit the end of the line. */