* buffer.c (Qclone_number): Remove for now, as it's unused.
[bpt/emacs.git] / src / menu.c
index 05a296e..fa31c8a 100644 (file)
@@ -1,6 +1,7 @@
 /* Platform-independent code for terminal communications.
-   Copyright (C) 1986, 1988, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+Copyright (C) 1986, 1988, 1993-1994, 1996, 1999-2011
+  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -20,6 +21,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include <limits.h> /* for INT_MAX */
 
 #include "lisp.h"
 #include "keyboard.h"
@@ -65,6 +67,9 @@ Lisp_Object menu_items;
 
 /* If non-nil, means that the global vars defined here are already in use.
    Used to detect cases where we try to re-enter this non-reentrant code.  */
+#if ! (defined USE_GTK || defined USE_MOTIF)
+static
+#endif
 Lisp_Object menu_items_inuse;
 
 /* Number of slots currently allocated in menu_items.  */
@@ -175,10 +180,15 @@ save_menu_items (void)
 static void
 grow_menu_items (void)
 {
+  if ((INT_MAX - MENU_ITEMS_PANE_LENGTH) / 2 < menu_items_allocated)
+    memory_full (SIZE_MAX);
   menu_items_allocated *= 2;
   menu_items = larger_vector (menu_items, menu_items_allocated, Qnil);
 }
 
+#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \
+     || defined HAVE_NTGUI)
+
 /* Begin a submenu.  */
 
 static void
@@ -203,6 +213,8 @@ push_submenu_end (void)
   menu_items_submenu_depth--;
 }
 
+#endif /* USE_X_TOOLKIT || USE_GTK || HAVE_NS || defined HAVE_NTGUI */
+
 /* Indicate boundary between left and right.  */
 
 static void
@@ -367,34 +379,34 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
        if (skp->notbuttons)
          /* The first button. Line up previous items in this menu.  */
          {
-           int index = skp->notbuttons; /* Index for first item this menu.  */
+           int idx = skp->notbuttons; /* Index for first item this menu.  */
            int submenu = 0;
            Lisp_Object tem;
-           while (index < menu_items_used)
+           while (idx < menu_items_used)
              {
                tem
-                 = XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME];
+                 = XVECTOR (menu_items)->contents[idx + MENU_ITEMS_ITEM_NAME];
                if (NILP (tem))
                  {
-                   index++;
+                   idx++;
                    submenu++;          /* Skip sub menu.  */
                  }
                else if (EQ (tem, Qlambda))
                  {
-                   index++;
+                   idx++;
                    submenu--;          /* End sub menu.  */
                  }
                else if (EQ (tem, Qt))
-                 index += 3;           /* Skip new pane marker. */
+                 idx += 3;             /* Skip new pane marker. */
                else if (EQ (tem, Qquote))
-                 index++;              /* Skip a left, right divider. */
+                 idx++;                /* Skip a left, right divider. */
                else
                  {
                    if (!submenu && SREF (tem, 0) != '\0'
                        && SREF (tem, 0) != '-')
-                     XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME]
+                     XVECTOR (menu_items)->contents[idx + MENU_ITEMS_ITEM_NAME]
                        = concat2 (build_string ("    "), tem);
-                   index += MENU_ITEMS_ITEM_LENGTH;
+                   idx += MENU_ITEMS_ITEM_LENGTH;
                  }
              }
            skp->notbuttons = 0;
@@ -661,13 +673,12 @@ digest_single_submenu (int start, int end, int top_level_items)
       else if (EQ (XVECTOR (menu_items)->contents[i], Qt))
        {
          /* Create a new pane.  */
-         Lisp_Object pane_name, prefix;
+         Lisp_Object pane_name;
          const char *pane_string;
 
          panes_seen++;
 
          pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME];
-         prefix = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX];
 
 #ifdef HAVE_NTGUI
          if (STRINGP (pane_name))
@@ -695,7 +706,7 @@ digest_single_submenu (int start, int end, int top_level_items)
 #endif
 
          pane_string = (NILP (pane_name)
-                        ? "" : (char *) SDATA (pane_name));
+                        ? "" : SSDATA (pane_name));
          /* If there is just one top-level pane, put all its items directly
             under the top-level menu.  */
          if (menu_items_n_panes == 1)
@@ -795,9 +806,9 @@ digest_single_submenu (int start, int end, int top_level_items)
          if (!NILP (descrip))
            wv->lkey = descrip;
          wv->value = 0;
-         /* The EMACS_INT cast avoids a warning.  There's no problem
+         /* The intptr_t cast avoids a warning.  There's no problem
             as long as pointers have enough bits to hold small integers.  */
-         wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0);
+         wv->call_data = (!NILP (def) ? (void *) (intptr_t) i : 0);
          wv->enabled = !NILP (enable);
 
          if (NILP (type))
@@ -847,7 +858,7 @@ update_submenu_strings (widget_value *first_wv)
     {
       if (STRINGP (wv->lname))
         {
-          wv->name = (char *) SDATA (wv->lname);
+          wv->name = SSDATA (wv->lname);
 
           /* Ignore the @ that means "separate pane".
              This is a kludge, but this isn't worth more time.  */
@@ -860,7 +871,7 @@ update_submenu_strings (widget_value *first_wv)
         }
 
       if (STRINGP (wv->lkey))
-        wv->key = (char *) SDATA (wv->lkey);
+        wv->key = SSDATA (wv->lkey);
 
       if (wv->contents)
         update_submenu_strings (wv->contents);
@@ -906,9 +917,9 @@ find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object
       else
        {
          entry = XVECTOR (vector)->contents[i + MENU_ITEMS_ITEM_VALUE];
-         /* The EMACS_INT cast avoids a warning.  There's no problem
+         /* Treat the pointer as an integer.  There's no problem
             as long as pointers have enough bits to hold small integers.  */
-         if ((int) (EMACS_INT) client_data == i)
+         if ((intptr_t) client_data == i)
            {
              int j;
              struct input_event buf;
@@ -1140,13 +1151,13 @@ no quit occurs and `x-popup-menu' returns nil.  */)
 #else /* not HAVE_X_WINDOWS */
        Lisp_Object bar_window;
        enum scroll_bar_part part;
-       unsigned long time;
+       Time time;
         void (*mouse_position_hook) (struct frame **, int,
                                      Lisp_Object *,
                                      enum scroll_bar_part *,
                                      Lisp_Object *,
                                      Lisp_Object *,
-                                     unsigned long *) =
+                                     Time *) =
          FRAME_TERMINAL (new_f)->mouse_position_hook;
 
        if (mouse_position_hook)
@@ -1340,7 +1351,7 @@ no quit occurs and `x-popup-menu' returns nil.  */)
 
   UNGCPRO;
 
-  if (error_name) error (error_name);
+  if (error_name) error ("%s", error_name);
   return selection;
 }
 
@@ -1353,6 +1364,3 @@ syms_of_menu (void)
 
   defsubr (&Sx_popup_menu);
 }
-
-/* arch-tag: 78bbc7cf-8025-4156-aa8a-6c7fd99bf51d
-   (do not change this comment) */