Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 2315 lines (2099 sloc) 37.756 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/

/*
* farsi.c: functions for Farsi language
*
* Included by main.c, when FEAT_FKMAP is defined.
*/

static int toF_Xor_X_ __ARGS((int c));
static int F_is_TyE __ARGS((int c));
static int F_is_TyC_TyD __ARGS((int c));
static int F_is_TyB_TyC_TyD __ARGS((int src, int offset));
static int toF_TyB __ARGS((int c));
static void put_curr_and_l_to_X __ARGS((int c));
static void put_and_redo __ARGS((int c));
static void chg_c_toX_orX __ARGS((void));
static void chg_c_to_X_orX_ __ARGS((void));
static void chg_c_to_X_or_X __ARGS((void));
static void chg_l_to_X_orX_ __ARGS((void));
static void chg_l_toXor_X __ARGS((void));
static void chg_r_to_Xor_X_ __ARGS((void));
static int toF_leading __ARGS((int c));
static int toF_Rjoin __ARGS((int c));
static int canF_Ljoin __ARGS((int c));
static int canF_Rjoin __ARGS((int c));
static int F_isterm __ARGS((int c));
static int toF_ending __ARGS((int c));
static void lrswapbuf __ARGS((char_u *buf, int len));

/*
** Convert the given Farsi character into a _X or _X_ type
*/
    static int
toF_Xor_X_(c)
    int c;
{
    int tempc;

    switch (c)
    {
case BE:
return _BE;
case PE:
return _PE;
case TE:
return _TE;
case SE:
return _SE;
case JIM:
return _JIM;
case CHE:
return _CHE;
case HE_J:
return _HE_J;
case XE:
return _XE;
case SIN:
return _SIN;
case SHIN:
return _SHIN;
case SAD:
return _SAD;
case ZAD:
return _ZAD;
case AYN:
return _AYN;
case AYN_:
return _AYN_;
case GHAYN:
return _GHAYN;
case GHAYN_:
return _GHAYN_;
case FE:
return _FE;
case GHAF:
return _GHAF;
case KAF:
return _KAF;
case GAF:
return _GAF;
case LAM:
return _LAM;
case MIM:
return _MIM;
case NOON:
return _NOON;
case YE:
case YE_:
return _YE;
case YEE:
case YEE_:
return _YEE;
case IE:
case IE_:
return _IE;
case F_HE:
tempc = _HE;

if (p_ri && (curwin->w_cursor.col + 1
< (colnr_T)STRLEN(ml_get_curline())))
{
inc_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _HE_;

dec_cursor();
}
if (!p_ri && STRLEN(ml_get_curline()))
{
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _HE_;

inc_cursor();
}

return tempc;
    }
    return 0;
}

/*
** Convert the given Farsi character into Farsi capital character .
*/
    int
toF_TyA(c)
    int c ;
{
    switch (c)
    {
case ALEF_:
return ALEF;
case ALEF_U_H_:
return ALEF_U_H;
case _BE:
return BE;
case _PE:
return PE;
case _TE:
return TE;
case _SE:
return SE;
case _JIM:
return JIM;
case _CHE:
return CHE;
case _HE_J:
return HE_J;
case _XE:
return XE;
case _SIN:
return SIN;
case _SHIN:
return SHIN;
case _SAD:
return SAD;
case _ZAD:
return ZAD;
case _AYN:
case AYN_:
case _AYN_:
return AYN;
case _GHAYN:
case GHAYN_:
case _GHAYN_:
return GHAYN;
case _FE:
return FE;
case _GHAF:
return GHAF;
/* I am not sure what it is !!! case _KAF_H: */
case _KAF:
return KAF;
case _GAF:
return GAF;
case _LAM:
return LAM;
case _MIM:
return MIM;
case _NOON:
return NOON;
case _YE:
case YE_:
return YE;
case _YEE:
case YEE_:
return YEE;
case TEE_:
return TEE;
case _IE:
case IE_:
return IE;
case _HE:
case _HE_:
return F_HE;
    }
    return c;
}

/*
** Is the character under the cursor+offset in the given buffer a join type.
** That is a character that is combined with the others.
** Note: the offset is used only for command line buffer.
*/
    static int
F_is_TyB_TyC_TyD(src, offset)
    int src, offset;
{
    int c;

    if (src == SRC_EDT)
c = gchar_cursor();
    else
c = cmd_gchar(AT_CURSOR+offset);

    switch (c)
    {
case _LAM:
case _BE:
case _PE:
case _TE:
case _SE:
case _JIM:
case _CHE:
case _HE_J:
case _XE:
case _SIN:
case _SHIN:
case _SAD:
case _ZAD:
case _TA:
case _ZA:
case _AYN:
case _AYN_:
case _GHAYN:
case _GHAYN_:
case _FE:
case _GHAF:
case _KAF:
case _KAF_H:
case _GAF:
case _MIM:
case _NOON:
case _YE:
case _YEE:
case _IE:
case _HE_:
case _HE:
return TRUE;
    }
    return FALSE;
}

/*
** Is the Farsi character one of the terminating only type.
*/
    static int
F_is_TyE(c)
    int c;
{
    switch (c)
    {
case ALEF_A:
case ALEF_D_H:
case DAL:
case ZAL:
case RE:
case ZE:
case JE:
case WAW:
case WAW_H:
case HAMZE:
return TRUE;
    }
    return FALSE;
}

/*
** Is the Farsi character one of the none leading type.
*/
    static int
