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.127 by ayin, Mon Dec 17 23:52:45 2007 UTC vs.
Revision 1.129 by ayin, Mon Jan 7 12:31:49 2008 UTC

5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 6 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
7 * - original version 7 * - original version
8 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca> 8 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca>
9 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 9 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
10 * Copyright (c) 2007 Emanuele Giaquinta <e.giaquinta@glauco.it>
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 15 * (at your option) any later version.
625} 626}
626 627
627/* 628/*
628 * look for something like this (XK_Delete) 629 * look for something like this (XK_Delete)
629 * rxvt*keysym.0xFFFF: "\177" 630 * rxvt*keysym.0xFFFF: "\177"
630 *
631 * arg will be
632 * NULL for ~/.Xdefaults and
633 * non-NULL for command-line options (need to allocate)
634 */ 631 */
635#define NEWARGLIM 500 /* `reasonable' size */
636 632
637struct keysym_vocabulary_t 633struct keysym_vocabulary_t
638{ 634{
639 const char *name; 635 const char *name;
640 unsigned short len; 636 unsigned short len;
670}; 666};
671 667
672int 668int
673rxvt_term::parse_keysym (const char *str, const char *arg) 669rxvt_term::parse_keysym (const char *str, const char *arg)
674{ 670{
675 int n, sym; 671 int sym;
676 unsigned int state = 0; 672 unsigned int state = 0;
677 const char *pmodend = NULL; 673 const char *key = strrchr (str, '-');
678 char *newarg = NULL;
679 char newargstr[NEWARGLIM];
680 674
681 if (arg == NULL) 675 if (!key)
682 { 676 key = str;
683 n = sizeof ("keysym.") - 1;
684 if (strncmp (str, "keysym.", n))
685 return 0;
686
687 str += n; /* skip `keysym.' */
688 if (!(pmodend = strchr (str, ':')))
689 return -1;
690 }
691 else 677 else
692 pmodend = str + strlen(str); 678 key++;
693 679
694 for (--pmodend; str < pmodend; --pmodend) 680 // string or key is empty
695 if (*pmodend == '-') 681 if (*arg == '\0' || *key == '\0')
696 break; 682 return -1;
697 683
684 // parse modifiers
698 while (str < pmodend) 685 while (str < key)
699 { 686 {
700 unsigned int i; 687 unsigned int i;
701 688
702 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)
703 { 690 {
714 701
715 if (*str == '-') 702 if (*str == '-')
716 ++str; 703 ++str;
717 } 704 }
718 705
719 /* some scanf () have trouble with a 0x prefix */ 706 // convert keysym name to keysym number
720 if (str[0] == '0' && toupper (str[1]) == 'X') 707 if ((sym = XStringToKeysym (str)) == None)
721 { 708 {
722 str += 2; 709 // fallback on hexadecimal parsing
723 710 char *end;
711 sym = strtol (str, &end, 16);
724 if (arg) 712 if (*end)
725 {
726 if (sscanf (str, (strchr (str, ':') ? "%x:" : "%x"), &sym) != 1)
727 return -1;
728 }
729 else
730 {
731 if (sscanf (str, "%x:", &sym) != 1)
732 return -1;
733
734 /* cue to ':', it's there since sscanf () worked */
735 strncpy (newargstr, strchr (str, ':') + 1, NEWARGLIM - 1);
736 newargstr[NEWARGLIM - 1] = '\0';
737 newarg = newargstr;
738 }
739 }
740 else
741 {
742 /*
743 * convert keysym name to keysym number
744 */
745 strncpy (newargstr, str, NEWARGLIM - 1);
746 newargstr[NEWARGLIM - 1] = '\0';
747
748 if (arg == NULL)
749 {
750 if ((newarg = strchr (newargstr, ':')) == NULL)
751 return -1;
752
753 *newarg++ = '\0'; /* terminate keysym name */
754 }
755
756 if ((sym = XStringToKeysym (newargstr)) == None)
757 return -1; 713 return -1;
758 } 714 }
759 715
760 if (newarg == NULL)
761 {
762 strncpy (newargstr, arg, NEWARGLIM - 1);
763 newargstr[NEWARGLIM - 1] = '\0';
764 newarg = newargstr;
765 }
766
767 if (*newarg == '\0')
768 return -1;
769
770 keyboard->register_user_translation (sym, state, newarg); 716 keyboard->register_user_translation (sym, state, arg);
771 return 1; 717 return 1;
772} 718}
773 719
774# endif /* KEYSYM_RESOURCE */ 720# endif /* KEYSYM_RESOURCE */
775#endif /* NO_RESOURCES */ 721#endif /* NO_RESOURCES */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines