From dc079bdf31c2e7e08fab4ed7ea7d1a1b8a887fd5 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 6 Aug 2018 21:12:22 +0200 Subject: [PATCH] tweaks: implement the name-to-menu function in another manner Use arrays, to make it easy to also implement the reverse function. --- src/global.c | 58 +++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/src/global.c b/src/global.c index 6e81e3ea..25b5b4da 100644 --- a/src/global.c +++ b/src/global.c @@ -239,7 +239,20 @@ char *homedir = NULL; /* The user's home directory, from $HOME or /etc/passwd. */ 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|MHELP|MYESNO }; + char *rcfile_with_errors = NULL; /* The first nanorc file, if any, that produced warnings. */ #endif @@ -1689,45 +1702,12 @@ sc *strtosc(const char *input) /* Interpret a menu name and return the corresponding menu flag. */ int strtomenu(const char *input) { - if (!strcasecmp(input, "all")) - return (MMOST|MHELP|MYESNO); - else if (!strcasecmp(input, "main")) - return MMAIN; - else if (!strcasecmp(input, "search")) - return MWHEREIS; - else if (!strcasecmp(input, "replace")) - return MREPLACE; - else if (!strcasecmp(input, "replacewith")) - return MREPLACEWITH; - else if (!strcasecmp(input, "yesno")) - return MYESNO; - else if (!strcasecmp(input, "gotoline")) - return MGOTOLINE; - else if (!strcasecmp(input, "writeout")) - return MWRITEFILE; - else if (!strcasecmp(input, "insert")) - return MINSERTFILE; - else if (!strcasecmp(input, "externalcmd") || - !strcasecmp(input, "extcmd")) - return MEXTCMD; -#ifdef ENABLE_HELP - else if (!strcasecmp(input, "help")) - return MHELP; -#endif -#ifdef ENABLE_SPELLER - else if (!strcasecmp(input, "spell")) - return MSPELL; -#endif - else if (!strcasecmp(input, "linter")) - return MLINTER; -#ifdef ENABLE_BROWSER - else if (!strcasecmp(input, "browser")) - return MBROWSER; - else if (!strcasecmp(input, "whereisfile")) - return MWHEREISFILE; - else if (!strcasecmp(input, "gotodir")) - return MGOTODIR; -#endif + int index = -1; + + while (++index < NUMBER_OF_MENUS) + if (strcasecmp(input, menunames[index]) == 0) + return menusymbols[index]; + return -1; } #endif /* ENABLE_NANORC */