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.11 by pcg, Fri Feb 13 12:16:21 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.11 2004/02/13 12:16:21 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
197 "input style: style = OverTheSpot|OffTheSpot|Root"), 193 "input style: style = OverTheSpot|OffTheSpot|Root"),
198#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 194#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
199 STRG (Rs_imLocale, "imLocale", "imlocale", "string", "locale to use for input method"), 195 STRG (Rs_imLocale, "imLocale", "imlocale", "string", "locale to use for input method"),
200#endif 196#endif
201#endif /* USE_XIM */ 197#endif /* USE_XIM */
202#ifdef GREEK_SUPPORT
203 STRG (Rs_greek_keyboard, "greek_keyboard", "grk", "mode",
204 "greek keyboard mapping; mode = iso | ibm"),
205 RSTRG (Rs_greektoggle_key, "greektoggle_key", "keysym"),
206#endif
207 STRG (Rs_name, NULL, "name", "string", 198 STRG (Rs_name, NULL, "name", "string",
208 "client instance, icon, and title strings"), 199 "client instance, icon, and title strings"),
209 STRG (Rs_title, "title", "title", "string", "title name for window"), 200 STRG (Rs_title, "title", "title", "string", "title name for window"),
210 STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */ 201 STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */
211 STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"), 202 STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"),
299 "24bit," 290 "24bit,"
300#endif 291#endif
301#if defined(USE_XIM) 292#if defined(USE_XIM)
302 "XIM," 293 "XIM,"
303#endif 294#endif
304#if defined(MULTICHAR_SET)
305 "multichar_languages,"
306#endif
307 "scrollbars=" 295 "scrollbars="
308#if !defined(HAVE_SCROLLBARS) 296#if !defined(HAVE_SCROLLBARS)
309 "NONE" 297 "NONE"
310#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
311# if defined(RXVT_SCROLLBAR) 305# if defined(RXVT_SCROLLBAR)
312 "rxvt" 306 "rxvt"
313# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) 307# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR)
314 "+" 308 "+"
315# endif 309# endif
323# if defined(XTERM_SCROLLBAR) 317# if defined(XTERM_SCROLLBAR)
324 "xterm" 318 "xterm"
325# endif 319# endif
326#endif 320#endif
327 "," 321 ","
328#if defined(GREEK_SUPPORT)
329 "Greek,"
330#endif
331#if defined(RXVT_GRAPHICS)
332 "graphics,"
333#endif
334#if defined(NO_BACKSPACE_KEY) 322#if defined(NO_BACKSPACE_KEY)
335 "no_backspace," 323 "no_backspace,"
336#endif 324#endif
337#if defined(NO_DELETE_KEY) 325#if defined(NO_DELETE_KEY)
338 "no_delete," 326 "no_delete,"
363{ 351{
364 unsigned int i, col; 352 unsigned int i, col;
365 353
366 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1); 354 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1);
367 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1); 355 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1);
368 write (STDERR_FILENO, APL_NAME, sizeof (APL_NAME) - 1); 356 write (STDERR_FILENO, RESNAME, sizeof (RESNAME) - 1);
369 357
370 switch (type) 358 switch (type)
371 { 359 {
372 case 0: /* brief listing */ 360 case 0: /* brief listing */
373 fprintf (stderr, " [-help] [--help]\n"); 361 fprintf (stderr, " [-help] [--help]\n");
570 * quarks will be something like 558 * quarks will be something like
571 * "rxvt" "keysym" "0xFF01" 559 * "rxvt" "keysym" "0xFF01"
572 * value will be a string 560 * value will be a string
573 */ 561 */
574/* ARGSUSED */ 562/* ARGSUSED */
575bool 563int
576rxvt_define_key(XrmDatabase *database __attribute__((unused)), XrmBindingList bindings __attribute__((unused)), XrmQuarkList quarks, XrmRepresentation *type __attribute__((unused)), XrmValue *value, XPointer closure __attribute__((unused))) 564rxvt_define_key (XrmDatabase *database __attribute__((unused)),
565 XrmBindingList bindings __attribute__((unused)),
566 XrmQuarkList quarks,
567 XrmRepresentation *type __attribute__((unused)),
568 XrmValue *value,
569 XPointer closure __attribute__((unused)))
577{ 570{
578 int last; 571 int last;
579 572
580 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */ 573 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */
581 ; 574 ;
677 * the matching algorithm used for memory-save fake resources 670 * the matching algorithm used for memory-save fake resources
678 */ 671 */
679void 672void
680rxvt_term::get_xdefaults (FILE *stream, const char *name) 673rxvt_term::get_xdefaults (FILE *stream, const char *name)
681{ 674{
682 unsigned int len; 675 unsigned int len;
683 char *str, buffer[256]; 676 char *str, buffer[256];
684 677
685 if (stream == NULL) 678 if (stream == NULL)
686 return; 679 return;
687 len = STRLEN (name); 680 len = STRLEN (name);
688 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) 681 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL)
708 continue; 701 continue;
709 n = STRLEN (kw); 702 n = STRLEN (kw);
710 if (str[n] == ':' && rxvt_Str_match (str, kw)) 703 if (str[n] == ':' && rxvt_Str_match (str, kw))
711 { 704 {
712 /* skip `keyword:' */ 705 /* skip `keyword:' */
713 str += (n + 1); 706 str += n + 1;
714 rxvt_Str_trim (str); 707 rxvt_Str_trim (str);
715 n = STRLEN (str); 708 n = STRLEN (str);
716 if (n && rs[optList[entry].doff] == NULL) 709 if (n && rs[optList[entry].doff] == NULL)
717 { 710 {
718 /* not already set */ 711 /* not already set */
719 int s; 712 int s;
720 char *p = (char *)rxvt_malloc ((n + 1) * sizeof (char)); 713 char *p = 0;
721 714
715 for (int o = 0;;)
716 {
717 p = (char *)rxvt_realloc (p, o + n + 1);
722 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
723 rs[optList[entry].doff] = p; 734 rs[optList[entry].doff] = p;
724 if (optList_isBool (entry)) 735 if (optList_isBool (entry))
725 { 736 {
726 s = STRCASECMP (str, "TRUE") == 0 737 s = STRCASECMP (str, "TRUE") == 0
727 || STRCASECMP (str, "YES") == 0 738 || STRCASECMP (str, "YES") == 0
762 char *localepath = NULL; 773 char *localepath = NULL;
763 774
764 if (locale != NULL) 775 if (locale != NULL)
765 { /* XXX: must limit length of string */ 776 { /* XXX: must limit length of string */
766 localepath = (char *)rxvt_malloc (256); 777 localepath = (char *)rxvt_malloc (256);
767 sprintf (localepath, XAPPLOADDIRLOCALE "/" APL_SUBCLASS, 778 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS,
768 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (APL_SUBCLASS)), 779 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (RESCLASS)),
769 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */ 780 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */
770 } 781 }
771 782
772 { 783 {
773# endif 784# endif
828 839
829 /* Add in Rxvt file */ 840 /* Add in Rxvt file */
830# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 841# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
831 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL) 842 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL)
832# endif 843# endif
833 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" APL_SUBCLASS); 844 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS);
845
834 if (rdb1 != NULL) 846 if (rdb1 != NULL)
835 XrmMergeDatabases (rdb1, &database); 847 XrmMergeDatabases (rdb1, &database);
836 848
837 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ 849 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
838 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL) 850 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL)
839 { 851 {
840 sprintf (fname, "%-.*s/" APL_SUBCLASS, sizeof (fname) 852 sprintf (fname, "%-.*s/" RESCLASS, sizeof (fname)
841 - sizeof (APL_SUBCLASS) - 2, xe); 853 - sizeof (RESCLASS) - 2, xe);
842 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) 854 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL)
843 XrmMergeDatabases (rdb1, &database); 855 XrmMergeDatabases (rdb1, &database);
844 } 856 }
845 857
846 XrmSetDatabase (display, database); 858 XrmSetDatabase (display, database);
860 872
861 p = XGetDefault (display, name, kw); 873 p = XGetDefault (display, name, kw);
862 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw); 874 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);
863 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 875 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
864 { 876 {
865 p = XGetDefault (display, APL_SUBCLASS, kw); 877 p = XGetDefault (display, RESCLASS, kw);
878#ifdef RESFALLBACK
866 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 879 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
867 p = XGetDefault (display, APL_CLASS, kw); 880 p = XGetDefault (display, RESFALLBACK, kw);
881#endif
868 } 882 }
883
869 if (p == NULL && p0) 884 if (p == NULL && p0)
870 p = p0; 885 p = p0;
886
871 if (p) 887 if (p)
872 { 888 {
873 rs[optList[entry].doff] = p; 889 rs[optList[entry].doff] = p;
874 890
875 if (optList_isBool (entry)) 891 if (optList_isBool (entry))
894# ifdef XrmEnumOneLevel 910# ifdef XrmEnumOneLevel
895# ifdef KEYSYM_RESOURCE 911# ifdef KEYSYM_RESOURCE
896 name_prefix[0] = XrmStringToName (name); 912 name_prefix[0] = XrmStringToName (name);
897 name_prefix[1] = XrmStringToName ("keysym"); 913 name_prefix[1] = XrmStringToName ("keysym");
898 name_prefix[2] = NULLQUARK; 914 name_prefix[2] = NULLQUARK;
899 class_prefix[0] = XrmStringToName (APL_SUBCLASS); 915 class_prefix[0] = XrmStringToName (RESCLASS);
900 class_prefix[1] = XrmStringToName ("Keysym"); 916 class_prefix[1] = XrmStringToName ("Keysym");
901 class_prefix[2] = NULLQUARK; 917 class_prefix[2] = NULLQUARK;
902 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 918 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
903 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 919 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
904 XrmEnumOneLevel, rxvt_define_key, NULL); 920 XrmEnumOneLevel, rxvt_define_key, NULL);
921# ifdef RESFALLBACK
905 name_prefix[0] = XrmStringToName (APL_CLASS); 922 name_prefix[0] = XrmStringToName (RESFALLBACK);
906 name_prefix[1] = XrmStringToName ("keysym"); 923 name_prefix[1] = XrmStringToName ("keysym");
907 class_prefix[0] = XrmStringToName (APL_CLASS); 924 class_prefix[0] = XrmStringToName (RESFALLBACK);
908 class_prefix[1] = XrmStringToName ("Keysym"); 925 class_prefix[1] = XrmStringToName ("Keysym");
909 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 926 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
910 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 927 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
911 XrmEnumOneLevel, rxvt_define_key, NULL); 928 XrmEnumOneLevel, rxvt_define_key, NULL);
929# endif
912# endif 930# endif
913# endif 931# endif
914 932
915# else /* USE_XGETDEFAULT */ 933# else /* USE_XGETDEFAULT */
916 /* get resources the hard way, but save lots of memory */ 934 /* get resources the hard way, but save lots of memory */
954 * 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
955 * "XTerm" and "Rxvt" as class names. 973 * "XTerm" and "Rxvt" as class names.
956 */ 974 */
957 975
958 get_xdefaults (fd, name); 976 get_xdefaults (fd, name);
959 get_xdefaults (fd, APL_SUBCLASS); 977 get_xdefaults (fd, RESCLASS);
978# ifdef RESFALLBACK
979 get_xdefaults (fd, RESFALLBACK);
980# endif
960 981
961# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) 982# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)
962 983
963 { 984 {
964 FILE *ad = NULL; 985 FILE *ad = NULL;
965 986
966# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 987# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
967 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) 988 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL)
968# endif 989# endif
969 ad = fopen (XAPPLOADDIR "/" APL_SUBCLASS, "r"); 990 ad = fopen (XAPPLOADDIR "/" RESCLASS, "r");
970 if (ad != NULL) 991 if (ad != NULL)
971 { 992 {
972 get_xdefaults (ad, APL_SUBCLASS); 993 get_xdefaults (ad, RESCLASS);
973 get_xdefaults (ad, ""); 994 get_xdefaults (ad, "");
974 fclose (ad); 995 fclose (ad);
975 } 996 }
976 } 997 }
977# endif /* XAPPLOADDIR */ 998# endif /* XAPPLOADDIR */
978 999
979 get_xdefaults (fd, APL_CLASS);
980 get_xdefaults (fd, ""); /* partial match */ 1000 get_xdefaults (fd, ""); /* partial match */
981 if (fd != NULL) 1001 if (fd != NULL)
982 fclose (fd); 1002 fclose (fd);
983# endif /* USE_XGETDEFAULT */ 1003# endif /* USE_XGETDEFAULT */
984 1004
996 1016
997 /* 1017 /*
998 * even without resources, at least do this setup for command-line 1018 * even without resources, at least do this setup for command-line
999 * options and command-line long options 1019 * options and command-line long options
1000 */ 1020 */
1001#ifdef MULTICHAR_SET
1002 set_multichar_encoding (rs[Rs_multichar_encoding]);
1003#endif
1004#ifdef GREEK_SUPPORT
1005 /* this could be a function in grkelot.c */
1006 /* void set_greek_keyboard (const char * str); */
1007 if (rs[Rs_greek_keyboard])
1008 {
1009 if (!STRCMP (rs[Rs_greek_keyboard], "iso"))
1010 greek_setmode (GREEK_ELOT928); /* former -grk9 */
1011 else if (!STRCMP (rs[Rs_greek_keyboard], "ibm"))
1012 greek_setmode (GREEK_IBM437); /* former -grk4 */
1013 }
1014 {
1015 KeySym sym;
1016
1017 if (rs[Rs_greektoggle_key]
1018 && ((sym = XStringToKeysym (rs[Rs_greektoggle_key])) != 0))
1019 ks_greekmodeswith = sym;
1020 }
1021#endif /* GREEK_SUPPORT */
1022 1021
1023#if defined (HOTKEY_CTRL) || defined (HOTKEY_META) 1022#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)
1024
1025 {
1026 KeySym sym; 1023 KeySym sym;
1027 1024
1028 if (rs[Rs_bigfont_key] 1025 if (rs[Rs_bigfont_key]
1029 && ((sym = XStringToKeysym (rs[Rs_bigfont_key])) != 0)) 1026 && ((sym = XStringToKeysym (rs[Rs_bigfont_key])) != 0))
1030 ks_bigfont = sym; 1027 ks_bigfont = sym;
1031 if (rs[Rs_smallfont_key] 1028 if (rs[Rs_smallfont_key]
1032 && ((sym = XStringToKeysym (rs[Rs_smallfont_key])) != 0)) 1029 && ((sym = XStringToKeysym (rs[Rs_smallfont_key])) != 0))
1033 ks_smallfont = sym; 1030 ks_smallfont = sym;
1034 }
1035#endif 1031#endif
1036} 1032}
1037 1033
1038/*}}} */ 1034/*}}} */
1039/*----------------------- end-of-file (C source) -----------------------*/ 1035/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines