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.126 by ayin, Sun Dec 2 16:19: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.
239 RSTRG (Rs_backspace_key, "backspacekey", "string"), 240 RSTRG (Rs_backspace_key, "backspacekey", "string"),
240#endif 241#endif
241#ifndef NO_DELETE_KEY 242#ifndef NO_DELETE_KEY
242 RSTRG (Rs_delete_key, "deletekey", "string"), 243 RSTRG (Rs_delete_key, "deletekey", "string"),
243#endif 244#endif
244 RSTRG (Rs_selectstyle, "selectstyle", "mode"),
245#ifdef PRINTPIPE 245#ifdef PRINTPIPE
246 RSTRG (Rs_print_pipe, "print-pipe", "string"), 246 RSTRG (Rs_print_pipe, "print-pipe", "string"),
247#endif 247#endif
248 STRG (Rs_modifier, "modifier", "mod", "modifier", "meta modifier = alt|meta|hyper|super|mod1|...|mod5"), 248 STRG (Rs_modifier, "modifier", "mod", "modifier", "meta modifier = alt|meta|hyper|super|mod1|...|mod5"),
249#ifdef CUTCHAR_RESOURCE 249#ifdef CUTCHAR_RESOURCE
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