| 1 |
/* |
| 2 |
* KANJI Code conversion routines. |
| 3 |
* (for upTeX and e-upTeX) |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "kanji.h" |
| 7 |
|
| 8 |
#define CS_TOKEN_FLAG 0x1FFFFFFF |
| 9 |
#define IVS_CHAR_LIMIT 0x4400000 |
| 10 |
#define CJK_CHAR_LIMIT 0x1000000 |
| 11 |
#define LATIN_CHAR_LIMIT 0x2E80 |
| 12 |
#define UCS_CHAR_LIMIT 0x110000 |
| 13 |
#define CJK_TOKEN_FLAG 0xFFFFFF |
| 14 |
#define CAT_LEFT_BRACE 1 |
| 15 |
#define CAT_DELIM_NUM 15 |
| 16 |
#define KCAT_KANJI 16 |
| 17 |
#define KCAT_MODIFIER 20 |
| 18 |
#define KCAT_KANJI_IVS 23 |
| 19 |
|
| 20 |
/* TOKEN */ |
| 21 |
integer check_kanji (integer c) |
| 22 |
{ |
| 23 |
integer c0, c1; |
| 24 |
|
| 25 |
if (c >= CS_TOKEN_FLAG) return 0; |
| 26 |
|
| 27 |
c0 = c & CJK_TOKEN_FLAG; |
| 28 |
c1 = XXHi(c); |
| 29 |
if (c1>=CAT_LEFT_BRACE && c1<=CAT_DELIM_NUM && |
| 30 |
c0 < LATIN_CHAR_LIMIT) { /* kcatcode latin_ucs */ |
| 31 |
return 1; |
| 32 |
} |
| 33 |
else if (c1>=KCAT_KANJI && c1<=KCAT_MODIFIER) { |
| 34 |
return is_char_kanji(c0)*2; |
| 35 |
} |
| 36 |
else if (c1>=KCAT_KANJI_IVS+1 && c1<=KCAT_KANJI_IVS+4) { |
| 37 |
return is_char_kanji(c - KCAT_KANJI_IVS * CJK_CHAR_LIMIT)*3; |
| 38 |
} |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
boolean is_char_ascii(integer c) |
| 43 |
{ |
| 44 |
return (0 <= c && c < LATIN_CHAR_LIMIT); |
| 45 |
} |
| 46 |
|
| 47 |
boolean is_char_kanji(integer c) |
| 48 |
{ |
| 49 |
if (is_internalUPTEX()) |
| 50 |
return ((c >= 0)&&(c<IVS_CHAR_LIMIT)); |
| 51 |
else |
| 52 |
return ((iskanji1(Hi(c)) && iskanji2(Lo(c))) || |
| 53 |
(UCS_CHAR_LIMIT<=c && c<IVS_CHAR_LIMIT)); |
| 54 |
} |
| 55 |
|
| 56 |
boolean ismultiprn(integer c) |
| 57 |
{ |
| 58 |
int i, j; |
| 59 |
|
| 60 |
for (i=2; i<=4; i++) for (j=1; j<=i; j++) { |
| 61 |
if (ismultichr(i,j,c)) return true; |
| 62 |
} |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
integer calc_pos(integer c) |
| 67 |
{ |
| 68 |
unsigned char c1, c2; |
| 69 |
|
| 70 |
if(c>=0 && c<=255) return(c); |
| 71 |
c1 = Hi(c); |
| 72 |
c2 = Lo(c); |
| 73 |
|
| 74 |
c1 = (c1 % 4) * 64; /* c1 = 0, 64, 128, 192 */ |
| 75 |
c2 = c2 % 64; /* c2 = 0..63 */ |
| 76 |
return(c1 + c2); /* ret = 0..255 */ |
| 77 |
} |
| 78 |
|
| 79 |
integer ktoken_to_cmd(integer c) |
| 80 |
{ |
| 81 |
if (c > KCAT_KANJI_IVS * CJK_CHAR_LIMIT) |
| 82 |
return KCAT_KANJI; |
| 83 |
else |
| 84 |
return (c / CJK_CHAR_LIMIT); |
| 85 |
} |
| 86 |
|
| 87 |
integer ktoken_to_chr(integer c) |
| 88 |
{ |
| 89 |
if (c > KCAT_KANJI_IVS * CJK_CHAR_LIMIT) |
| 90 |
return (c - KCAT_KANJI_IVS * CJK_CHAR_LIMIT); |
| 91 |
else |
| 92 |
return (c % CJK_CHAR_LIMIT); |
| 93 |
} |
| 94 |
|
| 95 |
/* Ref. http://www.unicode.org/Public/UNIDATA/Blocks.txt */ |
| 96 |
/* # Blocks-17.0.0.txt */ |
| 97 |
/* # Date: 2025-08-01 */ |
| 98 |
static long ucs_range[]={ |
| 99 |
0x0000, /* Basic Latin */ /* 0x00 */ |
| 100 |
0x0080, /* Latin-1 Supplement */ |
| 101 |
0x0100, /* Latin Extended-A */ |
| 102 |
0x0180, /* Latin Extended-B */ |
| 103 |
0x0250, /* IPA Extensions */ |
| 104 |
0x02B0, /* Spacing Modifier Letters */ |
| 105 |
0x0300, /* Combining Diacritical Marks */ |
| 106 |
0x0370, /* Greek and Coptic */ |
| 107 |
0x0400, /* Cyrillic */ |
| 108 |
0x0500, /* Cyrillic Supplement */ |
| 109 |
0x0530, /* Armenian */ |
| 110 |
0x0590, /* Hebrew */ |
| 111 |
0x0600, /* Arabic */ |
| 112 |
0x0700, /* Syriac */ |
| 113 |
0x0750, /* Arabic Supplement */ |
| 114 |
0x0780, /* Thaana */ |
| 115 |
0x07C0, /* NKo */ /* 0x10 */ |
| 116 |
0x0800, /* Samaritan */ |
| 117 |
0x0840, /* Mandaic */ |
| 118 |
0x0860, /* Syriac Supplement */ |
| 119 |
0x0870, /* Arabic Extended-B */ |
| 120 |
0x08A0, /* Arabic Extended-A */ |
| 121 |
0x0900, /* Devanagari */ |
| 122 |
0x0980, /* Bengali */ |
| 123 |
0x0A00, /* Gurmukhi */ |
| 124 |
0x0A80, /* Gujarati */ |
| 125 |
0x0B00, /* Oriya */ |
| 126 |
0x0B80, /* Tamil */ |
| 127 |
0x0C00, /* Telugu */ |
| 128 |
0x0C80, /* Kannada */ |
| 129 |
0x0D00, /* Malayalam */ |
| 130 |
0x0D80, /* Sinhala */ |
| 131 |
0x0E00, /* Thai */ /* 0x20 */ |
| 132 |
0x0E80, /* Lao */ |
| 133 |
0x0F00, /* Tibetan */ |
| 134 |
0x1000, /* Myanmar */ |
| 135 |
0x10A0, /* Georgian */ |
| 136 |
0x1100, /* Hangul Jamo */ |
| 137 |
0x1200, /* Ethiopic */ |
| 138 |
0x1380, /* Ethiopic Supplement */ |
| 139 |
0x13A0, /* Cherokee */ |
| 140 |
0x1400, /* Unified Canadian Aboriginal Syllabics */ |
| 141 |
0x1680, /* Ogham */ |
| 142 |
0x16A0, /* Runic */ |
| 143 |
0x1700, /* Tagalog */ |
| 144 |
0x1720, /* Hanunoo */ |
| 145 |
0x1740, /* Buhid */ |
| 146 |
0x1760, /* Tagbanwa */ |
| 147 |
0x1780, /* Khmer */ /* 0x30 */ |
| 148 |
0x1800, /* Mongolian */ |
| 149 |
0x18B0, /* Unified Canadian Aboriginal Syllabics Extended */ |
| 150 |
0x1900, /* Limbu */ |
| 151 |
0x1950, /* Tai Le */ |
| 152 |
0x1980, /* New Tai Lue */ |
| 153 |
0x19E0, /* Khmer Symbols */ |
| 154 |
0x1A00, /* Buginese */ |
| 155 |
0x1A20, /* Tai Tham */ |
| 156 |
0x1AB0, /* Combining Diacritical Marks Extended */ |
| 157 |
0x1B00, /* Balinese */ |
| 158 |
0x1B80, /* Sundanese */ |
| 159 |
0x1BC0, /* Batak */ |
| 160 |
0x1C00, /* Lepcha */ |
| 161 |
0x1C50, /* Ol Chiki */ |
| 162 |
0x1C80, /* Cyrillic Extended-C */ |
| 163 |
0x1C90, /* Georgian Extended */ /* 0x40 */ |
| 164 |
0x1CC0, /* Sundanese Supplement */ |
| 165 |
0x1CD0, /* Vedic Extensions */ |
| 166 |
0x1D00, /* Phonetic Extensions */ |
| 167 |
0x1D80, /* Phonetic Extensions Supplement */ |
| 168 |
0x1DC0, /* Combining Diacritical Marks Supplement */ |
| 169 |
0x1E00, /* Latin Extended Additional */ |
| 170 |
0x1F00, /* Greek Extended */ |
| 171 |
0x2000, /* General Punctuation */ |
| 172 |
0x2070, /* Superscripts and Subscripts */ |
| 173 |
0x20A0, /* Currency Symbols */ |
| 174 |
0x20D0, /* Combining Diacritical Marks for Symbols */ |
| 175 |
0x2100, /* Letterlike Symbols */ |
| 176 |
0x2150, /* Number Forms */ |
| 177 |
0x2190, /* Arrows */ |
| 178 |
0x2200, /* Mathematical Operators */ |
| 179 |
0x2300, /* Miscellaneous Technical */ /* 0x50 */ |
| 180 |
0x2400, /* Control Pictures */ |
| 181 |
0x2440, /* Optical Character Recognition */ |
| 182 |
0x2460, /* Enclosed Alphanumerics */ |
| 183 |
0x2500, /* Box Drawing */ |
| 184 |
0x2580, /* Block Elements */ |
| 185 |
0x25A0, /* Geometric Shapes */ |
| 186 |
0x2600, /* Miscellaneous Symbols */ |
| 187 |
0x2700, /* Dingbats */ |
| 188 |
0x27C0, /* Miscellaneous Mathematical Symbols-A */ |
| 189 |
0x27F0, /* Supplemental Arrows-A */ |
| 190 |
0x2800, /* Braille Patterns */ |
| 191 |
0x2900, /* Supplemental Arrows-B */ |
| 192 |
0x2980, /* Miscellaneous Mathematical Symbols-B */ |
| 193 |
0x2A00, /* Supplemental Mathematical Operators */ |
| 194 |
0x2B00, /* Miscellaneous Symbols and Arrows */ |
| 195 |
0x2C00, /* Glagolitic */ /* 0x60 */ |
| 196 |
0x2C60, /* Latin Extended-C */ |
| 197 |
0x2C80, /* Coptic */ |
| 198 |
0x2D00, /* Georgian Supplement */ |
| 199 |
0x2D30, /* Tifinagh */ |
| 200 |
0x2D80, /* Ethiopic Extended */ |
| 201 |
0x2DE0, /* Cyrillic Extended-A */ |
| 202 |
0x2E00, /* Supplemental Punctuation */ |
| 203 |
0x2E80, /* CJK Radicals Supplement */ |
| 204 |
0x2F00, /* Kangxi Radicals */ |
| 205 |
0x2FF0, /* Ideographic Description Characters */ |
| 206 |
0x3000, /* CJK Symbols and Punctuation */ |
| 207 |
0x3040, /* Hiragana */ |
| 208 |
0x30A0, /* Katakana */ |
| 209 |
0x3100, /* Bopomofo */ |
| 210 |
0x3130, /* Hangul Compatibility Jamo */ |
| 211 |
0x3190, /* Kanbun */ /* 0x70 */ |
| 212 |
0x31A0, /* Bopomofo Extended */ |
| 213 |
0x31C0, /* CJK Strokes */ |
| 214 |
0x31F0, /* Katakana Phonetic Extensions */ |
| 215 |
0x3200, /* Enclosed CJK Letters and Months */ |
| 216 |
0x3300, /* CJK Compatibility */ |
| 217 |
0x3400, /* CJK Unified Ideographs Extension A */ |
| 218 |
0x4DC0, /* Yijing Hexagram Symbols */ |
| 219 |
0x4E00, /* CJK Unified Ideographs */ |
| 220 |
0xA000, /* Yi Syllables */ |
| 221 |
0xA490, /* Yi Radicals */ |
| 222 |
0xA4D0, /* Lisu */ |
| 223 |
0xA500, /* Vai */ |
| 224 |
0xA640, /* Cyrillic Extended-B */ |
| 225 |
0xA6A0, /* Bamum */ |
| 226 |
0xA700, /* Modifier Tone Letters */ |
| 227 |
0xA720, /* Latin Extended-D */ /* 0x80 */ |
| 228 |
0xA800, /* Syloti Nagri */ |
| 229 |
0xA830, /* Common Indic Number Forms */ |
| 230 |
0xA840, /* Phags-pa */ |
| 231 |
0xA880, /* Saurashtra */ |
| 232 |
0xA8E0, /* Devanagari Extended */ |
| 233 |
0xA900, /* Kayah Li */ |
| 234 |
0xA930, /* Rejang */ |
| 235 |
0xA960, /* Hangul Jamo Extended-A */ |
| 236 |
0xA980, /* Javanese */ |
| 237 |
0xA9E0, /* Myanmar Extended-B */ |
| 238 |
0xAA00, /* Cham */ |
| 239 |
0xAA60, /* Myanmar Extended-A */ |
| 240 |
0xAA80, /* Tai Viet */ |
| 241 |
0xAAE0, /* Meetei Mayek Extensions */ |
| 242 |
0xAB00, /* Ethiopic Extended-A */ |
| 243 |
0xAB30, /* Latin Extended-E */ /* 0x90 */ |
| 244 |
0xAB70, /* Cherokee Supplement */ |
| 245 |
0xABC0, /* Meetei Mayek */ |
| 246 |
0xAC00, /* Hangul Syllables */ |
| 247 |
0xD7B0, /* Hangul Jamo Extended-B */ |
| 248 |
0xD800, /* High Surrogates */ |
| 249 |
0xDB80, /* High Private Use Surrogates */ |
| 250 |
0xDC00, /* Low Surrogates */ |
| 251 |
0xE000, /* Private Use Area */ |
| 252 |
0xF900, /* CJK Compatibility Ideographs */ |
| 253 |
0xFB00, /* Alphabetic Presentation Forms */ |
| 254 |
0xFB50, /* Arabic Presentation Forms-A */ |
| 255 |
0xFE00, /* Variation Selectors */ |
| 256 |
0xFE10, /* Vertical Forms */ |
| 257 |
0xFE20, /* Combining Half Marks */ |
| 258 |
0xFE30, /* CJK Compatibility Forms */ |
| 259 |
0xFE50, /* Small Form Variants */ /* 0xa0 */ |
| 260 |
0xFE70, /* Arabic Presentation Forms-B */ |
| 261 |
0xFF00, /* Halfwidth and Fullwidth Forms */ |
| 262 |
0xFFF0, /* Specials */ |
| 263 |
0x10000, /* Linear B Syllabary */ |
| 264 |
0x10080, /* Linear B Ideograms */ |
| 265 |
0x10100, /* Aegean Numbers */ |
| 266 |
0x10140, /* Ancient Greek Numbers */ |
| 267 |
0x10190, /* Ancient Symbols */ |
| 268 |
0x101D0, /* Phaistos Disc */ |
| 269 |
0x10280, /* Lycian */ |
| 270 |
0x102A0, /* Carian */ |
| 271 |
0x102E0, /* Coptic Epact Numbers */ |
| 272 |
0x10300, /* Old Italic */ |
| 273 |
0x10330, /* Gothic */ |
| 274 |
0x10350, /* Old Permic */ |
| 275 |
0x10380, /* Ugaritic */ /* 0xb0 */ |
| 276 |
0x103A0, /* Old Persian */ |
| 277 |
0x10400, /* Deseret */ |
| 278 |
0x10450, /* Shavian */ |
| 279 |
0x10480, /* Osmanya */ |
| 280 |
0x104B0, /* Osage */ |
| 281 |
0x10500, /* Elbasan */ |
| 282 |
0x10530, /* Caucasian Albanian */ |
| 283 |
0x10570, /* Vithkuqi */ |
| 284 |
0x105C0, /* Todhri */ |
| 285 |
0x10600, /* Linear A */ |
| 286 |
0x10780, /* Latin Extended-F */ |
| 287 |
0x10800, /* Cypriot Syllabary */ |
| 288 |
0x10840, /* Imperial Aramaic */ |
| 289 |
0x10860, /* Palmyrene */ |
| 290 |
0x10880, /* Nabataean */ |
| 291 |
0x108E0, /* Hatran */ /* 0xc0 */ |
| 292 |
0x10900, /* Phoenician */ |
| 293 |
0x10920, /* Lydian */ |
| 294 |
0x10940, /* Sidetic */ |
| 295 |
0x10980, /* Meroitic Hieroglyphs */ |
| 296 |
0x109A0, /* Meroitic Cursive */ |
| 297 |
0x10A00, /* Kharoshthi */ |
| 298 |
0x10A60, /* Old South Arabian */ |
| 299 |
0x10A80, /* Old North Arabian */ |
| 300 |
0x10AC0, /* Manichaean */ |
| 301 |
0x10B00, /* Avestan */ |
| 302 |
0x10B40, /* Inscriptional Parthian */ |
| 303 |
0x10B60, /* Inscriptional Pahlavi */ |
| 304 |
0x10B80, /* Psalter Pahlavi */ |
| 305 |
0x10C00, /* Old Turkic */ |
| 306 |
0x10C80, /* Old Hungarian */ |
| 307 |
0x10D00, /* Hanifi Rohingya */ /* 0xd0 */ |
| 308 |
0x10D40, /* Garay */ |
| 309 |
0x10E60, /* Rumi Numeral Symbols */ |
| 310 |
0x10E80, /* Yezidi */ |
| 311 |
0x10EC0, /* Arabic Extended-C */ |
| 312 |
0x10F00, /* Old Sogdian */ |
| 313 |
0x10F30, /* Sogdian */ |
| 314 |
0x10F70, /* Old Uyghur */ |
| 315 |
0x10FB0, /* Chorasmian */ |
| 316 |
0x10FE0, /* Elymaic */ |
| 317 |
0x11000, /* Brahmi */ |
| 318 |
0x11080, /* Kaithi */ |
| 319 |
0x110D0, /* Sora Sompeng */ |
| 320 |
0x11100, /* Chakma */ |
| 321 |
0x11150, /* Mahajani */ |
| 322 |
0x11180, /* Sharada */ |
| 323 |
0x111E0, /* Sinhala Archaic Numbers */ /* 0xe0 */ |
| 324 |
0x11200, /* Khojki */ |
| 325 |
0x11280, /* Multani */ |
| 326 |
0x112B0, /* Khudawadi */ |
| 327 |
0x11300, /* Grantha */ |
| 328 |
0x11380, /* Tulu-Tigalaria */ |
| 329 |
0x11400, /* Newa */ |
| 330 |
0x11480, /* Tirhuta */ |
| 331 |
0x11580, /* Siddham */ |
| 332 |
0x11600, /* Modi */ |
| 333 |
0x11660, /* Mongolian Supplement */ |
| 334 |
0x11680, /* Takri */ |
| 335 |
0x116D0, /* Myanmar Extended-C */ |
| 336 |
0x11700, /* Ahom */ |
| 337 |
0x11800, /* Dogra */ |
| 338 |
0x118A0, /* Warang Citi */ |
| 339 |
0x11900, /* Dives Akuru */ /* 0xf0 */ |
| 340 |
0x119A0, /* Nandinagari */ |
| 341 |
0x11A00, /* Zanabazar Square */ |
| 342 |
0x11A50, /* Soyombo */ |
| 343 |
0x11AB0, /* Unified Canadian Aboriginal Syllabics Extended-A */ |
| 344 |
0x11AC0, /* Pau Cin Hau */ |
| 345 |
0x11B00, /* Devanagari Extended-A */ |
| 346 |
0x11B60, /* Sharada Supplement */ |
| 347 |
0x11BC0, /* Sunuwar */ |
| 348 |
0x11C00, /* Bhaiksuki */ |
| 349 |
0x11C70, /* Marchen */ |
| 350 |
0x11D00, /* Masaram Gondi */ |
| 351 |
0x11D60, /* Gunjala Gondi */ |
| 352 |
0x11DB0, /* Tolong Siki */ |
| 353 |
0x11EE0, /* Makasar */ |
| 354 |
0x11F00, /* Kawi */ |
| 355 |
0x11FB0, /* Lisu Supplement */ /* 0x100 */ |
| 356 |
0x11FC0, /* Tamil Supplement */ |
| 357 |
0x12000, /* Cuneiform */ |
| 358 |
0x12400, /* Cuneiform Numbers and Punctuation */ |
| 359 |
0x12480, /* Early Dynastic Cuneiform */ |
| 360 |
0x12F90, /* Cypro-Minoan */ |
| 361 |
0x13000, /* Egyptian Hieroglyphs */ |
| 362 |
0x13430, /* Egyptian Hieroglyph Format Controls */ |
| 363 |
0x13460, /* Egyptian Hieroglyphs Extended-A */ |
| 364 |
0x14400, /* Anatolian Hieroglyphs */ |
| 365 |
0x16100, /* Gurung Khema */ |
| 366 |
0x16800, /* Bamum Supplement */ |
| 367 |
0x16A40, /* Mro */ |
| 368 |
0x16A70, /* Tangsa */ |
| 369 |
0x16AD0, /* Bassa Vah */ |
| 370 |
0x16B00, /* Pahawh Hmong */ |
| 371 |
0x16D40, /* Kirat Rai */ /* 0x110 */ |
| 372 |
0x16E40, /* Medefaidrin */ |
| 373 |
0x16EA0, /* Beria Erfe */ |
| 374 |
0x16F00, /* Miao */ |
| 375 |
0x16FE0, /* Ideographic Symbols and Punctuation */ |
| 376 |
0x17000, /* Tangut */ |
| 377 |
0x18800, /* Tangut Components */ |
| 378 |
0x18B00, /* Khitan Small Script */ |
| 379 |
0x18D00, /* Tangut Supplement */ |
| 380 |
0x18D80, /* Tangut Components Supplement */ |
| 381 |
0x1AFF0, /* Kana Extended-B */ |
| 382 |
0x1B000, /* Kana Supplement */ |
| 383 |
0x1B100, /* Kana Extended-A */ |
| 384 |
0x1B130, /* Small Kana Extension */ |
| 385 |
0x1B170, /* Nushu */ |
| 386 |
0x1BC00, /* Duployan */ |
| 387 |
0x1BCA0, /* Shorthand Format Controls */ /* 0x120 */ |
| 388 |
0x1CC00, /* Symbols for Legacy Computing Supplement */ |
| 389 |
0x1CEC0, /* Miscellaneous Symbols Supplement */ |
| 390 |
0x1CF00, /* Znamenny Musical Notation */ |
| 391 |
0x1D000, /* Byzantine Musical Symbols */ |
| 392 |
0x1D100, /* Musical Symbols */ |
| 393 |
0x1D200, /* Ancient Greek Musical Notation */ |
| 394 |
0x1D2C0, /* Kaktovik Numerals */ |
| 395 |
0x1D2E0, /* Mayan Numerals */ |
| 396 |
0x1D300, /* Tai Xuan Jing Symbols */ |
| 397 |
0x1D360, /* Counting Rod Numerals */ |
| 398 |
0x1D400, /* Mathematical Alphanumeric Symbols */ |
| 399 |
0x1D800, /* Sutton SignWriting */ |
| 400 |
0x1DF00, /* Latin Extended-G */ |
| 401 |
0x1E000, /* Glagolitic Supplement */ |
| 402 |
0x1E030, /* Cyrillic Extended-D */ |
| 403 |
0x1E100, /* Nyiakeng Puachue Hmong */ /* 0x130 */ |
| 404 |
0x1E290, /* Toto */ |
| 405 |
0x1E2C0, /* Wancho */ |
| 406 |
0x1E4D0, /* Nag Mundari */ |
| 407 |
0x1E5D0, /* Ol Onal */ |
| 408 |
0x1E6C0, /* Tai Yo */ |
| 409 |
0x1E7E0, /* Ethiopic Extended-B */ |
| 410 |
0x1E800, /* Mende Kikakui */ |
| 411 |
0x1E900, /* Adlam */ |
| 412 |
0x1EC70, /* Indic Siyaq Numbers */ |
| 413 |
0x1ED00, /* Ottoman Siyaq Numbers */ |
| 414 |
0x1EE00, /* Arabic Mathematical Alphabetic Symbols */ |
| 415 |
0x1F000, /* Mahjong Tiles */ |
| 416 |
0x1F030, /* Domino Tiles */ |
| 417 |
0x1F0A0, /* Playing Cards */ |
| 418 |
0x1F100, /* Enclosed Alphanumeric Supplement */ |
| 419 |
0x1F200, /* Enclosed Ideographic Supplement */ /* 0x140 */ |
| 420 |
0x1F300, /* Miscellaneous Symbols and Pictographs */ |
| 421 |
0x1F600, /* Emoticons */ |
| 422 |
0x1F650, /* Ornamental Dingbats */ |
| 423 |
0x1F680, /* Transport and Map Symbols */ |
| 424 |
0x1F700, /* Alchemical Symbols */ |
| 425 |
0x1F780, /* Geometric Shapes Extended */ |
| 426 |
0x1F800, /* Supplemental Arrows-C */ |
| 427 |
0x1F900, /* Supplemental Symbols and Pictographs */ |
| 428 |
0x1FA00, /* Chess Symbols */ |
| 429 |
0x1FA70, /* Symbols and Pictographs Extended-A */ |
| 430 |
0x1FB00, /* Symbols for Legacy Computing */ |
| 431 |
0x20000, /* CJK Unified Ideographs Extension B */ |
| 432 |
0x2A700, /* CJK Unified Ideographs Extension C */ |
| 433 |
0x2B740, /* CJK Unified Ideographs Extension D */ |
| 434 |
0x2B820, /* CJK Unified Ideographs Extension E */ |
| 435 |
0x2CEB0, /* CJK Unified Ideographs Extension F */ /* 0x150 */ |
| 436 |
0x2EBF0, /* CJK Unified Ideographs Extension I */ |
| 437 |
0x2F800, /* CJK Compatibility Ideographs Supplement */ |
| 438 |
0x30000, /* CJK Unified Ideographs Extension G */ |
| 439 |
0x31350, /* CJK Unified Ideographs Extension H */ |
| 440 |
0x323B0, /* CJK Unified Ideographs Extension J */ |
| 441 |
0x33480, /* reserved */ |
| 442 |
0x40000, /* reserved */ |
| 443 |
0x50000, /* reserved */ |
| 444 |
0x60000, /* reserved */ |
| 445 |
0x70000, /* reserved */ |
| 446 |
0x80000, /* reserved */ |
| 447 |
0x90000, /* reserved */ |
| 448 |
0xA0000, /* reserved */ |
| 449 |
0xB0000, /* reserved */ |
| 450 |
0xC0000, /* reserved */ |
| 451 |
0xD0000, /* reserved */ /* 0x160 */ |
| 452 |
0xE0000, /* Tags */ |
| 453 |
0xE0100, /* Variation Selectors Supplement */ |
| 454 |
0xE01F0, /* reserved */ |
| 455 |
0xF0000, /* Supplementary Private Use Area-A */ |
| 456 |
0x100000, /* Supplementary Private Use Area-B */ |
| 457 |
/* Value over 0x10FFFF is illegal under Unicode, |
| 458 |
We use for some special application. */ |
| 459 |
0x110000, /* Reserved */ |
| 460 |
0x120000, /* Reserved */ |
| 461 |
0x130000, /* Reserved */ |
| 462 |
0x140000, /* Reserved */ |
| 463 |
0x150000, /* Reserved */ |
| 464 |
0x160000, /* Reserved */ |
| 465 |
0x170000, /* Reserved */ |
| 466 |
0x180000, /* Reserved */ |
| 467 |
0x190000, /* Reserved */ |
| 468 |
0x1A0000, /* Reserved */ |
| 469 |
0x1B0000, /* Reserved */ /* 0x170 */ |
| 470 |
0x1C0000, /* Reserved */ |
| 471 |
0x1D0000, /* Reserved */ |
| 472 |
0x1E0000, /* Reserved */ |
| 473 |
0x1F0000, /* Reserved */ |
| 474 |
0x200000, /* Reserved */ |
| 475 |
0x210000, /* Reserved */ |
| 476 |
0x220000, /* Kana with Voiced Sound Mark */ |
| 477 |
0x240000, /* Kana with Semi-Voiced Sound Mark */ |
| 478 |
0x25E6E6, /* Emoji Flag Sequence */ |
| 479 |
0x260000, /* Emoji with Modifier Fitzpatrick */ |
| 480 |
0x300000, /* Reserved */ |
| 481 |
0x400000, /* Standardized Variation Sequence */ |
| 482 |
0x800000, /* Emoji Keycap Sequence */ |
| 483 |
0x800080, /* Ideographic Variation Sequence, VS17..VS48 */ |
| 484 |
CJK_CHAR_LIMIT, /* Ideographic Variation Sequence, VS49..VS256 */ /* 0x17F */ |
| 485 |
IVS_CHAR_LIMIT |
| 486 |
}; |
| 487 |
|
| 488 |
#define NUCS_RANGE (sizeof(ucs_range)/sizeof(ucs_range[0])) |
| 489 |
|
| 490 |
/* Return i, which satisfies a[i] <= x < a[i+1]. */ |
| 491 |
/* 'i' is serached between left <= i <= right. */ |
| 492 |
/* If no i satisfies such condition, return left-1. */ |
| 493 |
/* [Okumura et al.] An algorithm encyclopedia in Java, p.236. */ |
| 494 |
static int |
| 495 |
binary_search (long x, long *a, int left, int right) |
| 496 |
{ |
| 497 |
right++; |
| 498 |
while (left < right) { |
| 499 |
int mid = (left + right) / 2; |
| 500 |
if (a[mid] <= x ) left = mid + 1; |
| 501 |
else right = mid; |
| 502 |
} |
| 503 |
return left - 1; |
| 504 |
} |
| 505 |
|
| 506 |
#define FEMININE_ORDINAL_INDICATOR 0x00AA |
| 507 |
#define MASCULINE_ORDINAL_INDICATOR 0x00BA |
| 508 |
#define LATIN_CAPITAL_LETTER_A_WITH_GRAVE 0x00C0 |
| 509 |
#define LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS 0x00D6 |
| 510 |
#define LATIN_CAPITAL_LETTER_O_WITH_STROKE 0x00D8 |
| 511 |
#define LATIN_SMALL_LETTER_O_WITH_DIAERESIS 0x00F6 |
| 512 |
#define LATIN_SMALL_LETTER_O_WITH_STROKE 0x00F8 |
| 513 |
#define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS 0x00FF |
| 514 |
#define COMBINING_ENCLOSING_KEYCAP 0x20E3 |
| 515 |
#define COMBINING_KANA_VOICED_SOUND_MARK 0x3099 |
| 516 |
#define COMBINING_KANA_SEMI_VOICED_SOUND_MARK 0x309A |
| 517 |
#define FULLWIDTH_DIGIT_0 0xFF10 |
| 518 |
#define FULLWIDTH_DIGIT_9 0xFF19 |
| 519 |
#define FULLWIDTH_CAPITAL_A 0xFF21 |
| 520 |
#define FULLWIDTH_CAPITAL_Z 0xFF3A |
| 521 |
#define FULLWIDTH_SMALL_A 0xFF41 |
| 522 |
#define FULLWIDTH_SMALL_Z 0xFF5A |
| 523 |
#define HALFWIDTH_KATAKANA_WO 0xFF66 |
| 524 |
#define HALFWIDTH_KATAKANA_SMALL_TSU 0xFF6F |
| 525 |
#define HALFWIDTH_KATAKANA_A 0xFF71 |
| 526 |
#define HALFWIDTH_KATAKANA_N 0xFF9D |
| 527 |
#define REGIONAL_INDICATOR_SYMBOL_LETTER_A 0x1F1E6 |
| 528 |
#define REGIONAL_INDICATOR_SYMBOL_LETTER_Z 0x1F1FF |
| 529 |
#define EMOJI_MODIFIER_FITZPATRIC_TYPE1_2 0x1F3FB |
| 530 |
#define EMOJI_MODIFIER_FITZPATRIC_TYPE6 0x1F3FF |
| 531 |
|
| 532 |
integer kcatcodekey(integer c) |
| 533 |
{ |
| 534 |
integer block; |
| 535 |
if (is_internalUPTEX() || (UCS_CHAR_LIMIT<=c && c<IVS_CHAR_LIMIT)) { |
| 536 |
block = binary_search((long)c, ucs_range, 0, NUCS_RANGE-1); |
| 537 |
switch (block) { |
| 538 |
case 0x01: /* Block : Latin-1 Supplement */ |
| 539 |
/* Latin-1 Letters */ |
| 540 |
if ( FEMININE_ORDINAL_INDICATOR ==c |
| 541 |
|| MASCULINE_ORDINAL_INDICATOR==c |
| 542 |
|| (LATIN_CAPITAL_LETTER_A_WITH_GRAVE <=c && c<=LATIN_CAPITAL_LETTER_O_WITH_DIAERESIS) |
| 543 |
|| (LATIN_CAPITAL_LETTER_O_WITH_STROKE<=c && c<=LATIN_SMALL_LETTER_O_WITH_DIAERESIS ) |
| 544 |
|| (LATIN_SMALL_LETTER_O_WITH_STROKE <=c && c<=LATIN_SMALL_LETTER_Y_WITH_DIAERESIS ) ) |
| 545 |
return 0x1FD; |
| 546 |
break; |
| 547 |
case 0xa2: /* Block : Halfwidth and Fullwidth Forms */ |
| 548 |
/* Fullwidth ASCII variants except for U+FF01..FF0F, U+FF1A..FF20, U+FF3B..FF40, U+FF5B..FF5E */ |
| 549 |
if ( (FULLWIDTH_DIGIT_0 <=c && c<=FULLWIDTH_DIGIT_9 ) |
| 550 |
|| (FULLWIDTH_CAPITAL_A<=c && c<=FULLWIDTH_CAPITAL_Z) |
| 551 |
|| (FULLWIDTH_SMALL_A <=c && c<=FULLWIDTH_SMALL_Z ) ) |
| 552 |
return 0x1FE; |
| 553 |
/* Halfwidth Katakana variants except for U+FF65, U+FF70, U+FF9E..FF9F */ |
| 554 |
if ( (HALFWIDTH_KATAKANA_WO <=c && c<=HALFWIDTH_KATAKANA_SMALL_TSU ) |
| 555 |
|| (HALFWIDTH_KATAKANA_A <=c && c<=HALFWIDTH_KATAKANA_N ) ) |
| 556 |
return 0x1FF; |
| 557 |
break; |
| 558 |
case 0x6c: /* Block : Hiragana */ |
| 559 |
if ( COMBINING_KANA_VOICED_SOUND_MARK==c |
| 560 |
|| COMBINING_KANA_SEMI_VOICED_SOUND_MARK==c ) |
| 561 |
return 0x1F9; |
| 562 |
break; |
| 563 |
case 0x4b: /* Block : Combining Diacritical Marks for Symbols */ |
| 564 |
if ( COMBINING_ENCLOSING_KEYCAP==c ) |
| 565 |
return 0x1FA; |
| 566 |
break; |
| 567 |
case 0x13f: /* Block : Enclosed Alphanumeric Supplement */ |
| 568 |
if ( REGIONAL_INDICATOR_SYMBOL_LETTER_A <=c && c<= REGIONAL_INDICATOR_SYMBOL_LETTER_Z ) |
| 569 |
return 0x1FB; |
| 570 |
break; |
| 571 |
case 0x141: /* Block : Miscellaneous Symbols and Pictographs */ |
| 572 |
if ( EMOJI_MODIFIER_FITZPATRIC_TYPE1_2 <=c && c<= EMOJI_MODIFIER_FITZPATRIC_TYPE6 ) |
| 573 |
return 0x1FC; |
| 574 |
break; |
| 575 |
} |
| 576 |
return block; |
| 577 |
} else { |
| 578 |
return Hi(toDVI(c)); |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
integer multilenbuffchar(integer c) |
| 583 |
{ |
| 584 |
c=toBUFF(c); |
| 585 |
if (BYTE1(c)) return 4; |
| 586 |
if (BYTE2(c)) return 3; |
| 587 |
if (BYTE3(c)) return 2; |
| 588 |
if (BYTE4(c)) return 1; |
| 589 |
return 0; |
| 590 |
} |
| 591 |
|
| 592 |
void init_kanji (const_string file_str, const_string internal_str) |
| 593 |
{ |
| 594 |
if (!set_enc_string (file_str, internal_str)) { |
| 595 |
fprintf (stderr, "Bad kanji encoding \"%s\" or \"%s\".\n", |
| 596 |
file_str ? file_str : "NULL", |
| 597 |
internal_str ? internal_str : "NULL"); |
| 598 |
uexit(1); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
void init_default_kanji (const_string file_str, const_string internal_str) |
| 603 |
{ |
| 604 |
char *p; |
| 605 |
|
| 606 |
init_kanji (file_str, internal_str); |
| 607 |
|
| 608 |
p = getenv ("PTEX_KANJI_ENC"); |
| 609 |
if (p) { |
| 610 |
if (!set_enc_string (p, NULL)) |
| 611 |
fprintf (stderr, "Ignoring bad kanji encoding \"%s\".\n", p); |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
void init_default_kanji_select(void) |
| 616 |
{ |
| 617 |
char *base; |
| 618 |
|
| 619 |
base = kpse_program_basename (argv[0]); |
| 620 |
|
| 621 |
if (FILESTRNCASEEQ(base, "p", 1) || FILESTRNCASEEQ(base, "ep", 2)) { |
| 622 |
|
| 623 |
enable_UPTEX (false); /* disable */ |
| 624 |
#if defined(WIN32) |
| 625 |
/* pBibTeX is EUC only */ |
| 626 |
if (FILESTRNCASEEQ(base, "pbibtex", 7)) { |
| 627 |
init_default_kanji(NULL, "euc"); |
| 628 |
} else { |
| 629 |
/* for pTeX, e-pTeX, pDVItype, pPLtoTF, and pTFtoPL */ |
| 630 |
init_default_kanji(NULL, "sjis"); |
| 631 |
} |
| 632 |
#else |
| 633 |
init_default_kanji(NULL, "euc"); |
| 634 |
#endif |
| 635 |
|
| 636 |
} else { |
| 637 |
|
| 638 |
/* for upTeX, e-upTeX, upBibTeX, upDVItype, upPLtoTF, and upTFtoPL */ |
| 639 |
enable_UPTEX (true); /* enable */ |
| 640 |
init_default_kanji ("utf8", "uptex"); |
| 641 |
|
| 642 |
} |
| 643 |
} |