F_is_TyC_TyD(c)
    int c;
{
    switch (c)
    {
case ALEF_:
case ALEF_U_H_:
case _AYN_:
case AYN_:
case _GHAYN_:
case GHAYN_:
case _HE_:
case YE_:
case IE_:
case TEE_:
case YEE_:
return TRUE;
    }
    return FALSE;
}

/*
** Convert a none leading Farsi char into a leading type.
*/
    static int
toF_TyB(c)
    int c;
{
    switch (c)
    {
case ALEF_: return ALEF;
case ALEF_U_H_: return ALEF_U_H;
case _AYN_: return _AYN;
case AYN_: return AYN; /* exception - there are many of them */
case _GHAYN_: return _GHAYN;
case GHAYN_: return GHAYN; /* exception - there are many of them */
case _HE_: return _HE;
case YE_: return YE;
case IE_: return IE;
case TEE_: return TEE;
case YEE_: return YEE;
    }
    return c;
}

/*
** Overwrite the current redo and cursor characters + left adjust
*/
    static void
put_curr_and_l_to_X(c)
    int c;
{
    int tempc;

    if (curwin->w_p_rl && p_ri)
return;

    if ((curwin->w_cursor.col < (colnr_T)STRLEN(ml_get_curline())))
    {
if ((p_ri && curwin->w_cursor.col) || !p_ri)
{
if (p_ri)
dec_cursor();
else
inc_cursor();

if (F_is_TyC_TyD((tempc = gchar_cursor())))
{
pchar_cursor(toF_TyB(tempc));
AppendCharToRedobuff(K_BS);
AppendCharToRedobuff(tempc);
}

if (p_ri)
inc_cursor();
else
dec_cursor();
}
    }

    put_and_redo(c);
}

    static void
put_and_redo(c)
    int c;
{
    pchar_cursor(c);
    AppendCharToRedobuff(K_BS);
    AppendCharToRedobuff(c);
}

/*
** Change the char. under the cursor to a X_ or X type
*/
    static void
chg_c_toX_orX()
{
    int tempc, curc;

    switch ((curc = gchar_cursor()))
    {
case _BE:
tempc = BE;
break;
case _PE:
tempc = PE;
break;
case _TE:
tempc = TE;
break;
case _SE:
tempc = SE;
break;
case _JIM:
tempc = JIM;
break;
case _CHE:
tempc = CHE;
break;
case _HE_J:
tempc = HE_J;
break;
case _XE:
tempc = XE;
break;
case _SIN:
tempc = SIN;
break;
case _SHIN:
tempc = SHIN;
break;
case _SAD:
tempc = SAD;
break;
case _ZAD:
tempc = ZAD;
break;
case _FE:
tempc = FE;
break;
case _GHAF:
tempc = GHAF;
break;
case _KAF_H:
case _KAF:
tempc = KAF;
break;
case _GAF:
tempc = GAF;
break;
case _AYN:
tempc = AYN;
break;
case _AYN_:
tempc = AYN_;
break;
case _GHAYN:
tempc = GHAYN;
break;
case _GHAYN_:
tempc = GHAYN_;
break;
case _LAM:
tempc = LAM;
break;
case _MIM:
tempc = MIM;
break;
case _NOON:
tempc = NOON;
break;
case _HE:
case _HE_:
tempc = F_HE;
break;
case _YE:
case _IE:
case _YEE:
if (p_ri)
{
inc_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = (curc == _YE ? YE_ :
(curc == _IE ? IE_ : YEE_));
else
tempc = (curc == _YE ? YE :
(curc == _IE ? IE : YEE));
dec_cursor();
}
else
{
if (curwin->w_cursor.col)
{
dec_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = (curc == _YE ? YE_ :
(curc == _IE ? IE_ : YEE_));
else
tempc = (curc == _YE ? YE :
(curc == _IE ? IE : YEE));
inc_cursor();
}
else
tempc = (curc == _YE ? YE :
(curc == _IE ? IE : YEE));
}
break;
default:
tempc = 0;
    }

    if (tempc)
put_and_redo(tempc);
}

/*
** Change the char. under the cursor to a _X_ or X_ type
*/

    static void
chg_c_to_X_orX_()
{
    int tempc;

    switch (gchar_cursor())
    {
case ALEF:
tempc = ALEF_;
break;
case ALEF_U_H:
tempc = ALEF_U_H_;
break;
case _AYN:
tempc = _AYN_;
break;
case AYN:
tempc = AYN_;
break;
case _GHAYN:
tempc = _GHAYN_;
break;
case GHAYN:
tempc = GHAYN_;
break;
case _HE:
tempc = _HE_;
break;
case YE:
tempc = YE_;
break;
case IE:
tempc = IE_;
break;
case TEE:
tempc = TEE_;
break;
case YEE:
tempc = YEE_;
break;
default:
tempc = 0;
    }

    if (tempc)
put_and_redo(tempc);
}

/*
** Change the char. under the cursor to a _X_ or _X type
*/
    static void
chg_c_to_X_or_X ()
{
    int tempc;

    tempc = gchar_cursor();

    if (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(ml_get_curline()))
    {
inc_cursor();

if ((tempc == F_HE) && (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)))
{
tempc = _HE_;

dec_cursor();

put_and_redo(tempc);
return;
}

dec_cursor();
    }

    if ((tempc = toF_Xor_X_(tempc)) != 0)
put_and_redo(tempc);
}

