Mercurial > hg > xemacs-beta
comparison src/device-x.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 966663fcf606 |
children | 6330739388db |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
93 {"-mc", "*pointerColor", XrmoptionSepArg, NULL}, | 93 {"-mc", "*pointerColor", XrmoptionSepArg, NULL}, |
94 {"-cr", "*cursorColor", XrmoptionSepArg, NULL}, | 94 {"-cr", "*cursorColor", XrmoptionSepArg, NULL}, |
95 {"-fontset", "*FontSet", XrmoptionSepArg, NULL}, | 95 {"-fontset", "*FontSet", XrmoptionSepArg, NULL}, |
96 }; | 96 }; |
97 | 97 |
98 static void validify_resource_string (char *str); | |
99 | |
100 /* Functions to synchronize mirroring resources and specifiers */ | 98 /* Functions to synchronize mirroring resources and specifiers */ |
101 int in_resource_setting; | 99 int in_resource_setting; |
102 int in_specifier_change_function; | 100 int in_specifier_change_function; |
103 | 101 |
104 | 102 |
147 XSETDEVICE (device, decode_device (device)); | 145 XSETDEVICE (device, decode_device (device)); |
148 CHECK_X_DEVICE (device); | 146 CHECK_X_DEVICE (device); |
149 return XDEVICE (device); | 147 return XDEVICE (device); |
150 } | 148 } |
151 | 149 |
152 Display * | 150 static Display * |
153 get_x_display (Lisp_Object device) | 151 get_x_display (Lisp_Object device) |
154 { | 152 { |
155 return DEVICE_X_DISPLAY (decode_x_device (device)); | 153 return DEVICE_X_DISPLAY (decode_x_device (device)); |
156 } | 154 } |
157 | 155 |
200 "XEmacs (and most other X programs) malfunction in obscure ways. (i.e.\n" | 198 "XEmacs (and most other X programs) malfunction in obscure ways. (i.e.\n" |
201 "the Xt or Xm libraries will probably crash, which is a very bad thing.)\n" | 199 "the Xt or Xm libraries will probably crash, which is a very bad thing.)\n" |
202 "You should always use \".geometry\" or \"*EmacsFrame.geometry\" instead.\n", | 200 "You should always use \".geometry\" or \"*EmacsFrame.geometry\" instead.\n", |
203 app_name, (char *) value.addr, | 201 app_name, (char *) value.addr, |
204 app_class, (char *) value.addr); | 202 app_class, (char *) value.addr); |
205 suppress_early_backtrace = 1; | 203 suppress_early_error_handler_backtrace = 1; |
206 error ("Invalid geometry resource"); | 204 error ("Invalid geometry resource"); |
207 } | 205 } |
208 } | 206 } |
209 | 207 |
210 static void | 208 static void |
225 else | 223 else |
226 DEVICE_CLASS (d) = Qmono; | 224 DEVICE_CLASS (d) = Qmono; |
227 } | 225 } |
228 | 226 |
229 static int | 227 static int |
230 have_xemacs_resources_in_xrdb(char *disp_name) | 228 have_xemacs_resources_in_xrdb (CONST char *disp_name) |
231 { | 229 { |
232 Display *dpy; | 230 Display *dpy; |
233 char *xdefs, *key; | 231 char *xdefs, *key; |
234 int len, found; | 232 int len, found; |
235 | 233 |
246 len = strlen(key); | 244 len = strlen(key); |
247 | 245 |
248 dpy = XOpenDisplay(disp_name); | 246 dpy = XOpenDisplay(disp_name); |
249 | 247 |
250 if (!dpy) return 0; | 248 if (!dpy) return 0; |
251 | 249 |
252 xdefs = XResourceManagerString(dpy); /* don't free - owned by X */ | 250 xdefs = XResourceManagerString(dpy); /* don't free - owned by X */ |
253 for (found = 0; xdefs && *xdefs; ) { | 251 for (found = 0; xdefs && *xdefs; ) { |
254 if (strncmp(xdefs, key, len) == 0 && | 252 if (strncmp(xdefs, key, len) == 0 && |
255 (xdefs[len] == '*' || xdefs[len] == '.')) { | 253 (xdefs[len] == '*' || xdefs[len] == '.')) { |
256 found = 1; | 254 found = 1; |
258 } | 256 } |
259 | 257 |
260 while (*xdefs && *xdefs++ != '\n') /* find start of next entry.. */ | 258 while (*xdefs && *xdefs++ != '\n') /* find start of next entry.. */ |
261 ; | 259 ; |
262 } | 260 } |
263 | 261 |
264 XCloseDisplay(dpy); | 262 XCloseDisplay(dpy); |
265 return found; | 263 return found; |
264 } | |
265 | |
266 /* Only the characters [-_A-Za-z0-9] are allowed in the individual | |
267 components of a resource. Convert invalid characters to `-' */ | |
268 | |
269 static char valid_resource_char_p[256]; | |
270 | |
271 static void | |
272 validify_resource_component (char *str, size_t len) | |
273 { | |
274 for (; len; len--, str++) | |
275 if (!valid_resource_char_p[(unsigned char) (*str)]) | |
276 *str = '-'; | |
277 } | |
278 | |
279 static void | |
280 Dynarr_add_validified_lisp_string (char_dynarr *cda, Lisp_Object str) | |
281 { | |
282 Bytecount len = XSTRING_LENGTH (str); | |
283 Dynarr_add_many (cda, (char *) XSTRING_DATA (str), len); | |
284 validify_resource_component (Dynarr_atp (cda, Dynarr_length (cda) - len), len); | |
266 } | 285 } |
267 | 286 |
268 static void | 287 static void |
269 x_init_device (struct device *d, Lisp_Object props) | 288 x_init_device (struct device *d, Lisp_Object props) |
270 { | 289 { |
272 Lisp_Object device; | 291 Lisp_Object device; |
273 Display *dpy; | 292 Display *dpy; |
274 Widget app_shell; | 293 Widget app_shell; |
275 int argc; | 294 int argc; |
276 char **argv; | 295 char **argv; |
277 CONST char *app_class, *app_name; | 296 CONST char *app_class; |
297 CONST char *app_name; | |
278 CONST char *disp_name; | 298 CONST char *disp_name; |
279 Arg xargs[6]; | 299 Arg xargs[6]; |
280 Cardinal numargs; | 300 Cardinal numargs; |
281 Visual *visual = NULL; | 301 Visual *visual = NULL; |
282 int depth = 8; /* shut up the compiler */ | 302 int depth = 8; /* shut up the compiler */ |
294 | 314 |
295 if (STRINGP (Vx_emacs_application_class) && | 315 if (STRINGP (Vx_emacs_application_class) && |
296 XSTRING_LENGTH (Vx_emacs_application_class) > 0) | 316 XSTRING_LENGTH (Vx_emacs_application_class) > 0) |
297 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class); | 317 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class); |
298 else { | 318 else { |
299 app_class = (NILP(Vx_emacs_application_class) && | 319 app_class = (NILP (Vx_emacs_application_class) && |
300 have_xemacs_resources_in_xrdb(disp_name)) | 320 have_xemacs_resources_in_xrdb (disp_name)) |
301 ? "XEmacs" | 321 ? "XEmacs" |
302 : "Emacs"; | 322 : "Emacs"; |
303 /* need to update Vx_emacs_application_class: */ | 323 /* need to update Vx_emacs_application_class: */ |
304 Vx_emacs_application_class = build_string(app_class); | 324 Vx_emacs_application_class = build_string (app_class); |
305 } | 325 } |
306 | 326 |
307 slow_down_interrupts (); | 327 slow_down_interrupts (); |
308 /* The Xt code can't deal with signals here. Yuck. */ | 328 /* The Xt code can't deal with signals here. Yuck. */ |
309 dpy = DEVICE_X_DISPLAY (d) = | 329 dpy = DEVICE_X_DISPLAY (d) = |
311 XtNumber (emacs_options), &argc, argv); | 331 XtNumber (emacs_options), &argc, argv); |
312 speed_up_interrupts (); | 332 speed_up_interrupts (); |
313 | 333 |
314 if (dpy == 0) | 334 if (dpy == 0) |
315 { | 335 { |
316 suppress_early_backtrace = 1; | 336 suppress_early_error_handler_backtrace = 1; |
317 signal_simple_error ("X server not responding\n", display); | 337 signal_simple_error ("X server not responding\n", display); |
318 } | 338 } |
319 | 339 |
320 screen = DefaultScreen(dpy); | 340 screen = DefaultScreen(dpy); |
321 if (NILP (Vdefault_x_device)) | 341 if (NILP (Vdefault_x_device)) |
360 /* We're going to modify the string in-place, so be a nice XEmacs */ | 380 /* We're going to modify the string in-place, so be a nice XEmacs */ |
361 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d)); | 381 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d)); |
362 /* colons and periods can't appear in individual elements of resource | 382 /* colons and periods can't appear in individual elements of resource |
363 strings */ | 383 strings */ |
364 | 384 |
365 XtGetApplicationNameAndClass (dpy, &app_name, &app_class); | 385 XtGetApplicationNameAndClass (dpy, (char **) &app_name, (char **) &app_class); |
366 /* search for a matching visual if requested by the user, or setup the display default */ | 386 /* search for a matching visual if requested by the user, or setup the display default */ |
367 numargs = 0; | 387 numargs = 0; |
368 { | 388 { |
369 char *buf1 = (char *)alloca (strlen (app_name) + 17); | 389 char *buf1 = (char *)alloca (strlen (app_name) + 17); |
370 char *buf2 = (char *)alloca (strlen (app_class) + 17); | 390 char *buf2 = (char *)alloca (strlen (app_class) + 17); |
445 XtSetArg(xargs[numargs],XtNcolormap, cmap); numargs++; | 465 XtSetArg(xargs[numargs],XtNcolormap, cmap); numargs++; |
446 DEVICE_X_VISUAL (d) = visual; | 466 DEVICE_X_VISUAL (d) = visual; |
447 DEVICE_X_COLORMAP (d) = cmap; | 467 DEVICE_X_COLORMAP (d) = cmap; |
448 DEVICE_X_DEPTH (d) = depth; | 468 DEVICE_X_DEPTH (d) = depth; |
449 | 469 |
450 validify_resource_string ((char *) XSTRING_DATA (DEVICE_NAME (d))); | 470 validify_resource_component ((char *) XSTRING_DATA (DEVICE_NAME (d)), |
471 XSTRING_LENGTH (DEVICE_NAME (d))); | |
451 app_shell = XtAppCreateShell (NULL, app_class, | 472 app_shell = XtAppCreateShell (NULL, app_class, |
452 applicationShellWidgetClass, | 473 applicationShellWidgetClass, |
453 dpy, xargs, numargs); | 474 dpy, xargs, numargs); |
454 | 475 |
455 DEVICE_XT_APP_SHELL (d) = app_shell; | 476 DEVICE_XT_APP_SHELL (d) = app_shell; |
456 #ifdef HAVE_XIM | 477 #ifdef HAVE_XIM |
457 XIM_init_device(d); | 478 XIM_init_device(d); |
458 #endif /* HAVE_XIM */ | 479 #endif /* HAVE_XIM */ |
459 | 480 |
460 /* Realize the app_shell so that it's window exists for GC creation purposes, | 481 /* Realize the app_shell so that its window exists for GC creation purposes, |
461 and set it to the size of the root window for child placement purposes */ | 482 and set it to the size of the root window for child placement purposes */ |
462 { | 483 { |
463 Screen *scrn = ScreenOfDisplay(dpy, screen); | 484 Screen *scrn = ScreenOfDisplay(dpy, screen); |
464 int screen_width, screen_height; | 485 int screen_width, screen_height; |
465 screen_width = WidthOfScreen(scrn); | 486 screen_width = WidthOfScreen(scrn); |
596 | 617 |
597 /************************************************************************/ | 618 /************************************************************************/ |
598 /* handle X errors */ | 619 /* handle X errors */ |
599 /************************************************************************/ | 620 /************************************************************************/ |
600 | 621 |
601 static CONST char *events[] = | |
602 { | |
603 "0: ERROR!", | |
604 "1: REPLY", | |
605 "KeyPress", | |
606 "KeyRelease", | |
607 "ButtonPress", | |
608 "ButtonRelease", | |
609 "MotionNotify", | |
610 "EnterNotify", | |
611 "LeaveNotify", | |
612 "FocusIn", | |
613 "FocusOut", | |
614 "KeymapNotify", | |
615 "Expose", | |
616 "GraphicsExpose", | |
617 "NoExpose", | |
618 "VisibilityNotify", | |
619 "CreateNotify", | |
620 "DestroyNotify", | |
621 "UnmapNotify", | |
622 "MapNotify", | |
623 "MapRequest", | |
624 "ReparentNotify", | |
625 "ConfigureNotify", | |
626 "ConfigureRequest", | |
627 "GravityNotify", | |
628 "ResizeRequest", | |
629 "CirculateNotify", | |
630 "CirculateRequest", | |
631 "PropertyNotify", | |
632 "SelectionClear", | |
633 "SelectionRequest", | |
634 "SelectionNotify", | |
635 "ColormapNotify", | |
636 "ClientMessage", | |
637 "MappingNotify", | |
638 "LASTEvent" | |
639 }; | |
640 | |
641 CONST char * | 622 CONST char * |
642 x_event_name (int event_type) | 623 x_event_name (int event_type) |
643 { | 624 { |
644 if (event_type < 0) return 0; | 625 static CONST char *events[] = |
645 if (event_type >= countof (events)) return 0; | 626 { |
627 "0: ERROR!", | |
628 "1: REPLY", | |
629 "KeyPress", | |
630 "KeyRelease", | |
631 "ButtonPress", | |
632 "ButtonRelease", | |
633 "MotionNotify", | |
634 "EnterNotify", | |
635 "LeaveNotify", | |
636 "FocusIn", | |
637 "FocusOut", | |
638 "KeymapNotify", | |
639 "Expose", | |
640 "GraphicsExpose", | |
641 "NoExpose", | |
642 "VisibilityNotify", | |
643 "CreateNotify", | |
644 "DestroyNotify", | |
645 "UnmapNotify", | |
646 "MapNotify", | |
647 "MapRequest", | |
648 "ReparentNotify", | |
649 "ConfigureNotify", | |
650 "ConfigureRequest", | |
651 "GravityNotify", | |
652 "ResizeRequest", | |
653 "CirculateNotify", | |
654 "CirculateRequest", | |
655 "PropertyNotify", | |
656 "SelectionClear", | |
657 "SelectionRequest", | |
658 "SelectionNotify", | |
659 "ColormapNotify", | |
660 "ClientMessage", | |
661 "MappingNotify", | |
662 "LASTEvent" | |
663 }; | |
664 | |
665 if (event_type < 0 || event_type >= countof (events)) | |
666 return NULL; | |
646 return events [event_type]; | 667 return events [event_type]; |
647 } | 668 } |
648 | 669 |
649 /* Handling errors. | 670 /* Handling errors. |
650 | 671 |
951 } | 972 } |
952 } | 973 } |
953 | 974 |
954 #endif /* 0 */ | 975 #endif /* 0 */ |
955 | 976 |
956 /* Only the characters [-_A-Za-z0-9] are allowed in the individual | 977 static char_dynarr *name_char_dynarr; |
957 sections of a resource. Convert invalid characters to -. */ | 978 static char_dynarr *class_char_dynarr; |
958 | |
959 static void | |
960 validify_resource_string (char *str) | |
961 { | |
962 while (*str) | |
963 { | |
964 if (!strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
965 "abcdefghijklmnopqrstuvwxyz" | |
966 "0123456789-_", *str)) | |
967 *str = '-'; | |
968 str++; | |
969 } | |
970 } | |
971 | 979 |
972 /* Given a locale and device specification from x-get-resource or | 980 /* Given a locale and device specification from x-get-resource or |
973 x-get-resource-prefix, return the resource prefix and display to | 981 x-get-resource-prefix, return the resource prefix and display to |
974 fetch the resource on. */ | 982 fetch the resource on. */ |
975 | 983 |
976 static void | 984 static void |
977 x_get_resource_prefix (Lisp_Object locale, Lisp_Object device, | 985 x_get_resource_prefix (Lisp_Object locale, Lisp_Object device, |
978 Display **display_out, char *name_out, | 986 Display **display_out, char_dynarr *name, |
979 char *class_out) | 987 char_dynarr *class) |
980 { | 988 { |
981 char *appname, *appclass; | |
982 | |
983 if (NILP (locale)) | 989 if (NILP (locale)) |
984 locale = Qglobal; | 990 locale = Qglobal; |
985 if (NILP (Fvalid_specifier_locale_p (locale))) | 991 if (NILP (Fvalid_specifier_locale_p (locale))) |
986 signal_simple_error ("Invalid locale", locale); | 992 signal_simple_error ("Invalid locale", locale); |
987 if (WINDOWP (locale)) | 993 if (WINDOWP (locale)) |
1009 } | 1015 } |
1010 } | 1016 } |
1011 | 1017 |
1012 *display_out = DEVICE_X_DISPLAY (XDEVICE (device)); | 1018 *display_out = DEVICE_X_DISPLAY (XDEVICE (device)); |
1013 | 1019 |
1014 XtGetApplicationNameAndClass (*display_out, &appname, &appclass); | 1020 { |
1015 strcpy (name_out, appname); | 1021 char *appname, *appclass; |
1016 strcpy (class_out, appclass); | 1022 int name_len, class_len; |
1017 validify_resource_string (name_out); | 1023 XtGetApplicationNameAndClass (*display_out, &appname, &appclass); |
1018 validify_resource_string (class_out); | 1024 name_len = strlen (appname); |
1025 class_len = strlen (appclass); | |
1026 Dynarr_add_many (name , appname, name_len); | |
1027 Dynarr_add_many (class, appclass, class_len); | |
1028 validify_resource_component (Dynarr_atp (name, 0), name_len); | |
1029 validify_resource_component (Dynarr_atp (class, 0), class_len); | |
1030 } | |
1019 | 1031 |
1020 if (EQ (locale, Qglobal)) | 1032 if (EQ (locale, Qglobal)) |
1021 return; | 1033 return; |
1022 if (BUFFERP (locale)) | 1034 if (BUFFERP (locale)) |
1023 { | 1035 { |
1024 strcat (name_out, ".buffer."); | 1036 Dynarr_add_literal_string (name, ".buffer."); |
1025 /* we know buffer is live; otherwise we got an error above. */ | 1037 /* we know buffer is live; otherwise we got an error above. */ |
1026 strcat (name_out, (CONST char *) XSTRING_DATA (Fbuffer_name (locale))); | 1038 Dynarr_add_validified_lisp_string (name, Fbuffer_name (locale)); |
1027 strcat (class_out, ".EmacsLocaleType.EmacsBuffer"); | 1039 Dynarr_add_literal_string (class, ".EmacsLocaleType.EmacsBuffer"); |
1028 } | 1040 } |
1029 else if (FRAMEP (locale)) | 1041 else if (FRAMEP (locale)) |
1030 { | 1042 { |
1031 strcat (name_out, ".frame."); | 1043 Dynarr_add_literal_string (name, ".frame."); |
1032 /* we know frame is live; otherwise we got an error above. */ | 1044 /* we know frame is live; otherwise we got an error above. */ |
1033 strcat (name_out, (CONST char *) XSTRING_DATA (Fframe_name (locale))); | 1045 Dynarr_add_validified_lisp_string (name, Fframe_name (locale)); |
1034 strcat (class_out, ".EmacsLocaleType.EmacsFrame"); | 1046 Dynarr_add_literal_string (class, ".EmacsLocaleType.EmacsFrame"); |
1035 } | 1047 } |
1036 else | 1048 else |
1037 { | 1049 { |
1038 assert (DEVICEP (locale)); | 1050 assert (DEVICEP (locale)); |
1039 strcat (name_out, ".device."); | 1051 Dynarr_add_literal_string (name, ".device."); |
1040 /* we know device is live; otherwise we got an error above. */ | 1052 /* we know device is live; otherwise we got an error above. */ |
1041 strcat (name_out, (CONST char *) XSTRING_DATA (Fdevice_name (locale))); | 1053 Dynarr_add_validified_lisp_string (name, Fdevice_name (locale)); |
1042 strcat (class_out, ".EmacsLocaleType.EmacsDevice"); | 1054 Dynarr_add_literal_string (class, ".EmacsLocaleType.EmacsDevice"); |
1043 } | 1055 } |
1044 return; | 1056 return; |
1045 } | 1057 } |
1046 | 1058 |
1047 DEFUN ("x-get-resource", Fx_get_resource, 3, 6, 0, /* | 1059 DEFUN ("x-get-resource", Fx_get_resource, 3, 6, 0, /* |
1048 Retrieve an X resource from the resource manager. | 1060 Retrieve an X resource from the resource manager. |
1049 | 1061 |
1050 The first arg is the name of the resource to retrieve, such as "font". | 1062 The first arg is the name of the resource to retrieve, such as "font". |
1051 The second arg is the class of the resource to retrieve, like "Font". | 1063 The second arg is the class of the resource to retrieve, such as "Font". |
1052 The third arg should be one of the symbols 'string, 'integer, 'natnum, or | 1064 The third arg must be one of the symbols 'string, 'integer, 'natnum, or |
1053 'boolean, specifying the type of object that the database is searched for. | 1065 'boolean, specifying the type of object that the database is searched for. |
1054 The fourth arg is the locale to search for the resources on, and can | 1066 The fourth arg is the locale to search for the resources on, and can |
1055 currently be a a buffer, a frame, a device, or 'global. If omitted, it | 1067 currently be a buffer, a frame, a device, or 'global. If omitted, it |
1056 defaults to 'global. | 1068 defaults to 'global. |
1057 The fifth arg is the device to search for the resources on. (The resource | 1069 The fifth arg is the device to search for the resources on. (The resource |
1058 database for a particular device is constructed by combining non-device- | 1070 database for a particular device is constructed by combining non-device- |
1059 specific resources such as any command-line resources specified and any | 1071 specific resources such as any command-line resources specified and any |
1060 app-defaults files found [or the fallback resources supplied by XEmacs, | 1072 app-defaults files found [or the fallback resources supplied by XEmacs, |
1126 returned value is the list (t) for true, (nil) for false, and is nil to | 1138 returned value is the list (t) for true, (nil) for false, and is nil to |
1127 mean ``unspecified.'' | 1139 mean ``unspecified.'' |
1128 */ | 1140 */ |
1129 (name, class, type, locale, device, no_error)) | 1141 (name, class, type, locale, device, no_error)) |
1130 { | 1142 { |
1131 /* #### fixed limit, could be overflowed */ | 1143 char* name_string, *class_string; |
1132 char name_string[2048], class_string[2048]; | |
1133 char *raw_result; | 1144 char *raw_result; |
1134 XrmDatabase db; | 1145 XrmDatabase db; |
1135 Display *display; | 1146 Display *display; |
1136 Error_behavior errb = decode_error_behavior_flag (no_error); | 1147 Error_behavior errb = decode_error_behavior_flag (no_error); |
1137 | 1148 |
1138 CHECK_STRING (name); | 1149 CHECK_STRING (name); |
1139 CHECK_STRING (class); | 1150 CHECK_STRING (class); |
1140 CHECK_SYMBOL (type); | 1151 CHECK_SYMBOL (type); |
1141 | 1152 |
1142 if (!EQ (type, Qstring) && | 1153 Dynarr_reset (name_char_dynarr); |
1143 !EQ (type, Qboolean) && | 1154 Dynarr_reset (class_char_dynarr); |
1144 !EQ (type, Qinteger) && | 1155 |
1145 !EQ (type, Qnatnum)) | 1156 x_get_resource_prefix (locale, device, &display, |
1146 return maybe_signal_continuable_error | 1157 name_char_dynarr, class_char_dynarr); |
1147 (Qwrong_type_argument, | |
1148 list2 (build_translated_string | |
1149 ("should be string, integer, natnum or boolean"), | |
1150 type), | |
1151 Qresource, errb); | |
1152 | |
1153 x_get_resource_prefix (locale, device, &display, name_string, | |
1154 class_string); | |
1155 if (!display) | 1158 if (!display) |
1156 return Qnil; | 1159 return Qnil; |
1157 | 1160 |
1158 db = XtDatabase (display); | 1161 db = XtDatabase (display); |
1159 | 1162 |
1160 strcat (name_string, "."); | 1163 Dynarr_add (name_char_dynarr, '.'); |
1161 strcat (name_string, (CONST char *) XSTRING_DATA (name)); | 1164 Dynarr_add_lisp_string (name_char_dynarr, name); |
1162 strcat (class_string, "."); | 1165 Dynarr_add (class_char_dynarr, '.'); |
1163 strcat (class_string, (CONST char *) XSTRING_DATA (class)); | 1166 Dynarr_add_lisp_string (class_char_dynarr, class); |
1167 Dynarr_add (name_char_dynarr, '\0'); | |
1168 Dynarr_add (class_char_dynarr, '\0'); | |
1169 | |
1170 name_string = Dynarr_atp (name_char_dynarr, 0); | |
1171 class_string = Dynarr_atp (class_char_dynarr, 0); | |
1164 | 1172 |
1165 { | 1173 { |
1166 XrmValue xrm_value; | 1174 XrmValue xrm_value; |
1167 XrmName namelist[100]; | 1175 XrmName namelist[100]; |
1168 XrmClass classlist[100]; | 1176 XrmClass classlist[100]; |
1194 { | 1202 { |
1195 if (!strcasecmp (raw_result, "off") || | 1203 if (!strcasecmp (raw_result, "off") || |
1196 !strcasecmp (raw_result, "false") || | 1204 !strcasecmp (raw_result, "false") || |
1197 !strcasecmp (raw_result, "no")) | 1205 !strcasecmp (raw_result, "no")) |
1198 return Fcons (Qnil, Qnil); | 1206 return Fcons (Qnil, Qnil); |
1199 else if (!strcasecmp (raw_result, "on") || | 1207 if (!strcasecmp (raw_result, "on") || |
1200 !strcasecmp (raw_result, "true") || | 1208 !strcasecmp (raw_result, "true") || |
1201 !strcasecmp (raw_result, "yes")) | 1209 !strcasecmp (raw_result, "yes")) |
1202 return Fcons (Qt, Qnil); | 1210 return Fcons (Qt, Qnil); |
1203 else | 1211 return maybe_continuable_error |
1204 return maybe_continuable_error (Qresource, errb, | 1212 (Qresource, errb, |
1205 "can't convert %s: %s to a Boolean", | 1213 "can't convert %s: %s to a Boolean", name_string, raw_result); |
1206 name_string, raw_result); | |
1207 } | 1214 } |
1208 else if (EQ (type, Qinteger) || EQ (type, Qnatnum)) | 1215 else if (EQ (type, Qinteger) || EQ (type, Qnatnum)) |
1209 { | 1216 { |
1210 int i; | 1217 int i; |
1211 char c; | 1218 char c; |
1212 if (1 != sscanf (raw_result, "%d%c", &i, &c)) | 1219 if (1 != sscanf (raw_result, "%d%c", &i, &c)) |
1213 return maybe_continuable_error | 1220 return maybe_continuable_error |
1214 (Qresource, errb, | 1221 (Qresource, errb, |
1215 "can't convert %s: %s to an integer", | 1222 "can't convert %s: %s to an integer", name_string, raw_result); |
1216 name_string, raw_result); | |
1217 else if (EQ (type, Qnatnum) && i < 0) | 1223 else if (EQ (type, Qnatnum) && i < 0) |
1218 return maybe_continuable_error | 1224 return maybe_continuable_error |
1219 (Qresource, errb, | 1225 (Qresource, errb, |
1220 "invalid numerical value %d for resource %s", | 1226 "invalid numerical value %d for resource %s", i, name_string); |
1221 i, name_string); | |
1222 else | 1227 else |
1223 return make_int (i); | 1228 return make_int (i); |
1224 } | 1229 } |
1225 else | 1230 else |
1226 abort (); | 1231 { |
1227 | 1232 return maybe_signal_continuable_error |
1228 /* Can't get here. */ | 1233 (Qwrong_type_argument, |
1229 return Qnil; /* shut up compiler */ | 1234 list2 (build_translated_string |
1235 ("should be string, integer, natnum or boolean"), | |
1236 type), | |
1237 Qresource, errb); | |
1238 } | |
1230 } | 1239 } |
1231 | 1240 |
1232 DEFUN ("x-get-resource-prefix", Fx_get_resource_prefix, 1, 2, 0, /* | 1241 DEFUN ("x-get-resource-prefix", Fx_get_resource_prefix, 1, 2, 0, /* |
1233 Return the resource prefix for LOCALE on DEVICE. | 1242 Return the resource prefix for LOCALE on DEVICE. |
1234 The resource prefix is the strings used to prefix resources if | 1243 The resource prefix is the strings used to prefix resources if |
1239 If no valid X device for resourcing can be obtained, this function | 1248 If no valid X device for resourcing can be obtained, this function |
1240 returns nil. (In such a case, `x-get-resource' would always return nil.) | 1249 returns nil. (In such a case, `x-get-resource' would always return nil.) |
1241 */ | 1250 */ |
1242 (locale, device)) | 1251 (locale, device)) |
1243 { | 1252 { |
1244 /* #### fixed limit, could be overflowed */ | |
1245 char name[1024], class[1024]; | |
1246 Display *display; | 1253 Display *display; |
1247 | 1254 |
1248 x_get_resource_prefix (locale, device, &display, name, class); | 1255 Dynarr_reset (name_char_dynarr ); |
1256 Dynarr_reset (class_char_dynarr); | |
1257 | |
1258 x_get_resource_prefix (locale, device, &display, | |
1259 name_char_dynarr, class_char_dynarr); | |
1249 if (!display) | 1260 if (!display) |
1250 return Qnil; | 1261 return Qnil; |
1251 return Fcons (build_string (name), build_string (class)); | 1262 |
1263 return Fcons (make_string ((Bufbyte *) Dynarr_atp (name_char_dynarr, 0), | |
1264 Dynarr_length (name_char_dynarr)), | |
1265 make_string ((Bufbyte *) Dynarr_atp (class_char_dynarr, 0), | |
1266 Dynarr_length (class_char_dynarr))); | |
1252 } | 1267 } |
1253 | 1268 |
1254 DEFUN ("x-put-resource", Fx_put_resource, 1, 2, 0, /* | 1269 DEFUN ("x-put-resource", Fx_put_resource, 1, 2, 0, /* |
1255 Add a resource to the resource database for DEVICE. | 1270 Add a resource to the resource database for DEVICE. |
1256 RESOURCE-LINE specifies the resource to add and should be a | 1271 RESOURCE-LINE specifies the resource to add and should be a |
1267 invalid: | 1282 invalid: |
1268 signal_simple_error ("Invalid resource line", resource_line); | 1283 signal_simple_error ("Invalid resource line", resource_line); |
1269 if (strspn (str, | 1284 if (strspn (str, |
1270 /* Only the following chars are allowed before the colon */ | 1285 /* Only the following chars are allowed before the colon */ |
1271 " \t.*?abcdefghijklmnopqrstuvwxyz" | 1286 " \t.*?abcdefghijklmnopqrstuvwxyz" |
1272 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-") != colon_pos - str) | 1287 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-") |
1288 != (size_t) (colon_pos - str)) | |
1273 goto invalid; | 1289 goto invalid; |
1274 | 1290 |
1275 if (DEVICE_X_P (d)) | 1291 if (DEVICE_X_P (d)) |
1276 { | 1292 { |
1277 XrmDatabase db = XtDatabase (DEVICE_X_DISPLAY (d)); | 1293 XrmDatabase db = XtDatabase (DEVICE_X_DISPLAY (d)); |
1312 case PseudoColor: return intern ("pseudo-color"); | 1328 case PseudoColor: return intern ("pseudo-color"); |
1313 case TrueColor: return intern ("true-color"); | 1329 case TrueColor: return intern ("true-color"); |
1314 case DirectColor: return intern ("direct-color"); | 1330 case DirectColor: return intern ("direct-color"); |
1315 default: | 1331 default: |
1316 error ("display has an unknown visual class"); | 1332 error ("display has an unknown visual class"); |
1317 } | 1333 return Qnil; /* suppress compiler warning */ |
1318 | 1334 } |
1319 return Qnil; /* suppress compiler warning */ | |
1320 } | 1335 } |
1321 | 1336 |
1322 DEFUN ("x-display-visual-depth", Fx_display_visual_depth, 0, 1, 0, /* | 1337 DEFUN ("x-display-visual-depth", Fx_display_visual_depth, 0, 1, 0, /* |
1323 Return the bitplane depth of the visual the X display `device' is using. | 1338 Return the bitplane depth of the visual the X display `device' is using. |
1324 */ | 1339 */ |
1647 CONSOLE_HAS_METHOD (x, device_pixel_height); | 1662 CONSOLE_HAS_METHOD (x, device_pixel_height); |
1648 CONSOLE_HAS_METHOD (x, device_mm_width); | 1663 CONSOLE_HAS_METHOD (x, device_mm_width); |
1649 CONSOLE_HAS_METHOD (x, device_mm_height); | 1664 CONSOLE_HAS_METHOD (x, device_mm_height); |
1650 CONSOLE_HAS_METHOD (x, device_bitplanes); | 1665 CONSOLE_HAS_METHOD (x, device_bitplanes); |
1651 CONSOLE_HAS_METHOD (x, device_color_cells); | 1666 CONSOLE_HAS_METHOD (x, device_color_cells); |
1667 | |
1668 { | |
1669 /* Initialize variables to speed up X resource interactions */ | |
1670 CONST char *valid_resource_chars = | |
1671 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | |
1672 while (*valid_resource_chars) | |
1673 valid_resource_char_p[(unsigned int) (*valid_resource_chars++)] = 1; | |
1674 | |
1675 name_char_dynarr = Dynarr_new (char); | |
1676 class_char_dynarr = Dynarr_new (char); | |
1677 } | |
1652 } | 1678 } |
1653 | 1679 |
1654 void | 1680 void |
1655 vars_of_device_x (void) | 1681 vars_of_device_x (void) |
1656 { | 1682 { |
1665 If this variable is nil before the connection to the X server is first | 1691 If this variable is nil before the connection to the X server is first |
1666 initialized (which it is by default), the X resource database will be | 1692 initialized (which it is by default), the X resource database will be |
1667 consulted and the value will be set according to whether any resources | 1693 consulted and the value will be set according to whether any resources |
1668 are found for the application class `XEmacs'. If the user has set any | 1694 are found for the application class `XEmacs'. If the user has set any |
1669 resources for the XEmacs application class, the XEmacs process will use | 1695 resources for the XEmacs application class, the XEmacs process will use |
1670 the application class `XEmacs'. Otherwise, the XEmacs process will use | 1696 the application class `XEmacs'. Otherwise, the XEmacs process will use |
1671 the application class `Emacs' which is backwards compatible to previous | 1697 the application class `Emacs' which is backwards compatible to previous |
1672 XEmacs versions but may conflict with resources intended for GNU Emacs. | 1698 XEmacs versions but may conflict with resources intended for GNU Emacs. |
1673 */ ); | 1699 */ ); |
1674 Vx_emacs_application_class = Qnil; | 1700 Vx_emacs_application_class = Qnil; |
1675 | 1701 |