Add vc-annotate-goto-line.
[bpt/emacs.git] / lwlib / lwlib.c
index bee47aa..9d8ec33 100644 (file)
@@ -1,7 +1,7 @@
 /* A general interface to the widgets of different toolkits.
+
 Copyright (C) 1992, 1993 Lucid, Inc.
-Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003, 2004,
-  2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+Copyright (C) 1994-1996, 1999-2011  Free Software Foundation, Inc.
 
 This file is part of the Lucid Widget Library.
 
@@ -25,7 +25,7 @@ Boston, MA 02110-1301, USA.  */
 #endif
 
 #include <setjmp.h>
-#include "../src/lisp.h"
+#include <lisp.h>
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -66,21 +66,21 @@ static widget_info*
 all_widget_info = NULL;
 
 #ifdef USE_MOTIF
-char *lwlib_toolkit_type = "motif";
+const char *lwlib_toolkit_type = "motif";
 #else
-char *lwlib_toolkit_type = "lucid";
+const char *lwlib_toolkit_type = "lucid";
 #endif
 
 static widget_value *merge_widget_value (widget_value *,
                                          widget_value *,
                                          int, int *);
 static void instantiate_widget_instance (widget_instance *);
-static int my_strcasecmp (char *, char *);
+static int my_strcasecmp (const char *, const char *);
 static void safe_free_str (char *);
 static void free_widget_value_tree (widget_value *);
 static widget_value *copy_widget_value_tree (widget_value *,
                                              change_type);
-static widget_info *allocate_widget_info (char *, char *, LWLIB_ID,
+static widget_info *allocate_widget_info (const char *, const char *, LWLIB_ID,
                                           widget_value *,
                                           lw_callback, lw_callback,
                                           lw_callback, lw_callback);
@@ -92,14 +92,14 @@ static void free_widget_instance (widget_instance *);
 static widget_info *get_widget_info (LWLIB_ID, Boolean);
 static widget_instance *get_widget_instance (Widget, Boolean);
 static widget_instance *find_instance (LWLIB_ID, Widget, Boolean);
-static Boolean safe_strcmp (char *, char *);
-static Widget name_to_widget (widget_instance *, char *);
+static Boolean safe_strcmp (const char *, const char *);
+static Widget name_to_widget (widget_instance *, const char *);
 static void set_one_value (widget_instance *, widget_value *, Boolean);
 static void update_one_widget_instance (widget_instance *, Boolean);
 static void update_all_widget_values (widget_info *, Boolean);
 static void initialize_widget_instance (widget_instance *);
-static widget_creation_function find_in_table (char *, widget_creation_entry *);
-static Boolean dialog_spec_p (char *);
+static widget_creation_function find_in_table (const char *, const widget_creation_entry *);
+static Boolean dialog_spec_p (const char *);
 static void destroy_one_instance (widget_instance *);
 static void lw_pop_all_widgets (LWLIB_ID, Boolean);
 static Boolean get_one_value (widget_instance *, widget_value *);
@@ -110,9 +110,7 @@ safe_strdup (const char *s)
 {
   char *result;
   if (! s) return 0;
-  result = (char *) malloc (strlen (s) + 1);
-  if (! result)
-    return 0;
+  result = (char *) xmalloc (strlen (s) + 1);
   strcpy (result, s);
   return result;
 }
@@ -120,7 +118,7 @@ safe_strdup (const char *s)
 /* Like strcmp but ignore differences in case.  */
 
 static int
-my_strcasecmp (char *s1, char *s2)
+my_strcasecmp (const char *s1, const char *s2)
 {
   while (1)
     {
@@ -158,7 +156,7 @@ malloc_widget_value (void)
     }
   else
     {
-      wv = (widget_value *) malloc (sizeof (widget_value));
+      wv = (widget_value *) xmalloc (sizeof (widget_value));
       malloc_cpt++;
     }
   memset ((void*) wv, 0, sizeof (widget_value));
@@ -249,18 +247,16 @@ copy_widget_value_tree (widget_value *val, change_type change)
 }
 
 static widget_info *
-allocate_widget_info (type, name, id, val, pre_activate_cb,
-                     selection_cb, post_activate_cb, highlight_cb)
-     char* type;
-     char* name;
-     LWLIB_ID id;
-     widget_value* val;
-     lw_callback pre_activate_cb;
-     lw_callback selection_cb;
-     lw_callback post_activate_cb;
-     lw_callback highlight_cb;
+allocate_widget_info (const char* type,
+                      const char* name,
+                      LWLIB_ID id,
+                      widget_value* val,
+                      lw_callback pre_activate_cb,
+                      lw_callback selection_cb,
+                      lw_callback post_activate_cb,
+                      lw_callback highlight_cb)
 {
-  widget_info* info = (widget_info*)malloc (sizeof (widget_info));
+  widget_info* info = (widget_info*) xmalloc (sizeof (widget_info));
   info->type = safe_strdup (type);
   info->name = safe_strdup (name);
   info->id = id;
@@ -298,21 +294,11 @@ mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data)
     instance->widget = NULL;
 }
 
