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.192 by sf-exg, Thu Jul 14 05:33:26 2016 UTC vs.
Revision 1.196 by root, Wed Jun 23 11:24:34 2021 UTC

627{ 627{
628 term->bind_action (k, v); 628 term->bind_action (k, v);
629} 629}
630 630
631/* 631/*
632 * Define key from XrmEnumerateDatabase.
633 * quarks will be something like
634 * "rxvt" "keysym" "0xFF01"
635 * value will be a string
636 */
637static int
638rxvt_enumerate_helper (
639 XrmDatabase *database ecb_unused,
640 XrmBindingList bindings ecb_unused,
641 XrmQuarkList quarks,
642 XrmRepresentation *type ecb_unused,
643 XrmValue *value,
644 XPointer closure
645)
646{
647 int last;
648
649 for (last = 0; quarks[last] != NULLQUARK; last++) /* look for last quark in list */
650 ;
651
652 rxvt_term *term = (rxvt_term *)(((void **)closure)[0]);
653 void (*cb)(rxvt_term *, const char *, const char *)
654 = (void (*)(rxvt_term *, const char *, const char *))
655 (((void **)closure)[1]);
656
657 cb (term, XrmQuarkToString (quarks[last - 1]), (char *)value->addr);
658
659 return False;
660}
661
662/*
663 * look for something like this (XK_Delete) 632 * look for something like this (XK_Delete)
664 * rxvt*keysym.0xFFFF: "\177" 633 * rxvt*keysym.0xFFFF: "\177"
665 */ 634 */
666 635
667struct keysym_vocabulary_t 636struct keysym_vocabulary_t
847 } 816 }
848 } 817 }
849#endif /* NO_RESOURCES */ 818#endif /* NO_RESOURCES */
850} 819}
851 820
821struct rxvt_enumerate_closure
822{
823 rxvt_term *term;
824 void (*cb)(rxvt_term *, const char *, const char *);
825 int specific; // iterate over only a specific subhierarchy
826};
827
828/*
829 * Define key from XrmEnumerateDatabase.
830 * quarks will be something like
831 * "rxvt" "keysym" "0xFF01"
832 * value will be a string
833 */
834static int
835rxvt_enumerate_helper (
836 XrmDatabase *database ecb_unused,
837 XrmBindingList bindings ecb_unused,
838 XrmQuarkList quarks,
839 XrmRepresentation *type ecb_unused,
840 XrmValue *value,
841 XPointer closure
842)
843{
844 const rxvt_enumerate_closure *data = (const rxvt_enumerate_closure *)closure;
845
846 if (*quarks == NULLQUARK) return False;
847
848 // if the quark list starts with a tightly bound quark, we skip it,
849 // as it exactly matched the prefix. Otherwise, it matched because
850 // it started with "*", in which case we assume the prefix is part
851 // of the "*".
852 if (*bindings == XrmBindTightly)
853 {
854 ++quarks, ++bindings; // skip if this is a fixed prefix, rather than a *-match
855 if (*quarks == NULLQUARK) return False;
856 }
857
858 // specific, a bit misleadingly named, is used when a specific "subclass"
859 // is iterated over, e.g. "keysym", and is used to skip one more
860 // component, as well as all generic prefixes
861 // this is a bit of a hack, ideally, keysym (the only user) should use its
862 // own iteration function, but this ought to be less bloated
863 if (data->specific)
864 {
865 ++quarks, ++bindings;
866 if (*quarks == NULLQUARK) return False;
867 }
868
869 char *pattern;
870 if (quarks[1] == NULLQUARK)
871 pattern = XrmQuarkToString (quarks[0]); // single component, fast path
872 else
873 {
874 // multiple components, slow path - should be rare, don't optimize for speed
875 int size = 0;
876
877 for (int i = 0; quarks[i] != NULLQUARK; ++i)
878 size += strlen (XrmQuarkToString (quarks[i])) + 1;
879
880 pattern = rxvt_temp_buf<char> (size + 1);
881
882 // now print all components
883 {
884 char *cur = pattern;
885
886 for (int i = 0; quarks[i] != NULLQUARK; ++i)
887 cur += sprintf (cur, ".%s", XrmQuarkToString (quarks[i]));
888 }
889
890 ++pattern; // skip initial dot
891 }
892
893 data->cb (data->term, pattern, (char *)value->addr);
894
895 return False;
896}
897
852void 898void
853rxvt_term::enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p, const char *class_p) 899rxvt_term::enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p, const char *class_p)
854{ 900{
855 /* 901 /*
856 * [R5 or later]: enumerate the resource database 902 * [R5 or later]: enumerate the resource database
857 */ 903 */
904 assert (!name_p == !class_p); // both must be specified, or missing
905
858#ifdef KEYSYM_RESOURCE 906#ifdef KEYSYM_RESOURCE
859 void *closure[2] = { 907 rxvt_enumerate_closure closure = { this, cb, name_p ? 1 : 0 };
860 (void *)this,
861 (void *)cb,
862 };
863 908
864 XrmDatabase database = XrmGetDatabase (dpy); 909 XrmDatabase database = XrmGetDatabase (dpy);
865 XrmName name_prefix[3]; 910 XrmName name_prefix[3];
866 XrmClass class_prefix[3]; 911 XrmClass class_prefix[3];
867 912
870 class_prefix[1] = class_p ? XrmStringToName (class_p) : NULLQUARK; 915 class_prefix[1] = class_p ? XrmStringToName (class_p) : NULLQUARK;
871 class_prefix[2] = NULLQUARK; 916 class_prefix[2] = NULLQUARK;
872 917
873# ifdef RESFALLBACK 918# ifdef RESFALLBACK
874 name_prefix[0] = class_prefix[0] = XrmStringToName (RESFALLBACK); 919 name_prefix[0] = class_prefix[0] = XrmStringToName (RESFALLBACK);
875 /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */
876 XrmEnumerateDatabase (database, name_prefix, class_prefix, 920 XrmEnumerateDatabase (database, name_prefix, class_prefix,
877 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 921 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
878# endif 922# endif
879 923
880 name_prefix[0] = class_prefix[0] = XrmStringToName (RESCLASS); 924 name_prefix[0] = class_prefix[0] = XrmStringToName (RESCLASS);
881 XrmEnumerateDatabase (database, name_prefix, class_prefix, 925 XrmEnumerateDatabase (database, name_prefix, class_prefix,
882 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 926 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
883 927
884 name_prefix[0] = class_prefix[0] = XrmStringToName (rs[Rs_name]); 928 name_prefix[0] = class_prefix[0] = XrmStringToName (rs[Rs_name]);
885 XrmEnumerateDatabase (database, name_prefix, class_prefix, 929 XrmEnumerateDatabase (database, name_prefix, class_prefix,
886 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 930 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
887#endif 931#endif
888} 932}
889 933
890void 934void
891rxvt_term::extract_keysym_resources () 935rxvt_term::extract_keysym_resources ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines