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.13 by pcg, Tue Feb 24 21:41:16 2004 UTC vs.
Revision 1.16 by pcg, Thu Mar 4 00:59:10 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xdefaults.c 2 * File: xdefaults.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xdefaults.C,v 1.13 2004/02/24 21:41:16 pcg Exp $ 4 * $Id: xdefaults.C,v 1.16 2004/03/04 00:59:10 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 7 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
8 * - original version 8 * - original version
9 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca> 9 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca>
130 BOOL (Rs_meta8, "meta8", NULL, Opt_meta8, NULL), 130 BOOL (Rs_meta8, "meta8", NULL, Opt_meta8, NULL),
131#endif 131#endif
132#ifdef MOUSE_WHEEL 132#ifdef MOUSE_WHEEL
133 BOOL (Rs_mouseWheelScrollPage, "mouseWheelScrollPage", NULL, Opt_mouseWheelScrollPage, 133 BOOL (Rs_mouseWheelScrollPage, "mouseWheelScrollPage", NULL, Opt_mouseWheelScrollPage,
134 NULL), 134 NULL),
135#endif
136#ifdef MULTICHAR_SET
137 BOOL (Rs_mc_hack, "multibyte_cursor", "mcc", Opt_mc_hack,
138 "Multibyte character cursor movement"),
139#endif 135#endif
140#ifndef NO_FRILLS 136#ifndef NO_FRILLS
141 BOOL (Rs_tripleclickwords, "tripleclickwords", "tcw", Opt_tripleclickwords, 137 BOOL (Rs_tripleclickwords, "tripleclickwords", "tcw", Opt_tripleclickwords,
142 "triple click word selection"), 138 "triple click word selection"),
143#endif 139#endif
294 "24bit," 290 "24bit,"
295#endif 291#endif
296#if defined(USE_XIM) 292#if defined(USE_XIM)
297 "XIM," 293 "XIM,"
298#endif 294#endif
299#if defined(MULTICHAR_SET)
300 "multichar_languages,"
301#endif
302 "scrollbars=" 295 "scrollbars="
303#if !defined(HAVE_SCROLLBARS) 296#if !defined(HAVE_SCROLLBARS)
304 "NONE" 297 "NONE"
305#else 298#else
299# if defined(PLAIN_SCROLLBAR)
300 "plain"
301# if defined(RXVT_SCROLLBAR) || defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR)
302 "+"
303# endif
304# endif
306# if defined(RXVT_SCROLLBAR) 305# if defined(RXVT_SCROLLBAR)
307 "rxvt" 306 "rxvt"
308# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) 307# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR)
309 "+" 308 "+"
310# endif 309# endif
352{ 351{
353 unsigned int i, col; 352 unsigned int i, col;
354 353
355 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1); 354 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1);
356 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1); 355 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1);
357 write (STDERR_FILENO, APL_NAME, sizeof (APL_NAME) - 1); 356 write (STDERR_FILENO, RESNAME, sizeof (RESNAME) - 1);
358 357
359 switch (type) 358 switch (type)
360 { 359 {
361 case 0: /* brief listing */ 360 case 0: /* brief listing */
362 fprintf (stderr, " [-help] [--help]\n"); 361 fprintf (stderr, " [-help] [--help]\n");
671 * the matching algorithm used for memory-save fake resources 670 * the matching algorithm used for memory-save fake resources
672 */ 671 */
673void 672void
674rxvt_term::get_xdefaults (FILE *stream, const char *name) 673rxvt_term::get_xdefaults (FILE *stream, const char *name)
675{ 674{
676 unsigned int len; 675 unsigned int len;
677 char *str, buffer[256]; 676 char *str, buffer[256];
678 677
679 if (stream == NULL) 678 if (stream == NULL)
680 return; 679 return;
681 len = STRLEN (name); 680 len = STRLEN (name);
682 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) 681 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL)
702 continue; 701 continue;
703 n = STRLEN (kw); 702 n = STRLEN (kw);
704 if (str[n] == ':' && rxvt_Str_match (str, kw)) 703 if (str[n] == ':' && rxvt_Str_match (str, kw))
705 { 704 {
706 /* skip `keyword:' */ 705 /* skip `keyword:' */
707 str += (n + 1); 706 str += n + 1;
708 rxvt_Str_trim (str); 707 rxvt_Str_trim (str);
709 n = STRLEN (str); 708 n = STRLEN (str);
710 if (n && rs[optList[entry].doff] == NULL) 709 if (n && rs[optList[entry].doff] == NULL)
711 { 710 {
712 /* not already set */ 711 /* not already set */
713 int s; 712 int s;
714 char *p = (char *)rxvt_malloc ((n + 1) * sizeof (char)); 713 char *p = 0;
715 714
715 for (int o = 0;;)
716 {
717 p = (char *)rxvt_realloc (p, o + n + 1);
716 STRCPY (p, str); 718 MEMCPY (p + o, str, n);
719 o += n;
720 p[o] = 0;
721
722 if (o == 0 || p[o - 1] != '\\') // continuation line
723 break;
724
725 o--; // eat "\"
726
727 if ((str = fgets (buffer, sizeof (buffer), stream)) == NULL)
728 break;
729
730 rxvt_Str_trim (str);
731 n = STRLEN (str);
732 }
733
717 rs[optList[entry].doff] = p; 734 rs[optList[entry].doff] = p;
718 if (optList_isBool (entry)) 735 if (optList_isBool (entry))
719 { 736 {
720 s = STRCASECMP (str, "TRUE") == 0 737 s = STRCASECMP (str, "TRUE") == 0
721 || STRCASECMP (str, "YES") == 0 738 || STRCASECMP (str, "YES") == 0
756 char *localepath = NULL; 773 char *localepath = NULL;
757 774
758 if (locale != NULL) 775 if (locale != NULL)
759 { /* XXX: must limit length of string */ 776 { /* XXX: must limit length of string */
760 localepath = (char *)rxvt_malloc (256); 777 localepath = (char *)rxvt_malloc (256);
761 sprintf (localepath, XAPPLOADDIRLOCALE "/" APL_SUBCLASS, 778 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS,
762 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (APL_SUBCLASS)), 779 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (RESCLASS)),
763 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */ 780 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */
764 } 781 }
765 782
766 { 783 {
767# endif 784# endif
822 839
823 /* Add in Rxvt file */ 840 /* Add in Rxvt file */
824# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 841# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
825 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL) 842 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL)
826# endif 843# endif
827 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" APL_SUBCLASS); 844 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS);
845
828 if (rdb1 != NULL) 846 if (rdb1 != NULL)
829 XrmMergeDatabases (rdb1, &database); 847 XrmMergeDatabases (rdb1, &database);
830 848
831 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ 849 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
832 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL) 850 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL)
833 { 851 {
834 sprintf (fname, "%-.*s/" APL_SUBCLASS, sizeof (fname) 852 sprintf (fname, "%-.*s/" RESCLASS, sizeof (fname)
835 - sizeof (APL_SUBCLASS) - 2, xe); 853 - sizeof (RESCLASS) - 2, xe);
836 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) 854 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL)
837 XrmMergeDatabases (rdb1, &database); 855 XrmMergeDatabases (rdb1, &database);
838 } 856 }
839 857
840 XrmSetDatabase (display, database); 858 XrmSetDatabase (display, database);
854 872
855 p = XGetDefault (display, name, kw); 873 p = XGetDefault (display, name, kw);
856 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw); 874 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);
857 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 875 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
858 { 876 {
859 p = XGetDefault (display, APL_SUBCLASS, kw); 877 p = XGetDefault (display, RESCLASS, kw);
878#ifdef RESFALLBACK
860 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 879 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
861 p = XGetDefault (display, APL_CLASS, kw); 880 p = XGetDefault (display, RESFALLBACK, kw);
881#endif
862 } 882 }
883
863 if (p == NULL && p0) 884 if (p == NULL && p0)
864 p = p0; 885 p = p0;
886
865 if (p) 887 if (p)
866 { 888 {
867 rs[optList[entry].doff] = p; 889 rs[optList[entry].doff] = p;
868 890
869 if (optList_isBool (entry)) 891 if (optList_isBool (entry))
888# ifdef XrmEnumOneLevel 910# ifdef XrmEnumOneLevel
889# ifdef KEYSYM_RESOURCE 911# ifdef KEYSYM_RESOURCE
890 name_prefix[0] = XrmStringToName (name); 912 name_prefix[0] = XrmStringToName (name);
891 name_prefix[1] = XrmStringToName ("keysym"); 913 name_prefix[1] = XrmStringToName ("keysym");
892 name_prefix[2] = NULLQUARK; 914 name_prefix[2] = NULLQUARK;
893 class_prefix[0] = XrmStringToName (APL_SUBCLASS); 915 class_prefix[0] = XrmStringToName (RESCLASS);
894 class_prefix[1] = XrmStringToName ("Keysym"); 916 class_prefix[1] = XrmStringToName ("Keysym");
895 class_prefix[2] = NULLQUARK; 917 class_prefix[2] = NULLQUARK;
896 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 918 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
897 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 919 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
898 XrmEnumOneLevel, rxvt_define_key, NULL); 920 XrmEnumOneLevel, rxvt_define_key, NULL);
921# ifdef RESFALLBACK
899 name_prefix[0] = XrmStringToName (APL_CLASS); 922 name_prefix[0] = XrmStringToName (RESFALLBACK);
900 name_prefix[1] = XrmStringToName ("keysym"); 923 name_prefix[1] = XrmStringToName ("keysym");
901 class_prefix[0] = XrmStringToName (APL_CLASS); 924 class_prefix[0] = XrmStringToName (RESFALLBACK);
902 class_prefix[1] = XrmStringToName ("Keysym"); 925 class_prefix[1] = XrmStringToName ("Keysym");
903 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 926 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
904 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 927 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
905 XrmEnumOneLevel, rxvt_define_key, NULL); 928 XrmEnumOneLevel, rxvt_define_key, NULL);
929# endif
906# endif 930# endif
907# endif 931# endif
908 932
909# else /* USE_XGETDEFAULT */ 933# else /* USE_XGETDEFAULT */
910 /* get resources the hard way, but save lots of memory */ 934 /* get resources the hard way, but save lots of memory */
948 * Also, use a special sub-class so that we can use either or both of 972 * Also, use a special sub-class so that we can use either or both of
949 * "XTerm" and "Rxvt" as class names. 973 * "XTerm" and "Rxvt" as class names.
950 */ 974 */
951 975
952 get_xdefaults (fd, name); 976 get_xdefaults (fd, name);
953 get_xdefaults (fd, APL_SUBCLASS); 977 get_xdefaults (fd, RESCLASS);
978# ifdef RESFALLBACK
979 get_xdefaults (fd, RESFALLBACK);
980# endif
954 981
955# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) 982# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)
956 983
957 { 984 {
958 FILE *ad = NULL; 985 FILE *ad = NULL;
959 986
960# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 987# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
961 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) 988 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL)
962# endif 989# endif
963 ad = fopen (XAPPLOADDIR "/" APL_SUBCLASS, "r"); 990 ad = fopen (XAPPLOADDIR "/" RESCLASS, "r");
964 if (ad != NULL) 991 if (ad != NULL)
965 { 992 {
966 get_xdefaults (ad, APL_SUBCLASS); 993 get_xdefaults (ad, RESCLASS);
967 get_xdefaults (ad, ""); 994 get_xdefaults (ad, "");
968 fclose (ad); 995 fclose (ad);
969 } 996 }
970 } 997 }
971# endif /* XAPPLOADDIR */ 998# endif /* XAPPLOADDIR */
972 999
973 get_xdefaults (fd, APL_CLASS);
974 get_xdefaults (fd, ""); /* partial match */ 1000 get_xdefaults (fd, ""); /* partial match */
975 if (fd != NULL) 1001 if (fd != NULL)
976 fclose (fd); 1002 fclose (fd);
977# endif /* USE_XGETDEFAULT */ 1003# endif /* USE_XGETDEFAULT */
978 1004

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines