diff src/device-x.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children da8ed4261e83
line wrap: on
line diff
--- a/src/device-x.c	Mon Aug 13 11:19:22 2007 +0200
+++ b/src/device-x.c	Mon Aug 13 11:20:41 2007 +0200
@@ -50,10 +50,6 @@
 #include "sysfile.h"
 #include "systime.h"
 
-#if defined(HAVE_SHLIB) && defined(LWLIB_USES_ATHENA) && !defined(HAVE_ATHENA_3D)
-#include "sysdll.h"
-#endif /* HAVE_SHLIB and LWLIB_USES_ATHENA and not HAVE_ATHENA_3D */
-
 #ifdef HAVE_OFFIX_DND
 #include "offix.h"
 #endif
@@ -391,8 +387,8 @@
 		vi_out [i].depth == 1 ||
 		vi_out [i].depth == 8)
 #endif
-
-	    /* SGI has 30-bit deep visuals.  Ignore them.
+             
+	    /* SGI has 30-bit deep visuals.  Ignore them. 
                 (We only have 24-bit data anyway.)
               */
 	    && (vi_out [i].depth <= 24)
@@ -460,9 +456,9 @@
   Widget app_shell;
   int argc;
   char **argv;
-  const char *app_class;
-  const char *app_name;
-  const char *disp_name;
+  CONST char *app_class;
+  CONST char *app_name;
+  CONST char *disp_name;
   Visual *visual = NULL;
   int depth = 8;		/* shut up the compiler */
   Colormap cmap;
@@ -470,78 +466,6 @@
   /* */
   int best_visual_found = 0;
 
-#if defined(HAVE_SHLIB) && defined(LWLIB_USES_ATHENA) && !defined(HAVE_ATHENA_3D)
-  /*
-   * In order to avoid the lossage with flat Athena widgets dynamically
-   * linking to one of the ThreeD variants, using the dynamic symbol helpers
-   * to look for symbols that shouldn't be there and refusing to run if they
-   * are seems a less toxic idea than having XEmacs crash when we try and
-   * use a subclass of a widget that has changed size.
-   *
-   * It's ugly, I know, and not going to work everywhere. It seems better to
-   * do our damnedest to try and tell the user what to expect rather than
-   * simply blow up though.
-   *
-   * All the ThreeD variants I have access to define the following function
-   * symbols in the shared library. The flat Xaw library does not define them:
-   *
-   * Xaw3dComputeBottomShadowRGB
-   * Xaw3dComputeTopShadowRGB
-   *
-   * So far only Linux has shown this problem. This seems to be portable to
-   * all the distributions (certainly all the ones I checked - Debian and
-   * Redhat)
-   *
-   * This will only work, sadly, with dlopen() -- the other dynamic linkers
-   * are simply not capable of doing what is needed. :/
-   */
-
-  {
-    /* Get a dll handle to the main process. */
-    dll_handle xaw_dll_handle = dll_open (NULL);
-
-    /* Did that fail?  If so, continue without error.
-     * We could die here but, well, that's unfriendly and all -- plus I feel
-     * better about some crashing somewhere rather than preventing a perfectly
-     * good configuration working just because dll_open failed.
-     */
-    if (xaw_dll_handle != NULL)
-      {
-	/* Look for the Xaw3d function */
-	dll_func xaw_function_handle =
-	  dll_function (xaw_dll_handle, "Xaw3dComputeTopShadowRGB");
-
-	/* If we found it, warn the user in big, nasty, unfriendly letters */
-	if (xaw_function_handle != NULL)
-	  {
-	    warn_when_safe (Qdevice, Qerror, "\n"
-"It seems that XEmacs is built dynamically linked to the flat Athena widget\n"
-"library but it finds a 3D Athena variant with the same name at runtime.\n"
-"\n"
-"This WILL cause your XEmacs process to dump core at some point.\n"
-"You should not continue to use this binary without resolving this issue.\n"
-"\n"
-"This can be solved with the xaw-wrappers package under Debian\n"
-"(register XEmacs as incompatible with all 3d widget sets, see\n"
-"update-xaw-wrappers(8) and .../doc/xaw-wrappers/README.packagers).  It\n"
-"can be verified by checking the runtime path in /etc/ld.so.conf and by\n"
-"using `ldd /path/to/xemacs' under other Linux distributions.  One\n"
-"solution is to use LD_PRELOAD or LD_LIBRARY_PATH to force ld.so to\n"
-"load the flat Athena widget library instead of the aliased 3D widget\n"
-"library (see ld.so(8) for use of these environment variables).\n\n"
-			    );
-
-	  }
-
-	/* Otherwise release the handle to the library
-	 * No error catch here; I can't think of a way to recover anyhow.
-	 */
-	dll_close (xaw_dll_handle);
-      }
-  }
-#endif /* HAVE_SHLIB and LWLIB_USES_ATHENA and not HAVE_ATHENA_3D */
-
-
   XSETDEVICE (device, d);
   display = DEVICE_CONNECTION (d);
 