-/* The messy #ifdef PROTOTYPES here and elsewhere are prompted by a
-   flood of warnings about argument promotion from proprietary ISO C
-   compilers.  (etags still only makes one entry for each function.)  */
 static widget_instance *
-#ifdef PROTOTYPES
 allocate_widget_instance (widget_info* info, Widget parent, Boolean pop_up_p)
-#else
-allocate_widget_instance (info, parent, pop_up_p)
-     widget_info* info;
-     Widget parent;
-     Boolean pop_up_p;
-#endif
 {
   widget_instance* instance =
-    (widget_instance*)malloc (sizeof (widget_instance));
+    (widget_instance*) xmalloc (sizeof (widget_instance));
   memset (instance, 0, sizeof *instance);
   instance->parent = parent;
   instance->pop_up_p = pop_up_p;
@@ -335,13 +321,7 @@ free_widget_instance (widget_instance *instance)
 }
 
 static widget_info *
-#ifdef PROTOTYPES
 get_widget_info (LWLIB_ID id, Boolean remove_p)
-#else
-get_widget_info (id, remove_p)
-     LWLIB_ID id;
-     Boolean remove_p;
-#endif
 {
   widget_info* info;
   widget_info* prev;
@@ -371,13 +351,7 @@ lw_get_widget_info (LWLIB_ID id)
 }
 
 static widget_instance *
-#ifdef PROTOTYPES
 get_widget_instance (Widget widget, Boolean remove_p)
-#else
-get_widget_instance (widget, remove_p)
-     Widget widget;
-     Boolean remove_p;
-#endif
 {
   widget_info* info;
   widget_instance* instance;
@@ -410,14 +384,7 @@ lw_get_widget_instance (Widget widget)
 }
 
 static widget_instance*
-#ifdef PROTOTYPES
 find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p)
-#else
-find_instance (id, parent, pop_up_p)
-     LWLIB_ID id;
-     Widget parent;
-     Boolean pop_up_p;
-#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_instance* instance;
@@ -433,7 +400,7 @@ find_instance (id, parent, pop_up_p)
 \f
 /* utility function for widget_value */
 static Boolean
-safe_strcmp (char *s1, char *s2)
+safe_strcmp (const char *s1, const char *s2)
 {
   if (!!s1 ^ !!s2) return True;
   return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
@@ -455,12 +422,15 @@ safe_strcmp (char *s1, char *s2)
              (nc == STRUCTURAL_CHANGE ? "structural" : "???")))),      \
           nc, desc, a1, a2)
 #else
-# define EXPLAIN(name, oc, nc, desc, a1, a2)
+# define EXPLAIN(name, oc, nc, desc, a1, a2) ((void) 0)
 #endif
 
 
 static widget_value *
