X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/f7ff1b0f0792f1f870778404531e68e77832c4a1..refs/heads/wip:/lwlib/lwlib.c diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c index 9d8ec3330d..7f2f753c1d 100644 --- a/lwlib/lwlib.c +++ b/lwlib/lwlib.c @@ -1,7 +1,7 @@ /* A general interface to the widgets of different toolkits. Copyright (C) 1992, 1993 Lucid, Inc. -Copyright (C) 1994-1996, 1999-2011 Free Software Foundation, Inc. +Copyright (C) 1994-1996, 1999-2014 Free Software Foundation, Inc. This file is part of the Lucid Widget Library. @@ -16,20 +16,16 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +along with GNU Emacs. If not, see . */ -#ifdef HAVE_CONFIG_H #include -#endif #include #include +#include #include #include -#include #include "lwlib-int.h" #include "lwlib-utils.h" #include @@ -75,8 +71,6 @@ static widget_value *merge_widget_value (widget_value *, widget_value *, int, int *); static void instantiate_widget_instance (widget_instance *); -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); @@ -104,87 +98,6 @@ 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 *); static void show_one_widget_busy (Widget, Boolean); - /* utility functions for widget_instance and widget_info */ -char * -safe_strdup (const char *s) -{ - char *result; - if (! s) return 0; - result = (char *) xmalloc (strlen (s) + 1); - strcpy (result, s); - return result; -} - -/* Like strcmp but ignore differences in case. */ - -static int -my_strcasecmp (const char *s1, const char *s2) -{ - while (1) - { - int c1 = *s1++; - int c2 = *s2++; - if (isupper (c1)) - c1 = tolower (c1); - if (isupper (c2)) - c2 = tolower (c2); - if (c1 != c2) - return (c1 > c2 ? 1 : -1); - if (c1 == 0) - return 0; - } -} - -static void -safe_free_str (char *s) -{ - free (s); -} - -static widget_value *widget_value_free_list = 0; -static int malloc_cpt = 0; - -widget_value * -malloc_widget_value (void) -{ - widget_value *wv; - if (widget_value_free_list) - { - wv = widget_value_free_list; - widget_value_free_list = wv->free_list; - wv->free_list = 0; - } - else - { - wv = (widget_value *) xmalloc (sizeof (widget_value)); - malloc_cpt++; - } - memset ((void*) wv, 0, sizeof (widget_value)); - return wv; -} - -/* this is analogous to free(). It frees only what was allocated - by malloc_widget_value(), and no substructures. - */ -void -free_widget_value (widget_value *wv) -{ - if (wv->free_list) - abort (); - - if (malloc_cpt > 25) - { - /* When the number of already allocated cells is too big, - We free it. */ - free (wv); - malloc_cpt--; - } - else - { - wv->free_list = widget_value_free_list; - widget_value_free_list = wv; - } -} static void free_widget_value_tree (widget_value *wv) @@ -192,9 +105,9 @@ free_widget_value_tree (widget_value *wv) if (!wv) return; - free (wv->name); - free (wv->value); - free (wv->key); + xfree (wv->name); + xfree (wv->value); + xfree (wv->key); wv->name = wv->value = wv->key = (char *) 0xDEADBEEF; @@ -214,7 +127,7 @@ free_widget_value_tree (widget_value *wv) free_widget_value_tree (wv->next); wv->next = (widget_value *) 0xDEADBEEF; } - free_widget_value (wv); + xfree (wv); } static widget_value * @@ -227,10 +140,11 @@ copy_widget_value_tree (widget_value *val, change_type change) if (val == (widget_value *) 1) return val; - copy = malloc_widget_value (); - copy->name = safe_strdup (val->name); - copy->value = safe_strdup (val->value); - copy->key = safe_strdup (val->key); + copy = xmalloc (sizeof (widget_value)); + copy->lname = copy->lkey = Qnil; + copy->name = xstrdup (val->name); + copy->value = val->value ? xstrdup (val->value) : NULL; + copy->key = val->key ? xstrdup (val->key) : NULL; copy->help = val->help; copy->enabled = val->enabled; copy->button_type = val->button_type; @@ -257,8 +171,8 @@ allocate_widget_info (const char* type, lw_callback highlight_cb) { widget_info* info = (widget_info*) xmalloc (sizeof (widget_info)); - info->type = safe_strdup (type); - info->name = safe_strdup (name); + info->type = xstrdup (type); + info->name = xstrdup (name); info->id = id; info->val = copy_widget_value_tree (val, STRUCTURAL_CHANGE); info->busy = False; @@ -277,11 +191,11 @@ allocate_widget_info (const char* type, static void free_widget_info (widget_info *info) { - safe_free_str (info->type); - safe_free_str (info->name); + xfree (info->type); + xfree (info->name); free_widget_value_tree (info->val); memset ((void*)info, 0xDEADBEEF, sizeof (widget_info)); - free (info); + xfree (info); } static void @@ -317,7 +231,7 @@ static void free_widget_instance (widget_instance *instance) { memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance)); - free (instance); + xfree (instance); } static widget_info * @@ -460,24 +374,21 @@ merge_widget_value (widget_value *val1, EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "name change", val1->name, val2->name); change = max (change, STRUCTURAL_CHANGE); - safe_free_str (val1->name); - val1->name = safe_strdup (val2->name); + dupstring (&val1->name, val2->name); } if (safe_strcmp (val1->value, val2->value)) { EXPLAIN (val1->name, change, VISIBLE_CHANGE, "value change", val1->value, val2->value); change = max (change, VISIBLE_CHANGE); - safe_free_str (val1->value); - val1->value = safe_strdup (val2->value); + dupstring (&val1->value, val2->value); } if (safe_strcmp (val1->key, val2->key)) { EXPLAIN (val1->name, change, VISIBLE_CHANGE, "key change", val1->key, val2->key); change = max (change, VISIBLE_CHANGE); - safe_free_str (val1->key); - val1->key = safe_strdup (val2->key); + dupstring (&val1->key, val2->key); } if (! EQ (val1->help, val2->help)) { @@ -602,7 +513,7 @@ name_to_widget (widget_instance *instance, const char *name) widget = XtNameToWidget (instance->widget, real_name); - free (real_name); + xfree (real_name); } return widget; } @@ -731,7 +642,7 @@ find_in_table (const char *type, const widget_creation_entry *table) { const widget_creation_entry* cur; for (cur = table; cur->type; cur++) - if (!my_strcasecmp (type, cur->type)) + if (!c_strcasecmp (type, cur->type)) return cur->function; return NULL; } @@ -1156,9 +1067,9 @@ lw_get_widget_value_for_widget (widget_instance *instance, Widget w) /* To forbid recursive calls */ static Boolean lwlib_updating; -/* This function can be used as a an XtCallback for the widgets that get - modified to update other instances of the widgets. Closure should be the - widget_instance. */ +/* This function can be used as an XtCallback for the widgets that get + modified to update other instances of the widgets. Closure should be the + widget_instance. */ void lw_internal_update_other_instances (Widget widget, XtPointer closure,