/*
** Change the character left to the cursor to a _X_ or X_ type
*/
    static void
chg_l_to_X_orX_ ()
{
    int tempc;

    if (curwin->w_cursor.col != 0 &&
(curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline())))
return;

    if (!curwin->w_cursor.col && p_ri)
return;

    if (p_ri)
dec_cursor();
    else
inc_cursor();

    switch (gchar_cursor())
    {
case ALEF:
tempc = ALEF_;
break;
case ALEF_U_H:
tempc = ALEF_U_H_;
break;
case _AYN:
tempc = _AYN_;
break;
case AYN:
tempc = AYN_;
break;
case _GHAYN:
tempc = _GHAYN_;
break;
case GHAYN:
tempc = GHAYN_;
break;
case _HE:
tempc = _HE_;
break;
case YE:
tempc = YE_;
break;
case IE:
tempc = IE_;
break;
case TEE:
tempc = TEE_;
break;
case YEE:
tempc = YEE_;
break;
default:
tempc = 0;
    }

    if (tempc)
put_and_redo(tempc);

    if (p_ri)
inc_cursor();
    else
dec_cursor();
}

/*
** Change the character left to the cursor to a X or _X type
*/

    static void
chg_l_toXor_X ()
{
    int tempc;

    if (curwin->w_cursor.col != 0 &&
(curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline())))
return;

    if (!curwin->w_cursor.col && p_ri)
return;

    if (p_ri)
dec_cursor();
    else
inc_cursor();

    switch (gchar_cursor())
    {
case ALEF_:
tempc = ALEF;
break;
case ALEF_U_H_:
tempc = ALEF_U_H;
break;
case _AYN_:
tempc = _AYN;
break;
case AYN_:
tempc = AYN;
break;
case _GHAYN_:
tempc = _GHAYN;
break;
case GHAYN_:
tempc = GHAYN;
break;
case _HE_:
tempc = _HE;
break;
case YE_:
tempc = YE;
break;
case IE_:
tempc = IE;
break;
case TEE_:
tempc = TEE;
break;
case YEE_:
tempc = YEE;
break;
default:
tempc = 0;
    }

    if (tempc)
put_and_redo(tempc);

    if (p_ri)
inc_cursor();
    else
dec_cursor();
}

/*
** Change the character right to the cursor to a _X or _X_ type
*/

    static void
chg_r_to_Xor_X_()
{
    int tempc, c;

    if (curwin->w_cursor.col)
    {
if (!p_ri)
dec_cursor();

tempc = gchar_cursor();

if ((c = toF_Xor_X_(tempc)) != 0)
put_and_redo(c);

if (!p_ri)
inc_cursor();

    }
}

/*
** Map Farsi keyboard when in fkmap mode.
*/

    int
