tweaks: move the arrays of menu names and symbols to where they are used

Also, use a better return value for the "unrecognized name" case,
so that it cannot possibly be confused with the "all menus" case.
This commit is contained in:
Benno Schulenberg 2022-08-31 17:28:09 +02:00
parent 3925c137a4
commit 41b89aef8c

View File

@ -153,18 +153,6 @@ static bool seen_color_command = FALSE;
static colortype *lastcolor = NULL; static colortype *lastcolor = NULL;
/* The end of the color list for the current syntax. */ /* The end of the color list for the current syntax. */
#endif #endif
#define NUMBER_OF_MENUS 16
char *menunames[NUMBER_OF_MENUS] = { "main", "search", "replace", "replacewith",
"yesno", "gotoline", "writeout", "insert",
"execute", "help", "spell", "linter",
"browser", "whereisfile", "gotodir",
"all" };
int menusymbols[NUMBER_OF_MENUS] = { MMAIN, MWHEREIS, MREPLACE, MREPLACEWITH,
MYESNO, MGOTOLINE, MWRITEFILE, MINSERTFILE,
MEXECUTE, MHELP, MSPELL, MLINTER,
MBROWSER, MWHEREISFILE, MGOTODIR,
MMOST|MBROWSER|MHELP|MYESNO };
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
#if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES) #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES)
@ -495,6 +483,18 @@ keystruct *strtosc(const char *input)
return s; return s;
} }
#define NUMBER_OF_MENUS 16
char *menunames[NUMBER_OF_MENUS] = { "main", "search", "replace", "replacewith",
"yesno", "gotoline", "writeout", "insert",
"execute", "help", "spell", "linter",
"browser", "whereisfile", "gotodir",
"all" };
int menusymbols[NUMBER_OF_MENUS] = { MMAIN, MWHEREIS, MREPLACE, MREPLACEWITH,
MYESNO, MGOTOLINE, MWRITEFILE, MINSERTFILE,
MEXECUTE, MHELP, MSPELL, MLINTER,
MBROWSER, MWHEREISFILE, MGOTODIR,
MMOST|MBROWSER|MHELP|MYESNO };
/* Return the symbol that corresponds to the given menu name. */ /* Return the symbol that corresponds to the given menu name. */
int name_to_menu(const char *name) int name_to_menu(const char *name)
{ {
@ -504,7 +504,7 @@ int name_to_menu(const char *name)
if (strcmp(name, menunames[index]) == 0) if (strcmp(name, menunames[index]) == 0)
return menusymbols[index]; return menusymbols[index];
return -1; return 0;
} }
/* Return the name that corresponds to the given menu symbol. */ /* Return the name that corresponds to the given menu symbol. */
@ -788,7 +788,7 @@ void parse_binding(char *ptr, bool dobind)
} }
menu = name_to_menu(menuptr); menu = name_to_menu(menuptr);
if (menu < 1) { if (menu == 0) {
jot_error(N_("Unknown menu: %s"), menuptr); jot_error(N_("Unknown menu: %s"), menuptr);
goto free_things; goto free_things;
} }