-merge_widget_value (widget_value *val1, widget_value *val2, int level, int *change_p)
+merge_widget_value (widget_value *val1,
+                    widget_value *val2,
+                    int level,
+                    int *change_p)
 {
   change_type change, this_one_change;
   widget_value* merged_next;
@@ -614,7 +584,7 @@ merge_widget_value (widget_value *val1, widget_value *val2, int level, int *chan
 \f
 /* modifying the widgets */
 static Widget
-name_to_widget (widget_instance *instance, char *name)
+name_to_widget (widget_instance *instance, const char *name)
 {
   Widget widget = NULL;
 
@@ -638,14 +608,7 @@ name_to_widget (widget_instance *instance, char *name)
 }
 
 static void
-#ifdef PROTOTYPES
 set_one_value (widget_instance* instance, widget_value* val, Boolean deep_p)
-#else
-set_one_value (instance, val, deep_p)
-     widget_instance* instance;
-     widget_value* val;
-     Boolean deep_p;
-#endif
 {
   Widget widget = name_to_widget (instance, val->name);
 
@@ -667,13 +630,7 @@ set_one_value (instance, val, deep_p)
 }
 
 static void
-#ifdef PROTOTYPES
 update_one_widget_instance (widget_instance* instance, Boolean deep_p)
-#else
-update_one_widget_instance (instance, deep_p)
-     widget_instance* instance;
-     Boolean deep_p;
-#endif
 {
   widget_value *val;
 
@@ -687,13 +644,7 @@ update_one_widget_instance (instance, deep_p)
 }
 
 static void
-#ifdef PROTOTYPES
 update_all_widget_values (widget_info* info, Boolean deep_p)
-#else
-update_all_widget_values (info, deep_p)
-     widget_info* info;
-     Boolean deep_p;
-#endif
 {
   widget_instance* instance;
   widget_value* val;
@@ -706,14 +657,7 @@ update_all_widget_values (info, deep_p)
 }
 
 int
-#ifdef PROTOTYPES
 lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
-#else
-lw_modify_all_widgets (id, val, deep_p)
-     LWLIB_ID id;
-     widget_value* val;
-     Boolean deep_p;
-#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_value* new_val;
@@ -783,9 +727,9 @@ initialize_widget_instance (widget_instance *instance)
 
 
 static widget_creation_function
-find_in_table (char *type, widget_creation_entry *table)
+find_in_table (const char *type, const widget_creation_entry *table)
 {
-  widget_creation_entry* cur;
+  const widget_creation_entry* cur;
   for (cur = table; cur->type; cur++)
     if (!my_strcasecmp (type, cur->type))
       return cur->function;
@@ -793,7 +737,7 @@ find_in_table (char *type, widget_creation_entry *table)
 }
 
 static Boolean
-dialog_spec_p (char *name)
+dialog_spec_p (const char *name)
 {
   /* return True if name matches [EILPQeilpq][1-9][Bb] or
      [EILPQeilpq][1-9][Bb][Rr][1-9] */
@@ -877,16 +821,14 @@ instantiate_widget_instance (widget_instance *instance)
 }
 
 void
-lw_register_widget (type, name, id, val, pre_activate_cb,
-                   selection_cb, post_activate_cb, highlight_cb)
-     char* type;
-     char* name;
-     LWLIB_ID id;
-     widget_value* val;
-     lw_callback pre_activate_cb;
-     lw_callback selection_cb;
-     lw_callback post_activate_cb;
-     lw_callback highlight_cb;
+lw_register_widget (const char* type,
+                    const char* name,
+                    LWLIB_ID id,
+                    widget_value* val,
+                    lw_callback pre_activate_cb,
+                    lw_callback selection_cb,
+                    lw_callback post_activate_cb,
+                    lw_callback highlight_cb)
 {
   if (!get_widget_info (id, False))
     allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb,
@@ -894,14 +836,7 @@ lw_register_widget (type, name, id, val, pre_activate_cb,
 }
 
 Widget
-#ifdef PROTOTYPES
 lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
-#else
-lw_get_widget (id, parent, pop_up_p)
-     LWLIB_ID id;
-     Widget parent;
-     Boolean pop_up_p;
-#endif
 {
   widget_instance* instance;
 
@@ -910,14 +845,7 @@ lw_get_widget (id, parent, pop_up_p)
 }
 
 Widget
-#ifdef PROTOTYPES
 lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
-#else
-lw_make_widget (id, parent, pop_up_p)
-     LWLIB_ID id;
-     Widget parent;
-     Boolean pop_up_p;
-#endif
 {
   widget_instance* instance;
   widget_info* info;
@@ -937,25 +865,10 @@ lw_make_widget (id, parent, pop_up_p)
 }
 
 Widget
-#ifdef PROTOTYPES
-lw_create_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
+lw_create_widget (const char* type, const char* name, LWLIB_ID id, widget_value* val,
                  Widget parent, Boolean pop_up_p,
                  lw_callback pre_activate_cb, lw_callback selection_cb,
                  lw_callback post_activate_cb, lw_callback highlight_cb)
-#else
-lw_create_widget (type, name, id, val, parent, pop_up_p, pre_activate_cb,
-                 selection_cb, post_activate_cb, highlight_cb)
-     char* type;
-     char* name;
-     LWLIB_ID id;
-     widget_value* val;
-     Widget parent;
-     Boolean pop_up_p;
-     lw_callback pre_activate_cb;
-     lw_callback selection_cb;
-     lw_callback post_activate_cb;
-     lw_callback highlight_cb;
-#endif
 {
   lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb,
                      post_activate_cb, highlight_cb);
@@ -999,8 +912,9 @@ destroy_one_instance (widget_instance *instance)
        xaw_destroy_instance (instance);
       else
 #endif
-       /* do not remove the empty statement */
-       ;
+       {
+         /* Empty compound statement to terminate if-then-else chain.  */
+       }
     }
 
   free_widget_instance (instance);
@@ -1065,7 +979,7 @@ lw_destroy_all_pop_ups (void)
 }
 
 #ifdef USE_MOTIF
-extern Widget first_child (/* Widget */);      /* garbage */
+extern Widget first_child (Widget);    /* garbage */
 #endif
 
 Widget
@@ -1102,13 +1016,7 @@ lw_raise_all_pop_up_widgets (void)
 }
 
 static void