fkmap(c)
    int c;
{
    int tempc;
    static int revins;

    if (IS_SPECIAL(c))
return c;

    if (VIM_ISDIGIT(c) || ((c == '.' || c == '+' || c == '-' ||
c == '^' || c == '%' || c == '#' || c == '=') && revins))
    {
if (!revins)
{
if (curwin->w_cursor.col)
{
if (!p_ri)
dec_cursor();

chg_c_toX_orX ();
chg_l_toXor_X ();

if (!p_ri)
inc_cursor();
}
}

arrow_used = TRUE;
(void)stop_arrow();

if (!curwin->w_p_rl && revins)
inc_cursor();

++revins;
p_ri=1;
    }
    else
    {
if (revins)
{
arrow_used = TRUE;
(void)stop_arrow();

revins = 0;
if (curwin->w_p_rl)
{
while ((F_isdigit(gchar_cursor())
|| (gchar_cursor() == F_PERIOD
|| gchar_cursor() == F_PLUS
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL
|| gchar_cursor() == F_DIVIDE
|| gchar_cursor() == F_PERCENT
|| gchar_cursor() == F_EQUALS))
&& gchar_cursor() != NUL)
++curwin->w_cursor.col;
}
else
{
if (curwin->w_cursor.col)
while ((F_isdigit(gchar_cursor())
|| (gchar_cursor() == F_PERIOD
|| gchar_cursor() == F_PLUS
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL
|| gchar_cursor() == F_DIVIDE
|| gchar_cursor() == F_PERCENT
|| gchar_cursor() == F_EQUALS))
&& --curwin->w_cursor.col)
;

if (!F_isdigit(gchar_cursor()))
++curwin->w_cursor.col;
}
}
    }

    if (!revins)
    {
if (curwin->w_p_rl)
p_ri=0;
if (!curwin->w_p_rl)
p_ri=1;
    }

    if ((c < 0x100) && (isalpha(c) || c == '&' || c == '^' || c == ';' ||
c == '\''|| c == ',' || c == '[' ||
c == ']' || c == '{' || c == '}' ))
chg_r_to_Xor_X_();

    tempc = 0;

    switch (c)
    {
case '`':
case ' ':
case '.':
case '!':
case '"':
case '$':
case '%':
case '^':
case '&':
case '/':
case '(':
case ')':
case '=':
case '\\':
case '?':
case '+':
case '-':
case '_':
case '*':
case ':':
case '#':
case '~':
case '@':
case '<':
case '>':
case '{':
case '}':
case '|':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'B':
case 'E':
case 'F':
case 'H':
case 'I':
case 'K':
case 'L':
case 'M':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'T':
case 'U':
case 'W':
case 'Y':
case NL:
case TAB:

if (p_ri && c == NL && curwin->w_cursor.col)
{
/*
** If the char before the cursor is _X_ or X_ do not change
** the one under the cursor with X type.
*/

dec_cursor();

if (F_isalpha(gchar_cursor()))
{
inc_cursor();
return NL;
}

inc_cursor();
}

if (!p_ri)
if (!curwin->w_cursor.col)
{
switch (c)
{
case '0': return FARSI_0;
case '1': return FARSI_1;
case '2': return FARSI_2;
case '3': return FARSI_3;
case '4': return FARSI_4;
case '5': return FARSI_5;
case '6': return FARSI_6;
case '7': return FARSI_7;
case '8': return FARSI_8;
case '9': return FARSI_9;
case 'B': return F_PSP;
case 'E': return JAZR_N;
case 'F': return ALEF_D_H;
case 'H': return ALEF_A;
case 'I': return TASH;
case 'K': return F_LQUOT;
case 'L': return F_RQUOT;
case 'M': return HAMZE;
case 'O': return '[';
case 'P': return ']';
case 'Q': return OO;
case 'R': return MAD_N;
case 'T': return OW;
case 'U': return MAD;
case 'W': return OW_OW;
case 'Y': return JAZR;
case '`': return F_PCN;
case '!': return F_EXCL;
case '@': return F_COMMA;
case '#': return F_DIVIDE;
case '$': return F_CURRENCY;
case '%': return F_PERCENT;
case '^': return F_MUL;
case '&': return F_BCOMMA;
case '*': return F_STAR;
case '(': return F_LPARENT;
case ')': return F_RPARENT;
case '-': return F_MINUS;
case '_': return F_UNDERLINE;
case '=': return F_EQUALS;
case '+': return F_PLUS;
case '\\': return F_BSLASH;
case '|': return F_PIPE;
case ':': return F_DCOLON;
case '"': return F_SEMICOLON;
case '.': return F_PERIOD;
case '/': return F_SLASH;
case '<': return F_LESS;
case '>': return F_GREATER;
case '?': return F_QUESTION;
case ' ': return F_BLANK;
}
break;
}
if (!p_ri)
dec_cursor();

switch ((tempc = gchar_cursor()))
{
case _BE:
case _PE:
case _TE:
case _SE:
case _JIM:
case _CHE:
case _HE_J:
case _XE:
case _SIN:
case _SHIN:
case _SAD:
case _ZAD:
case _FE:
case _GHAF:
case _KAF:
case _KAF_H:
case _GAF:
case _LAM:
case _MIM:
case _NOON:
case _HE:
case _HE_:
case _TA:
case _ZA:
put_curr_and_l_to_X(toF_TyA(tempc));
break;
case _AYN:
case _AYN_:

if (!p_ri)
if (!curwin->w_cursor.col)
{
put_curr_and_l_to_X(AYN);
break;
}

if (p_ri)
inc_cursor();
else
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = AYN_;
else
tempc = AYN;

if (p_ri)
dec_cursor();
else
inc_cursor();

put_curr_and_l_to_X(tempc);

break;
case _GHAYN:
case _GHAYN_:

if (!p_ri)
if (!curwin->w_cursor.col)
{
put_curr_and_l_to_X(GHAYN);
break;
}

if (p_ri)
inc_cursor();
else
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = GHAYN_;
else
tempc = GHAYN;

if (p_ri)
dec_cursor();
else
inc_cursor();

put_curr_and_l_to_X(tempc);
break;
case _YE:
case _IE:
case _YEE:
if (!p_ri)
if (!curwin->w_cursor.col)
{
put_curr_and_l_to_X((tempc == _YE ? YE :
(tempc == _IE ? IE : YEE)));
break;
}

if (p_ri)
inc_cursor();
else
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = (tempc == _YE ? YE_ :
(tempc == _IE ? IE_ : YEE_));
else
tempc = (tempc == _YE ? YE :
(tempc == _IE ? IE : YEE));

if (p_ri)
dec_cursor();
else
inc_cursor();

put_curr_and_l_to_X(tempc);
break;
}

if (!p_ri)
inc_cursor();

tempc = 0;

switch (c)
{
case '0': return FARSI_0;
case '1': return FARSI_1;
case '2': return FARSI_2;
case '3': return FARSI_3;
case '4': return FARSI_4;
case '5': return FARSI_5;
case '6': return FARSI_6;
case '7': return FARSI_7;
case '8': return FARSI_8;
case '9': return FARSI_9;
case 'B': return F_PSP;
case 'E': return JAZR_N;
case 'F': return ALEF_D_H;
case 'H': return ALEF_A;
case 'I': return TASH;
case 'K': return F_LQUOT;
case 'L': return F_RQUOT;
case 'M': return HAMZE;
case 'O': return '[';
case 'P': return ']';
case 'Q': return OO;
case 'R': return MAD_N;
case 'T': return OW;
case 'U': return MAD;
case 'W': return OW_OW;
case 'Y': return JAZR;
case '`': return F_PCN;
case '!': return F_EXCL;
case '@': return F_COMMA;
case '#': return F_DIVIDE;
case '$': return F_CURRENCY;
case '%': return F_PERCENT;
case '^': return F_MUL;
case '&': return F_BCOMMA;
case '*': return F_STAR;
case '(': return F_LPARENT;
case ')': return F_RPARENT;
case '-': return F_MINUS;
case '_': return F_UNDERLINE;
case '=': return F_EQUALS;
case '+': return F_PLUS;
case '\\': return F_BSLASH;
case '|': return F_PIPE;
case ':': return F_DCOLON;
case '"': return F_SEMICOLON;
case '.': return F_PERIOD;
case '/': return F_SLASH;
case '<': return F_LESS;
case '>': return F_GREATER;
case '?': return F_QUESTION;
case ' ': return F_BLANK;
}
break;

case 'a':
tempc = _SHIN;
break;
case 'A':
tempc = WAW_H;
break;
case 'b':
tempc = ZAL;
break;
case 'c':
tempc = ZE;
break;
case 'C':
tempc = JE;
break;
case 'd':
tempc = _YE;
break;
case 'D':
tempc = _YEE;
break;
case 'e':
tempc = _SE;
break;
case 'f':
tempc = _BE;
break;
case 'g':
tempc = _LAM;
break;
case 'G':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{

if (gchar_cursor() == _LAM)
chg_c_toX_orX ();
else
if (p_ri)
chg_c_to_X_or_X ();
}

if (!p_ri)
if (!curwin->w_cursor.col)
return ALEF_U_H;

if (!p_ri)
dec_cursor();

if (gchar_cursor() == _LAM)
{
chg_c_toX_orX ();
chg_l_toXor_X ();
tempc = ALEF_U_H;
}
else
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{
tempc = ALEF_U_H_;
chg_l_toXor_X ();
}
else
tempc = ALEF_U_H;

if (!p_ri)
inc_cursor();

return tempc;
case 'h':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (p_ri)
chg_c_to_X_or_X ();

}

if (!p_ri)
if (!curwin->w_cursor.col)
return ALEF;

if (!p_ri)
dec_cursor();

if (gchar_cursor() == _LAM)
{
chg_l_toXor_X();
del_char(FALSE);
AppendCharToRedobuff(K_BS);

if (!p_ri)
dec_cursor();

tempc = LA;
}
else
{
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{
tempc = ALEF_;
chg_l_toXor_X ();
}
else
tempc = ALEF;
}

if (!p_ri)
inc_cursor();

return tempc;
case 'i':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ ();
if (p_ri)
chg_c_to_X_or_X ();

}

if (!p_ri && !curwin->w_cursor.col)
return _HE;

if (!p_ri)
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _HE_;
else
tempc = _HE;

if (!p_ri)
inc_cursor();
break;
case 'j':
tempc = _TE;
break;
case 'J':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (p_ri)
chg_c_to_X_or_X ();

}

if (!p_ri)
if (!curwin->w_cursor.col)
return TEE;

if (!p_ri)
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{
tempc = TEE_;
chg_l_toXor_X ();
}
else
tempc = TEE;

if (!p_ri)
inc_cursor();

return tempc;
case 'k':
tempc = _NOON;
break;
case 'l':
tempc = _MIM;
break;
case 'm':
tempc = _PE;
break;
case 'n':
case 'N':
tempc = DAL;
break;
case 'o':
tempc = _XE;
break;
case 'p':
tempc = _HE_J;
break;
case 'q':
tempc = _ZAD;
break;
case 'r':
tempc = _GHAF;
break;
case 's':
tempc = _SIN;
break;
case 'S':
tempc = _IE;
break;
case 't':
tempc = _FE;
break;
case 'u':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ ();
if (p_ri)
chg_c_to_X_or_X ();

}

if (!p_ri && !curwin->w_cursor.col)
return _AYN;

if (!p_ri)
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _AYN_;
else
tempc = _AYN;

if (!p_ri)
inc_cursor();
break;
case 'v':
case 'V':
tempc = RE;
break;
case 'w':
tempc = _SAD;
break;
case 'x':
case 'X':
tempc = _TA;
break;
case 'y':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ ();
if (p_ri)
chg_c_to_X_or_X ();

}

if (!p_ri && !curwin->w_cursor.col)
return _GHAYN;

if (!p_ri)
dec_cursor();

if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _GHAYN_;
else
tempc = _GHAYN;

if (!p_ri)
inc_cursor();

break;
case 'z':
tempc = _ZA;
break;
case 'Z':
tempc = _KAF_H;
break;
case ';':
tempc = _KAF;
break;
case '\'':
tempc = _GAF;
break;
case ',':
tempc = WAW;
break;
case '[':
tempc = _JIM;
break;
case ']':
tempc = _CHE;
break;
    }

    if ((F_isalpha(tempc) || F_isdigit(tempc)))
    {
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{
if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ ();
if (p_ri)
chg_c_to_X_or_X ();
}

if (curwin->w_cursor.col)
{
if (!p_ri)
dec_cursor();

if (F_is_TyE(tempc))
chg_l_toXor_X ();
else
chg_l_to_X_orX_ ();

if (!p_ri)
inc_cursor();
}
    }
    if (tempc)
return tempc;
    return c;
}

/*
** Convert a none leading Farsi char into a leading type.
*/
    static int
toF_leading(c)
    int c;
{
    switch (c)
    {
case ALEF_: return ALEF;
case ALEF_U_H_: return ALEF_U_H;
case BE: return _BE;
case PE: return _PE;
case TE: return _TE;
case SE: return _SE;
case JIM: return _JIM;
case CHE: return _CHE;
case HE_J: return _HE_J;
case XE: return _XE;
case SIN: return _SIN;
case SHIN: return _SHIN;
case SAD: return _SAD;
case ZAD: return _ZAD;

case AYN:
case AYN_:
case _AYN_: return _AYN;

case GHAYN:
case GHAYN_:
case _GHAYN_: return _GHAYN;

case FE: return _FE;
case GHAF: return _GHAF;
case KAF: return _KAF;
case GAF: return _GAF;
case LAM: return _LAM;
case MIM: return _MIM;
case NOON: return _NOON;

case _HE_:
case F_HE: return _HE;

case YE:
case YE_: return _YE;

case IE_:
case IE: return _IE;

case YEE:
case YEE_: return _YEE;
    }
    return c;
}

/*
** Convert a given Farsi char into right joining type.
*/
    static int
toF_Rjoin(c)
    int c;
{
    switch (c)
    {
case ALEF: return ALEF_;
case ALEF_U_H: return ALEF_U_H_;
case BE: return _BE;
case PE: return _PE;
case TE: return _TE;
case SE: return _SE;
case JIM: return _JIM;
case CHE: return _CHE;
case HE_J: return _HE_J;
case XE: return _XE;
case SIN: return _SIN;
case SHIN: return _SHIN;
case SAD: return _SAD;
case ZAD: return _ZAD;

case AYN:
case AYN_:
case _AYN: return _AYN_;

case GHAYN:
case GHAYN_:
case _GHAYN_: return _GHAYN_;

case FE: return _FE;
case GHAF: return _GHAF;
case KAF: return _KAF;
case GAF: return _GAF;
case LAM: return _LAM;
case MIM: return _MIM;
case NOON: return _NOON;

case _HE:
case F_HE: return _HE_;

case YE:
case YE_: return _YE;

case IE_:
case IE: return _IE;

case TEE: return TEE_;

case YEE:
case YEE_: return _YEE;
    }
    return c;
}

/*
** Can a given Farsi character join via its left edj.
*/
    static int
canF_Ljoin(c)
    int c;
{
    switch (c)
    {
case _BE:
case BE:
case PE:
case _PE:
case TE:
case _TE:
case SE:
case _SE:
case JIM:
case _JIM:
case CHE:
case _CHE:
case HE_J:
case _HE_J:
case XE:
case _XE:
case SIN:
case _SIN:
case SHIN:
case _SHIN:
case SAD:
case _SAD:
case ZAD:
case _ZAD:
case _TA:
case _ZA:
case AYN:
case _AYN:
case _AYN_:
case AYN_:
case GHAYN:
case GHAYN_:
case _GHAYN_:
case _GHAYN:
case FE:
case _FE:
case GHAF:
case _GHAF:
case _KAF_H:
case KAF:
case _KAF:
case GAF:
case _GAF:
case LAM:
case _LAM:
case MIM:
case _MIM:
case NOON:
case _NOON:
case IE:
case _IE:
case IE_:
case YE:
case _YE:
case YE_:
case YEE:
case _YEE:
case YEE_:
case F_HE:
case _HE:
case _HE_:
return TRUE;
    }
    return FALSE;
}

/*
** Can a given Farsi character join via its right edj.
*/
    static int
canF_Rjoin(c)
    int c;
{
    switch (c)
    {
case ALEF:
case ALEF_:
case ALEF_U_H:
case ALEF_U_H_:
case DAL:
case ZAL:
case RE:
case JE:
case ZE:
case TEE:
case TEE_:
case WAW:
case WAW_H:
return TRUE;
    }

    return canF_Ljoin(c);

}

/*
** is a given Farsi character a terminating type.
*/
    static int
F_isterm(c)
    int c;
{
    switch (c)
    {
case ALEF:
case ALEF_:
case ALEF_U_H:
case ALEF_U_H_:
case DAL:
case ZAL:
case RE:
case JE:
case ZE:
case WAW:
case WAW_H:
case TEE:
case TEE_:
return TRUE;
    }

    return FALSE;
}

/*
** Convert the given Farsi character into a ending type .
*/
    static int
toF_ending(c)
    int c;
{

    switch (c)
    {
case _BE:
return BE;
case _PE:
return PE;
case _TE:
return TE;
case _SE:
return SE;
case _JIM:
return JIM;
case _CHE:
return CHE;
case _HE_J:
return HE_J;
case _XE:
return XE;
case _SIN:
return SIN;
case _SHIN:
return SHIN;
case _SAD:
return SAD;
case _ZAD:
return ZAD;
case _AYN:
return AYN;
case _AYN_:
return AYN_;
case _GHAYN:
return GHAYN;
case _GHAYN_:
return GHAYN_;
case _FE:
return FE;
case _GHAF:
return GHAF;
case _KAF_H:
case _KAF:
return KAF;
case _GAF:
return GAF;
case _LAM:
return LAM;
case _MIM:
return MIM;
case _NOON:
return NOON;
case _YE:
return YE_;
case YE_:
return YE;
case _YEE:
return YEE_;
case YEE_:
return YEE;
case TEE:
return TEE_;
case _IE:
return IE_;
case IE_:
return IE;
case _HE:
case _HE_:
return F_HE;
    }
    return c;
}

/*
** Convert the Farsi 3342 standard into Farsi VIM.
*/
    void
