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
|
/* Further modified for PHP */
/* $Id$ */
/* $OpenLDAP: pkg/ldap/libraries/liblunicode/ucdata/ucgendat.c,v 1.36.2.4 2007/01/02 21:43:51 kurt Exp $ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2007 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available at
* <http://www.OpenLDAP.org/license.html>.
*/
/* Copyright 2001 Computing Research Labs, New Mexico State University
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* orig Id: ucgendat.c,v 1.4 2001/01/02 18:46:20 mleisher Exp $" */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define ac_uint2 unsigned short
#define ac_uint4 unsigned int
#define LDAP_DIRSEP "/"
#define AC_MEMCPY memcpy
#ifndef HARDCODE_DATA
#define HARDCODE_DATA 1
#endif
#undef ishdigit
#define ishdigit(cc) (((cc) >= '0' && (cc) <= '9') ||\
((cc) >= 'A' && (cc) <= 'F') ||\
((cc) >= 'a' && (cc) <= 'f'))
/*
* A header written to the output file with the byte-order-mark and the number
* of property nodes.
*/
static ac_uint2 hdr[2] = {0xfeff, 0};
#define NUMPROPS 50
#define NEEDPROPS (NUMPROPS + (4 - (NUMPROPS & 3)))
typedef struct {
char *name;
int len;
} _prop_t;
/*
* List of properties expected to be found in the Unicode Character Database
* including some implementation specific properties.
*
* The implementation specific properties are:
* Cm = Composed (can be decomposed)
* Nb = Non-breaking
* Sy = Symmetric (has left and right forms)
* Hd = Hex digit
* Qm = Quote marks
* Mr = Mirroring
* Ss = Space, other
* Cp = Defined character
*/
static _prop_t props[NUMPROPS] = {
{"Mn", 2}, {"Mc", 2}, {"Me", 2}, {"Nd", 2}, {"Nl", 2}, {"No", 2},
{"Zs", 2}, {"Zl", 2}, {"Zp", 2}, {"Cc", 2}, {"Cf", 2}, {"Cs", 2},
{"Co", 2}, {"Cn", 2}, {"Lu", 2}, {"Ll", 2}, {"Lt", 2}, {"Lm", 2},
{"Lo", 2}, {"Pc", 2}, {"Pd", 2}, {"Ps", 2}, {"Pe", 2}, {"Po", 2},
{"Sm", 2}, {"Sc", 2}, {"Sk", 2}, {"So", 2}, {"L", 1}, {"R", 1},
{"EN", 2}, {"ES", 2}, {"ET", 2}, {"AN", 2}, {"CS", 2}, {"B", 1},
{"S", 1}, {"WS", 2}, {"ON", 2},
{"Cm", 2}, {"Nb", 2}, {"Sy", 2}, {"Hd", 2}, {"Qm", 2}, {"Mr", 2},
{"Ss", 2}, {"Cp", 2}, {"Pi", 2}, {"Pf", 2}, {"AL", 2}
};
typedef struct {
ac_uint4 *ranges;
ac_uint2 used;
ac_uint2 size;
} _ranges_t;
static _ranges_t proptbl[NUMPROPS];
/*
* Make sure this array is sized to be on a 4-byte boundary at compile time.
*/
static ac_uint2 propcnt[NEEDPROPS];
/*
* Array used to collect a decomposition before adding it to the decomposition
* table.
*/
static ac_uint4 dectmp[64];
static ac_uint4 dectmp_size;
typedef struct {
ac_uint4 code;
ac_uint2 size;
ac_uint2 used;
ac_uint4 *decomp;
} _decomp_t;
/*
* List of decomposition. Created and expanded in order as the characters are
* encountered. First list contains canonical mappings, second also includes
* compatibility mappings.
*/
static _decomp_t *decomps;
static ac_uint4 decomps_used;
static ac_uint4 decomps_size;
static _decomp_t *kdecomps;
static ac_uint4 kdecomps_used;
static ac_uint4 kdecomps_size;
/*
* Composition exclusion table stuff.
*/
#define COMPEX_SET(c) (compexs[(c) >> 5] |= (1 << ((c) & 31)))
#define COMPEX_TEST(c) (compexs[(c) >> 5] & (1 << ((c) & 31)))
static ac_uint4 compexs[8192];
/*
* Struct for holding a composition pair, and array of composition pairs
*/
typedef struct {
ac_uint4 comp;
ac_uint4 count;
ac_uint4 code1;
ac_uint4 code2;
} _comp_t;
#if 0
static _comp_t *comps;
#endif
static ac_uint4 comps_used;
/*
* Types and lists for handling lists of case mappings.
*/
typedef struct {
ac_uint4 key;
ac_uint4 other1;
ac_uint4 other2;
} _case_t;
static _case_t *upper;
static _case_t *lower;
static _case_t *title;
static ac_uint4 upper_used;
static ac_uint4 upper_size;
static ac_uint4 lower_used;
static ac_uint4 lower_size;
static ac_uint4 title_used;
static ac_uint4 title_size;
/*
* Array used to collect case mappings before adding them to a list.
*/
static ac_uint4 cases[3];
/*
* An array to hold ranges for combining classes.
*/
static ac_uint4 *ccl;
static ac_uint4 ccl_used;
static ac_uint4 ccl_size;
/*
* Structures for handling numbers.
*/
typedef struct {
ac_uint4 code;
ac_uint4 idx;
} _codeidx_t;
typedef struct {
short numerator;
short denominator;
} _num_t;
/*
* Arrays to hold the mapping of codes to numbers.
*/
static _codeidx_t *ncodes;
static ac_uint4 ncodes_used;
static ac_uint4 ncodes_size;
static _num_t *nums;
static ac_uint4 nums_used;
static ac_uint4 nums_size;
/*
* Array for holding numbers.
*/
static _num_t *nums;
static ac_uint4 nums_used;
static ac_uint4 nums_size;
static void
add_range(ac_uint4 start, ac_uint4 end, char *p1, char *p2)
{
int i, j, k, len;
_ranges_t *rlp;
char *name;
for (k = 0; k < 2; k++) {
if (k == 0) {
name = p1;
len = 2;
} else {
if (p2 == 0)
break;
name = p2;
len = 1;
}
for (i = 0; i < NUMPROPS; i++) {
if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
break;
}
if (i == NUMPROPS)
continue;
rlp = &proptbl[i];
/*
* Resize the range list if necessary.
*/
if (rlp->used == rlp->size) {
if (rlp->size == 0)
rlp->ranges = (ac_uint4 *)
malloc(sizeof(ac_uint4) << 3);
else
rlp->ranges = (ac_uint4 *)
realloc((char *) rlp->ranges,
sizeof(ac_uint4) * (rlp->size + 8));
rlp->size += 8;
}
/*
* If this is the first code for this property list, just add it
* and return.
*/
if (rlp->used == 0) {
rlp->ranges[0] = start;
rlp->ranges[1] = end;
rlp->used += 2;
continue;
}
/*
* Optimize the case of adding the range to the end.
*/
j = rlp->used - 1;
if (start > rlp->ranges[j]) {
j = rlp->used;
rlp->ranges[j++] = start;
rlp->ranges[j++] = end;
rlp->used = j;
continue;
}
/*
* Need to locate the insertion point.
*/
for (i = 0;
i < rlp->used && start > rlp->ranges[i + 1] + 1; i += 2) ;
/*
* If the start value lies in the current range, then simply set the
* new end point of the range to the end value passed as a parameter.
*/
if (rlp->ranges[i] <= start && start <= rlp->ranges[i + 1] + 1) {
rlp->ranges[i + 1] = end;
return;
}
/*
* Shift following values up by two.
*/
for (j = rlp->used; j > i; j -= 2) {
rlp->ranges[j] = rlp->ranges[j - 2];
rlp->ranges[j + 1] = rlp->ranges[j - 1];
}
/*
* Add the new range at the insertion point.
*/
rlp->ranges[i] = start;
rlp->ranges[i + 1] = end;
rlp->used += 2;
}
}
static void
ordered_range_insert(ac_uint4 c, char *name, int len)
{
int i, j;
ac_uint4 s, e;
_ranges_t *rlp;
if (len == 0)
return;
/*
* Deal with directionality codes introduced in Unicode 3.0.
*/
if ((len == 2 && memcmp(name, "BN", 2) == 0) ||
(len == 3 &&
(memcmp(name, "NSM", 3) == 0 || memcmp(name, "PDF", 3) == 0 ||
memcmp(name, "LRE", 3) == 0 || memcmp(name, "LRO", 3) == 0 ||
memcmp(name, "RLE", 3) == 0 || memcmp(name, "RLO", 3) == 0))) {
/*
* Mark all of these as Other Neutral to preserve compatibility with
* older versions.
*/
len = 2;
name = "ON";
}
for (i = 0; i < NUMPROPS; i++) {
if (props[i].len == len && memcmp(props[i].name, name, len) == 0)
break;
}
if (i == NUMPROPS)
return;
/*
* Have a match, so insert the code in order.
*/
rlp = &proptbl[i];
/*
* Resize the range list if necessary.
*/
if (rlp->used == rlp->size) {
if (rlp->size == 0)
rlp->ranges = (ac_uint4 *)
malloc(sizeof(ac_uint4) << 3);
else
rlp->ranges = (ac_uint4 *)
realloc((char *) rlp->ranges,
sizeof(ac_uint4) * (rlp->size + 8));
rlp->size += 8;
}
/*
* If this is the first code for this property list, just add it
* and return.
*/
if (rlp->used == 0) {
rlp->ranges[0] = rlp->ranges[1] = c;
rlp->used += 2;
return;
}
/*
* Optimize the cases of extending the last range and adding new ranges to
* the end.
*/
j = rlp->used - 1;
e = rlp->ranges[j];
s = rlp->ranges[j - 1];
if (c == e + 1) {
/*
* Extend the last range.
*/
rlp->ranges[j] = c;
return;
}
if (c > e + 1) {
/*
* Start another range on the end.
*/
j = rlp->used;
rlp->ranges[j] = rlp->ranges[j + 1] = c;
rlp->used += 2;
return;
}
if (c >= s)
/*
* The code is a duplicate of a code in the last range, so just return.
*/
return;
/*
* The code should be inserted somewhere before the last range in the
* list. Locate the insertion point.
*/
for (i = 0;
i < rlp->used && c > rlp->ranges[i + 1] + 1; i += 2) ;
s = rlp->ranges[i];
e = rlp->ranges[i + 1];
if (c == e + 1)
/*
* Simply extend the current range.
*/
rlp->ranges[i + 1] = c;
else if (c < s) {
/*
* Add a new entry before the current location. Shift all entries
* before the current one up by one to make room.
*/
for (j = rlp->used; j > i; j -= 2) {
rlp->ranges[j] = rlp->ranges[j - 2];
rlp->ranges[j + 1] = rlp->ranges[j - 1];
}
rlp->ranges[i] = rlp->ranges[i + 1] = c;
rlp->used += 2;
}
}
static void
add_decomp(ac_uint4 code, short compat)
{
ac_uint4 i, j, size;
_decomp_t **pdecomps;
ac_uint4 *pdecomps_used;
ac_uint4 *pdecomps_size;
if (compat) {
pdecomps = &kdecomps;
pdecomps_used = &kdecomps_used;
pdecomps_size = &kdecomps_size;
} else {
pdecomps = &decomps;
pdecomps_used = &decomps_used;
pdecomps_size = &decomps_size;
}
/*
* Add the code to the composite property.
*/
if (!compat) {
ordered_range_insert(code, "Cm", 2);
}
/*
* Locate the insertion point for the code.
*/
for (i = 0; i < *pdecomps_used && code > (*pdecomps)[i].code; i++) ;
/*
* Allocate space for a new decomposition.
*/
if (*pdecomps_used == *pdecomps_size) {
if (*pdecomps_size == 0)
*pdecomps = (_decomp_t *) malloc(sizeof(_decomp_t) << 3);
else
*pdecomps = (_decomp_t *)
realloc((char *) *pdecomps,
sizeof(_decomp_t) * (*pdecomps_size + 8));
(void) memset((char *) (*pdecomps + *pdecomps_size), '\0',
sizeof(_decomp_t) << 3);
*pdecomps_size += 8;
}
if (i < *pdecomps_used && code != (*pdecomps)[i].code) {
/*
* Shift the decomps up by one if the codes don't match.
*/
for (j = *pdecomps_used; j > i; j--)
(void) AC_MEMCPY((char *) &(*pdecomps)[j], (char *) &(*pdecomps)[j - 1],
sizeof(_decomp_t));
}
/*
* Insert or replace a decomposition.
*/
size = dectmp_size + (4 - (dectmp_size & 3));
if ((*pdecomps)[i].size < size) {
if ((*pdecomps)[i].size == 0)
(*pdecomps)[i].decomp = (ac_uint4 *)
malloc(sizeof(ac_uint4) * size);
else
(*pdecomps)[i].decomp = (ac_uint4 *)
realloc((char *) (*pdecomps)[i].decomp,
sizeof(ac_uint4) * size);
(*pdecomps)[i].size = size;
}
if ((*pdecomps)[i].code != code)
(*pdecomps_used)++;
(*pdecomps)[i].code = code;
(*pdecomps)[i].used = dectmp_size;
(void) AC_MEMCPY((char *) (*pdecomps)[i].decomp, (char *) dectmp,
sizeof(ac_uint4) * dectmp_size);
/*
* NOTICE: This needs changing later so it is more general than simply
* pairs. This calculation is done here to simplify allocation elsewhere.
*/
if (!compat && dectmp_size == 2)
comps_used++;
}
static void
add_title(ac_uint4 code)
{
ac_uint4 i, j;
/*
* Always map the code to itself.
*/
cases[2] = code;
if (title_used == title_size) {
if (title_size == 0)
title = (_case_t *) malloc(sizeof(_case_t) << 3);
else
title = (_case_t *) realloc((char *) title,
sizeof(_case_t) * (title_size + 8));
title_size += 8;
}
/*
* Locate the insertion point.
*/
for (i = 0; i < title_used && code > title[i].key; i++) ;
if (i < title_used) {
/*
* Shift the array up by one.
*/
for (j = title_used; j > i; j--)
(void) AC_MEMCPY((char *) &title[j], (char *) &title[j - 1],
sizeof(_case_t));
}
title[i].key = cases[2]; /* Title */
title[i].other1 = cases[0]; /* Upper */
title[i].other2 = cases[1]; /* Lower */
title_used++;
}
static void
add_upper(ac_uint4 code)
{
ac_uint4 i, j;
/*
* Always map the code to itself.
*/
cases[0] = code;
/*
* If the title case character is not present, then make it the same as
* the upper case.
*/
if (cases[2] == 0)
cases[2] = code;
if (upper_used == upper_size) {
if (upper_size == 0)
upper = (_case_t *) malloc(sizeof(_case_t) << 3);
else
upper = (_case_t *) realloc((char *) upper,
sizeof(_case_t) * (upper_size + 8));
upper_size += 8;
}
/*
* Locate the insertion point.
*/
for (i = 0; i < upper_used && code > upper[i].key; i++) ;
if (i < upper_used) {
/*
* Shift the array up by one.
*/
for (j = upper_used; j > i; j--)
(void) AC_MEMCPY((char *) &upper[j], (char *) &upper[j - 1],
sizeof(_case_t));
}
upper[i].key = cases[0]; /* Upper */
upper[i].other1 = cases[1]; /* Lower */
upper[i].other2 = cases[2]; /* Title */
upper_used++;
}
static void
add_lower(ac_uint4 code)
{
ac_uint4 i, j;
/*
* Always map the code to itself.
*/
cases[1] = code;
/*
* If the title case character is empty, then make it the same as the
* upper case.
*/
if (cases[2] == 0)
cases[2] = cases[0];
if (lower_used == lower_size) {
if (lower_size == 0)
lower = (_case_t *) malloc(sizeof(_case_t) << 3);
else
lower = (_case_t *) realloc((char *) lower,
sizeof(_case_t) * (lower_size + 8));
lower_size += 8;
}
/*
* Locate the insertion point.
*/
for (i = 0; i < lower_used && code > lower[i].key; i++) ;
if (i < lower_used) {
/*
* Shift the array up by one.
*/
for (j = lower_used; j > i; j--)
(void) AC_MEMCPY((char *) &lower[j], (char *) &lower[j - 1],
sizeof(_case_t));
}
lower[i].key = cases[1]; /* Lower */
lower[i].other1 = cases[0]; /* Upper */
lower[i].other2 = cases[2]; /* Title */
lower_used++;
}
static void
ordered_ccl_insert(ac_uint4 c, ac_uint4 ccl_code)
{
ac_uint4 i, j;
if (ccl_used == ccl_size) {
if (ccl_size == 0)
ccl = (ac_uint4 *) malloc(sizeof(ac_uint4) * 24);
else
ccl = (ac_uint4 *)
realloc((char *) ccl, sizeof(ac_uint4) * (ccl_size + 24));
ccl_size += 24;
}
/*
* Optimize adding the first item.
*/
if (ccl_used == 0) {
ccl[0] = ccl[1] = c;
ccl[2] = ccl_code;
ccl_used += 3;
return;
}
/*
* Handle the special case of extending the range on the end. This
* requires that the combining class codes are the same.
*/
if (ccl_code == ccl[ccl_used - 1] && c == ccl[ccl_used - 2] + 1) {
ccl[ccl_used - 2] = c;
return;
}
/*
* Handle the special case of adding another range on the end.
*/
if (c > ccl[ccl_used - 2] + 1 ||
(c == ccl[ccl_used - 2] + 1 && ccl_code != ccl[ccl_used - 1])) {
ccl[ccl_used++] = c;
ccl[ccl_used++] = c;
ccl[ccl_used++] = ccl_code;
return;
}
/*
* Locate either the insertion point or range for the code.
*/
for (i = 0; i < ccl_used && c > ccl[i + 1] + 1; i += 3) ;
if (ccl_code == ccl[i + 2] && c == ccl[i + 1] + 1) {
/*
* Extend an existing range.
*/
ccl[i + 1] = c;
return;
} else if (c < ccl[i]) {
/*
* Start a new range before the current location.
*/
for (j = ccl_used; j > i; j -= 3) {
ccl[j] = ccl[j - 3];
ccl[j - 1] = ccl[j - 4];
ccl[j - 2] = ccl[j - 5];
}
ccl[i] = ccl[i + 1] = c;
ccl[i + 2] = ccl_code;
}
}
/*
* Adds a number if it does not already exist and returns an index value
* multiplied by 2.
*/
static ac_uint4
make_number(short num, short denom)
{
ac_uint4 n;
/*
* Determine if the number already exists.
*/
for (n = 0; n < nums_used; n++) {
if (nums[n].numerator == num && nums[n].denominator == denom)
return n << 1;
}
if (nums_used == nums_size) {
if (nums_size == 0)
nums = (_num_t *) malloc(sizeof(_num_t) << 3);
else
nums = (_num_t *) realloc((char *) nums,
sizeof(_num_t) * (nums_size + 8));
nums_size += 8;
}
n = nums_used++;
nums[n].numerator = num;
nums[n].denominator = denom;
return n << 1;
}
static void
add_number(ac_uint4 code, short num, short denom)
{
ac_uint4 i, j;
/*
* Insert the code in order.
*/
for (i = 0; i < ncodes_used && code > ncodes[i].code; i++) ;
/*
* Handle the case of the codes matching and simply replace the number
* that was there before.
*/
if (i < ncodes_used && code == ncodes[i].code) {
ncodes[i].idx = make_number(num, denom);
return;
}
/*
* Resize the array if necessary.
*/
if (ncodes_used == ncodes_size) {
if (ncodes_size == 0)
ncodes = (_codeidx_t *) malloc(sizeof(_codeidx_t) << 3);
else
ncodes = (_codeidx_t *)
realloc((char *) ncodes, sizeof(_codeidx_t) * (ncodes_size + 8));
ncodes_size += 8;
}
/*
* Shift things around to insert the code if necessary.
*/
if (i < ncodes_used) {
for (j = ncodes_used; j > i; j--) {
ncodes[j].code = ncodes[j - 1].code;
ncodes[j].idx = ncodes[j - 1].idx;
}
}
ncodes[i].code = code;
ncodes[i].idx = make_number(num, denom);
ncodes_used++;
}
/*
* This routine assumes that the line is a valid Unicode Character Database
* entry.
*/
static void
read_cdata(FILE *in)
{
ac_uint4 i, lineno, skip, code, ccl_code;
short wnum, neg, number[2], compat;
char line[512], *s, *e;
lineno = skip = 0;
while (fgets(line, sizeof(line), in)) {
if( (s=strchr(line, '\n')) ) *s = '\0';
lineno++;
/*
* Skip blank lines and lines that start with a '#'.
*/
if (line[0] == 0 || line[0] == '#')
continue;
/*
* If lines need to be skipped, do it here.
*/
if (skip) {
skip--;
continue;
}
/*
* Collect the code. The code can be up to 6 hex digits in length to
* allow surrogates to be specified.
*/
for (s = line, i = code = 0; *s != ';' && i < 6; i++, s++) {
code <<= 4;
if (*s >= '0' && *s <= '9')
code += *s - '0';
else if (*s >= 'A' && *s <= 'F')
code += (*s - 'A') + 10;
else if (*s >= 'a' && *s <= 'f')
code += (*s - 'a') + 10;
}
/*
* Handle the following special cases:
* 1. 4E00-9FA5 CJK Ideographs.
* 2. AC00-D7A3 Hangul Syllables.
* 3. D800-DFFF Surrogates.
* 4. E000-F8FF Private Use Area.
* 5. F900-FA2D Han compatibility.
* ...Plus additional ranges in newer Unicode versions...
*/
switch (code) {
case 0x3400:
/* CJK Ideograph Extension A */
add_range(0x3400, 0x4db5, "Lo", "L");
add_range(0x3400, 0x4db5, "Cp", 0);
skip = 1;
break;
case 0x4e00:
/*
* The Han ideographs.
*/
add_range(0x4e00, 0x9fff, "Lo", "L");
/*
* Add the characters to the defined category.
*/
add_range(0x4e00, 0x9fa5, "Cp", 0);
skip = 1;
break;
case 0xac00:
/*
* The Hangul syllables.
*/
add_range(0xac00, 0xd7a3, "Lo", "L");
/*
* Add the characters to the defined category.
*/
add_range(0xac00, 0xd7a3, "Cp", 0);
skip = 1;
break;
case 0xd800:
/*
* Make a range of all surrogates and assume some default
* properties.
*/
add_range(0x010000, 0x10ffff, "Cs", "L");
skip = 5;
break;
case 0xe000:
/*
* The Private Use area. Add with a default set of properties.
*/
add_range(0xe000, 0xf8ff, "Co", "L");
skip = 1;
break;
case 0xf900:
/*
* The CJK compatibility area.
*/
add_range(0xf900, 0xfaff, "Lo", "L");
/*
* Add the characters to the defined category.
*/
add_range(0xf900, 0xfaff, "Cp", 0);
skip = 1;
break;
case 0x20000:
/* CJK Ideograph Extension B */
add_range(0x20000, 0x2a6d6, "Lo", "L");
add_range(0x20000, 0x2a6d6, "Cp", 0);
skip = 1;
break;
case 0xf0000:
/* Plane 15 private use */
add_range(0xf0000, 0xffffd, "Co", "L");
skip = 1;
break;
case 0x100000:
/* Plane 16 private use */
add_range(0x100000, 0x10fffd, "Co", "L");
skip = 1;
break;
}
if (skip)
continue;
/*
* Add the code to the defined category.
*/
ordered_range_insert(code, "Cp", 2);
/*
* Locate the first character property field.
*/
for (i = 0; *s != 0 && i < 2; s++) {
if (*s == ';')
i++;
}
for (e = s; *e && *e != ';'; e++) ;
ordered_range_insert(code, s, e - s);
/*
* Locate the combining class code.
*/
for (s = e; *s != 0 && i < 3; s++) {
if (*s == ';')
i++;
}
/*
* Convert the combining class code from decimal.
*/
for (ccl_code = 0, e = s; *e && *e != ';'; e++)
ccl_code = (ccl_code * 10) + (*e - '0');
/*
* Add the code if it not 0.
*/
if (ccl_code != 0)
ordered_ccl_insert(code, ccl_code);
/*
* Locate the second character property field.
*/
for (s = e; *s != 0 && i < 4; s++) {
if (*s == ';')
i++;
}
for (e = s; *e && *e != ';'; e++) ;
ordered_range_insert(code, s, e - s);
/*
* Check for a decomposition.
*/
s = ++e;
if (*s != ';') {
compat = *s == '<';
if (compat) {
/*
* Skip compatibility formatting tag.
*/
while (*s++ != '>');
}
/*
* Collect the codes of the decomposition.
*/
for (dectmp_size = 0; *s != ';'; ) {
/*
* Skip all leading non-hex digits.
*/
while (!ishdigit(*s))
s++;
for (dectmp[dectmp_size] = 0; ishdigit(*s); s++) {
dectmp[dectmp_size] <<= 4;
if (*s >= '0' && *s <= '9')
dectmp[dectmp_size] += *s - '0';
else if (*s >= 'A' && *s <= 'F')
dectmp[dectmp_size] += (*s - 'A') + 10;
else if (*s >= 'a' && *s <= 'f')
dectmp[dectmp_size] += (*s - 'a') + 10;
}
dectmp_size++;
}
/*
* If there are any codes in the temporary decomposition array,
* then add the character with its decomposition.
*/
if (dectmp_size > 0) {
if (!compat) {
add_decomp(code, 0);
}
add_decomp(code, 1);
}
}
/*
* Skip to the number field.
*/
for (i = 0; i < 3 && *s; s++) {
if (*s == ';')
i++;
}
/*
* Scan the number in.
*/
number[0] = number[1] = 0;
for (e = s, neg = wnum = 0; *e && *e != ';'; e++) {
if (*e == '-') {
neg = 1;
continue;
}
if (*e == '/') {
/*
* Move the the denominator of the fraction.
*/
if (neg)
number[wnum] *= -1;
neg = 0;
e++;
wnum++;
}
number[wnum] = (number[wnum] * 10) + (*e - '0');
}
if (e > s) {
/*
* Adjust the denominator in case of integers and add the number.
*/
if (wnum == 0)
number[1] = 1;
add_number(code, number[0], number[1]);
}
/*
* Skip to the start of the possible case mappings.
*/
for (s = e, i = 0; i < 4 && *s; s++) {
if (*s == ';')
i++;
}
/*
* Collect the case mappings.
*/
cases[0] = cases[1] = cases[2] = 0;
for (i = 0; i < 3; i++) {
while (ishdigit(*s)) {
cases[i] <<= 4;
if (*s >= '0' && *s <= '9')
cases[i] += *s - '0';
else if (*s >= 'A' && *s <= 'F')
cases[i] += (*s - 'A') + 10;
else if (*s >= 'a' && *s <= 'f')
cases[i] += (*s - 'a') + 10;
s++;
}
if (*s == ';')
s++;
}
if (cases[0] && cases[1])
/*
* Add the upper and lower mappings for a title case character.
*/
add_title(code);
else if (cases[1])
/*
* Add the lower and title case mappings for the upper case
* character.
*/
add_upper(code);
else if (cases[0])
/*
* Add the upper and title case mappings for the lower case
* character.
*/
add_lower(code);
}
}
#if 0
static _decomp_t *
find_decomp(ac_uint4 code, short compat)
{
long l, r, m;
_decomp_t *decs;
l = 0;
r = (compat ? kdecomps_used : decomps_used) - 1;
decs = compat ? kdecomps : decomps;
while (l <= r) {
m = (l + r) >> 1;
if (code > decs[m].code)
l = m + 1;
else if (code < decs[m].code)
r = m - 1;
else
return &decs[m];
}
return 0;
}
static void
decomp_it(_decomp_t *d, short compat)
{
ac_uint4 i;
_decomp_t *dp;
for (i = 0; i < d->used; i++) {
if ((dp = find_decomp(d->decomp[i], compat)) != 0)
decomp_it(dp, compat);
else
dectmp[dectmp_size++] = d->decomp[i];
}
}
/*
* Expand all decompositions by recursively decomposing each character
* in the decomposition.
*/
static void
expand_decomp(void)
{
ac_uint4 i;
for (i = 0; i < decomps_used; i++) {
dectmp_size = 0;
decomp_it(&decomps[i], 0);
if (dectmp_size > 0)
add_decomp(decomps[i].code, 0);
}
for (i = 0; i < kdecomps_used; i++) {
dectmp_size = 0;
decomp_it(&kdecomps[i], 1);
if (dectmp_size > 0)
add_decomp(kdecomps[i].code, 1);
}
}
static int
cmpcomps(const void *v_comp1, const void *v_comp2)
{
const _comp_t *comp1 = v_comp1, *comp2 = v_comp2;
long diff = comp1->code1 - comp2->code1;
if (!diff)
diff = comp1->code2 - comp2->code2;
return (int) diff;
}
#endif
/*
* Load composition exclusion data
*/
static void
read_compexdata(FILE *in)
{
ac_uint2 i;
ac_uint4 code;
char line[512], *s;
(void) memset((char *) compexs, 0, sizeof(compexs));
while (fgets(line, sizeof(line), in)) {
if( (s=strchr(line, '\n')) ) *s = '\0';
/*
* Skip blank lines and lines that start with a '#'.
*/
if (line[0] == 0 || line[0] == '#')
continue;
/*
* Collect the code. Assume max 6 digits
*/
for (s = line, i = code = 0; *s != '#' && i < 6; i++, s++) {
if (isspace((unsigned char)*s)) break;
code <<= 4;
if (*s >= '0' && *s <= '9')
code += *s - '0';
else if (*s >= 'A' && *s <= 'F')
code += (*s - 'A') + 10;
else if (*s >= 'a' && *s <= 'f')
code += (*s - 'a') + 10;
}
COMPEX_SET(code);
}
}
#if 0
/*
* Creates array of compositions from decomposition array
*/
static void
create_comps(void)
{
ac_uint4 i, cu;
comps = (_comp_t *) malloc(comps_used * sizeof(_comp_t));
for (i = cu = 0; i < decomps_used; i++) {
if (decomps[i].used != 2 || COMPEX_TEST(decomps[i].code))
continue;
comps[cu].comp = decomps[i].code;
comps[cu].count = 2;
comps[cu].code1 = decomps[i].decomp[0];
comps[cu].code2 = decomps[i].decomp[1];
cu++;
}
comps_used = cu;
qsort(comps, comps_used, sizeof(_comp_t), cmpcomps);
}
#endif
#if HARDCODE_DATA
static void
write_case(FILE *out, _case_t *tab, int num, int first)
{
int i;
for (i=0; i<num; i++) {
if (first) first = 0;
else fprintf(out, ",");
fprintf(out, "\n\t0x%08lx, 0x%08lx, 0x%08lx",
(unsigned long) tab[i].key, (unsigned long) tab[i].other1,
(unsigned long) tab[i].other2);
}
}
#define PREF "static const "
#endif
static void
write_cdata(char *opath)
{
FILE *out;
ac_uint4 bytes;
ac_uint4 i, idx, nprops;
#if !(HARDCODE_DATA)
ac_uint2 casecnt[2];
#endif
char path[BUFSIZ];
#if HARDCODE_DATA
int j, k;
/*****************************************************************
*
* Generate the ctype data.
*
*****************************************************************/
/*
* Open the output file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "uctable.h", opath);
if ((out = fopen(path, "w")) == 0)
return;
#else
/*
* Open the ctype.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "ctype.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
#endif
/*
* Collect the offsets for the properties. The offsets array is
* on a 4-byte boundary to keep things efficient for architectures
* that need such a thing.
*/
for (i = idx = 0; i < NUMPROPS; i++) {
propcnt[i] = (proptbl[i].used != 0) ? idx : 0xffff;
idx += proptbl[i].used;
}
/*
* Add the sentinel index which is used by the binary search as the upper
* bound for a search.
*/
propcnt[i] = idx;
/*
* Record the actual number of property lists. This may be different than
* the number of offsets actually written because of aligning on a 4-byte
* boundary.
*/
hdr[1] = NUMPROPS;
/*
* Calculate the byte count needed and pad the property counts array to a
* 4-byte boundary.
*/
if ((bytes = sizeof(ac_uint2) * (NUMPROPS + 1)) & 3)
bytes += 4 - (bytes & 3);
nprops = bytes / sizeof(ac_uint2);
bytes += sizeof(ac_uint4) * idx;
#if HARDCODE_DATA
fprintf(out,
"/* This file was generated from a modified version UCData's ucgendat.\n"
" *\n"
" * DO NOT EDIT THIS FILE!\n"
" * \n"
" * Instead, compile ucgendat.c (bundled with PHP in ext/mbstring), download\n"
" * the appropriate UnicodeData-x.x.x.txt and CompositionExclusions-x.x.x.txt\n"
" * files from http://www.unicode.org/Public/ and run this program.\n"
" *\n"
" * More information can be found in the UCData package. Unfortunately,\n"
" * the project's page doesn't seem to be live anymore, so you can use\n"
" * OpenLDAPs modified copy (look in libraries/liblunicode/ucdata) */\n\n");
fprintf(out, PREF "unsigned short _ucprop_size = %d;\n\n", NUMPROPS);
fprintf(out, PREF "unsigned short _ucprop_offsets[] = {");
for (i = 0; i<nprops; i++) {
if (i) fprintf(out, ",");
if (!(i&7)) fprintf(out, "\n\t");
else fprintf(out, " ");
fprintf(out, "0x%04x", propcnt[i]);
}
fprintf(out, "\n};\n\n");
fprintf(out, PREF "unsigned int _ucprop_ranges[] = {");
k = 0;
for (i = 0; i < NUMPROPS; i++) {
if (proptbl[i].used > 0) {
for (j=0; j<proptbl[i].used; j++) {
if (k) fprintf(out, ",");
if (!(k&3)) fprintf(out,"\n\t");
else fprintf(out, " ");
k++;
fprintf(out, "0x%08lx", (unsigned long) proptbl[i].ranges[j]);
}
}
}
fprintf(out, "\n};\n\n");
#else
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write the byte count.
*/
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
/*
* Write the property list counts.
*/
fwrite((char *) propcnt, sizeof(ac_uint2), nprops, out);
/*
* Write the property lists.
*/
for (i = 0; i < NUMPROPS; i++) {
if (proptbl[i].used > 0)
fwrite((char *) proptbl[i].ranges, sizeof(ac_uint4),
proptbl[i].used, out);
}
fclose(out);
#endif
/*****************************************************************
*
* Generate the case mapping data.
*
*****************************************************************/
#if HARDCODE_DATA
fprintf(out, PREF "unsigned int _uccase_size = %ld;\n\n",
(long) (upper_used + lower_used + title_used));
fprintf(out,
"/* Starting indexes of the case tables\n"
" * UpperIndex = 0\n"
" * LowerIndex = _uccase_len[0]\n"
" * TitleIndex = LowerIndex + _uccase_len[1] */\n\n");
fprintf(out, PREF "unsigned short _uccase_len[2] = {%ld, %ld};\n\n",
(long) upper_used * 3, (long) lower_used * 3);
fprintf(out, PREF "unsigned int _uccase_map[] = {");
if (upper_used > 0)
/*
* Write the upper case table.
*/
write_case(out, upper, upper_used, 1);
if (lower_used > 0)
/*
* Write the lower case table.
*/
write_case(out, lower, lower_used, !upper_used);
if (title_used > 0)
/*
* Write the title case table.
*/
write_case(out, title, title_used, !(upper_used||lower_used));
if (!(upper_used || lower_used || title_used))
fprintf(out, "\t0");
fprintf(out, "\n};\n\n");
#else
/*
* Open the case.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "case.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
/*
* Write the case mapping tables.
*/
hdr[1] = upper_used + lower_used + title_used;
casecnt[0] = upper_used;
casecnt[1] = lower_used;
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write the upper and lower case table sizes.
*/
fwrite((char *) casecnt, sizeof(ac_uint2), 2, out);
if (upper_used > 0)
/*
* Write the upper case table.
*/
fwrite((char *) upper, sizeof(_case_t), upper_used, out);
if (lower_used > 0)
/*
* Write the lower case table.
*/
fwrite((char *) lower, sizeof(_case_t), lower_used, out);
if (title_used > 0)
/*
* Write the title case table.
*/
fwrite((char *) title, sizeof(_case_t), title_used, out);
fclose(out);
#endif
#if 0
/*****************************************************************
*
* Generate the composition data.
*
*****************************************************************/
/*
* Create compositions from decomposition data
*/
create_comps();
#if HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _uccomp_size = %ld;\n\n",
comps_used * 4L);
fprintf(out, PREF "ac_uint4 _uccomp_data[] = {");
/*
* Now, if comps exist, write them out.
*/
if (comps_used > 0) {
for (i=0; i<comps_used; i++) {
if (i) fprintf(out, ",");
fprintf(out, "\n\t0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx",
(unsigned long) comps[i].comp, (unsigned long) comps[i].count,
(unsigned long) comps[i].code1, (unsigned long) comps[i].code2);
}
} else {
fprintf(out, "\t0");
}
fprintf(out, "\n};\n\n");
#else
/*
* Open the comp.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "comp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
/*
* Write the header.
*/
hdr[1] = (ac_uint2) comps_used * 4;
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write out the byte count to maintain header size.
*/
bytes = comps_used * sizeof(_comp_t);
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
/*
* Now, if comps exist, write them out.
*/
if (comps_used > 0)
fwrite((char *) comps, sizeof(_comp_t), comps_used, out);
fclose(out);
#endif
/*****************************************************************
*
* Generate the decomposition data.
*
*****************************************************************/
/*
* Fully expand all decompositions before generating the output file.
*/
expand_decomp();
#if HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _ucdcmp_size = %ld;\n\n",
decomps_used * 2L);
fprintf(out, PREF "ac_uint4 _ucdcmp_nodes[] = {");
if (decomps_used) {
/*
* Write the list of decomp nodes.
*/
for (i = idx = 0; i < decomps_used; i++) {
fprintf(out, "\n\t0x%08lx, 0x%08lx,",
(unsigned long) decomps[i].code, (unsigned long) idx);
idx += decomps[i].used;
}
/*
* Write the sentinel index as the last decomp node.
*/
fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx);
fprintf(out, PREF "ac_uint4 _ucdcmp_decomp[] = {");
/*
* Write the decompositions themselves.
*/
k = 0;
for (i = 0; i < decomps_used; i++)
for (j=0; j<decomps[i].used; j++) {
if (k) fprintf(out, ",");
if (!(k&3)) fprintf(out,"\n\t");
else fprintf(out, " ");
k++;
fprintf(out, "0x%08lx", (unsigned long) decomps[i].decomp[j]);
}
fprintf(out, "\n};\n\n");
}
#else
/*
* Open the decomp.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "decomp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
hdr[1] = decomps_used;
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write a temporary byte count which will be calculated as the
* decompositions are written out.
*/
bytes = 0;
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
if (decomps_used) {
/*
* Write the list of decomp nodes.
*/
for (i = idx = 0; i < decomps_used; i++) {
fwrite((char *) &decomps[i].code, sizeof(ac_uint4), 1, out);
fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
idx += decomps[i].used;
}
/*
* Write the sentinel index as the last decomp node.
*/
fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
/*
* Write the decompositions themselves.
*/
for (i = 0; i < decomps_used; i++)
fwrite((char *) decomps[i].decomp, sizeof(ac_uint4),
decomps[i].used, out);
/*
* Seek back to the beginning and write the byte count.
*/
bytes = (sizeof(ac_uint4) * idx) +
(sizeof(ac_uint4) * ((hdr[1] << 1) + 1));
fseek(out, sizeof(ac_uint2) << 1, 0L);
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
fclose(out);
}
#endif
#ifdef HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _uckdcmp_size = %ld;\n\n",
kdecomps_used * 2L);
fprintf(out, PREF "ac_uint4 _uckdcmp_nodes[] = {");
if (kdecomps_used) {
/*
* Write the list of kdecomp nodes.
*/
for (i = idx = 0; i < kdecomps_used; i++) {
fprintf(out, "\n\t0x%08lx, 0x%08lx,",
(unsigned long) kdecomps[i].code, (unsigned long) idx);
idx += kdecomps[i].used;
}
/*
* Write the sentinel index as the last decomp node.
*/
fprintf(out, "\n\t0x%08lx\n};\n\n", (unsigned long) idx);
fprintf(out, PREF "ac_uint4 _uckdcmp_decomp[] = {");
/*
* Write the decompositions themselves.
*/
k = 0;
for (i = 0; i < kdecomps_used; i++)
for (j=0; j<kdecomps[i].used; j++) {
if (k) fprintf(out, ",");
if (!(k&3)) fprintf(out,"\n\t");
else fprintf(out, " ");
k++;
fprintf(out, "0x%08lx", (unsigned long) kdecomps[i].decomp[j]);
}
fprintf(out, "\n};\n\n");
}
#else
/*
* Open the kdecomp.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "kdecomp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
hdr[1] = kdecomps_used;
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write a temporary byte count which will be calculated as the
* decompositions are written out.
*/
bytes = 0;
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
if (kdecomps_used) {
/*
* Write the list of kdecomp nodes.
*/
for (i = idx = 0; i < kdecomps_used; i++) {
fwrite((char *) &kdecomps[i].code, sizeof(ac_uint4), 1, out);
fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
idx += kdecomps[i].used;
}
/*
* Write the sentinel index as the last decomp node.
*/
fwrite((char *) &idx, sizeof(ac_uint4), 1, out);
/*
* Write the decompositions themselves.
*/
for (i = 0; i < kdecomps_used; i++)
fwrite((char *) kdecomps[i].decomp, sizeof(ac_uint4),
kdecomps[i].used, out);
/*
* Seek back to the beginning and write the byte count.
*/
bytes = (sizeof(ac_uint4) * idx) +
(sizeof(ac_uint4) * ((hdr[1] << 1) + 1));
fseek(out, sizeof(ac_uint2) << 1, 0L);
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
fclose(out);
}
#endif
/*****************************************************************
*
* Generate the combining class data.
*
*****************************************************************/
#ifdef HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _uccmcl_size = %ld;\n\n", (long) ccl_used);
fprintf(out, PREF "ac_uint4 _uccmcl_nodes[] = {");
if (ccl_used > 0) {
/*
* Write the combining class ranges out.
*/
for (i = 0; i<ccl_used; i++) {
if (i) fprintf(out, ",");
if (!(i&3)) fprintf(out, "\n\t");
else fprintf(out, " ");
fprintf(out, "0x%08lx", (unsigned long) ccl[i]);
}
} else {
fprintf(out, "\t0");
}
fprintf(out, "\n};\n\n");
#else
/*
* Open the cmbcl.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "cmbcl.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
/*
* Set the number of ranges used. Each range has a combining class which
* means each entry is a 3-tuple.
*/
hdr[1] = ccl_used / 3;
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write out the byte count to maintain header size.
*/
bytes = ccl_used * sizeof(ac_uint4);
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
if (ccl_used > 0)
/*
* Write the combining class ranges out.
*/
fwrite((char *) ccl, sizeof(ac_uint4), ccl_used, out);
fclose(out);
#endif
/*****************************************************************
*
* Generate the number data.
*
*****************************************************************/
#if HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _ucnum_size = %lu;\n\n",
(unsigned long)ncodes_used<<1);
fprintf(out, PREF "ac_uint4 _ucnum_nodes[] = {");
/*
* Now, if number mappings exist, write them out.
*/
if (ncodes_used > 0) {
for (i = 0; i<ncodes_used; i++) {
if (i) fprintf(out, ",");
if (!(i&1)) fprintf(out, "\n\t");
else fprintf(out, " ");
fprintf(out, "0x%08lx, 0x%08lx",
(unsigned long) ncodes[i].code, (unsigned long) ncodes[i].idx);
}
fprintf(out, "\n};\n\n");
fprintf(out, PREF "short _ucnum_vals[] = {");
for (i = 0; i<nums_used; i++) {
if (i) fprintf(out, ",");
if (!(i&3)) fprintf(out, "\n\t");
else fprintf(out, " ");
if (nums[i].numerator < 0) {
fprintf(out, "%6d, 0x%04x",
nums[i].numerator, nums[i].denominator);
} else {
fprintf(out, "0x%04x, 0x%04x",
nums[i].numerator, nums[i].denominator);
}
}
fprintf(out, "\n};\n\n");
}
#else
/*
* Open the num.dat file.
*/
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "num.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
/*
* The count part of the header will be the total number of codes that
* have numbers.
*/
hdr[1] = (ac_uint2) (ncodes_used << 1);
bytes = (ncodes_used * sizeof(_codeidx_t)) + (nums_used * sizeof(_num_t));
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write out the byte count to maintain header size.
*/
fwrite((char *) &bytes, sizeof(ac_uint4), 1, out);
/*
* Now, if number mappings exist, write them out.
*/
if (ncodes_used > 0) {
fwrite((char *) ncodes, sizeof(_codeidx_t), ncodes_used, out);
fwrite((char *) nums, sizeof(_num_t), nums_used, out);
}
#endif
#endif
fclose(out);
}
static void
usage(char *prog)
{
fprintf(stderr,
"Usage: %s [-o output-directory|-x composition-exclusions]", prog);
fprintf(stderr, " datafile1 datafile2 ...\n\n");
fprintf(stderr,
"-o output-directory\n\t\tWrite the output files to a different");
fprintf(stderr, " directory (default: .).\n");
fprintf(stderr,
"-x composition-exclusion\n\t\tFile of composition codes");
fprintf(stderr, " that should be excluded.\n");
exit(1);
}
int
main(int argc, char *argv[])
{
FILE *in;
char *prog, *opath;
prog = argv[1];
opath = 0;
in = stdin;
argc--;
argv++;
while (argc > 0) {
if (argv[0][0] == '-') {
switch (argv[0][1]) {
case 'o':
argc--;
argv++;
opath = argv[0];
break;
case 'x':
argc--;
argv++;
if ((in = fopen(argv[0], "r")) == 0)
fprintf(stderr,
"%s: unable to open composition exclusion file %s\n",
prog, argv[0]);
else {
read_compexdata(in);
fclose(in);
in = 0;
}
break;
default:
usage(prog);
}
} else {
if (in != stdin && in != NULL)
fclose(in);
if ((in = fopen(argv[0], "r")) == 0)
fprintf(stderr, "%s: unable to open ctype file %s\n",
prog, argv[0]);
else {
read_cdata(in);
fclose(in);
in = 0;
}
}
argc--;
argv++;
}
if (opath == 0)
opath = ".";
write_cdata(opath);
return 0;
}
|