-#ifdef PROTOTYPES
 lw_pop_all_widgets (LWLIB_ID id, Boolean up)
-#else
-lw_pop_all_widgets (id, up)
-     LWLIB_ID id;
-     Boolean up;
-#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_instance* instance;
@@ -1252,7 +1160,9 @@ static Boolean lwlib_updating;
   modified to update other instances of the widgets.  Closure should be the
   widget_instance. */
 void
-lw_internal_update_other_instances (Widget widget, XtPointer closure, XtPointer call_data)
+lw_internal_update_other_instances (Widget widget,
+                                    XtPointer closure,
+                                    XtPointer call_data)
 {
   widget_instance* instance = (widget_instance*)closure;
   char* name = XtName (widget);
@@ -1309,13 +1219,7 @@ lw_set_keyboard_focus (Widget parent, Widget w)
 
 \f/* Show busy */
 static void
-#ifdef PROTOTYPES
 show_one_widget_busy (Widget w, Boolean flag)
-#else
-show_one_widget_busy (w, flag)
-     Widget w;
-     Boolean flag;
-#endif
 {
   Pixel foreground = 0;
   Pixel background = 1;
@@ -1334,13 +1238,7 @@ show_one_widget_busy (w, flag)
 }
 
 void
-#ifdef PROTOTYPES
 lw_show_busy (Widget w, Boolean busy)
-#else
-lw_show_busy (w, busy)
-     Widget w;
-     Boolean busy;
-#endif
 {
   widget_instance* instance = get_widget_instance (w, False);
   widget_info* info;
@@ -1362,13 +1260,7 @@ lw_show_busy (w, busy)
 /* This hack exists because Lucid/Athena need to execute the strange
    function below to support geometry management. */
 void
-#ifdef PROTOTYPES
 lw_refigure_widget (Widget w, Boolean doit)
-#else
-lw_refigure_widget (w, doit)
-     Widget w;
-     Boolean doit;
-#endif
 {
 #if defined (USE_XAW)
   XawPanedSetRefigureMode (w, doit);
@@ -1410,13 +1302,7 @@ lw_set_main_areas (Widget parent, Widget menubar, Widget work_area)
 /* Manage resizing for Motif.  This disables resizing when the menubar
    is about to be modified. */
 void
-#ifdef PROTOTYPES
 lw_allow_resizing (Widget w, Boolean flag)
-#else
-lw_allow_resizing (w, flag)
-     Widget w;
-     Boolean flag;
-#endif
 {
 #if defined (USE_MOTIF)
   xm_manage_resizing (w, flag);
@@ -1430,7 +1316,7 @@ lw_allow_resizing (w, flag)
    to similar ones that are supported.  */
 
 int
-lw_separator_p (char *label, enum menu_separator *type, int motif_p)
+lw_separator_p (const char *label, enum menu_separator *type, int motif_p)
 {
   int separator_p = 0;
 
@@ -1439,7 +1325,7 @@ lw_separator_p (char *label, enum menu_separator *type, int motif_p)
     {
       static struct separator_table
       {
-       char *name;
+       const char *name;
        enum menu_separator type;
       }
       separator_names[] =
@@ -1484,7 +1370,7 @@ lw_separator_p (char *label, enum menu_separator *type, int motif_p)
       /* Alternative, more Emacs-style names.  */
       static struct separator_table
       {
-       char *name;
+       const char *name;
        enum menu_separator type;
       }
       separator_names[] =
@@ -1534,6 +1420,3 @@ lw_separator_p (char *label, enum menu_separator *type, int motif_p)
 
   return separator_p;
 }
-
-/* arch-tag: 3d730f36-a441-4a71-9971-48ef3b5a4d9f
-   (do not change this comment) */