conv_to_pvim()
{
    char_u *ptr;
    int lnum, llen, i;

    for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
    {
ptr = ml_get((linenr_T)lnum);

llen = (int)STRLEN(ptr);

for ( i = 0; i < llen-1; i++)
{
if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i+1]))
{
ptr[i] = toF_leading(ptr[i]);
++i;

while (canF_Rjoin(ptr[i]) && i < llen)
{
ptr[i] = toF_Rjoin(ptr[i]);
if (F_isterm(ptr[i]) || !F_isalpha(ptr[i]))
break;
++i;
}
if (!F_isalpha(ptr[i]) || !canF_Rjoin(ptr[i]))
ptr[i-1] = toF_ending(ptr[i-1]);
}
else
ptr[i] = toF_TyA(ptr[i]);
}
    }

    /*
* Following lines contains Farsi encoded character.
*/

    do_cmdline_cmd((char_u *)"%s/\202\231/\232/g");
    do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/g");

    /* Assume the screen has been messed up: clear it and redraw. */
    redraw_later(CLEAR);
    MSG_ATTR(farsi_text_1, hl_attr(HLF_S));
}

/*
* Convert the Farsi VIM into Farsi 3342 standad.
*/
    void
conv_to_pstd()
{
    char_u *ptr;
    int lnum, llen, i;

    /*
* Following line contains Farsi encoded character.
*/

    do_cmdline_cmd((char_u *)"%s/\232/\202\231/g");

    for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
    {
ptr = ml_get((linenr_T)lnum);

llen = (int)STRLEN(ptr);

for ( i = 0; i < llen; i++)
{
ptr[i] = toF_TyA(ptr[i]);

}
    }

    /* Assume the screen has been messed up: clear it and redraw. */
    redraw_later(CLEAR);
    MSG_ATTR(farsi_text_2, hl_attr(HLF_S));
}

/*
* left-right swap the characters in buf[len].
*/
    static void
lrswapbuf(buf, len)
    char_u *buf;
    int len;
{
    char_u *s, *e;
    int c;

    s = buf;
    e = buf + len - 1;

    while (e > s)
    {
c = *s;
*s = *e;
*e = c;
++s;
--e;
    }
}

/*
* swap all the characters in reverse direction
*/
    char_u *
lrswap(ibuf)
    char_u *ibuf;
{
    if (ibuf != NULL && *ibuf != NUL)
lrswapbuf(ibuf, (int)STRLEN(ibuf));
    return ibuf;
}

/*
* swap all the Farsi characters in reverse direction
*/
    char_u *
lrFswap(cmdbuf, len)
    char_u *cmdbuf;
    int len;
{
    int i, cnt;

    if (cmdbuf == NULL)
return cmdbuf;

    if (len == 0 && (len = (int)STRLEN(cmdbuf)) == 0)
return cmdbuf;

    for (i = 0; i < len; i++)
    {
for (cnt = 0; i + cnt < len
&& (F_isalpha(cmdbuf[i + cnt])
|| F_isdigit(cmdbuf[i + cnt])
|| cmdbuf[i + cnt] == ' '); ++cnt)
;

lrswapbuf(cmdbuf + i, cnt);
i += cnt;
    }
    return cmdbuf;
}

/*
* Reverse the characters in the search path and substitute section
* accordingly.
* TODO: handle different separator characters. Use skip_regexp().
*/
    char_u *
lrF_sub(ibuf)
    char_u *ibuf;
{
    char_u *p, *ep;
    int i, cnt;

    p = ibuf;

    /* Find the boundary of the search path */
    while (((p = vim_strchr(p + 1, '/')) != NULL) && p[-1] == '\\')
;

    if (p == NULL)
return ibuf;

    /* Reverse the Farsi characters in the search path. */
    lrFswap(ibuf, (int)(p-ibuf));

    /* Now find the boundary of the substitute section */
    if ((ep = (char_u *)strrchr((char *)++p, '/')) != NULL)
cnt = (int)(ep - p);
    else
cnt = (int)STRLEN(p);

    /* Reverse the characters in the substitute section and take care of '\' */
    for (i = 0; i < cnt-1; i++)
if (p[i] == '\\')
{
p[i] = p[i+1] ;
p[++i] = '\\';
}

    lrswapbuf(p, cnt);

    return ibuf;
}

/*
* Map Farsi keyboard when in cmd_fkmap mode.
*/
    int
cmdl_fkmap(c)
    int c;
{
    int tempc;

    switch (c)
    {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '`':
case ' ':
case '.':
case '!':
case '"':
case '$':
case '%':
case '^':
case '&':
case '/':
case '(':
case ')':
case '=':
case '\\':
case '?':
case '+':
case '-':
case '_':
case '*':
case ':':
case '#':
case '~':
case '@':
case '<':
case '>':
case '{':
case '}':
case '|':
case 'B':
case 'E':
case 'F':
case 'H':
case 'I':
case 'K':
case 'L':
case 'M':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'T':
case 'U':
case 'W':
case 'Y':
case NL:
case TAB:

switch ((tempc = cmd_gchar(AT_CURSOR)))
{
case _BE:
case _PE:
case _TE:
case _SE:
case _JIM:
case _CHE:
case _HE_J:
case _XE:
case _SIN:
case _SHIN:
case _SAD:
case _ZAD:
case _AYN:
case _GHAYN:
case _FE:
case _GHAF:
case _KAF:
case _GAF:
case _LAM:
case _MIM:
case _NOON:
case _HE:
case _HE_:
cmd_pchar(toF_TyA(tempc), AT_CURSOR);
break;
case _AYN_:
cmd_pchar(AYN_, AT_CURSOR);
break;
case _GHAYN_:
cmd_pchar(GHAYN_, AT_CURSOR);
break;
case _IE:
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR+1))
cmd_pchar(IE_, AT_CURSOR);
else
cmd_pchar(IE, AT_CURSOR);
break;
case _YEE:
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR+1))
cmd_pchar(YEE_, AT_CURSOR);
else
cmd_pchar(YEE, AT_CURSOR);
break;
case _YE:
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR+1))
cmd_pchar(YE_, AT_CURSOR);
else
cmd_pchar(YE, AT_CURSOR);
}

switch (c)
{
case '0': return FARSI_0;
case '1': return FARSI_1;
case '2': return FARSI_2;
case '3': return FARSI_3;
case '4': return FARSI_4;
case '5': return FARSI_5;
case '6': return FARSI_6;
case '7': return FARSI_7;
case '8': return FARSI_8;
case '9': return FARSI_9;
case 'B': return F_PSP;
case 'E': return JAZR_N;
case 'F': return ALEF_D_H;
case 'H': return ALEF_A;
case 'I': return TASH;
case 'K': return F_LQUOT;
case 'L': return F_RQUOT;
case 'M': return HAMZE;
case 'O': return '[';
case 'P': return ']';
case 'Q': return OO;
case 'R': return MAD_N;
case 'T': return OW;
case 'U': return MAD;
case 'W': return OW_OW;
case 'Y': return JAZR;
case '`': return F_PCN;
case '!': return F_EXCL;
case '@': return F_COMMA;
case '#': return F_DIVIDE;
case '$': return F_CURRENCY;
case '%': return F_PERCENT;
case '^': return F_MUL;
case '&': return F_BCOMMA;
case '*': return F_STAR;
case '(': return F_LPARENT;
case ')': return F_RPARENT;
case '-': return F_MINUS;
case '_': return F_UNDERLINE;
case '=': return F_EQUALS;
case '+': return F_PLUS;
case '\\': return F_BSLASH;
case '|': return F_PIPE;
case ':': return F_DCOLON;
case '"': return F_SEMICOLON;
case '.': return F_PERIOD;
case '/': return F_SLASH;
case '<': return F_LESS;
case '>': return F_GREATER;
case '?': return F_QUESTION;
case ' ': return F_BLANK;
}

break;

case 'a': return _SHIN;
case 'A': return WAW_H;
case 'b': return ZAL;
case 'c': return ZE;
case 'C': return JE;
case 'd': return _YE;
case 'D': return _YEE;
case 'e': return _SE;
case 'f': return _BE;
case 'g': return _LAM;
case 'G':
if (cmd_gchar(AT_CURSOR) == _LAM )
{
cmd_pchar(LAM, AT_CURSOR);
return ALEF_U_H;
}

if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return ALEF_U_H_;
else
return ALEF_U_H;
case 'h':
if (cmd_gchar(AT_CURSOR) == _LAM )
{
cmd_pchar(LA, AT_CURSOR);
redrawcmdline();
return K_IGNORE;
}

if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return ALEF_;
else
return ALEF;
case 'i':
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return _HE_;
else
return _HE;
case 'j': return _TE;
case 'J':
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return TEE_;
else
return TEE;
case 'k': return _NOON;
case 'l': return _MIM;
case 'm': return _PE;
case 'n':
case 'N': return DAL;
case 'o': return _XE;
case 'p': return _HE_J;
case 'q': return _ZAD;
case 'r': return _GHAF;
case 's': return _SIN;
case 'S': return _IE;
case 't': return _FE;
case 'u':
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return _AYN_;
else
return _AYN;
case 'v':
case 'V': return RE;
case 'w': return _SAD;
case 'x':
case 'X': return _TA;
case 'y':
if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR))
return _GHAYN_;
else
return _GHAYN;
case 'z':
case 'Z': return _ZA;
case ';': return _KAF;
case '\'': return _GAF;
case ',': return WAW;
case '[': return _JIM;
case ']': return _CHE;
}

return c;
}

/*
* F_isalpha returns TRUE if 'c' is a Farsi alphabet
*/
    int
F_isalpha(c)
    int c;
{
    return (( c >= TEE_ && c <= _YE)
|| (c >= ALEF_A && c <= YE)
|| (c >= _IE && c <= YE_));
}

/*
* F_isdigit returns TRUE if 'c' is a Farsi digit
*/
    int
F_isdigit(c)
    int c;
{
    return (c >= FARSI_0 && c <= FARSI_9);
}

/*
* F_ischar returns TRUE if 'c' is a Farsi character.
*/
    int
F_ischar(c)
    int c;
{
    return (c >= TEE_ && c <= YE_);
}

    void
farsi_fkey(cap)
    cmdarg_T *cap;
{
    int c = cap->cmdchar;

    if (c == K_F8)
    {
if (p_altkeymap)
{
if (curwin->w_farsi & W_R_L)
{
p_fkmap = 0;
do_cmdline_cmd((char_u *)"set norl");
MSG("");
}
else
{
p_fkmap = 1;
do_cmdline_cmd((char_u *)"set rl");
MSG("");
}

curwin->w_farsi = curwin->w_farsi ^ W_R_L;
}
    }

    if (c == K_F9)
    {
if (p_altkeymap && curwin->w_p_rl)
{
curwin->w_farsi = curwin->w_farsi ^ W_CONV;
if (curwin->w_farsi & W_CONV)
conv_to_pvim();
else
conv_to_pstd();
}
    }
}
Something went wrong with that request. Please try again.