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.128 by ayin, Mon Dec 31 01:16:47 2007 UTC vs.
Revision 1.129 by ayin, Mon Jan 7 12:31:49 2008 UTC

626} 626}
627 627
628/* 628/*
629 * look for something like this (XK_Delete) 629 * look for something like this (XK_Delete)
630 * rxvt*keysym.0xFFFF: "\177" 630 * rxvt*keysym.0xFFFF: "\177"
631 *
632 * arg will be
633 * NULL for ~/.Xdefaults and
634 * non-NULL for command-line options (need to allocate)
635 */ 631 */
636#define NEWARGLIM 500 /* `reasonable' size */
637 632
638struct keysym_vocabulary_t 633struct keysym_vocabulary_t
639{ 634{
640 const char *name; 635 const char *name;
641 unsigned short len; 636 unsigned short len;
671}; 666};
672 667
673int 668int
674rxvt_term::parse_keysym (const char *str, const char *arg) 669rxvt_term::parse_keysym (const char *str, const char *arg)
675{ 670{
676 int n, sym; 671 int sym;
677 unsigned int state = 0; 672 unsigned int state = 0;
678 const char *pmodend = NULL; 673 const char *key = strrchr (str, '-');
679 char *newarg = NULL;
680 char newargstr[NEWARGLIM];
681 674
682 if (arg == NULL) 675 if (!key)
683 { 676 key = str;
684 n = sizeof ("keysym.") - 1;
685 if (strncmp (str, "keysym.", n))
686 return 0;
687
688 str += n; /* skip `keysym.' */
689 if (!(pmodend = strchr (str, ':')))
690 return -1;
691 }
692 else 677 else
693 pmodend = str + strlen(str); 678 key++;
694 679
695 for (--pmodend; str < pmodend; --pmodend) 680 // string or key is empty
696 if (*pmodend == '-') 681 if (*arg == '\0' || *key == '\0')
697 break; 682 return -1;
698 683
684 // parse modifiers
699 while (str < pmodend) 685 while (str < key)
700 { 686 {
701 unsigned int i; 687 unsigned int i;
702 688
703 for (i=0; i < sizeof (keysym_vocabulary) / sizeof (keysym_vocabulary_t); ++i) 689 for (i=0; i < sizeof (keysym_vocabulary) / sizeof (keysym_vocabulary_t); ++i)
704 { 690 {
715 701
716 if (*str == '-') 702 if (*str == '-')
717 ++str; 703 ++str;
718 } 704 }
719 705
720 /* some scanf () have trouble with a 0x prefix */ 706 // convert keysym name to keysym number
721 if (str[0] == '0' && toupper (str[1]) == 'X') 707 if ((sym = XStringToKeysym (str)) == None)
722 { 708 {
723 str += 2; 709 // fallback on hexadecimal parsing
724 710 char *end;
711 sym = strtol (str, &end, 16);
725 if (arg) 712 if (*end)
726 {
727 if (sscanf (str, (strchr (str, ':') ? "%x:" : "%x"), &sym) != 1)
728 return -1;
729 }
730 else
731 {
732 if (sscanf (str, "%x:", &sym) != 1)
733 return -1;
734
735 /* cue to ':', it's there since sscanf () worked */
736 strncpy (newargstr, strchr (str, ':') + 1, NEWARGLIM - 1);
737 newargstr[NEWARGLIM - 1] = '\0';
738 newarg = newargstr;
739 }
740 }
741 else
742 {
743 /*
744 * convert keysym name to keysym number
745 */
746 strncpy (newargstr, str, NEWARGLIM - 1);
747 newargstr[NEWARGLIM - 1] = '\0';
748
749 if (arg == NULL)
750 {
751 if ((newarg = strchr (newargstr, ':')) == NULL)
752 return -1;
753
754 *newarg++ = '\0'; /* terminate keysym name */
755 }
756
757 if ((sym = XStringToKeysym (newargstr)) == None)
758 return -1; 713 return -1;
759 } 714 }
760 715
761 if (newarg == NULL)
762 {
763 strncpy (newargstr, arg, NEWARGLIM - 1);
764 newargstr[NEWARGLIM - 1] = '\0';
765 newarg = newargstr;
766 }
767
768 if (*newarg == '\0')
769 return -1;
770
771 keyboard->register_user_translation (sym, state, newarg); 716 keyboard->register_user_translation (sym, state, arg);
772 return 1; 717 return 1;
773} 718}
774 719
775# endif /* KEYSYM_RESOURCE */ 720# endif /* KEYSYM_RESOURCE */
776#endif /* NO_RESOURCES */ 721#endif /* NO_RESOURCES */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines