ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xdefaults.C
(Generate patch)

Comparing rxvt-unicode/src/xdefaults.C (file contents):
Revision 1.49 by root, Thu Feb 3 10:24:10 2005 UTC vs.
Revision 1.55 by root, Mon Feb 14 18:47:54 2005 UTC

29 29
30#include "../config.h" /* NECESSARY */ 30#include "../config.h" /* NECESSARY */
31#include "rxvt.h" /* NECESSARY */ 31#include "rxvt.h" /* NECESSARY */
32#include "version.h" 32#include "version.h"
33 33
34#include <sys/utsname.h>
35
34#ifdef KEYSYM_RESOURCE 36#ifdef KEYSYM_RESOURCE
35#include "keyboard.h" 37#include "keyboard.h"
36#endif 38#endif
37 39
38/* #define DEBUG_RESOURCES */ 40/* #define DEBUG_RESOURCES */
39
40static const char *const xnames[2] = { ".Xdefaults", ".Xresources" };
41 41
42/*{{{ monolithic option/resource structure: */ 42/*{{{ monolithic option/resource structure: */
43/* 43/*
44 * `string' options MUST have a usage argument 44 * `string' options MUST have a usage argument
45 * `switch' and `boolean' options have no argument 45 * `switch' and `boolean' options have no argument
71 (optList[i].flag ? 0 : (optList[i].arg ? strlen (optList[i].arg) : 1)) 71 (optList[i].flag ? 0 : (optList[i].arg ? strlen (optList[i].arg) : 1))
72#define optList_isBool(i) \ 72#define optList_isBool(i) \
73 (optList[i].flag & Opt_Boolean) 73 (optList[i].flag & Opt_Boolean)
74#define optList_isReverse(i) \ 74#define optList_isReverse(i) \
75 (optList[i].flag & Opt_Reverse) 75 (optList[i].flag & Opt_Reverse)
76#define optList_size() \ 76#define optList_size \
77 (sizeof (optList) / sizeof (optList[0])) 77 (sizeof (optList) / sizeof (optList[0]))
78 78
79static const struct 79static const struct
80 { 80 {
81 const unsigned long flag; /* Option flag */ 81 const unsigned long flag; /* Option flag */
217 STRG (Rs_title, "title", "title", "string", "title name for window"), 217 STRG (Rs_title, "title", "title", "string", "title name for window"),
218 STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */ 218 STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */
219 STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"), 219 STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"),
220 STRG (Rs_saveLines, "saveLines", "sl", "number", "number of scrolled lines to save"), 220 STRG (Rs_saveLines, "saveLines", "sl", "number", "number of scrolled lines to save"),
221#if ENABLE_FRILLS 221#if ENABLE_FRILLS
222 STRG (Rs_embed, NULL, "embed", "windowid", "window id to embed terminal in"),
222 STRG (Rs_ext_bwidth, "externalBorder", "w", "number", "external border in pixels"), 223 STRG (Rs_ext_bwidth, "externalBorder", "w", "number", "external border in pixels"),
223 STRG (Rs_ext_bwidth, NULL, "bw", NULL, NULL), 224 STRG (Rs_ext_bwidth, NULL, "bw", NULL, NULL),
224 STRG (Rs_ext_bwidth, NULL, "borderwidth", NULL, NULL), 225 STRG (Rs_ext_bwidth, NULL, "borderwidth", NULL, NULL),
225 STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"), 226 STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"),
226 BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, "borderless window"), 227 BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, "borderless window"),
246 RSTRG (Rs_answerbackstring, "answerbackString", "string"), 247 RSTRG (Rs_answerbackstring, "answerbackString", "string"),
247#ifndef NO_SECONDARY_SCREEN 248#ifndef NO_SECONDARY_SCREEN
248 BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, "enable secondary screen"), 249 BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, "enable secondary screen"),
249 BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, "enable secondary screen scroll"), 250 BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, "enable secondary screen scroll"),
250#endif 251#endif
252#if 0 && TODO
251#if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT) 253#if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT)
252 INFO ("xrm", "string", "X resource"), 254 INFO ("xrm", "string", "X resource"),
255#endif
253#endif 256#endif
254 INFO ("e", "command arg ...", "command to execute") 257 INFO ("e", "command arg ...", "command to execute")
255 }; 258 };
256 259
257#undef INFO 260#undef INFO
407 switch (type) 410 switch (type)
408 { 411 {
409 case 0: /* brief listing */ 412 case 0: /* brief listing */
410 rxvt_log (" [-help] [--help]\n"); 413 rxvt_log (" [-help] [--help]\n");
411 414
412 for (col = 1, i = 0; i < optList_size (); i++) 415 for (col = 1, i = 0; i < optList_size; i++)
413 if (optList[i].desc != NULL) 416 if (optList[i].desc != NULL)
414 { 417 {
415 int len = 0; 418 int len = 0;
416 419
417 if (!optList_isBool (i)) 420 if (!optList_isBool (i))
440 break; 443 break;
441 444
442 case 1: /* full command-line listing */ 445 case 1: /* full command-line listing */
443 rxvt_log (" [options] [-e command args]\n\nwhere options include:\n"); 446 rxvt_log (" [options] [-e command args]\n\nwhere options include:\n");
444 447
445 for (i = 0; i < optList_size (); i++) 448 for (i = 0; i < optList_size; i++)
446 if (optList[i].desc != NULL) 449 if (optList[i].desc != NULL)
447 { 450 {
448#ifdef DEBUG_STRICT 451#ifdef DEBUG_STRICT
449 assert (optList[i].opt != NULL); 452 assert (optList[i].opt != NULL);
450#endif 453#endif
461 464
462 case 2: /* full resource listing */ 465 case 2: /* full resource listing */
463 rxvt_log (" [options] [-e command args]\n\n" 466 rxvt_log (" [options] [-e command args]\n\n"
464 "where resources (long-options) include:\n"); 467 "where resources (long-options) include:\n");
465 468
466 for (i = 0; i < optList_size (); i++) 469 for (i = 0; i < optList_size; i++)
467 if (optList[i].kw != NULL) 470 if (optList[i].kw != NULL)
468 rxvt_log (" %s: %*s%s\n", 471 rxvt_log (" %s: %*s%s\n",
469 optList[i].kw, 472 optList[i].kw,
470 (INDENT - strlen (optList[i].kw)), "", /* XXX */ 473 (INDENT - strlen (optList[i].kw)), "", /* XXX */
471 (optList_isBool (i) ? "boolean" : optList[i].arg)); 474 (optList_isBool (i) ? "boolean" : optList[i].arg));
492 int i, bad_option = 0; 495 int i, bad_option = 0;
493 static const char On[3] = "ON", Off[4] = "OFF"; 496 static const char On[3] = "ON", Off[4] = "OFF";
494 497
495 for (i = 1; i < argc; i++) 498 for (i = 1; i < argc; i++)
496 { 499 {
497 unsigned int entry, longopt = 0; 500 unsigned int entry, longopt = 0;
498 const char *flag, *opt; 501 const char *flag, *opt;
499 502
500 opt = argv[i]; 503 opt = argv[i];
501#ifdef DEBUG_RESOURCES 504#ifdef DEBUG_RESOURCES
502 fprintf (stderr, "argv[%d] = %s: ", i, opt); 505 fprintf (stderr, "argv[%d] = %s: ", i, opt);
503#endif 506#endif
524 rxvt_usage (longopt ? 2 : 1); 527 rxvt_usage (longopt ? 2 : 1);
525 if (!strcmp (opt, "h")) 528 if (!strcmp (opt, "h"))
526 rxvt_usage (0); 529 rxvt_usage (0);
527 530
528 /* feature: always try to match long-options */ 531 /* feature: always try to match long-options */
529 for (entry = 0; entry < optList_size (); entry++) 532 for (entry = 0; entry < optList_size; entry++)
530 if ((optList[entry].kw && !strcmp (opt, optList[entry].kw)) 533 if ((optList[entry].kw && !strcmp (opt, optList[entry].kw))
531 || (!longopt 534 || (!longopt
532 && optList[entry].opt && !strcmp (opt, optList[entry].opt))) 535 && optList[entry].opt && !strcmp (opt, optList[entry].opt)))
533 break; 536 break;
534 537
535 if (entry < optList_size ()) 538 if (entry < optList_size)
536 { 539 {
537 if (optList_isReverse (entry)) 540 if (optList_isReverse (entry))
538 flag = flag == On ? Off : On; 541 flag = flag == On ? Off : On;
539 542
540 if (optList_strlen (entry)) 543 if (optList_strlen (entry))
554#ifdef DEBUG_RESOURCES 557#ifdef DEBUG_RESOURCES
555 fprintf (stderr, "boolean (%s,%s) = %s\n", 558 fprintf (stderr, "boolean (%s,%s) = %s\n",
556 optList[entry].opt, optList[entry].kw, flag); 559 optList[entry].opt, optList[entry].kw, flag);
557#endif 560#endif
558 if (flag == On) 561 if (flag == On)
559 options |= (optList[entry].flag); 562 options |= optList[entry].flag;
560 else 563 else
561 options &= ~ (optList[entry].flag); 564 options &= ~optList[entry].flag;
562 565
563 if (optList[entry].doff != -1) 566 if (optList[entry].doff != -1)
564 rs[optList[entry].doff] = flag; 567 rs[optList[entry].doff] = flag;
565 } 568 }
566 } 569 }
781 return; 784 return;
782 785
783 len = strlen (name); 786 len = strlen (name);
784 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) 787 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL)
785 { 788 {
786 unsigned int entry, n; 789 unsigned int entry, n;
787 790
788 while (*str && isspace (*str)) 791 while (*str && isspace (*str))
789 str++; /* leading whitespace */ 792 str++; /* leading whitespace */
790 793
791 if ((str[len] != '*' && str[len] != '.') 794 if ((str[len] != '*' && str[len] != '.')
794 str += (len + 1); /* skip `name*' or `name.' */ 797 str += (len + 1); /* skip `name*' or `name.' */
795 798
796# ifdef KEYSYM_RESOURCE 799# ifdef KEYSYM_RESOURCE
797 if (!parse_keysym (str, NULL)) 800 if (!parse_keysym (str, NULL))
798# endif /* KEYSYM_RESOURCE */ 801# endif /* KEYSYM_RESOURCE */
799 for (entry = 0; entry < optList_size (); entry++) 802 for (entry = 0; entry < optList_size; entry++)
800 { 803 {
801 const char *kw = optList[entry].kw; 804 const char *kw = optList[entry].kw;
802 805
803 if (kw == NULL) 806 if (kw == NULL)
804 continue; 807 continue;
808 { 811 {
809 /* skip `keyword:' */ 812 /* skip `keyword:' */
810 str += n + 1; 813 str += n + 1;
811 rxvt_Str_trim (str); 814 rxvt_Str_trim (str);
812 n = strlen (str); 815 n = strlen (str);
816
813 if (n && rs[optList[entry].doff] == NULL) 817 if (n && rs[optList[entry].doff] == NULL)
814 { 818 {
815 /* not already set */ 819 /* not already set */
816 int s; 820 int s;
817 char *p = 0; 821 char *p = 0;
838 rs[optList[entry].doff] = p; 842 rs[optList[entry].doff] = p;
839 allocated.push_back (p); 843 allocated.push_back (p);
840 844
841 if (optList_isBool (entry)) 845 if (optList_isBool (entry))
842 { 846 {
843 s = strcasecmp (str, "TRUE") == 0 847 s = strcasecmp (str, "true") == 0
844 || strcasecmp (str, "YES") == 0 848 || strcasecmp (str, "yes") == 0
845 || strcasecmp (str, "ON") == 0 849 || strcasecmp (str, "on") == 0
846 || strcasecmp (str, "1") == 0; 850 || strcmp (str, "1") == 0;
847 851
848 if (optList_isReverse (entry)) 852 if (optList_isReverse (entry))
849 s = !s; 853 s = !s;
850 854
851 if (s) 855 if (s)
871/* 875/*
872 * using XGetDefault () or the hand-rolled replacement 876 * using XGetDefault () or the hand-rolled replacement
873 */ 877 */
874/* ARGSUSED */ 878/* ARGSUSED */
875void 879void
876rxvt_term::extract_resources (Display *display __attribute__ ((unused)), const char *name) 880rxvt_term::extract_resources ()
877{ 881{
882 dDisp;
883
878#ifndef NO_RESOURCES 884#ifndef NO_RESOURCES
885
886 char *homedir = (char *)getenv ("HOME");
887 char fname[1024];
879 888
880# if defined XAPPLOADDIR 889# if defined XAPPLOADDIR
881# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 890# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
882 /* Compute the path of the possibly available localized Rxvt file */ 891 /* Compute the path of the possibly available localized Rxvt file */
883 char *localepath = NULL; 892 char localepath[1024];
884 893
885 if (locale != NULL) 894 if (locale)
886 { /* XXX: must limit length of string */
887 localepath = (char *)rxvt_malloc (256);
888 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, 895 snprintf (localepath, sizeof (localepath), XAPPLOADDIRLOCALE "/" RESCLASS, locale);
889 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (RESCLASS)), 896 else
890 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */ 897 localepath[0] = 0;
891 }
892
893 {
894# endif 898# endif
895# endif 899# endif
896 900
897# ifdef USE_XGETDEFAULT 901# ifdef USE_XGETDEFAULT
898 /* 902 /*
899 * get resources using the X library function 903 * get resources using the X library function
900 */ 904 */
901 int entry; 905 int entry;
902 906
903# ifdef XrmEnumOneLevel 907# ifdef XrmEnumOneLevel
904 int i; 908 int i;
905 char *displayResource, *xe; 909 char *displayResource, *xe;
906 XrmName name_prefix[3]; 910 XrmName name_prefix[3];
907 XrmClass class_prefix[3]; 911 XrmClass class_prefix[3];
908 XrmDatabase database, rdb1; 912 XrmDatabase database, rdb1;
909 char fname[1024];
910 913
911 XrmInitialize (); 914 XrmInitialize ();
912 database = NULL; 915 database = NULL;
913 916
917 // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20
918
919 // 6. System wide per application default file.
920 /* Add in Rxvt file */
921# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
922 if (*localepath
923 && ((rdb1 = XrmGetFileDatabase (localepath))
924 || (rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS))))
925# endif
926 XrmMergeDatabases (rdb1, &database);
927
928 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
929 if ((xe = (char *)getenv ("XAPPLRESDIR")))
930 {
931 snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS);
932
933 if ((rdb1 = XrmGetFileDatabase (fname)))
934 XrmMergeDatabases (rdb1, &database);
935 }
936
937 // 5. User's per application default file.
938 // none
939
940 // 4. User's defaults file.
914 /* Get any Xserver defaults */ 941 /* Get any Xserver defaults */
915
916 displayResource = XResourceManagerString (display); 942 displayResource = XResourceManagerString (disp);
917 if (displayResource != NULL) 943 if (displayResource != NULL)
944 {
918 database = XrmGetStringDatabase (displayResource); 945 if ((rdb1 = XrmGetStringDatabase (displayResource)))
919 946 XrmMergeDatabases (rdb1, &database);
920# ifdef HAVE_EXTRA_XRESOURCE_FILES
921 /* Add in ~/.Xdefaults or ~/.Xresources */
922 { 947 }
923 char *ptr; 948 else if (homedir)
949 {
950 snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir);
924 951
925 if ((ptr = (char *)getenv ("HOME")) == NULL) 952 if ((rdb1 = XrmGetFileDatabase (fname)))
926 ptr = "."; 953 XrmMergeDatabases (rdb1, &database);
954 }
927 955
928 for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) 956 /* Get screen specific resources */
957 displayResource = XScreenResourceString (ScreenOfDisplay (disp, display->screen));
958 if (displayResource != NULL)
959 {
960 if ((rdb1 = XrmGetStringDatabase (displayResource)))
961 /* Merge with screen-independent resources */
962 XrmMergeDatabases (rdb1, &database);
963
964 XFree (displayResource);
965 }
966
967 // 3. User's per host defaults file
968 /* Add in XENVIRONMENT file */
969 if ((xe = (char *)getenv ("XENVIRONMENT"))
970 && (rdb1 = XrmGetFileDatabase (xe)))
971 XrmMergeDatabases (rdb1, &database);
972 else if (homedir)
973 {
974 struct utsname un;
975
976 if (!uname (&un))
929 { 977 {
930 sprintf (fname, "%-.*s/%s", sizeof (fname) - strlen (xnames[i]) - 2, 978 snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename);
931 ptr, xnames[i]); 979
932 if ((rdb1 = XrmGetFileDatabase (fname))) 980 if ((rdb1 = XrmGetFileDatabase (fname)))
981 XrmMergeDatabases (rdb1, &database);
982 }
983 }
984
985 XrmSetDatabase (disp, database);
986# endif
987
988 /*
989 * Query resources for options that affect us
990 */
991 for (entry = 0; entry < optList_size; entry++)
992 {
993 int s;
994 char *p, *p0;
995 const char *kw = optList[entry].kw;
996
997 if (kw == NULL || rs[optList[entry].doff] != NULL)
998 continue; /* previously set */
999
1000 p = XGetDefault (disp, rs[Rs_name], kw);
1001 p0 = XGetDefault (disp, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);
1002 if (p == NULL || (p0 && strcmp (p, p0) == 0))
1003 {
1004 p = XGetDefault (disp, RESCLASS, kw);
1005#ifdef RESFALLBACK
1006 if (p == NULL || (p0 && strcmp (p, p0) == 0))
1007 p = XGetDefault (disp, RESFALLBACK, kw);
1008#endif
1009 }
1010
1011 if (p == NULL && p0)
1012 p = p0;
1013
1014 if (p)
1015 {
1016 rs[optList[entry].doff] = p;
1017
1018 if (optList_isBool (entry))
933 { 1019 {
934 XrmMergeDatabases (rdb1, &database); 1020 s = strcasecmp (p, "TRUE") == 0
935# ifndef HAVE_BOTH_XRESOURCE_FILES 1021 || strcasecmp (p, "YES") == 0
1022 || strcasecmp (p, "ON") == 0
1023 || strcasecmp (p, "1") == 0;
1024
1025 if (optList_isReverse (entry))
1026 s = !s;
1027
1028 if (s)
1029 options |= optList[entry].flag;
936 break; 1030 else
937# endif 1031 options &= ~optList[entry].flag;
938 } 1032 }
939 } 1033 }
940 } 1034 }
941# endif
942 1035
943 /* Add in XENVIRONMENT file */
944
945 if ((xe = (char *)getenv ("XENVIRONMENT")) != NULL
946 && (rdb1 = XrmGetFileDatabase (xe)) != NULL)
947 XrmMergeDatabases (rdb1, &database);
948
949 /* Add in Rxvt file */
950# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
951 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL)
952# endif
953 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS);
954
955 if (rdb1 != NULL)
956 XrmMergeDatabases (rdb1, &database);
957
958 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
959 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL)
960 {
961 sprintf (fname, "%-.*s/" RESCLASS, sizeof (fname)
962 - sizeof (RESCLASS) - 2, xe);
963 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL)
964 XrmMergeDatabases (rdb1, &database);
965 }
966
967 XrmSetDatabase (display, database);
968# endif
969
970 /* 1036 /*
971 * Query resources for options that affect us
972 */
973 for (entry = 0; entry < optList_size (); entry++)
974 {
975 int s;
976 char *p, *p0;
977 const char *kw = optList[entry].kw;
978
979 if (kw == NULL || rs[optList[entry].doff] != NULL)
980 continue; /* previously set */
981
982 p = XGetDefault (display, name, kw);
983 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);
984 if (p == NULL || (p0 && strcmp (p, p0) == 0))
985 {
986 p = XGetDefault (display, RESCLASS, kw);
987#ifdef RESFALLBACK
988 if (p == NULL || (p0 && strcmp (p, p0) == 0))
989 p = XGetDefault (display, RESFALLBACK, kw);
990#endif
991 }
992
993 if (p == NULL && p0)
994 p = p0;
995
996 if (p)
997 {
998 rs[optList[entry].doff] = p;
999
1000 if (optList_isBool (entry))
1001 {
1002 s = strcasecmp (p, "TRUE") == 0
1003 || strcasecmp (p, "YES") == 0
1004 || strcasecmp (p, "ON") == 0
1005 || strcasecmp (p, "1") == 0;
1006 if (optList_isReverse (entry))
1007 s = !s;
1008 if (s)
1009 options |= (optList[entry].flag);
1010 else
1011 options &= ~ (optList[entry].flag);
1012 }
1013 }
1014 }
1015
1016 /*
1017 * [R5 or later]: enumerate the resource database 1037 * [R5 or later]: enumerate the resource database
1018 */ 1038 */
1019# ifdef XrmEnumOneLevel
1020# ifdef KEYSYM_RESOURCE 1039# ifdef KEYSYM_RESOURCE
1021 name_prefix[0] = XrmStringToName (name); 1040 name_prefix[0] = XrmStringToName (rs[Rs_name]);
1022 name_prefix[1] = XrmStringToName ("keysym"); 1041 name_prefix[1] = XrmStringToName ("keysym");
1023 name_prefix[2] = NULLQUARK; 1042 name_prefix[2] = NULLQUARK;
1024 class_prefix[0] = XrmStringToName (RESCLASS); 1043 class_prefix[0] = XrmStringToName (RESCLASS);
1025 class_prefix[1] = XrmStringToName ("Keysym"); 1044 class_prefix[1] = XrmStringToName ("Keysym");
1026 class_prefix[2] = NULLQUARK; 1045 class_prefix[2] = NULLQUARK;
1027 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 1046 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
1028 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 1047 XrmEnumerateDatabase (XrmGetDatabase (disp), name_prefix, class_prefix,
1029 XrmEnumOneLevel, rxvt_define_key, NULL); 1048 XrmEnumOneLevel, rxvt_define_key, NULL);
1030# ifdef RESFALLBACK 1049# ifdef RESFALLBACK
1031 name_prefix[0] = XrmStringToName (RESFALLBACK); 1050 name_prefix[0] = XrmStringToName (RESFALLBACK);
1032 name_prefix[1] = XrmStringToName ("keysym"); 1051 name_prefix[1] = XrmStringToName ("keysym");
1033 class_prefix[0] = XrmStringToName (RESFALLBACK); 1052 class_prefix[0] = XrmStringToName (RESFALLBACK);
1034 class_prefix[1] = XrmStringToName ("Keysym"); 1053 class_prefix[1] = XrmStringToName ("Keysym");
1035 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 1054 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
1036 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 1055 XrmEnumerateDatabase (XrmGetDatabase (disp), name_prefix, class_prefix,
1037 XrmEnumOneLevel, rxvt_define_key, NULL); 1056 XrmEnumOneLevel, rxvt_define_key, NULL);
1038# endif
1039# endif 1057# endif
1040# endif 1058# endif
1041 1059
1042# else /* USE_XGETDEFAULT */ 1060# else /* USE_XGETDEFAULT */
1043 /* get resources the hard way, but save lots of memory */ 1061 /* get resources the hard way, but save lots of memory */
1062 FILE *fd = NULL;
1063
1064 if (homedir)
1065 {
1066 static const char *const xnames[2] = { ".Xdefaults", ".Xresources" };
1067
1068 for (int i = 0; i < (sizeof (xnames) / sizeof (xnames [0])); i++)
1069 {
1070 snprintf (fname, sizeof (fname), "%s/%s", homedir, xnames [i]);
1071
1072 if ((fd = fopen (fname, "r")) != NULL)
1073 break;
1074 }
1075 }
1076 /*
1077 * The normal order to match resources is the following:
1078 * @ global resources (partial match, ~/.Xdefaults)
1079 * @ application file resources (XAPPLOADDIR/Rxvt)
1080 * @ class resources (~/.Xdefaults)
1081 * @ private resources (~/.Xdefaults)
1082 *
1083 * However, for the hand-rolled resources, the matching algorithm
1084 * checks if a resource string value has already been allocated
1085 * and won't overwrite it with (in this case) a less specific
1086 * resource value.
1087 *
1088 * This avoids multiple allocation. Also, when we've called this
1089 * routine command-line string options have already been applied so we
1090 * needn't to allocate for those resources.
1091 *
1092 * So, search in resources from most to least specific.
1093 *
1094 * Also, use a special sub-class so that we can use either or both of
1095 * "XTerm" and "Rxvt" as class names.
1096 */
1097
1098 get_xdefaults (fd, rs[Rs_name]);
1099 get_xdefaults (fd, RESCLASS);
1100# ifdef RESFALLBACK
1101 get_xdefaults (fd, RESFALLBACK);
1102# endif
1103
1104# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)
1105 {
1044 FILE *fd = NULL; 1106 FILE *ad = NULL;
1045 char *home;
1046 1107
1047 if ((home = getenv ("HOME")) != NULL) 1108# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1109 if (!*localepath || (ad = fopen (localepath, "r")) == NULL)
1110# endif
1111 ad = fopen (XAPPLOADDIR "/" RESCLASS, "r");
1112 if (ad != NULL)
1048 { 1113 {
1049 unsigned int i, len = strlen (home) + 2; 1114 get_xdefaults (ad, RESCLASS);
1050 char *f = NULL; 1115 get_xdefaults (ad, "");
1051
1052 for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++)
1053 {
1054 f = (char *)rxvt_realloc (f, len + strlen (xnames[i]));
1055
1056 sprintf (f, "%s/%s", home, xnames[i]);
1057
1058 if ((fd = fopen (f, "r")) != NULL)
1059 break;
1060 }
1061
1062 free (f); 1116 fclose (ad);
1063 } 1117 }
1064 /*
1065 * The normal order to match resources is the following:
1066 * @ global resources (partial match, ~/.Xdefaults)
1067 * @ application file resources (XAPPLOADDIR/Rxvt)
1068 * @ class resources (~/.Xdefaults)
1069 * @ private resources (~/.Xdefaults)
1070 *
1071 * However, for the hand-rolled resources, the matching algorithm
1072 * checks if a resource string value has already been allocated
1073 * and won't overwrite it with (in this case) a less specific
1074 * resource value.
1075 *
1076 * This avoids multiple allocation. Also, when we've called this
1077 * routine command-line string options have already been applied so we
1078 * needn't to allocate for those resources.
1079 *
1080 * So, search in resources from most to least specific.
1081 *
1082 * Also, use a special sub-class so that we can use either or both of
1083 * "XTerm" and "Rxvt" as class names.
1084 */
1085
1086 get_xdefaults (fd, name);
1087 get_xdefaults (fd, RESCLASS);
1088# ifdef RESFALLBACK
1089 get_xdefaults (fd, RESFALLBACK);
1090# endif
1091
1092# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)
1093 {
1094 FILE *ad = NULL;
1095
1096# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1097 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL)
1098# endif
1099 ad = fopen (XAPPLOADDIR "/" RESCLASS, "r");
1100 if (ad != NULL)
1101 {
1102 get_xdefaults (ad, RESCLASS);
1103 get_xdefaults (ad, "");
1104 fclose (ad);
1105 }
1106 } 1118 }
1107# endif /* XAPPLOADDIR */ 1119# endif /* XAPPLOADDIR */
1108 1120
1109 get_xdefaults (fd, ""); /* partial match */ 1121 get_xdefaults (fd, ""); /* partial match */
1110 if (fd != NULL) 1122 if (fd != NULL)
1111 fclose (fd); 1123 fclose (fd);
1112# endif /* USE_XGETDEFAULT */ 1124# endif /* USE_XGETDEFAULT */
1113
1114# if defined XAPPLOADDIR
1115# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1116
1117 }
1118
1119 /* Free the path of the possibly available localized Rxvt file */
1120 free (localepath);
1121# endif
1122# endif
1123 1125
1124#endif /* NO_RESOURCES */ 1126#endif /* NO_RESOURCES */
1125} 1127}
1126 1128
1127/*}}} */ 1129/*}}} */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines