aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/menu.c')
-rw-r--r--src/menu.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/menu.c b/src/menu.c
index 66247c713a2..61163ae0216 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -354,7 +354,7 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
354 front of them. */ 354 front of them. */
355 if (!have_boxes ()) 355 if (!have_boxes ())
356 { 356 {
357 Lisp_Object prefix = Qnil; 357 char const *prefix = 0;
358 Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE); 358 Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE);
359 if (!NILP (type)) 359 if (!NILP (type))
360 { 360 {
@@ -389,8 +389,11 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
389 { 389 {
390 if (!submenu && SREF (tem, 0) != '\0' 390 if (!submenu && SREF (tem, 0) != '\0'
391 && SREF (tem, 0) != '-') 391 && SREF (tem, 0) != '-')
392 ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME, 392 {
393 concat2 (build_string (" "), tem)); 393 AUTO_STRING (spaces, " ");
394 ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME,
395 concat2 (spaces, tem));
396 }
394 idx += MENU_ITEMS_ITEM_LENGTH; 397 idx += MENU_ITEMS_ITEM_LENGTH;
395 } 398 }
396 } 399 }
@@ -399,24 +402,30 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
399 402
400 /* Calculate prefix, if any, for this item. */ 403 /* Calculate prefix, if any, for this item. */
401 if (EQ (type, QCtoggle)) 404 if (EQ (type, QCtoggle))
402 prefix = build_string (NILP (selected) ? "[ ] " : "[X] "); 405 prefix = NILP (selected) ? "[ ] " : "[X] ";
403 else if (EQ (type, QCradio)) 406 else if (EQ (type, QCradio))
404 prefix = build_string (NILP (selected) ? "( ) " : "(*) "); 407 prefix = NILP (selected) ? "( ) " : "(*) ";
405 } 408 }
406 /* Not a button. If we have earlier buttons, then we need a prefix. */ 409 /* Not a button. If we have earlier buttons, then we need a prefix. */
407 else if (!skp->notbuttons && SREF (item_string, 0) != '\0' 410 else if (!skp->notbuttons && SREF (item_string, 0) != '\0'
408 && SREF (item_string, 0) != '-') 411 && SREF (item_string, 0) != '-')
409 prefix = build_string (" "); 412 prefix = " ";
410 413
411 if (!NILP (prefix)) 414 if (prefix)
412 item_string = concat2 (prefix, item_string); 415 {
416 AUTO_STRING (prefix_obj, prefix);
417 item_string = concat2 (prefix_obj, item_string);
418 }
413 } 419 }
414 420
415 if ((FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame)) 421 if ((FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame))
416 || FRAME_MSDOS_P (XFRAME (Vmenu_updating_frame))) 422 || FRAME_MSDOS_P (XFRAME (Vmenu_updating_frame)))
417 && !NILP (map)) 423 && !NILP (map))
418 /* Indicate visually that this is a submenu. */ 424 /* Indicate visually that this is a submenu. */
419 item_string = concat2 (item_string, build_string (" >")); 425 {
426 AUTO_STRING (space_gt, " >");
427 item_string = concat2 (item_string, space_gt);
428 }
420 429
421 push_menu_item (item_string, enabled, key, 430 push_menu_item (item_string, enabled, key,
422 AREF (item_properties, ITEM_PROPERTY_DEF), 431 AREF (item_properties, ITEM_PROPERTY_DEF),
@@ -632,8 +641,9 @@ digest_single_submenu (int start, int end, bool top_level_items)
632 widget_value **submenu_stack; 641 widget_value **submenu_stack;
633 bool panes_seen = 0; 642 bool panes_seen = 0;
634 struct frame *f = XFRAME (Vmenu_updating_frame); 643 struct frame *f = XFRAME (Vmenu_updating_frame);
644 USE_SAFE_ALLOCA;
635 645
636 submenu_stack = alloca (menu_items_used * sizeof *submenu_stack); 646 SAFE_NALLOCA (submenu_stack, 1, menu_items_used);
637 wv = make_widget_value ("menu", NULL, true, Qnil); 647 wv = make_widget_value ("menu", NULL, true, Qnil);
638 wv->button_type = BUTTON_TYPE_NONE; 648 wv->button_type = BUTTON_TYPE_NONE;
639 first_wv = wv; 649 first_wv = wv;
@@ -835,11 +845,12 @@ digest_single_submenu (int start, int end, bool top_level_items)
835 that was originally a button, return it by itself. */ 845 that was originally a button, return it by itself. */
836 if (top_level_items && first_wv->contents && first_wv->contents->next == 0) 846 if (top_level_items && first_wv->contents && first_wv->contents->next == 0)
837 { 847 {
838 wv = first_wv->contents; 848 wv = first_wv;
839 xfree (first_wv); 849 first_wv = first_wv->contents;
840 return wv; 850 xfree (wv);
841 } 851 }
842 852
853 SAFE_FREE ();
843 return first_wv; 854 return first_wv;
844} 855}
845 856
@@ -890,9 +901,10 @@ find_and_call_menu_selection (struct frame *f, int menu_bar_items_used,
890 Lisp_Object *subprefix_stack; 901 Lisp_Object *subprefix_stack;
891 int submenu_depth = 0; 902 int submenu_depth = 0;
892 int i; 903 int i;
904 USE_SAFE_ALLOCA;
893 905
894 entry = Qnil; 906 entry = Qnil;
895 subprefix_stack = alloca (menu_bar_items_used * sizeof *subprefix_stack); 907 SAFE_NALLOCA (subprefix_stack, 1, menu_bar_items_used);
896 prefix = Qnil; 908 prefix = Qnil;
897 i = 0; 909 i = 0;
898 910
@@ -954,11 +966,13 @@ find_and_call_menu_selection (struct frame *f, int menu_bar_items_used,
954 buf.arg = entry; 966 buf.arg = entry;
955 kbd_buffer_store_event (&buf); 967 kbd_buffer_store_event (&buf);
956 968
957 return; 969 break;
958 } 970 }
959 i += MENU_ITEMS_ITEM_LENGTH; 971 i += MENU_ITEMS_ITEM_LENGTH;
960 } 972 }
961 } 973 }
974
975 SAFE_FREE ();
962} 976}
963 977
964#endif /* USE_X_TOOLKIT || USE_GTK || HAVE_NS || HAVE_NTGUI */ 978#endif /* USE_X_TOOLKIT || USE_GTK || HAVE_NS || HAVE_NTGUI */
@@ -973,10 +987,11 @@ find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data
973 int i; 987 int i;
974 Lisp_Object *subprefix_stack; 988 Lisp_Object *subprefix_stack;
975 int submenu_depth = 0; 989 int submenu_depth = 0;
990 USE_SAFE_ALLOCA;
976 991
977 prefix = entry = Qnil; 992 prefix = entry = Qnil;
978 i = 0; 993 i = 0;
979 subprefix_stack = alloca (menu_items_used * word_size); 994 SAFE_ALLOCA_LISP (subprefix_stack, menu_items_used);
980 995
981 while (i < menu_items_used) 996 while (i < menu_items_used)
982 { 997 {
@@ -1018,11 +1033,13 @@ find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data
1018 if (!NILP (subprefix_stack[j])) 1033 if (!NILP (subprefix_stack[j]))
1019 entry = Fcons (subprefix_stack[j], entry); 1034 entry = Fcons (subprefix_stack[j], entry);
1020 } 1035 }
1036 SAFE_FREE ();
1021 return entry; 1037 return entry;
1022 } 1038 }
1023 i += MENU_ITEMS_ITEM_LENGTH; 1039 i += MENU_ITEMS_ITEM_LENGTH;
1024 } 1040 }
1025 } 1041 }
1042 SAFE_FREE ();
1026 return Qnil; 1043 return Qnil;
1027} 1044}
1028#endif /* HAVE_NS */ 1045#endif /* HAVE_NS */