From: Eli Zaretskii Date: Sat, 16 Jun 2007 18:19:42 +0000 (+0000) Subject: (add_menu_item): Escape `&' characters in menu items and their keybindings. X-Git-Tag: emacs-pretest-22.1.90~1344 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=96f6c17002cd4b4fb6649ed1dc592f3328d04922;p=emacs.git (add_menu_item): Escape `&' characters in menu items and their keybindings. --- diff --git a/src/ChangeLog b/src/ChangeLog index e4b578d8de8..3d303ac3c5f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-06-16 Eli Zaretskii + + * w32menu.c (add_menu_item): Escape `&' characters in menu items + and their keybindings. + 2007-06-14 Chong Yidong * composite.c (update_compositions): Check validity of compositions. diff --git a/src/w32menu.c b/src/w32menu.c index ba29c6ae433..bcd56c8c88e 100644 --- a/src/w32menu.c +++ b/src/w32menu.c @@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA. */ #include #include +#include #include "lisp.h" #include "termhooks.h" #include "keyboard.h" @@ -2261,8 +2262,9 @@ static int add_menu_item (HMENU menu, widget_value *wv, HMENU item) { UINT fuFlags; - char *out_string; + char *out_string, *p, *q; int return_value; + size_t nlen, orig_len; if (name_is_separator (wv->name)) { @@ -2286,6 +2288,33 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item) else out_string = wv->name; + /* Quote any special characters within the menu item's text and + key binding. */ + nlen = orig_len = strlen (out_string); + for (p = out_string; *p; p = _mbsinc (p)) + { + if (_mbsnextc (p) == '&') + nlen++; + } + if (nlen > orig_len) + { + p = out_string; + out_string = alloca (nlen + 1); + q = out_string; + while (*p) + { + if (_mbsnextc (p) == '&') + { + _mbsncpy (q, p, 1); + q = _mbsinc (q); + } + _mbsncpy (q, p, 1); + p = _mbsinc (p); + q = _mbsinc (q); + } + *q = '\0'; + } + if (item != NULL) fuFlags = MF_POPUP; else if (wv->title || wv->call_data == 0)