@@ -549,9 +473,7 @@
 
   make_argc_argv (Vx_initial_argv_list, &argc, &argv);
 
-  TO_EXTERNAL_FORMAT (LISP_STRING, display,
-		      C_STRING_ALLOCA, disp_name,
-		      Qctext);
+  GET_C_STRING_CTEXT_DATA_ALLOCA (display, disp_name);
 
   /*
    * Break apart the old XtOpenDisplay call into XOpenDisplay and
@@ -573,9 +495,7 @@
 
   if (STRINGP (Vx_emacs_application_class) &&
       XSTRING_LENGTH (Vx_emacs_application_class) > 0)
-    TO_EXTERNAL_FORMAT (LISP_STRING, Vx_emacs_application_class,
-			C_STRING_ALLOCA, app_class,
-			Qctext);
+    GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class);
   else
     {
       app_class = (NILP (Vx_emacs_application_class)  &&
@@ -609,17 +529,15 @@
        data-directory/app-defaults/$LANG/Emacs.
        This is in addition to the standard app-defaults files, and
        does not override resources defined elsewhere */
-    const char *data_dir;
+    CONST char *data_dir;
     char *path;
     XrmDatabase db = XtDatabase (dpy); /* #### XtScreenDatabase(dpy) ? */
-    const char *locale = XrmLocaleOfDatabase (db);
+    CONST char *locale = XrmLocaleOfDatabase (db);
 
     if (STRINGP (Vx_app_defaults_directory) &&
 	XSTRING_LENGTH (Vx_app_defaults_directory) > 0)
       {
-	TO_EXTERNAL_FORMAT (LISP_STRING, Vx_app_defaults_directory,
-			    C_STRING_ALLOCA, data_dir,
-			    Qfile_name);
+	GET_C_STRING_FILENAME_DATA_ALLOCA(Vx_app_defaults_directory, data_dir);
 	path = (char *)alloca (strlen (data_dir) + strlen (locale) + 7);
 	sprintf (path, "%s%s/Emacs", data_dir, locale);
 	if (!access (path, R_OK))
@@ -627,9 +545,7 @@
       }
     else if (STRINGP (Vdata_directory) && XSTRING_LENGTH (Vdata_directory) > 0)
       {
-	TO_EXTERNAL_FORMAT (LISP_STRING, Vdata_directory,
-			    C_STRING_ALLOCA, data_dir,
-			    Qfile_name);
+	GET_C_STRING_FILENAME_DATA_ALLOCA (Vdata_directory, data_dir);
 	path = (char *)alloca (strlen (data_dir) + 13 + strlen (locale) + 7);
 	sprintf (path, "%sapp-defaults/%s/Emacs", data_dir, locale);
 	if (!access (path, R_OK))
@@ -650,10 +566,8 @@
   XtGetApplicationNameAndClass (dpy, (char **) &app_name, (char **) &app_class);
   /* search for a matching visual if requested by the user, or setup the display default */
   {
-    int resource_name_length = max (sizeof (".emacsVisual"),
-				    sizeof (".privateColormap"));
-    char *buf1 = alloca_array (char, strlen (app_name)  + resource_name_length);
-    char *buf2 = alloca_array (char, strlen (app_class) + resource_name_length);
+    char *buf1 = (char *)alloca (strlen (app_name)  + 17);
+    char *buf2 = (char *)alloca (strlen (app_class) + 17);
     char *type;
     XrmValue value;
 
@@ -661,14 +575,13 @@
     sprintf (buf2, "%s.EmacsVisual", app_class);
     if (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True)
       {
-	int cnt = 0;
-	int vis_class = PseudoColor;
+	int cnt = 0, vis_class = PseudoColor;
 	XVisualInfo vinfo;
-	char *str = (char*) value.addr;
+	char *res, *str = (char*)value.addr;
 
-#define CHECK_VIS_CLASS(visual_class)					\
- else if (memcmp (str, #visual_class, sizeof (#visual_class) - 1) == 0)	\
-	cnt = sizeof (#visual_class) - 1, vis_class = visual_class
+#define CHECK_VIS_CLASS(class)					\
+ else if (strncmp (str, #class, sizeof (#class) - 1) == 0)	\
+	cnt = sizeof (#class) - 1, vis_class = class
 
 	if (1)
 	  ;
@@ -681,7 +594,8 @@
 
 	if (cnt)
 	  {
-	    depth = atoi (str + cnt);
+	    res = str + cnt;
+	    depth = atoi (res);
 	    if (depth == 0)
 	      {
 		stderr_out ("Invalid Depth specification in %s... ignoring...\n", str);
@@ -739,7 +653,7 @@
 	else
 	  {
 	    /* We have to create a matching colormap anyway...
-	       #### think about using standard colormaps (need the Xmu libs?) */
+	       ### think about using standard colormaps (need the Xmu libs?) */
 	    cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone);
 	    XInstallColormap(dpy, cmap);
 	  }
@@ -782,7 +696,7 @@
     XtRealizeWidget (app_shell);
   }
 
-#ifdef HAVE_WMCOMMAND
+#ifdef HAVE_SESSION
   {
     int new_argc;
     char **new_argv;
@@ -790,7 +704,7 @@
     XSetCommand (XtDisplay (app_shell), XtWindow (app_shell), new_argv, new_argc);
     free_argc_argv (new_argv);
   }
-#endif /* HAVE_WMCOMMAND */
+#endif /* HAVE_SESSION */
 
 
 #ifdef HAVE_OFFIX_DND
@@ -814,7 +728,7 @@
   DEVICE_X_GC_CACHE (d) = make_gc_cache (dpy, XtWindow(app_shell));
   DEVICE_X_GRAY_PIXMAP (d) = None;
   Xatoms_of_device_x (d);
-  Xatoms_of_select_x (d);
+  Xatoms_of_xselect (d);
   Xatoms_of_objects_x (d);
   x_init_device_class (d);
 
@@ -829,10 +743,10 @@
 }
 
 static void
-x_mark_device (struct device *d)
+x_mark_device (struct device *d, void (*markobj) (Lisp_Object))
 {
-  mark_object (DEVICE_X_WM_COMMAND_FRAME (d));
-  mark_object (DEVICE_X_DATA (d)->x_keysym_map_hash_table);
+  markobj (DEVICE_X_WM_COMMAND_FRAME (d));
+  markobj (DEVICE_X_DATA (d)->x_keysym_map_hash_table);
 }
 
 
@@ -913,10 +827,10 @@
 /*				handle X errors				*/
 /************************************************************************/
 
-const char *
+CONST char *
 x_event_name (int event_type)
 {
-  static const char *events[] =
+  static CONST char *events[] =
   {
     "0: ERROR!",
     "1: REPLY",
@@ -1362,7 +1276,7 @@
 The sixth arg NOERROR, if non-nil, means do not signal an error if a
   bogus resource specification was retrieved (e.g. if a non-integer was
   given when an integer was requested).  In this case, a warning is issued
-  instead, unless NOERROR is t, in which case no warning is issued.
+  instead.
 
 The resource names passed to this function are looked up relative to the
 locale.
@@ -1421,7 +1335,7 @@
 found.  If the third arg is `string', a string is returned, and if it is
 `integer', an integer is returned.  If the third arg is `boolean', then the
 returned value is the list (t) for true, (nil) for false, and is nil to
-mean ``unspecified''.
+mean ``unspecified.''
 */
        (name, class, type, locale, device, no_error))
 {
@@ -1684,19 +1598,17 @@
 */
        (keysym))
 {
-  const char *keysym_ext;
+  CONST char *keysym_ext;
 
   CHECK_STRING (keysym);
-  TO_EXTERNAL_FORMAT (LISP_STRING, keysym,
-		      C_STRING_ALLOCA, keysym_ext,
-		      Qctext);
+  GET_C_STRING_CTEXT_DATA_ALLOCA (keysym, keysym_ext);
 
   return XStringToKeysym (keysym_ext) ? Qt : Qnil;
 }
 
 DEFUN ("x-keysym-hash-table", Fx_keysym_hash_table, 0, 1, 0, /*
-Return a hash table containing a key for all keysyms on DEVICE.
-DEVICE must be an X11 display device.  See `x-keysym-on-keyboard-p'.
+Return a hash table which contains a hash key for all keysyms which
+name keys on the keyboard.  See `x-keysym-on-keyboard-p'.
 */
        (device))
 {
@@ -1838,7 +1750,7 @@
 So long as the keyboard is grabbed, all keyboard events will be delivered
 to emacs -- it is not possible for other X clients to eavesdrop on them.
 Ungrab the keyboard with `x-ungrab-keyboard' (use an unwind-protect).
-Returns t if the grab is successful, nil otherwise.
+Returns t if the grab was successful; nil otherwise.
 */
        (device))
 {
@@ -1890,16 +1802,15 @@
 {
   Display *dpy = get_x_display (device);
   int ndirs_return;
-  const char **directories = (const char **) XGetFontPath (dpy, &ndirs_return);
+  CONST char **directories = (CONST char **) XGetFontPath (dpy, &ndirs_return);
   Lisp_Object font_path = Qnil;
 
   if (!directories)
     signal_simple_error ("Can't get X font path", device);
 
   while (ndirs_return--)
-      font_path = Fcons (build_ext_string (directories[ndirs_return],
-                                           Qfile_name),
-			 font_path);
+      font_path = Fcons (build_ext_string (directories[ndirs_return], 
+                                           FORMAT_FILENAME), font_path);
 
   return font_path;
 }
@@ -1922,7 +1833,7 @@
 {
   Display *dpy = get_x_display (device);
   Lisp_Object path_entry;
-  const char **directories;
+  CONST char **directories;
   int i=0,ndirs=0;
 
   EXTERNAL_LIST_LOOP (path_entry, font_path)
@@ -1931,13 +1842,11 @@
       ndirs++;
     }
 
-  directories = alloca_array (const char *, ndirs);
+  directories = alloca_array (CONST char *, ndirs);
 
   EXTERNAL_LIST_LOOP (path_entry, font_path)
     {
-      TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (path_entry),
-			  C_STRING_ALLOCA, directories[i++],
-			  Qfile_name);
+      GET_C_STRING_FILENAME_DATA_ALLOCA (XCAR (path_entry), directories[i++]);
     }
 
   expect_x_error (dpy);
@@ -1984,43 +1893,29 @@
 }
 
 void
-reinit_console_type_create_device_x (void)
-{
-  /* Initialize variables to speed up X resource interactions */
-  const char *valid_resource_chars =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-  while (*valid_resource_chars)
-    valid_resource_char_p[(unsigned int) (*valid_resource_chars++)] = 1;
-
-  name_char_dynarr  = Dynarr_new (char);
-  class_char_dynarr = Dynarr_new (char);
-}
-
-void
 console_type_create_device_x (void)
 {
-  reinit_console_type_create_device_x ();
   CONSOLE_HAS_METHOD (x, init_device);
   CONSOLE_HAS_METHOD (x, finish_init_device);
   CONSOLE_HAS_METHOD (x, mark_device);
   CONSOLE_HAS_METHOD (x, delete_device);
   CONSOLE_HAS_METHOD (x, device_system_metrics);
-}
 
-void
-reinit_vars_of_device_x (void)
-{
-  error_expected = 0;
-  error_occurred = 0;
+  {
+    /* Initialize variables to speed up X resource interactions */
+    CONST char *valid_resource_chars =
+      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+    while (*valid_resource_chars)
+      valid_resource_char_p[(unsigned int) (*valid_resource_chars++)] = 1;
 
-  in_resource_setting = 0;
+    name_char_dynarr  = Dynarr_new (char);
+    class_char_dynarr = Dynarr_new (char);
+  }
 }
 
 void
 vars_of_device_x (void)
 {
-  reinit_vars_of_device_x ();
-
   DEFVAR_LISP ("x-emacs-application-class", &Vx_emacs_application_class /*
 The X application class of the XEmacs process.
 This controls, among other things, the name of the `app-defaults' file
@@ -2063,4 +1958,9 @@
 
   staticpro (&Vdefault_x_device);
   Vdefault_x_device = Qnil;
+
+  error_expected = 0;
+  error_occurred = 0;
+
+  in_resource_setting = 0;
 }