+static void free_widget_value_args (widget_value* wv)
+{
+ if (wv->args)
+ {
+ if (--wv->args->ref_count <= 0)
+ {
+#ifdef LWLIB_WIDGETS_MOTIF
+ int i;
+ for (i = 0; i < wv->args->nargs; i++)
+ {
+ if (!strcmp (wv->args->args[i].name, XmNfontList))
+ XmFontListFree ((XmFontList)wv->args->args[i].value);
+ }
+#endif
+ free (wv->args->args);
+ free (wv->args);
+ wv->args = 0;
+ }
+ }
+}
+
+void lw_copy_widget_value_args (widget_value* val, widget_value* copy)
+{
+ if (val == copy || val->args == copy->args)
+ return;
+
+ if (copy->args)
+ {
+ free_widget_value_args (copy);
+ }
+
+ if (val->args)
+ {
+ copy->args = val->args;
+ copy->args->ref_count++;
+ }
+}
+
+/* Remove %_ and convert %% to %. We can do this in-place because we
+ are always shortening, never lengthening, the string. */
+void
+lw_remove_accelerator_spec (char *val)
+{
+ char *foo = val, *bar = val;
+
+ while (*bar)
+ {
+ if (*bar == '%' && *(bar+1) == '_')
+ bar += 2;
+ else if (*bar == '%' && *(bar+1) == '%')
+ {
+ *foo++ = *bar++;
+ bar++;
+ }
+ else
+ *foo++ = *bar++;
+ }
+ *foo = '\0';
+}