Mercurial > vim
comparison src/farsi.c @ 9399:43b8570abbec v7.4.1981
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 2 18:25:34 2016 +0200
patch 7.4.1981
Problem: No testing for Farsi code.
Solution: Add a minimal test. Clean up Farsi code.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 02 Jul 2016 18:30:05 +0200 |
parents | d7e1526ae1b9 |
children | 9b048dced116 |
comparison
equal
deleted
inserted
replaced
9398:8a735bf153d0 | 9399:43b8570abbec |
---|---|
33 static int F_isterm(int c); | 33 static int F_isterm(int c); |
34 static int toF_ending(int c); | 34 static int toF_ending(int c); |
35 static void lrswapbuf(char_u *buf, int len); | 35 static void lrswapbuf(char_u *buf, int len); |
36 | 36 |
37 /* | 37 /* |
38 ** Convert the given Farsi character into a _X or _X_ type | 38 * Convert the given Farsi character into a _X or _X_ type |
39 */ | 39 */ |
40 static int | 40 static int |
41 toF_Xor_X_(int c) | 41 toF_Xor_X_(int c) |
42 { | 42 { |
43 int tempc; | 43 int tempc; |
44 | 44 |
45 switch (c) | 45 switch (c) |
46 { | 46 { |
47 case BE: | 47 case BE: return _BE; |
48 return _BE; | 48 case PE: return _PE; |
49 case PE: | 49 case TE: return _TE; |
50 return _PE; | 50 case SE: return _SE; |
51 case TE: | 51 case JIM: return _JIM; |
52 return _TE; | 52 case CHE: return _CHE; |
53 case SE: | 53 case HE_J: return _HE_J; |
54 return _SE; | 54 case XE: return _XE; |
55 case JIM: | 55 case SIN: return _SIN; |
56 return _JIM; | 56 case SHIN: return _SHIN; |
57 case CHE: | 57 case SAD: return _SAD; |
58 return _CHE; | 58 case ZAD: return _ZAD; |
59 case HE_J: | 59 case AYN: return _AYN; |
60 return _HE_J; | 60 case AYN_: return _AYN_; |
61 case XE: | 61 case GHAYN: return _GHAYN; |
62 return _XE; | 62 case GHAYN_: return _GHAYN_; |
63 case SIN: | 63 case FE: return _FE; |
64 return _SIN; | 64 case GHAF: return _GHAF; |
65 case SHIN: | 65 case KAF: return _KAF; |
66 return _SHIN; | 66 case GAF: return _GAF; |
67 case SAD: | 67 case LAM: return _LAM; |
68 return _SAD; | 68 case MIM: return _MIM; |
69 case ZAD: | 69 case NOON: return _NOON; |
70 return _ZAD; | |
71 case AYN: | |
72 return _AYN; | |
73 case AYN_: | |
74 return _AYN_; | |
75 case GHAYN: | |
76 return _GHAYN; | |
77 case GHAYN_: | |
78 return _GHAYN_; | |
79 case FE: | |
80 return _FE; | |
81 case GHAF: | |
82 return _GHAF; | |
83 case KAF: | |
84 return _KAF; | |
85 case GAF: | |
86 return _GAF; | |
87 case LAM: | |
88 return _LAM; | |
89 case MIM: | |
90 return _MIM; | |
91 case NOON: | |
92 return _NOON; | |
93 case YE: | 70 case YE: |
94 case YE_: | 71 case YE_: return _YE; |
95 return _YE; | |
96 case YEE: | 72 case YEE: |
97 case YEE_: | 73 case YEE_: return _YEE; |
98 return _YEE; | |
99 case IE: | 74 case IE: |
100 case IE_: | 75 case IE_: return _IE; |
101 return _IE; | |
102 case F_HE: | 76 case F_HE: |
103 tempc = _HE; | 77 tempc = _HE; |
104 | 78 |
105 if (p_ri && (curwin->w_cursor.col + 1 | 79 if (p_ri && (curwin->w_cursor.col + 1 |
106 < (colnr_T)STRLEN(ml_get_curline()))) | 80 < (colnr_T)STRLEN(ml_get_curline()))) |
126 } | 100 } |
127 return 0; | 101 return 0; |
128 } | 102 } |
129 | 103 |
130 /* | 104 /* |
131 ** Convert the given Farsi character into Farsi capital character . | 105 * Convert the given Farsi character into Farsi capital character. |
132 */ | 106 */ |
133 int | 107 static int |
134 toF_TyA(int c ) | 108 toF_TyA(int c) |
135 { | 109 { |
136 switch (c) | 110 switch (c) |
137 { | 111 { |
138 case ALEF_: | 112 case ALEF_: return ALEF; |
139 return ALEF; | 113 case ALEF_U_H_: return ALEF_U_H; |
140 case ALEF_U_H_: | 114 case _BE: return BE; |
141 return ALEF_U_H; | 115 case _PE: return PE; |
142 case _BE: | 116 case _TE: return TE; |
143 return BE; | 117 case _SE: return SE; |
144 case _PE: | 118 case _JIM: return JIM; |
145 return PE; | 119 case _CHE: return CHE; |
146 case _TE: | 120 case _HE_J: return HE_J; |
147 return TE; | 121 case _XE: return XE; |
148 case _SE: | 122 case _SIN: return SIN; |
149 return SE; | 123 case _SHIN: return SHIN; |
150 case _JIM: | 124 case _SAD: return SAD; |
151 return JIM; | 125 case _ZAD: return ZAD; |
152 case _CHE: | |
153 return CHE; | |
154 case _HE_J: | |
155 return HE_J; | |
156 case _XE: | |
157 return XE; | |
158 case _SIN: | |
159 return SIN; | |
160 case _SHIN: | |
161 return SHIN; | |
162 case _SAD: | |
163 return SAD; | |
164 case _ZAD: | |
165 return ZAD; | |
166 case _AYN: | 126 case _AYN: |
167 case AYN_: | 127 case AYN_: |
168 case _AYN_: | 128 case _AYN_: return AYN; |
169 return AYN; | |
170 case _GHAYN: | 129 case _GHAYN: |
171 case GHAYN_: | 130 case GHAYN_: |
172 case _GHAYN_: | 131 case _GHAYN_: return GHAYN; |
173 return GHAYN; | 132 case _FE: return FE; |
174 case _FE: | 133 case _GHAF: return GHAF; |
175 return FE; | 134 /* I am not sure what it is !!! case _KAF_H: */ |
176 case _GHAF: | 135 case _KAF: return KAF; |
177 return GHAF; | 136 case _GAF: return GAF; |
178 /* I am not sure what it is !!! case _KAF_H: */ | 137 case _LAM: return LAM; |
179 case _KAF: | 138 case _MIM: return MIM; |
180 return KAF; | 139 case _NOON: return NOON; |
181 case _GAF: | |
182 return GAF; | |
183 case _LAM: | |
184 return LAM; | |
185 case _MIM: | |
186 return MIM; | |
187 case _NOON: | |
188 return NOON; | |
189 case _YE: | 140 case _YE: |
190 case YE_: | 141 case YE_: return YE; |
191 return YE; | |
192 case _YEE: | 142 case _YEE: |
193 case YEE_: | 143 case YEE_: return YEE; |
194 return YEE; | 144 case TEE_: return TEE; |
195 case TEE_: | |
196 return TEE; | |
197 case _IE: | 145 case _IE: |
198 case IE_: | 146 case IE_: return IE; |
199 return IE; | |
200 case _HE: | 147 case _HE: |
201 case _HE_: | 148 case _HE_: return F_HE; |
202 return F_HE; | |
203 } | 149 } |
204 return c; | 150 return c; |
205 } | 151 } |
206 | 152 |
207 /* | 153 /* |
208 ** Is the character under the cursor+offset in the given buffer a join type. | 154 * Is the character under the cursor+offset in the given buffer a join type. |
209 ** That is a character that is combined with the others. | 155 * That is a character that is combined with the others. |
210 ** Note: the offset is used only for command line buffer. | 156 * Note: the offset is used only for command line buffer. |
211 */ | 157 */ |
212 static int | 158 static int |
213 F_is_TyB_TyC_TyD(int src, int offset) | 159 F_is_TyB_TyC_TyD(int src, int offset) |
214 { | 160 { |
215 int c; | 161 int c; |
256 } | 202 } |
257 return FALSE; | 203 return FALSE; |
258 } | 204 } |
259 | 205 |
260 /* | 206 /* |
261 ** Is the Farsi character one of the terminating only type. | 207 * Is the Farsi character one of the terminating only type. |
262 */ | 208 */ |
263 static int | 209 static int |
264 F_is_TyE(int c) | 210 F_is_TyE(int c) |
265 { | 211 { |
266 switch (c) | 212 switch (c) |
279 } | 225 } |
280 return FALSE; | 226 return FALSE; |
281 } | 227 } |
282 | 228 |
283 /* | 229 /* |
284 ** Is the Farsi character one of the none leading type. | 230 * Is the Farsi character one of the none leading type. |
285 */ | 231 */ |
286 static int | 232 static int |
287 F_is_TyC_TyD(int c) | 233 F_is_TyC_TyD(int c) |
288 { | 234 { |
289 switch (c) | 235 switch (c) |
303 } | 249 } |
304 return FALSE; | 250 return FALSE; |
305 } | 251 } |
306 | 252 |
307 /* | 253 /* |
308 ** Convert a none leading Farsi char into a leading type. | 254 * Convert a none leading Farsi char into a leading type. |
309 */ | 255 */ |
310 static int | 256 static int |
311 toF_TyB(int c) | 257 toF_TyB(int c) |
312 { | 258 { |
313 switch (c) | 259 switch (c) |
314 { | 260 { |
315 case ALEF_: return ALEF; | 261 case ALEF_: return ALEF; |
316 case ALEF_U_H_: return ALEF_U_H; | 262 case ALEF_U_H_: return ALEF_U_H; |
317 case _AYN_: return _AYN; | 263 case _AYN_: return _AYN; |
318 case AYN_: return AYN; /* exception - there are many of them */ | 264 case AYN_: return AYN; /* exception - there are many of them */ |
319 case _GHAYN_: return _GHAYN; | 265 case _GHAYN_: return _GHAYN; |
320 case GHAYN_: return GHAYN; /* exception - there are many of them */ | 266 case GHAYN_: return GHAYN; /* exception - there are many of them */ |
321 case _HE_: return _HE; | 267 case _HE_: return _HE; |
326 } | 272 } |
327 return c; | 273 return c; |
328 } | 274 } |
329 | 275 |
330 /* | 276 /* |
331 ** Overwrite the current redo and cursor characters + left adjust | 277 * Overwrite the current redo and cursor characters + left adjust. |
332 */ | 278 */ |
333 static void | 279 static void |
334 put_curr_and_l_to_X(int c) | 280 put_curr_and_l_to_X(int c) |
335 { | 281 { |
336 int tempc; | 282 int tempc; |
371 AppendCharToRedobuff(K_BS); | 317 AppendCharToRedobuff(K_BS); |
372 AppendCharToRedobuff(c); | 318 AppendCharToRedobuff(c); |
373 } | 319 } |
374 | 320 |
375 /* | 321 /* |
376 ** Change the char. under the cursor to a X_ or X type | 322 * Change the char. under the cursor to a X_ or X type |
377 */ | 323 */ |
378 static void | 324 static void |
379 chg_c_toX_orX(void) | 325 chg_c_toX_orX(void) |
380 { | 326 { |
381 int tempc, curc; | 327 int tempc, curc; |
495 if (tempc) | 441 if (tempc) |
496 put_and_redo(tempc); | 442 put_and_redo(tempc); |
497 } | 443 } |
498 | 444 |
499 /* | 445 /* |
500 ** Change the char. under the cursor to a _X_ or X_ type | 446 * Change the char. under the cursor to a _X_ or X_ type |
501 */ | 447 */ |
502 | 448 |
503 static void | 449 static void |
504 chg_c_to_X_orX_(void) | 450 chg_c_to_X_orX_(void) |
505 { | 451 { |
547 if (tempc) | 493 if (tempc) |
548 put_and_redo(tempc); | 494 put_and_redo(tempc); |
549 } | 495 } |
550 | 496 |
551 /* | 497 /* |
552 ** Change the char. under the cursor to a _X_ or _X type | 498 * Change the char. under the cursor to a _X_ or _X type |
553 */ | 499 */ |
554 static void | 500 static void |
555 chg_c_to_X_or_X (void) | 501 chg_c_to_X_or_X (void) |
556 { | 502 { |
557 int tempc; | 503 int tempc; |
578 if ((tempc = toF_Xor_X_(tempc)) != 0) | 524 if ((tempc = toF_Xor_X_(tempc)) != 0) |
579 put_and_redo(tempc); | 525 put_and_redo(tempc); |
580 } | 526 } |
581 | 527 |
582 /* | 528 /* |
583 ** Change the character left to the cursor to a _X_ or X_ type | 529 * Change the character left to the cursor to a _X_ or X_ type |
584 */ | 530 */ |
585 static void | 531 static void |
586 chg_l_to_X_orX_ (void) | 532 chg_l_to_X_orX_(void) |
587 { | 533 { |
588 int tempc; | 534 int tempc; |
589 | 535 |
590 if (curwin->w_cursor.col != 0 && | 536 if (curwin->w_cursor.col != 0 && |
591 (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) | 537 (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) |
646 else | 592 else |
647 dec_cursor(); | 593 dec_cursor(); |
648 } | 594 } |
649 | 595 |
650 /* | 596 /* |
651 ** Change the character left to the cursor to a X or _X type | 597 * Change the character left to the cursor to a X or _X type |
652 */ | 598 */ |
653 | 599 |
654 static void | 600 static void |
655 chg_l_toXor_X (void) | 601 chg_l_toXor_X (void) |
656 { | 602 { |
715 else | 661 else |
716 dec_cursor(); | 662 dec_cursor(); |
717 } | 663 } |
718 | 664 |
719 /* | 665 /* |
720 ** Change the character right to the cursor to a _X or _X_ type | 666 * Change the character right to the cursor to a _X or _X_ type |
721 */ | 667 */ |
722 | 668 |
723 static void | 669 static void |
724 chg_r_to_Xor_X_(void) | 670 chg_r_to_Xor_X_(void) |
725 { | 671 { |
740 | 686 |
741 } | 687 } |
742 } | 688 } |
743 | 689 |
744 /* | 690 /* |
745 ** Map Farsi keyboard when in fkmap mode. | 691 * Map Farsi keyboard when in fkmap mode. |
746 */ | 692 */ |
747 | 693 |
748 int | 694 int |
749 fkmap(int c) | 695 fkmap(int c) |
750 { | 696 { |
897 case TAB: | 843 case TAB: |
898 | 844 |
899 if (p_ri && c == NL && curwin->w_cursor.col) | 845 if (p_ri && c == NL && curwin->w_cursor.col) |
900 { | 846 { |
901 /* | 847 /* |
902 ** If the char before the cursor is _X_ or X_ do not change | 848 * If the char before the cursor is _X_ or X_ do not change |
903 ** the one under the cursor with X type. | 849 * the one under the cursor with X type. |
904 */ | 850 */ |
905 | 851 |
906 dec_cursor(); | 852 dec_cursor(); |
907 | 853 |
908 if (F_isalpha(gchar_cursor())) | 854 if (F_isalpha(gchar_cursor())) |
912 } | 858 } |
913 | 859 |
914 inc_cursor(); | 860 inc_cursor(); |
915 } | 861 } |
916 | 862 |
917 if (!p_ri) | 863 if (!p_ri && !curwin->w_cursor.col) |
918 if (!curwin->w_cursor.col) | |
919 { | 864 { |
920 switch (c) | 865 switch (c) |
921 { | 866 { |
922 case '0': return FARSI_0; | 867 case '0': return FARSI_0; |
923 case '1': return FARSI_1; | 868 case '1': return FARSI_1; |
1152 } | 1097 } |
1153 break; | 1098 break; |
1154 | 1099 |
1155 case 'a': | 1100 case 'a': |
1156 tempc = _SHIN; | 1101 tempc = _SHIN; |
1157 break; | 1102 break; |
1158 case 'A': | 1103 case 'A': |
1159 tempc = WAW_H; | 1104 tempc = WAW_H; |
1160 break; | 1105 break; |
1161 case 'b': | 1106 case 'b': |
1162 tempc = ZAL; | 1107 tempc = ZAL; |
1163 break; | 1108 break; |
1164 case 'c': | 1109 case 'c': |
1165 tempc = ZE; | 1110 tempc = ZE; |
1166 break; | 1111 break; |
1167 case 'C': | 1112 case 'C': |
1168 tempc = JE; | 1113 tempc = JE; |
1169 break; | 1114 break; |
1170 case 'd': | 1115 case 'd': |
1171 tempc = _YE; | 1116 tempc = _YE; |
1172 break; | 1117 break; |
1173 case 'D': | 1118 case 'D': |
1174 tempc = _YEE; | 1119 tempc = _YEE; |
1175 break; | 1120 break; |
1176 case 'e': | 1121 case 'e': |
1177 tempc = _SE; | 1122 tempc = _SE; |
1178 break; | 1123 break; |
1179 case 'f': | 1124 case 'f': |
1180 tempc = _BE; | 1125 tempc = _BE; |
1181 break; | 1126 break; |
1182 case 'g': | 1127 case 'g': |
1183 tempc = _LAM; | 1128 tempc = _LAM; |
1184 break; | 1129 break; |
1185 case 'G': | 1130 case 'G': |
1186 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) | 1131 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) |
1187 { | 1132 { |
1188 | 1133 |
1189 if (gchar_cursor() == _LAM) | 1134 if (gchar_cursor() == _LAM) |
1190 chg_c_toX_orX (); | 1135 chg_c_toX_orX (); |
1191 else | 1136 else if (p_ri) |
1192 if (p_ri) | 1137 chg_c_to_X_or_X (); |
1193 chg_c_to_X_or_X (); | |
1194 } | 1138 } |
1195 | 1139 |
1196 if (!p_ri) | 1140 if (!p_ri) |
1197 if (!curwin->w_cursor.col) | 1141 if (!curwin->w_cursor.col) |
1198 return ALEF_U_H; | 1142 return ALEF_U_H; |
1202 | 1146 |
1203 if (gchar_cursor() == _LAM) | 1147 if (gchar_cursor() == _LAM) |
1204 { | 1148 { |
1205 chg_c_toX_orX (); | 1149 chg_c_toX_orX (); |
1206 chg_l_toXor_X (); | 1150 chg_l_toXor_X (); |
1207 tempc = ALEF_U_H; | 1151 tempc = ALEF_U_H; |
1152 } | |
1153 else if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) | |
1154 { | |
1155 tempc = ALEF_U_H_; | |
1156 chg_l_toXor_X (); | |
1208 } | 1157 } |
1209 else | 1158 else |
1210 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) | 1159 tempc = ALEF_U_H; |
1211 { | |
1212 tempc = ALEF_U_H_; | |
1213 chg_l_toXor_X (); | |
1214 } | |
1215 else | |
1216 tempc = ALEF_U_H; | |
1217 | 1160 |
1218 if (!p_ri) | 1161 if (!p_ri) |
1219 inc_cursor(); | 1162 inc_cursor(); |
1220 | 1163 |
1221 return tempc; | 1164 return tempc; |
1247 } | 1190 } |
1248 else | 1191 else |
1249 { | 1192 { |
1250 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) | 1193 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) |
1251 { | 1194 { |
1252 tempc = ALEF_; | 1195 tempc = ALEF_; |
1253 chg_l_toXor_X (); | 1196 chg_l_toXor_X (); |
1254 } | 1197 } |
1255 else | 1198 else |
1256 tempc = ALEF; | 1199 tempc = ALEF; |
1257 } | 1200 } |
1258 | 1201 |
1259 if (!p_ri) | 1202 if (!p_ri) |
1260 inc_cursor(); | 1203 inc_cursor(); |
1261 | 1204 |
1262 return tempc; | 1205 return tempc; |
1263 case 'i': | 1206 case 'i': |
1264 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) | 1207 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) |
1265 { | 1208 { |
1266 if (!p_ri && !F_is_TyE(tempc)) | 1209 if (!p_ri && !F_is_TyE(tempc)) |
1267 chg_c_to_X_orX_ (); | 1210 chg_c_to_X_orX_ (); |
1268 if (p_ri) | 1211 if (p_ri) |
1269 chg_c_to_X_or_X (); | 1212 chg_c_to_X_or_X (); |
1270 | 1213 |
1275 | 1218 |
1276 if (!p_ri) | 1219 if (!p_ri) |
1277 dec_cursor(); | 1220 dec_cursor(); |
1278 | 1221 |
1279 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) | 1222 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) |
1280 tempc = _HE_; | 1223 tempc = _HE_; |
1281 else | 1224 else |
1282 tempc = _HE; | 1225 tempc = _HE; |
1283 | 1226 |
1284 if (!p_ri) | 1227 if (!p_ri) |
1285 inc_cursor(); | 1228 inc_cursor(); |
1286 break; | 1229 break; |
1287 case 'j': | 1230 case 'j': |
1288 tempc = _TE; | 1231 tempc = _TE; |
1289 break; | 1232 break; |
1290 case 'J': | 1233 case 'J': |
1291 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) | 1234 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) |
1292 { | 1235 { |
1293 if (p_ri) | 1236 if (p_ri) |
1294 chg_c_to_X_or_X (); | 1237 chg_c_to_X_or_X (); |
1295 | 1238 |
1296 } | 1239 } |
1297 | 1240 |
1302 if (!p_ri) | 1245 if (!p_ri) |
1303 dec_cursor(); | 1246 dec_cursor(); |
1304 | 1247 |
1305 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) | 1248 if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) |
1306 { | 1249 { |
1307 tempc = TEE_; | 1250 tempc = TEE_; |
1308 chg_l_toXor_X (); | 1251 chg_l_toXor_X (); |
1309 } | 1252 } |
1310 else | 1253 else |
1311 tempc = TEE; | 1254 tempc = TEE; |
1312 | 1255 |
1313 if (!p_ri) | 1256 if (!p_ri) |
1314 inc_cursor(); | 1257 inc_cursor(); |
1315 | 1258 |
1316 return tempc; | 1259 return tempc; |
1383 case 'X': | 1326 case 'X': |
1384 tempc = _TA; | 1327 tempc = _TA; |
1385 break; | 1328 break; |
1386 case 'y': | 1329 case 'y': |
1387 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) | 1330 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) |
1388 { | 1331 { |
1389 if (!p_ri && !F_is_TyE(tempc)) | 1332 if (!p_ri && !F_is_TyE(tempc)) |
1390 chg_c_to_X_orX_ (); | 1333 chg_c_to_X_orX_ (); |
1391 if (p_ri) | 1334 if (p_ri) |
1392 chg_c_to_X_or_X (); | 1335 chg_c_to_X_or_X (); |
1393 | 1336 |
1432 } | 1375 } |
1433 | 1376 |
1434 if ((F_isalpha(tempc) || F_isdigit(tempc))) | 1377 if ((F_isalpha(tempc) || F_isdigit(tempc))) |
1435 { | 1378 { |
1436 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) | 1379 if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) |
1437 { | 1380 { |
1438 if (!p_ri && !F_is_TyE(tempc)) | 1381 if (!p_ri && !F_is_TyE(tempc)) |
1439 chg_c_to_X_orX_ (); | 1382 chg_c_to_X_orX_ (); |
1440 if (p_ri) | 1383 if (p_ri) |
1441 chg_c_to_X_or_X (); | 1384 chg_c_to_X_or_X (); |
1442 } | 1385 } |
1459 return tempc; | 1402 return tempc; |
1460 return c; | 1403 return c; |
1461 } | 1404 } |
1462 | 1405 |
1463 /* | 1406 /* |
1464 ** Convert a none leading Farsi char into a leading type. | 1407 * Convert a none leading Farsi char into a leading type. |
1465 */ | 1408 */ |
1466 static int | 1409 static int |
1467 toF_leading(int c) | 1410 toF_leading(int c) |
1468 { | 1411 { |
1469 switch (c) | 1412 switch (c) |
1513 } | 1456 } |
1514 return c; | 1457 return c; |
1515 } | 1458 } |
1516 | 1459 |
1517 /* | 1460 /* |
1518 ** Convert a given Farsi char into right joining type. | 1461 * Convert a given Farsi char into right joining type. |
1519 */ | 1462 */ |
1520 static int | 1463 static int |
1521 toF_Rjoin(int c) | 1464 toF_Rjoin(int c) |
1522 { | 1465 { |
1523 switch (c) | 1466 switch (c) |
1569 } | 1512 } |
1570 return c; | 1513 return c; |
1571 } | 1514 } |
1572 | 1515 |
1573 /* | 1516 /* |
1574 ** Can a given Farsi character join via its left edj. | 1517 * Can a given Farsi character join via its left edj. |
1575 */ | 1518 */ |
1576 static int | 1519 static int |
1577 canF_Ljoin(int c) | 1520 canF_Ljoin(int c) |
1578 { | 1521 { |
1579 switch (c) | 1522 switch (c) |
1643 } | 1586 } |
1644 return FALSE; | 1587 return FALSE; |
1645 } | 1588 } |
1646 | 1589 |
1647 /* | 1590 /* |
1648 ** Can a given Farsi character join via its right edj. | 1591 * Can a given Farsi character join via its right edj. |
1649 */ | 1592 */ |
1650 static int | 1593 static int |
1651 canF_Rjoin(int c) | 1594 canF_Rjoin(int c) |
1652 { | 1595 { |
1653 switch (c) | 1596 switch (c) |
1671 return canF_Ljoin(c); | 1614 return canF_Ljoin(c); |
1672 | 1615 |
1673 } | 1616 } |
1674 | 1617 |
1675 /* | 1618 /* |
1676 ** is a given Farsi character a terminating type. | 1619 * is a given Farsi character a terminating type. |
1677 */ | 1620 */ |
1678 static int | 1621 static int |
1679 F_isterm(int c) | 1622 F_isterm(int c) |
1680 { | 1623 { |
1681 switch (c) | 1624 switch (c) |
1698 | 1641 |
1699 return FALSE; | 1642 return FALSE; |
1700 } | 1643 } |
1701 | 1644 |
1702 /* | 1645 /* |
1703 ** Convert the given Farsi character into a ending type . | 1646 * Convert the given Farsi character into a ending type . |
1704 */ | 1647 */ |
1705 static int | 1648 static int |
1706 toF_ending(int c) | 1649 toF_ending(int c) |
1707 { | 1650 { |
1708 | |
1709 switch (c) | 1651 switch (c) |
1710 { | 1652 { |
1711 case _BE: | 1653 case _BE: return BE; |
1712 return BE; | 1654 case _PE: return PE; |
1713 case _PE: | 1655 case _TE: return TE; |
1714 return PE; | 1656 case _SE: return SE; |
1715 case _TE: | 1657 case _JIM: return JIM; |
1716 return TE; | 1658 case _CHE: return CHE; |
1717 case _SE: | 1659 case _HE_J: return HE_J; |
1718 return SE; | 1660 case _XE: return XE; |
1719 case _JIM: | 1661 case _SIN: return SIN; |
1720 return JIM; | 1662 case _SHIN: return SHIN; |
1721 case _CHE: | 1663 case _SAD: return SAD; |
1722 return CHE; | 1664 case _ZAD: return ZAD; |
1723 case _HE_J: | 1665 case _AYN: return AYN; |
1724 return HE_J; | 1666 case _AYN_: return AYN_; |
1725 case _XE: | 1667 case _GHAYN: return GHAYN; |
1726 return XE; | 1668 case _GHAYN_: return GHAYN_; |
1727 case _SIN: | 1669 case _FE: return FE; |
1728 return SIN; | 1670 case _GHAF: return GHAF; |
1729 case _SHIN: | |
1730 return SHIN; | |
1731 case _SAD: | |
1732 return SAD; | |
1733 case _ZAD: | |
1734 return ZAD; | |
1735 case _AYN: | |
1736 return AYN; | |
1737 case _AYN_: | |
1738 return AYN_; | |
1739 case _GHAYN: | |
1740 return GHAYN; | |
1741 case _GHAYN_: | |
1742 return GHAYN_; | |
1743 case _FE: | |
1744 return FE; | |
1745 case _GHAF: | |
1746 return GHAF; | |
1747 case _KAF_H: | 1671 case _KAF_H: |
1748 case _KAF: | 1672 case _KAF: return KAF; |
1749 return KAF; | 1673 case _GAF: return GAF; |
1750 case _GAF: | 1674 case _LAM: return LAM; |
1751 return GAF; | 1675 case _MIM: return MIM; |
1752 case _LAM: | 1676 case _NOON: return NOON; |
1753 return LAM; | 1677 case _YE: return YE_; |
1754 case _MIM: | 1678 case YE_: return YE; |
1755 return MIM; | 1679 case _YEE: return YEE_; |
1756 case _NOON: | 1680 case YEE_: return YEE; |
1757 return NOON; | 1681 case TEE: return TEE_; |
1758 case _YE: | 1682 case _IE: return IE_; |
1759 return YE_; | 1683 case IE_: return IE; |
1760 case YE_: | |
1761 return YE; | |
1762 case _YEE: | |
1763 return YEE_; | |
1764 case YEE_: | |
1765 return YEE; | |
1766 case TEE: | |
1767 return TEE_; | |
1768 case _IE: | |
1769 return IE_; | |
1770 case IE_: | |
1771 return IE; | |
1772 case _HE: | 1684 case _HE: |
1773 case _HE_: | 1685 case _HE_: return F_HE; |
1774 return F_HE; | |
1775 } | 1686 } |
1776 return c; | 1687 return c; |
1777 } | 1688 } |
1778 | 1689 |
1779 /* | 1690 /* |
1780 ** Convert the Farsi 3342 standard into Farsi VIM. | 1691 * Convert the Farsi 3342 standard into Farsi VIM. |
1781 */ | 1692 */ |
1782 void | 1693 static void |
1783 conv_to_pvim(void) | 1694 conv_to_pvim(void) |
1784 { | 1695 { |
1785 char_u *ptr; | 1696 char_u *ptr; |
1786 int lnum, llen, i; | 1697 int lnum, llen, i; |
1787 | 1698 |
1789 { | 1700 { |
1790 ptr = ml_get((linenr_T)lnum); | 1701 ptr = ml_get((linenr_T)lnum); |
1791 | 1702 |
1792 llen = (int)STRLEN(ptr); | 1703 llen = (int)STRLEN(ptr); |
1793 | 1704 |
1794 for ( i = 0; i < llen-1; i++) | 1705 for (i = 0; i < llen-1; i++) |
1795 { | 1706 { |
1796 if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i+1])) | 1707 if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i+1])) |
1797 { | 1708 { |
1798 ptr[i] = toF_leading(ptr[i]); | 1709 ptr[i] = toF_leading(ptr[i]); |
1799 ++i; | 1710 ++i; |
1815 | 1726 |
1816 /* | 1727 /* |
1817 * Following lines contains Farsi encoded character. | 1728 * Following lines contains Farsi encoded character. |
1818 */ | 1729 */ |
1819 | 1730 |
1820 do_cmdline_cmd((char_u *)"%s/\202\231/\232/g"); | 1731 do_cmdline_cmd((char_u *)"%s/\202\231/\232/ge"); |
1821 do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/g"); | 1732 do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/ge"); |
1822 | 1733 |
1823 /* Assume the screen has been messed up: clear it and redraw. */ | 1734 /* Assume the screen has been messed up: clear it and redraw. */ |
1824 redraw_later(CLEAR); | 1735 redraw_later(CLEAR); |
1825 MSG_ATTR(farsi_text_1, hl_attr(HLF_S)); | 1736 MSG_ATTR(farsi_text_1, hl_attr(HLF_S)); |
1826 } | 1737 } |
1827 | 1738 |
1828 /* | 1739 /* |
1829 * Convert the Farsi VIM into Farsi 3342 standard. | 1740 * Convert the Farsi VIM into Farsi 3342 standard. |
1830 */ | 1741 */ |
1831 void | 1742 static void |
1832 conv_to_pstd(void) | 1743 conv_to_pstd(void) |
1833 { | 1744 { |
1834 char_u *ptr; | 1745 char_u *ptr; |
1835 int lnum, llen, i; | 1746 int lnum, llen, i; |
1836 | 1747 |
1837 /* | 1748 /* |
1838 * Following line contains Farsi encoded character. | 1749 * Following line contains Farsi encoded character. |
1839 */ | 1750 */ |
1840 | 1751 do_cmdline_cmd((char_u *)"%s/\232/\202\231/ge"); |
1841 do_cmdline_cmd((char_u *)"%s/\232/\202\231/g"); | |
1842 | 1752 |
1843 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | 1753 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) |
1844 { | 1754 { |
1845 ptr = ml_get((linenr_T)lnum); | 1755 ptr = ml_get((linenr_T)lnum); |
1846 | |
1847 llen = (int)STRLEN(ptr); | 1756 llen = (int)STRLEN(ptr); |
1848 | 1757 |
1849 for ( i = 0; i < llen; i++) | 1758 for (i = 0; i < llen; i++) |
1850 { | |
1851 ptr[i] = toF_TyA(ptr[i]); | 1759 ptr[i] = toF_TyA(ptr[i]); |
1852 | |
1853 } | |
1854 } | 1760 } |
1855 | 1761 |
1856 /* Assume the screen has been messed up: clear it and redraw. */ | 1762 /* Assume the screen has been messed up: clear it and redraw. */ |
1857 redraw_later(CLEAR); | 1763 redraw_later(CLEAR); |
1858 MSG_ATTR(farsi_text_2, hl_attr(HLF_S)); | 1764 MSG_ATTR(farsi_text_2, hl_attr(HLF_S)); |
2146 case 'D': return _YEE; | 2052 case 'D': return _YEE; |
2147 case 'e': return _SE; | 2053 case 'e': return _SE; |
2148 case 'f': return _BE; | 2054 case 'f': return _BE; |
2149 case 'g': return _LAM; | 2055 case 'g': return _LAM; |
2150 case 'G': | 2056 case 'G': |
2151 if (cmd_gchar(AT_CURSOR) == _LAM ) | 2057 if (cmd_gchar(AT_CURSOR) == _LAM) |
2152 { | 2058 { |
2153 cmd_pchar(LAM, AT_CURSOR); | 2059 cmd_pchar(LAM, AT_CURSOR); |
2154 return ALEF_U_H; | 2060 return ALEF_U_H; |
2155 } | 2061 } |
2156 | 2062 |
2157 if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) | 2063 if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) |
2158 return ALEF_U_H_; | 2064 return ALEF_U_H_; |
2159 else | 2065 else |
2160 return ALEF_U_H; | 2066 return ALEF_U_H; |
2161 case 'h': | 2067 case 'h': |
2162 if (cmd_gchar(AT_CURSOR) == _LAM ) | 2068 if (cmd_gchar(AT_CURSOR) == _LAM) |
2163 { | 2069 { |
2164 cmd_pchar(LA, AT_CURSOR); | 2070 cmd_pchar(LA, AT_CURSOR); |
2165 redrawcmdline(); | 2071 redrawcmdline(); |
2166 return K_IGNORE; | 2072 return K_IGNORE; |
2167 } | 2073 } |
2213 case ';': return _KAF; | 2119 case ';': return _KAF; |
2214 case '\'': return _GAF; | 2120 case '\'': return _GAF; |
2215 case ',': return WAW; | 2121 case ',': return WAW; |
2216 case '[': return _JIM; | 2122 case '[': return _JIM; |
2217 case ']': return _CHE; | 2123 case ']': return _CHE; |
2218 } | 2124 } |
2219 | 2125 |
2220 return c; | 2126 return c; |
2221 } | 2127 } |
2222 | 2128 |
2223 /* | 2129 /* |
2224 * F_isalpha returns TRUE if 'c' is a Farsi alphabet | 2130 * F_isalpha returns TRUE if 'c' is a Farsi alphabet |
2225 */ | 2131 */ |
2226 int | 2132 int |
2227 F_isalpha(int c) | 2133 F_isalpha(int c) |
2228 { | 2134 { |
2229 return (( c >= TEE_ && c <= _YE) | 2135 return ((c >= TEE_ && c <= _YE) |
2230 || (c >= ALEF_A && c <= YE) | 2136 || (c >= ALEF_A && c <= YE) |
2231 || (c >= _IE && c <= YE_)); | 2137 || (c >= _IE && c <= YE_)); |
2232 } | 2138 } |
2233 | 2139 |
2234 /* | 2140 /* |
2244 * F_ischar returns TRUE if 'c' is a Farsi character. | 2150 * F_ischar returns TRUE if 'c' is a Farsi character. |
2245 */ | 2151 */ |
2246 int | 2152 int |
2247 F_ischar(int c) | 2153 F_ischar(int c) |
2248 { | 2154 { |
2249 return (c >= TEE_ && c <= YE_); | 2155 return (c >= TEE_ && c <= YE_); |
2250 } | 2156 } |
2251 | 2157 |
2252 void | 2158 void |
2253 farsi_fkey( | 2159 farsi_f8(cmdarg_T *cap UNUSED) |
2254 cmdarg_T *cap) | 2160 { |
2255 { | 2161 if (p_altkeymap) |
2256 int c = cap->cmdchar; | 2162 { |
2257 | 2163 if (curwin->w_farsi & W_R_L) |
2258 if (c == K_F8) | |
2259 { | |
2260 if (p_altkeymap) | |
2261 { | 2164 { |
2262 if (curwin->w_farsi & W_R_L) | 2165 p_fkmap = 0; |
2263 { | 2166 do_cmdline_cmd((char_u *)"set norl"); |
2264 p_fkmap = 0; | 2167 MSG(""); |
2265 do_cmdline_cmd((char_u *)"set norl"); | |
2266 MSG(""); | |
2267 } | |
2268 else | |
2269 { | |
2270 p_fkmap = 1; | |
2271 do_cmdline_cmd((char_u *)"set rl"); | |
2272 MSG(""); | |
2273 } | |
2274 | |
2275 curwin->w_farsi = curwin->w_farsi ^ W_R_L; | |
2276 } | 2168 } |
2277 } | 2169 else |
2278 | |
2279 if (c == K_F9) | |
2280 { | |
2281 if (p_altkeymap && curwin->w_p_rl) | |
2282 { | 2170 { |
2283 curwin->w_farsi = curwin->w_farsi ^ W_CONV; | 2171 p_fkmap = 1; |
2284 if (curwin->w_farsi & W_CONV) | 2172 do_cmdline_cmd((char_u *)"set rl"); |
2285 conv_to_pvim(); | 2173 MSG(""); |
2286 else | |
2287 conv_to_pstd(); | |
2288 } | 2174 } |
2289 } | 2175 |
2290 } | 2176 curwin->w_farsi = curwin->w_farsi ^ W_R_L; |
2177 } | |
2178 } | |
2179 | |
2180 void | |
2181 farsi_f9(cmdarg_T *cap UNUSED) | |
2182 { | |
2183 if (p_altkeymap && curwin->w_p_rl) | |
2184 { | |
2185 curwin->w_farsi = curwin->w_farsi ^ W_CONV; | |
2186 if (curwin->w_farsi & W_CONV) | |
2187 conv_to_pvim(); | |
2188 else | |
2189 conv_to_pstd(); | |
2190 } | |
2191 } |