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.17 by pcg, Sun Mar 14 17:33:08 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.17 2004/03/14 17:33:08 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"),
249 RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"), 240 RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"),
250#endif 241#endif
251#ifdef PRINTPIPE 242#ifdef PRINTPIPE
252 RSTRG (Rs_print_pipe, "print-pipe", "string"), 243 RSTRG (Rs_print_pipe, "print-pipe", "string"),
253#endif 244#endif
254#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)
255 RSTRG (Rs_bigfont_key, "bigfont_key", "keysym"),
256 RSTRG (Rs_smallfont_key, "smallfont_key", "keysym"),
257#endif
258 STRG (Rs_modifier, "modifier", "mod", "modifier", 245 STRG (Rs_modifier, "modifier", "mod", "modifier",
259 "meta modifier = alt|meta|hyper|super|mod1|...|mod5"), 246 "meta modifier = alt|meta|hyper|super|mod1|...|mod5"),
260 INFO ("xrm", "string", "X resource"), 247 INFO ("xrm", "string", "X resource"),
261#ifdef CUTCHAR_RESOURCE 248#ifdef CUTCHAR_RESOURCE
262 RSTRG (Rs_cutchars, "cutchars", "string"), 249 RSTRG (Rs_cutchars, "cutchars", "string"),
263#endif /* CUTCHAR_RESOURCE */ 250#endif /* CUTCHAR_RESOURCE */
264#ifdef ACS_ASCII
265 RSTRG (Rs_acs_chars, "acsChars", "string"),
266#endif /* ACS_ASCII */
267 RSTRG (Rs_answerbackstring, "answerbackString", "string"), 251 RSTRG (Rs_answerbackstring, "answerbackString", "string"),
268 INFO ("e", "command arg ...", "command to execute") 252 INFO ("e", "command arg ...", "command to execute")
269 }; 253 };
270 254
271#undef INFO 255#undef INFO
299 "24bit," 283 "24bit,"
300#endif 284#endif
301#if defined(USE_XIM) 285#if defined(USE_XIM)
302 "XIM," 286 "XIM,"
303#endif 287#endif
304#if defined(MULTICHAR_SET)
305 "multichar_languages,"
306#endif
307 "scrollbars=" 288 "scrollbars="
308#if !defined(HAVE_SCROLLBARS) 289#if !defined(HAVE_SCROLLBARS)
309 "NONE" 290 "NONE"
310#else 291#else
292# if defined(PLAIN_SCROLLBAR)
293 "plain"
294# if defined(RXVT_SCROLLBAR) || defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR)
295 "+"
296# endif
297# endif
311# if defined(RXVT_SCROLLBAR) 298# if defined(RXVT_SCROLLBAR)
312 "rxvt" 299 "rxvt"
313# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) 300# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR)
314 "+" 301 "+"
315# endif 302# endif
323# if defined(XTERM_SCROLLBAR) 310# if defined(XTERM_SCROLLBAR)
324 "xterm" 311 "xterm"
325# endif 312# endif
326#endif 313#endif
327 "," 314 ","
328#if defined(GREEK_SUPPORT)
329 "Greek,"
330#endif
331#if defined(RXVT_GRAPHICS)
332 "graphics,"
333#endif
334#if defined(NO_BACKSPACE_KEY) 315#if defined(NO_BACKSPACE_KEY)
335 "no_backspace," 316 "no_backspace,"
336#endif 317#endif
337#if defined(NO_DELETE_KEY) 318#if defined(NO_DELETE_KEY)
338 "no_delete," 319 "no_delete,"
363{ 344{
364 unsigned int i, col; 345 unsigned int i, col;
365 346
366 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1); 347 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1);
367 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1); 348 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1);
368 write (STDERR_FILENO, APL_NAME, sizeof (APL_NAME) - 1); 349 write (STDERR_FILENO, RESNAME, sizeof (RESNAME) - 1);
369 350
370 switch (type) 351 switch (type)
371 { 352 {
372 case 0: /* brief listing */ 353 case 0: /* brief listing */
373 fprintf (stderr, " [-help] [--help]\n"); 354 fprintf (stderr, " [-help] [--help]\n");
570 * quarks will be something like 551 * quarks will be something like
571 * "rxvt" "keysym" "0xFF01" 552 * "rxvt" "keysym" "0xFF01"
572 * value will be a string 553 * value will be a string
573 */ 554 */
574/* ARGSUSED */ 555/* ARGSUSED */
575bool 556int
576rxvt_define_key(XrmDatabase *database __attribute__((unused)), XrmBindingList bindings __attribute__((unused)), XrmQuarkList quarks, XrmRepresentation *type __attribute__((unused)), XrmValue *value, XPointer closure __attribute__((unused))) 557rxvt_define_key (XrmDatabase *database __attribute__((unused)),
558 XrmBindingList bindings __attribute__((unused)),
559 XrmQuarkList quarks,
560 XrmRepresentation *type __attribute__((unused)),
561 XrmValue *value,
562 XPointer closure __attribute__((unused)))
577{ 563{
578 int last; 564 int last;
579 565
580 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */ 566 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */
581 ; 567 ;
677 * the matching algorithm used for memory-save fake resources 663 * the matching algorithm used for memory-save fake resources
678 */ 664 */
679void 665void
680rxvt_term::get_xdefaults (FILE *stream, const char *name) 666rxvt_term::get_xdefaults (FILE *stream, const char *name)
681{ 667{
682 unsigned int len; 668 unsigned int len;
683 char *str, buffer[256]; 669 char *str, buffer[256];
684 670
685 if (stream == NULL) 671 if (stream == NULL)
686 return; 672 return;
687 len = STRLEN (name); 673 len = STRLEN (name);
688 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) 674 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL)
708 continue; 694 continue;
709 n = STRLEN (kw); 695 n = STRLEN (kw);
710 if (str[n] == ':' && rxvt_Str_match (str, kw)) 696 if (str[n] == ':' && rxvt_Str_match (str, kw))
711 { 697 {
712 /* skip `keyword:' */ 698 /* skip `keyword:' */
713 str += (n + 1); 699 str += n + 1;
714 rxvt_Str_trim (str); 700 rxvt_Str_trim (str);
715 n = STRLEN (str); 701 n = STRLEN (str);
716 if (n && rs[optList[entry].doff] == NULL) 702 if (n && rs[optList[entry].doff] == NULL)
717 { 703 {
718 /* not already set */ 704 /* not already set */
719 int s; 705 int s;
720 char *p = (char *)rxvt_malloc ((n + 1) * sizeof (char)); 706 char *p = 0;
721 707
708 for (int o = 0;;)
709 {
710 p = (char *)rxvt_realloc (p, o + n + 1);
722 STRCPY (p, str); 711 MEMCPY (p + o, str, n);
712 o += n;
713 p[o] = 0;
714
715 if (o == 0 || p[o - 1] != '\\') // continuation line
716 break;
717
718 o--; // eat "\"
719
720 if ((str = fgets (buffer, sizeof (buffer), stream)) == NULL)
721 break;
722
723 rxvt_Str_trim (str);
724 n = STRLEN (str);
725 }
726
723 rs[optList[entry].doff] = p; 727 rs[optList[entry].doff] = p;
724 if (optList_isBool (entry)) 728 if (optList_isBool (entry))
725 { 729 {
726 s = STRCASECMP (str, "TRUE") == 0 730 s = STRCASECMP (str, "TRUE") == 0
727 || STRCASECMP (str, "YES") == 0 731 || STRCASECMP (str, "YES") == 0
762 char *localepath = NULL; 766 char *localepath = NULL;
763 767
764 if (locale != NULL) 768 if (locale != NULL)
765 { /* XXX: must limit length of string */ 769 { /* XXX: must limit length of string */
766 localepath = (char *)rxvt_malloc (256); 770 localepath = (char *)rxvt_malloc (256);
767 sprintf (localepath, XAPPLOADDIRLOCALE "/" APL_SUBCLASS, 771 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS,
768 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (APL_SUBCLASS)), 772 (int) (258 - sizeof (XAPPLOADDIRLOCALE) - sizeof (RESCLASS)),
769 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */ 773 locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */
770 } 774 }
771 775
772 { 776 {
773# endif 777# endif
828 832
829 /* Add in Rxvt file */ 833 /* Add in Rxvt file */
830# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 834# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
831 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL) 835 if (localepath == NULL || (rdb1 = XrmGetFileDatabase (localepath)) == NULL)
832# endif 836# endif
833 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" APL_SUBCLASS); 837 rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS);
838
834 if (rdb1 != NULL) 839 if (rdb1 != NULL)
835 XrmMergeDatabases (rdb1, &database); 840 XrmMergeDatabases (rdb1, &database);
836 841
837 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ 842 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
838 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL) 843 if ((xe = (char *)getenv ("XAPPLRESDIR")) != NULL)
839 { 844 {
840 sprintf (fname, "%-.*s/" APL_SUBCLASS, sizeof (fname) 845 sprintf (fname, "%-.*s/" RESCLASS, sizeof (fname)
841 - sizeof (APL_SUBCLASS) - 2, xe); 846 - sizeof (RESCLASS) - 2, xe);
842 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) 847 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL)
843 XrmMergeDatabases (rdb1, &database); 848 XrmMergeDatabases (rdb1, &database);
844 } 849 }
845 850
846 XrmSetDatabase (display, database); 851 XrmSetDatabase (display, database);
860 865
861 p = XGetDefault (display, name, kw); 866 p = XGetDefault (display, name, kw);
862 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw); 867 p0 = XGetDefault (display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);
863 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 868 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
864 { 869 {
865 p = XGetDefault (display, APL_SUBCLASS, kw); 870 p = XGetDefault (display, RESCLASS, kw);
871#ifdef RESFALLBACK
866 if (p == NULL || (p0 && STRCMP (p, p0) == 0)) 872 if (p == NULL || (p0 && STRCMP (p, p0) == 0))
867 p = XGetDefault (display, APL_CLASS, kw); 873 p = XGetDefault (display, RESFALLBACK, kw);
874#endif
868 } 875 }
876
869 if (p == NULL && p0) 877 if (p == NULL && p0)
870 p = p0; 878 p = p0;
879
871 if (p) 880 if (p)
872 { 881 {
873 rs[optList[entry].doff] = p; 882 rs[optList[entry].doff] = p;
874 883
875 if (optList_isBool (entry)) 884 if (optList_isBool (entry))
894# ifdef XrmEnumOneLevel 903# ifdef XrmEnumOneLevel
895# ifdef KEYSYM_RESOURCE 904# ifdef KEYSYM_RESOURCE
896 name_prefix[0] = XrmStringToName (name); 905 name_prefix[0] = XrmStringToName (name);
897 name_prefix[1] = XrmStringToName ("keysym"); 906 name_prefix[1] = XrmStringToName ("keysym");
898 name_prefix[2] = NULLQUARK; 907 name_prefix[2] = NULLQUARK;
899 class_prefix[0] = XrmStringToName (APL_SUBCLASS); 908 class_prefix[0] = XrmStringToName (RESCLASS);
900 class_prefix[1] = XrmStringToName ("Keysym"); 909 class_prefix[1] = XrmStringToName ("Keysym");
901 class_prefix[2] = NULLQUARK; 910 class_prefix[2] = NULLQUARK;
902 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 911 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
903 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 912 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
904 XrmEnumOneLevel, rxvt_define_key, NULL); 913 XrmEnumOneLevel, rxvt_define_key, NULL);
914# ifdef RESFALLBACK
905 name_prefix[0] = XrmStringToName (APL_CLASS); 915 name_prefix[0] = XrmStringToName (RESFALLBACK);
906 name_prefix[1] = XrmStringToName ("keysym"); 916 name_prefix[1] = XrmStringToName ("keysym");
907 class_prefix[0] = XrmStringToName (APL_CLASS); 917 class_prefix[0] = XrmStringToName (RESFALLBACK);
908 class_prefix[1] = XrmStringToName ("Keysym"); 918 class_prefix[1] = XrmStringToName ("Keysym");
909 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ 919 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
910 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix, 920 XrmEnumerateDatabase (XrmGetDatabase (display), name_prefix, class_prefix,
911 XrmEnumOneLevel, rxvt_define_key, NULL); 921 XrmEnumOneLevel, rxvt_define_key, NULL);
922# endif
912# endif 923# endif
913# endif 924# endif
914 925
915# else /* USE_XGETDEFAULT */ 926# else /* USE_XGETDEFAULT */
916 /* get resources the hard way, but save lots of memory */ 927 /* 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 965 * Also, use a special sub-class so that we can use either or both of
955 * "XTerm" and "Rxvt" as class names. 966 * "XTerm" and "Rxvt" as class names.
956 */ 967 */
957 968
958 get_xdefaults (fd, name); 969 get_xdefaults (fd, name);
959 get_xdefaults (fd, APL_SUBCLASS); 970 get_xdefaults (fd, RESCLASS);
971# ifdef RESFALLBACK
972 get_xdefaults (fd, RESFALLBACK);
973# endif
960 974
961# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) 975# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)
962
963 { 976 {
964 FILE *ad = NULL; 977 FILE *ad = NULL;
965 978
966# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 979# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
967 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) 980 if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL)
968# endif 981# endif
969 ad = fopen (XAPPLOADDIR "/" APL_SUBCLASS, "r"); 982 ad = fopen (XAPPLOADDIR "/" RESCLASS, "r");
970 if (ad != NULL) 983 if (ad != NULL)
971 { 984 {
972 get_xdefaults (ad, APL_SUBCLASS); 985 get_xdefaults (ad, RESCLASS);
973 get_xdefaults (ad, ""); 986 get_xdefaults (ad, "");
974 fclose (ad); 987 fclose (ad);
975 } 988 }
976 } 989 }
977# endif /* XAPPLOADDIR */ 990# endif /* XAPPLOADDIR */
978 991
979 get_xdefaults (fd, APL_CLASS);
980 get_xdefaults (fd, ""); /* partial match */ 992 get_xdefaults (fd, ""); /* partial match */
981 if (fd != NULL) 993 if (fd != NULL)
982 fclose (fd); 994 fclose (fd);
983# endif /* USE_XGETDEFAULT */ 995# endif /* USE_XGETDEFAULT */
984 996
991 free (localepath); 1003 free (localepath);
992# endif 1004# endif
993# endif 1005# endif
994 1006
995#endif /* NO_RESOURCES */ 1007#endif /* NO_RESOURCES */
996
997 /*
998 * even without resources, at least do this setup for command-line
999 * options and command-line long options
1000 */
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
1023#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)
1024
1025 {
1026 KeySym sym;
1027
1028 if (rs[Rs_bigfont_key]
1029 && ((sym = XStringToKeysym (rs[Rs_bigfont_key])) != 0))
1030 ks_bigfont = sym;
1031 if (rs[Rs_smallfont_key]
1032 && ((sym = XStringToKeysym (rs[Rs_smallfont_key])) != 0))
1033 ks_smallfont = sym;
1034 }
1035#endif
1036} 1008}
1037 1009
1038/*}}} */ 1010/*}}} */
1039/*----------------------- end-of-file (C source) -----------------------*/ 1011/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines