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.194 by root, Tue Sep 17 20:38:53 2019 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 tighly bound quark, we skip it,
849 // as it is the exactly matched the prefix. Otherwise, it matched because
850 // it started with "*", in which case we assuime 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 if (*bindings != XrmBindTightly)
866 return False;
867
868 ++quarks, ++bindings; // skip if this is a fixed prefix, rather than a *-match
869 if (*quarks == NULLQUARK) return False;
870 }
871
872 char *pattern;
873 if (quarks[1] == NULLQUARK)
874 pattern = XrmQuarkToString (quarks[0]); // single component, fats path
875 else
876 {
877 // multiple components, slow path - should be rare, to don't optimize for speed
878 int size = 0;
879
880 for (int i = 0; quarks[i] != NULLQUARK; ++i)
881 size += strlen (XrmQuarkToString (quarks[i])) + 1;
882
883 pattern = rxvt_temp_buf<char> (size + 1);
884
885 // now print all components
886 {
887 char *cur = pattern;
888
889 for (int i = 0; quarks[i] != NULLQUARK; ++i)
890 cur += sprintf (cur, ".%s", XrmQuarkToString (quarks[i]));
891 }
892
893 ++pattern; // skip initial dot
894 }
895
896 data->cb (data->term, pattern, (char *)value->addr);
897
898 return False;
899}
900
852void 901void
853rxvt_term::enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p, const char *class_p) 902rxvt_term::enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p, const char *class_p)
854{ 903{
855 /* 904 /*
856 * [R5 or later]: enumerate the resource database 905 * [R5 or later]: enumerate the resource database
857 */ 906 */
907 assert (!name_p == !class_p); // both must be specified, or missing
908
858#ifdef KEYSYM_RESOURCE 909#ifdef KEYSYM_RESOURCE
859 void *closure[2] = { 910 rxvt_enumerate_closure closure = { this, cb, name_p ? 1 : 0 };
860 (void *)this,
861 (void *)cb,
862 };
863 911
864 XrmDatabase database = XrmGetDatabase (dpy); 912 XrmDatabase database = XrmGetDatabase (dpy);
865 XrmName name_prefix[3]; 913 XrmName name_prefix[3];
866 XrmClass class_prefix[3]; 914 XrmClass class_prefix[3];
867 915
870 class_prefix[1] = class_p ? XrmStringToName (class_p) : NULLQUARK; 918 class_prefix[1] = class_p ? XrmStringToName (class_p) : NULLQUARK;
871 class_prefix[2] = NULLQUARK; 919 class_prefix[2] = NULLQUARK;
872 920
873# ifdef RESFALLBACK 921# ifdef RESFALLBACK
874 name_prefix[0] = class_prefix[0] = XrmStringToName (RESFALLBACK); 922 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, 923 XrmEnumerateDatabase (database, name_prefix, class_prefix,
877 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 924 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
878# endif 925# endif
879 926
880 name_prefix[0] = class_prefix[0] = XrmStringToName (RESCLASS); 927 name_prefix[0] = class_prefix[0] = XrmStringToName (RESCLASS);
881 XrmEnumerateDatabase (database, name_prefix, class_prefix, 928 XrmEnumerateDatabase (database, name_prefix, class_prefix,
882 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 929 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
883 930
884 name_prefix[0] = class_prefix[0] = XrmStringToName (rs[Rs_name]); 931 name_prefix[0] = class_prefix[0] = XrmStringToName (rs[Rs_name]);
885 XrmEnumerateDatabase (database, name_prefix, class_prefix, 932 XrmEnumerateDatabase (database, name_prefix, class_prefix,
886 XrmEnumOneLevel, rxvt_enumerate_helper, (XPointer)closure); 933 XrmEnumAllLevels, rxvt_enumerate_helper, (XPointer)&closure);
887#endif 934#endif
888} 935}
889 936
890void 937void
891rxvt_term::extract_keysym_resources () 938rxvt_term::extract_keysym_resources ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines