aboutsummaryrefslogtreecommitdiffstats
path: root/src/character.c
diff options
context:
space:
mode:
authorKenichi Handa2008-03-05 02:08:30 +0000
committerKenichi Handa2008-03-05 02:08:30 +0000
commit2bde7652cdeeca9a19f57df7e824a014c875ab35 (patch)
tree690f82a982288193cb6f019d8afcfaf461aff0d0 /src/character.c
parent40dd88cfb3e7bff190adfd8bea6e60cea02deacc (diff)
downloademacs-2bde7652cdeeca9a19f57df7e824a014c875ab35.tar.gz
emacs-2bde7652cdeeca9a19f57df7e824a014c875ab35.zip
(char_resolve_modifier_mask): New function.
(char_string): Use char_resolve_modifier_mask.
Diffstat (limited to 'src/character.c')
-rw-r--r--src/character.c81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/character.c b/src/character.c
index 9fa4dffc11f..a296fa94b24 100644
--- a/src/character.c
+++ b/src/character.c
@@ -96,6 +96,51 @@ char unibyte_has_multibyte_table[256];
96 96
97 97
98 98
99/* If character code C has modifier masks, reflect them to the
100 character code if possible. Return the resulting code. */
101
102int
103char_resolve_modifier_mask (c)
104 int c;
105{
106 /* An non-ASCII character can't reflect modifier bits to the code. */
107 if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
108 return c;
109
110 /* For Meta, Shift, and Control modifiers, we need special care. */
111 if (c & CHAR_META)
112 {
113 /* Move the meta bit to the right place for a string. */
114 c = (c & ~CHAR_META) | 0x80;
115 }
116 if (c & CHAR_SHIFT)
117 {
118 /* Shift modifier is valid only with [A-Za-z]. */
119 if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
120 c &= ~CHAR_SHIFT;
121 else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
122 c = (c & ~CHAR_SHIFT) - ('a' - 'A');
123 }
124 if (c & CHAR_CTL)
125 {
126 /* Simulate the code in lread.c. */
127 /* Allow `\C- ' and `\C-?'. */
128 if ((c & ~CHAR_CTL) == ' ')
129 c = 0;
130 else if ((c & ~CHAR_CTL) == '?')
131 c = 127;
132 /* ASCII control chars are made from letters (both cases),
133 as well as the non-letters within 0100...0137. */
134 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
135 c &= (037 | (~0177 & ~CHAR_CTL));
136 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
137 c &= (037 | (~0177 & ~CHAR_CTL));
138 }
139
140 return c;
141}
142
143
99/* Store multibyte form of character C at P. If C has modifier bits, 144/* Store multibyte form of character C at P. If C has modifier bits,
100 handle them appropriately. */ 145 handle them appropriately. */
101 146
@@ -108,41 +153,7 @@ char_string (c, p)
108 153
109 if (c & CHAR_MODIFIER_MASK) 154 if (c & CHAR_MODIFIER_MASK)
110 { 155 {
111 /* As an non-ASCII character can't have modifier bits, we just 156 c = (unsigned) char_resolve_modifier_mask ((int) c);
112 ignore the bits. */
113 if (ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
114 {
115 /* For Meta, Shift, and Control modifiers, we need special care. */
116 if (c & CHAR_META)
117 {
118 /* Move the meta bit to the right place for a string. */
119 c = (c & ~CHAR_META) | 0x80;
120 }
121 if (c & CHAR_SHIFT)
122 {
123 /* Shift modifier is valid only with [A-Za-z]. */
124 if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
125 c &= ~CHAR_SHIFT;
126 else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
127 c = (c & ~CHAR_SHIFT) - ('a' - 'A');
128 }
129 if (c & CHAR_CTL)
130 {
131 /* Simulate the code in lread.c. */
132 /* Allow `\C- ' and `\C-?'. */
133 if (c == (CHAR_CTL | ' '))
134 c = 0;
135 else if (c == (CHAR_CTL | '?'))
136 c = 127;
137 /* ASCII control chars are made from letters (both cases),
138 as well as the non-letters within 0100...0137. */
139 else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
140 c &= (037 | (~0177 & ~CHAR_CTL));
141 else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
142 c &= (037 | (~0177 & ~CHAR_CTL));
143 }
144 }
145
146 /* If C still has any modifier bits, just ignore it. */ 157 /* If C still has any modifier bits, just ignore it. */
147 c &= ~CHAR_MODIFIER_MASK; 158 c &= ~CHAR_MODIFIER_MASK;
148 } 159 }