| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/mkchrtab.c,v 1.2 1999/05/17 02:52:14 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
#include <ctype.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include "os.h" |
| 29 |
#include "cmap.h" |
| 30 |
|
| 31 |
#ifndef TRUE |
| 32 |
#define TRUE 1 |
| 33 |
#endif |
| 34 |
#ifndef FALSE |
| 35 |
#define FALSE 0 |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
static int read_number(unsigned int *result, char **p, |
| 42 |
char *infile, int linenum, int is_char) |
| 43 |
{ |
| 44 |
unsigned int base; |
| 45 |
unsigned int acc; |
| 46 |
int digcnt; |
| 47 |
|
| 48 |
|
| 49 |
while (isspace(**p)) |
| 50 |
++(*p); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
if (**p == '\'') |
| 56 |
{ |
| 57 |
unsigned char c; |
| 58 |
|
| 59 |
|
| 60 |
++(*p); |
| 61 |
|
| 62 |
|
| 63 |
if (**p == '\\') |
| 64 |
{ |
| 65 |
|
| 66 |
++(*p); |
| 67 |
|
| 68 |
|
| 69 |
switch(**p) |
| 70 |
{ |
| 71 |
case 'n': |
| 72 |
c = '\n'; |
| 73 |
break; |
| 74 |
|
| 75 |
case 'r': |
| 76 |
c = '\r'; |
| 77 |
break; |
| 78 |
|
| 79 |
case 't': |
| 80 |
c = '\t'; |
| 81 |
break; |
| 82 |
|
| 83 |
case '\\': |
| 84 |
c = '\\'; |
| 85 |
break; |
| 86 |
|
| 87 |
case '\'': |
| 88 |
c = '\''; |
| 89 |
break; |
| 90 |
|
| 91 |
default: |
| 92 |
printf("%s: line %d: invalid backslash sequence '\\%c'\n", |
| 93 |
infile, linenum, **p); |
| 94 |
return 4; |
| 95 |
} |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
|
| 100 |
c = (unsigned char)**p; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
++(*p); |
| 105 |
if (**p != '\'') |
| 106 |
{ |
| 107 |
printf("%s: line %d: missing close quote\n", infile, linenum); |
| 108 |
return 5; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
++(*p); |
| 113 |
|
| 114 |
|
| 115 |
while (isspace(**p)) |
| 116 |
++(*p); |
| 117 |
|
| 118 |
|
| 119 |
*result = (unsigned int)c; |
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
if (**p == '0') |
| 128 |
{ |
| 129 |
|
| 130 |
++(*p); |
| 131 |
|
| 132 |
|
| 133 |
if (**p == 'x' || **p == 'X') |
| 134 |
{ |
| 135 |
|
| 136 |
++(*p); |
| 137 |
|
| 138 |
|
| 139 |
base = 16; |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
|
| 144 |
base = 8; |
| 145 |
} |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
|
| 150 |
base = 10; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
for (acc = 0, digcnt = 0 ;; ++(*p), ++digcnt) |
| 155 |
{ |
| 156 |
|
| 157 |
if (isdigit(**p) || (base == 16 && isxdigit(**p))) |
| 158 |
{ |
| 159 |
unsigned int dig; |
| 160 |
|
| 161 |
|
| 162 |
dig = (unsigned int)(isdigit(**p) |
| 163 |
? **p - '0' |
| 164 |
: **p - (isupper(**p) ? 'A' : 'a') + 10); |
| 165 |
|
| 166 |
|
| 167 |
if (dig >= base) |
| 168 |
{ |
| 169 |
printf("%s: line %d: invalid digit for radix\n", |
| 170 |
infile, linenum); |
| 171 |
return 3; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
acc *= base; |
| 176 |
acc += dig; |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
|
| 181 |
break; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
if (digcnt == 0) |
| 187 |
{ |
| 188 |
printf("%s: line %d: invalid number\n", infile, linenum); |
| 189 |
return 1; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
while (isspace(**p)) |
| 194 |
++(*p); |
| 195 |
|
| 196 |
|
| 197 |
if ((is_char && acc > (unsigned int)(unsigned char)0xff) |
| 198 |
|| acc > (unsigned int)0xffff) |
| 199 |
{ |
| 200 |
printf("%s: line %d: value out of range\n", infile, linenum); |
| 201 |
return 2; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
*result = acc; |
| 206 |
|
| 207 |
|
| 208 |
return 0; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
static int id_matches(const char *idp, size_t idlen, const char *str) |
| 216 |
{ |
| 217 |
return (idlen == strlen(str) && memicmp(idp, str, idlen) == 0); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
struct entity_t |
| 224 |
{ |
| 225 |
const char *ename; |
| 226 |
unsigned int charval; |
| 227 |
}; |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
static const struct entity_t entities[] = |
| 233 |
{ |
| 234 |
{ "nbsp", 160 }, |
| 235 |
{ "iexcl", 161 }, |
| 236 |
{ "cent", 162 }, |
| 237 |
{ "pound", 163 }, |
| 238 |
{ "curren", 164 }, |
| 239 |
{ "yen", 165 }, |
| 240 |
{ "brvbar", 166 }, |
| 241 |
{ "sect", 167 }, |
| 242 |
{ "uml", 168 }, |
| 243 |
{ "copy", 169 }, |
| 244 |
{ "ordf", 170 }, |
| 245 |
{ "laquo", 171 }, |
| 246 |
{ "not", 172 }, |
| 247 |
{ "shy", 173 }, |
| 248 |
{ "reg", 174 }, |
| 249 |
{ "macr", 175 }, |
| 250 |
{ "deg", 176 }, |
| 251 |
{ "plusmn", 177 }, |
| 252 |
{ "sup2", 178 }, |
| 253 |
{ "sup3", 179 }, |
| 254 |
{ "acute", 180 }, |
| 255 |
{ "micro", 181 }, |
| 256 |
{ "para", 182 }, |
| 257 |
{ "middot", 183 }, |
| 258 |
{ "cedil", 184 }, |
| 259 |
{ "sup1", 185 }, |
| 260 |
{ "ordm", 186 }, |
| 261 |
{ "raquo", 187 }, |
| 262 |
{ "frac14", 188 }, |
| 263 |
{ "frac12", 189 }, |
| 264 |
{ "frac34", 190 }, |
| 265 |
{ "iquest", 191 }, |
| 266 |
{ "times", 215 }, |
| 267 |
{ "divide", 247 }, |
| 268 |
{ "AElig", 198 }, |
| 269 |
{ "Aacute", 193 }, |
| 270 |
{ "Acirc", 194 }, |
| 271 |
{ "Agrave", 192 }, |
| 272 |
{ "Aring", 197 }, |
| 273 |
{ "Atilde", 195 }, |
| 274 |
{ "Auml", 196 }, |
| 275 |
{ "Ccedil", 199 }, |
| 276 |
{ "ETH", 208 }, |
| 277 |
{ "Eacute", 201 }, |
| 278 |
{ "Ecirc", 202 }, |
| 279 |
{ "Egrave", 200 }, |
| 280 |
{ "Euml", 203 }, |
| 281 |
{ "Iacute", 205 }, |
| 282 |
{ "Icirc", 206 }, |
| 283 |
{ "Igrave", 204 }, |
| 284 |
{ "Iuml", 207 }, |
| 285 |
{ "Ntilde", 209 }, |
| 286 |
{ "Oacute", 211 }, |
| 287 |
{ "Ocirc", 212 }, |
| 288 |
{ "Ograve", 210 }, |
| 289 |
{ "Oslash", 216 }, |
| 290 |
{ "Otilde", 213 }, |
| 291 |
{ "Ouml", 214 }, |
| 292 |
{ "THORN", 222 }, |
| 293 |
{ "Uacute", 218 }, |
| 294 |
{ "Ucirc", 219 }, |
| 295 |
{ "Ugrave", 217 }, |
| 296 |
{ "Uuml", 220 }, |
| 297 |
{ "Yacute", 221 }, |
| 298 |
{ "aacute", 225 }, |
| 299 |
{ "acirc", 226 }, |
| 300 |
{ "aelig", 230 }, |
| 301 |
{ "agrave", 224 }, |
| 302 |
{ "aring", 229 }, |
| 303 |
{ "atilde", 227 }, |
| 304 |
{ "auml", 228 }, |
| 305 |
{ "ccedil", 231 }, |
| 306 |
{ "eacute", 233 }, |
| 307 |
{ "ecirc", 234 }, |
| 308 |
{ "egrave", 232 }, |
| 309 |
{ "eth", 240 }, |
| 310 |
{ "euml", 235 }, |
| 311 |
{ "iacute", 237 }, |
| 312 |
{ "icirc", 238 }, |
| 313 |
{ "igrave", 236 }, |
| 314 |
{ "iuml", 239 }, |
| 315 |
{ "ntilde", 241 }, |
| 316 |
{ "oacute", 243 }, |
| 317 |
{ "ocirc", 244 }, |
| 318 |
{ "ograve", 242 }, |
| 319 |
{ "oslash", 248 }, |
| 320 |
{ "otilde", 245 }, |
| 321 |
{ "ouml", 246 }, |
| 322 |
{ "szlig", 223 }, |
| 323 |
{ "thorn", 254 }, |
| 324 |
{ "uacute", 250 }, |
| 325 |
{ "ucirc", 251 }, |
| 326 |
{ "ugrave", 249 }, |
| 327 |
{ "uuml", 252 }, |
| 328 |
{ "yacute", 253 }, |
| 329 |
{ "thorn", 254 }, |
| 330 |
{ "yuml", 255 }, |
| 331 |
|
| 332 |
|
| 333 |
{ "lsq", 8216 }, |
| 334 |
{ "rsq", 8217 }, |
| 335 |
{ "ldq", 8220 }, |
| 336 |
{ "rdq", 8221 }, |
| 337 |
{ "endash", 8211 }, |
| 338 |
{ "emdash", 8212 }, |
| 339 |
{ "trade", 8482 }, |
| 340 |
|
| 341 |
|
| 342 |
{ "ndash", 8211 }, |
| 343 |
{ "mdash", 8212 }, |
| 344 |
{ "lsquo", 8216 }, |
| 345 |
{ "rsquo", 8217 }, |
| 346 |
{ "ldquo", 8220 }, |
| 347 |
{ "rdquo", 8221 }, |
| 348 |
{ "sbquo", 8218 }, |
| 349 |
{ "bdquo", 8222 }, |
| 350 |
{ "lsaquo", 8249 }, |
| 351 |
{ "rsaquo", 8250 }, |
| 352 |
{ "dagger", 8224 }, |
| 353 |
{ "Dagger", 8225 }, |
| 354 |
{ "OElig", 338 }, |
| 355 |
{ "oelig", 339 }, |
| 356 |
{ "permil", 8240 }, |
| 357 |
{ "Yuml", 376 }, |
| 358 |
{ "scaron", 353 }, |
| 359 |
{ "Scaron", 352 }, |
| 360 |
{ "circ", 710 }, |
| 361 |
{ "tilde", 732 }, |
| 362 |
|
| 363 |
|
| 364 |
{ "Alpha", 913 }, |
| 365 |
{ "Beta", 914 }, |
| 366 |
{ "Gamma", 915 }, |
| 367 |
{ "Delta", 916 }, |
| 368 |
{ "Epsilon", 917 }, |
| 369 |
{ "Zeta", 918 }, |
| 370 |
{ "Eta", 919 }, |
| 371 |
{ "Theta", 920 }, |
| 372 |
{ "Iota", 921 }, |
| 373 |
{ "Kappa", 922 }, |
| 374 |
{ "Lambda", 923 }, |
| 375 |
{ "Mu", 924 }, |
| 376 |
{ "Nu", 925 }, |
| 377 |
{ "Xi", 926 }, |
| 378 |
{ "Omicron", 927 }, |
| 379 |
{ "Pi", 928 }, |
| 380 |
{ "Rho", 929 }, |
| 381 |
{ "Sigma", 931 }, |
| 382 |
{ "Tau", 932 }, |
| 383 |
{ "Upsilon", 933 }, |
| 384 |
{ "Phi", 934 }, |
| 385 |
{ "Chi", 935 }, |
| 386 |
{ "Psi", 936 }, |
| 387 |
{ "Omega", 937 }, |
| 388 |
{ "alpha", 945 }, |
| 389 |
{ "beta", 946 }, |
| 390 |
{ "gamma", 947 }, |
| 391 |
{ "delta", 948 }, |
| 392 |
{ "epsilon", 949 }, |
| 393 |
{ "zeta", 950 }, |
| 394 |
{ "eta", 951 }, |
| 395 |
{ "theta", 952 }, |
| 396 |
{ "iota", 953 }, |
| 397 |
{ "kappa", 954 }, |
| 398 |
{ "lambda", 955 }, |
| 399 |
{ "mu", 956 }, |
| 400 |
{ "nu", 957 }, |
| 401 |
{ "xi", 958 }, |
| 402 |
{ "omicron", 959 }, |
| 403 |
{ "pi", 960 }, |
| 404 |
{ "rho", 961 }, |
| 405 |
{ "sigmaf", 962 }, |
| 406 |
{ "sigma", 963 }, |
| 407 |
{ "tau", 964 }, |
| 408 |
{ "upsilon", 965 }, |
| 409 |
{ "phi", 966 }, |
| 410 |
{ "chi", 967 }, |
| 411 |
{ "psi", 968 }, |
| 412 |
{ "omega", 969 }, |
| 413 |
{ "thetasym", 977 }, |
| 414 |
{ "upsih", 978 }, |
| 415 |
{ "piv", 982 }, |
| 416 |
|
| 417 |
|
| 418 |
{ "bull", 8226 }, |
| 419 |
{ "hellip", 8230 }, |
| 420 |
{ "prime", 8242 }, |
| 421 |
{ "Prime", 8243 }, |
| 422 |
{ "oline", 8254 }, |
| 423 |
{ "frasl", 8260 }, |
| 424 |
|
| 425 |
|
| 426 |
{ "weierp", 8472 }, |
| 427 |
{ "image", 8465 }, |
| 428 |
{ "real", 8476 }, |
| 429 |
{ "alefsym", 8501 }, |
| 430 |
|
| 431 |
|
| 432 |
{ "larr", 8592 }, |
| 433 |
{ "uarr", 8593 }, |
| 434 |
{ "rarr", 8594 }, |
| 435 |
{ "darr", 8595 }, |
| 436 |
{ "harr", 8596 }, |
| 437 |
{ "crarr", 8629 }, |
| 438 |
{ "lArr", 8656 }, |
| 439 |
{ "uArr", 8657 }, |
| 440 |
{ "rArr", 8658 }, |
| 441 |
{ "dArr", 8659 }, |
| 442 |
{ "hArr", 8660 }, |
| 443 |
|
| 444 |
|
| 445 |
{ "forall", 8704 }, |
| 446 |
{ "part", 8706 }, |
| 447 |
{ "exist", 8707 }, |
| 448 |
{ "empty", 8709 }, |
| 449 |
{ "nabla", 8711 }, |
| 450 |
{ "isin", 8712 }, |
| 451 |
{ "notin", 8713 }, |
| 452 |
{ "ni", 8715 }, |
| 453 |
{ "prod", 8719 }, |
| 454 |
{ "sum", 8721 }, |
| 455 |
{ "minus", 8722 }, |
| 456 |
{ "lowast", 8727 }, |
| 457 |
{ "radic", 8730 }, |
| 458 |
{ "prop", 8733 }, |
| 459 |
{ "infin", 8734 }, |
| 460 |
{ "ang", 8736 }, |
| 461 |
{ "and", 8743 }, |
| 462 |
{ "or", 8744 }, |
| 463 |
{ "cap", 8745 }, |
| 464 |
{ "cup", 8746 }, |
| 465 |
{ "int", 8747 }, |
| 466 |
{ "there4", 8756 }, |
| 467 |
{ "sim", 8764 }, |
| 468 |
{ "cong", 8773 }, |
| 469 |
{ "asymp", 8776 }, |
| 470 |
{ "ne", 8800 }, |
| 471 |
{ "equiv", 8801 }, |
| 472 |
{ "le", 8804 }, |
| 473 |
{ "ge", 8805 }, |
| 474 |
{ "sub", 8834 }, |
| 475 |
{ "sup", 8835 }, |
| 476 |
{ "nsub", 8836 }, |
| 477 |
{ "sube", 8838 }, |
| 478 |
{ "supe", 8839 }, |
| 479 |
{ "oplus", 8853 }, |
| 480 |
{ "otimes", 8855 }, |
| 481 |
{ "perp", 8869 }, |
| 482 |
{ "sdot", 8901 }, |
| 483 |
{ "lceil", 8968 }, |
| 484 |
{ "rceil", 8969 }, |
| 485 |
{ "lfloor", 8970 }, |
| 486 |
{ "rfloor", 8971 }, |
| 487 |
{ "lang", 9001 }, |
| 488 |
{ "rang", 9002 }, |
| 489 |
|
| 490 |
|
| 491 |
{ "loz", 9674 }, |
| 492 |
|
| 493 |
|
| 494 |
{ "spades", 9824 }, |
| 495 |
{ "clubs", 9827 }, |
| 496 |
{ "hearts", 9829 }, |
| 497 |
{ "diams", 9830 }, |
| 498 |
|
| 499 |
|
| 500 |
{ "fnof", 402 }, |
| 501 |
|
| 502 |
|
| 503 |
{ "Aogon", 260 }, |
| 504 |
{ "breve", 728 }, |
| 505 |
{ "Lstrok", 321 }, |
| 506 |
{ "Lcaron", 317 }, |
| 507 |
{ "Sacute", 346 }, |
| 508 |
{ "Scedil", 350 }, |
| 509 |
{ "Tcaron", 356 }, |
| 510 |
{ "Zacute", 377 }, |
| 511 |
{ "Zcaron", 381 }, |
| 512 |
{ "Zdot", 379 }, |
| 513 |
{ "aogon", 261 }, |
| 514 |
{ "ogon", 731 }, |
| 515 |
{ "lstrok", 322 }, |
| 516 |
{ "lcaron", 318 }, |
| 517 |
{ "sacute", 347 }, |
| 518 |
{ "caron", 711 }, |
| 519 |
{ "scedil", 351 }, |
| 520 |
{ "tcaron", 357 }, |
| 521 |
{ "zacute", 378 }, |
| 522 |
{ "dblac", 733 }, |
| 523 |
{ "zcaron", 382 }, |
| 524 |
{ "zdot", 380 }, |
| 525 |
{ "Racute", 340 }, |
| 526 |
{ "Abreve", 258 }, |
| 527 |
{ "Lacute", 313 }, |
| 528 |
{ "Cacute", 262 }, |
| 529 |
{ "Ccaron", 268 }, |
| 530 |
{ "Eogon", 280 }, |
| 531 |
{ "Ecaron", 282 }, |
| 532 |
{ "Dcaron", 270 }, |
| 533 |
{ "Dstrok", 272 }, |
| 534 |
{ "Nacute", 323 }, |
| 535 |
{ "Ncaron", 327 }, |
| 536 |
{ "Odblac", 336 }, |
| 537 |
{ "Rcaron", 344 }, |
| 538 |
{ "Uring", 366 }, |
| 539 |
{ "Udblac", 368 }, |
| 540 |
{ "Tcedil", 354 }, |
| 541 |
{ "racute", 341 }, |
| 542 |
{ "abreve", 259 }, |
| 543 |
{ "lacute", 314 }, |
| 544 |
{ "cacute", 263 }, |
| 545 |
{ "ccaron", 269 }, |
| 546 |
{ "eogon", 281 }, |
| 547 |
{ "ecaron", 283 }, |
| 548 |
{ "dcaron", 271 }, |
| 549 |
{ "dstrok", 273 }, |
| 550 |
{ "nacute", 324 }, |
| 551 |
{ "ncaron", 328 }, |
| 552 |
{ "odblac", 337 }, |
| 553 |
{ "rcaron", 345 }, |
| 554 |
{ "uring", 367 }, |
| 555 |
{ "udblac", 369 }, |
| 556 |
{ "tcedil", 355 }, |
| 557 |
{ "dot", 729 }, |
| 558 |
{ 0, 0 } |
| 559 |
}; |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
typedef struct entity_map_t entity_map_t; |
| 567 |
struct entity_map_t |
| 568 |
{ |
| 569 |
|
| 570 |
entity_map_t *nxt; |
| 571 |
|
| 572 |
|
| 573 |
unsigned int html_char; |
| 574 |
|
| 575 |
|
| 576 |
size_t exp_len; |
| 577 |
|
| 578 |
|
| 579 |
unsigned char expansion[1]; |
| 580 |
}; |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
static entity_map_t *parse_entity(char *p, char *infile, int linenum) |
| 586 |
{ |
| 587 |
const char *start; |
| 588 |
const struct entity_t *entp; |
| 589 |
unsigned char buf[CMAP_MAX_ENTITY_EXPANSION]; |
| 590 |
unsigned char *dstp; |
| 591 |
entity_map_t *mapp; |
| 592 |
|
| 593 |
|
| 594 |
start = p; |
| 595 |
for ( ; isalpha(*p) || isdigit(*p) ; ++p) ; |
| 596 |
|
| 597 |
|
| 598 |
for (entp = entities ; entp->ename != 0 ; ++entp) |
| 599 |
{ |
| 600 |
|
| 601 |
if (strlen(entp->ename) == (size_t)(p - start) |
| 602 |
&& memcmp(entp->ename, start, p - start) == 0) |
| 603 |
break; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
if (entp->ename == 0) |
| 608 |
{ |
| 609 |
printf("%s: line %d: unknown entity name \"%.*s\"\n", |
| 610 |
infile, linenum, p - start, start); |
| 611 |
return 0; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
for ( ; isspace(*p) ; ++p) ; |
| 616 |
if (*p != '=') |
| 617 |
{ |
| 618 |
printf("%s: line %d: expected '=' after entity name\n", |
| 619 |
infile, linenum); |
| 620 |
return 0; |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
++p; |
| 625 |
|
| 626 |
|
| 627 |
for (dstp = buf ; *p != '\0' ; ) |
| 628 |
{ |
| 629 |
unsigned int intval; |
| 630 |
unsigned char c; |
| 631 |
|
| 632 |
|
| 633 |
while (isspace(*p)) |
| 634 |
++p; |
| 635 |
|
| 636 |
|
| 637 |
if (*p == '\0' || *p == '#') |
| 638 |
break; |
| 639 |
|
| 640 |
|
| 641 |
if (read_number(&intval, &p, infile, linenum, TRUE)) |
| 642 |
return 0; |
| 643 |
c = (unsigned char)intval; |
| 644 |
|
| 645 |
|
| 646 |
if (dstp >= buf + sizeof(buf)) |
| 647 |
{ |
| 648 |
printf("%s: line %d: entity mapping is too long (maximum of %d " |
| 649 |
"characters are allowed\n", |
| 650 |
infile, linenum, sizeof(buf)); |
| 651 |
return 0; |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
*dstp++ = c; |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
if (dstp == buf) |
| 660 |
{ |
| 661 |
printf("%s: line %d: no local character codes found after '='\n", |
| 662 |
infile, linenum); |
| 663 |
return 0; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
mapp = (entity_map_t *)malloc(sizeof(entity_map_t) + dstp - buf); |
| 668 |
mapp->nxt = 0; |
| 669 |
mapp->html_char = entp->charval; |
| 670 |
mapp->exp_len = dstp - buf; |
| 671 |
memcpy(mapp->expansion, buf, dstp - buf); |
| 672 |
|
| 673 |
|
| 674 |
return mapp; |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
typedef struct unicode_map_t unicode_map_t; |
| 682 |
struct unicode_map_t |
| 683 |
{ |
| 684 |
|
| 685 |
unsigned int unicode_val; |
| 686 |
}; |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
static void gen_unicode_mapping(unicode_map_t map_from[256], |
| 692 |
unicode_map_t map_to[256], |
| 693 |
unsigned char result_fwd[256], |
| 694 |
unsigned char result_fwd_set[256], |
| 695 |
unsigned char result_rev[256], |
| 696 |
unsigned char result_rev_set[256]) |
| 697 |
{ |
| 698 |
int i; |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
for (i = 0 ; i < 256 ; ++i) |
| 706 |
{ |
| 707 |
int j; |
| 708 |
|
| 709 |
|
| 710 |
for (j = 0 ; j < 256 ; ++j) |
| 711 |
{ |
| 712 |
|
| 713 |
if (map_to[j].unicode_val == map_from[i].unicode_val) |
| 714 |
{ |
| 715 |
|
| 716 |
if (!result_fwd_set[i]) |
| 717 |
{ |
| 718 |
result_fwd[i] = j; |
| 719 |
result_fwd_set[i] = TRUE; |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
if (!result_rev_set[j]) |
| 724 |
{ |
| 725 |
result_rev[j] = i; |
| 726 |
result_rev_set[j] = TRUE; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
break; |
| 731 |
} |
| 732 |
} |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
static void load_unicode_file(char *filename, unicode_map_t map[256], |
| 740 |
char *infile, int linenum) |
| 741 |
{ |
| 742 |
osfildef *fp; |
| 743 |
int linenum_u; |
| 744 |
|
| 745 |
|
| 746 |
fp = osfoprs(filename, OSFTTEXT); |
| 747 |
if (fp == 0) |
| 748 |
{ |
| 749 |
printf("%s: line %d: unable to open unicode mapping file \"%s\"\n", |
| 750 |
infile, linenum, filename); |
| 751 |
return; |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
for (linenum_u = 1 ;; ++linenum_u) |
| 756 |
{ |
| 757 |
char buf[256]; |
| 758 |
char *p; |
| 759 |
unsigned int n1; |
| 760 |
unsigned int n2; |
| 761 |
|
| 762 |
|
| 763 |
if (osfgets(buf, sizeof(buf), fp) == 0) |
| 764 |
break; |
| 765 |
|
| 766 |
|
| 767 |
for (p = buf ; isspace(*p) ; ++p) ; |
| 768 |
|
| 769 |
|
| 770 |
if (*p == 0x1a || *p == '#' || *p == '\n' || *p == '\r' || *p == '\0') |
| 771 |
continue; |
| 772 |
|
| 773 |
|
| 774 |
if (read_number(&n1, &p, filename, linenum_u, TRUE)) |
| 775 |
break; |
| 776 |
|
| 777 |
|
| 778 |
if (read_number(&n2, &p, filename, linenum_u, FALSE)) |
| 779 |
break; |
| 780 |
|
| 781 |
|
| 782 |
map[n1].unicode_val = n2; |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
osfcls(fp); |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
static void gen_unicode_html_mapping(unicode_map_t map_native[256], |
| 793 |
entity_map_t **entity_first, |
| 794 |
entity_map_t **entity_last) |
| 795 |
{ |
| 796 |
unsigned int i; |
| 797 |
|
| 798 |
|
| 799 |
for (i = 0 ; i < 255 ; ++i) |
| 800 |
{ |
| 801 |
const struct entity_t *entity; |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
for (entity = entities ; entity->ename != 0 ; ++entity) |
| 808 |
{ |
| 809 |
|
| 810 |
if (entity->charval == map_native[i].unicode_val) |
| 811 |
{ |
| 812 |
entity_map_t *mapp; |
| 813 |
|
| 814 |
|
| 815 |
mapp = (entity_map_t *)malloc(sizeof(entity_map_t) + 1); |
| 816 |
|
| 817 |
|
| 818 |
mapp->nxt = 0; |
| 819 |
mapp->html_char = map_native[i].unicode_val; |
| 820 |
mapp->exp_len = 1; |
| 821 |
mapp->expansion[0] = (unsigned char)i; |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
mapp->nxt = *entity_first; |
| 831 |
if (*entity_last == 0) |
| 832 |
*entity_last = mapp; |
| 833 |
*entity_first = mapp; |
| 834 |
|
| 835 |
|
| 836 |
break; |
| 837 |
} |
| 838 |
} |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
static void parse_unicode_files(char *val, size_t vallen, |
| 847 |
char *infile, int linenum, |
| 848 |
unsigned char input_map[256], |
| 849 |
unsigned char input_map_set[256], |
| 850 |
unsigned char output_map[256], |
| 851 |
unsigned char output_map_set[256], |
| 852 |
entity_map_t **entity_first, |
| 853 |
entity_map_t **entity_last) |
| 854 |
{ |
| 855 |
char fn_native[OSFNMAX]; |
| 856 |
char fn_internal[OSFNMAX]; |
| 857 |
char *dst; |
| 858 |
unicode_map_t map_native[256]; |
| 859 |
unicode_map_t map_internal[256]; |
| 860 |
|
| 861 |
|
| 862 |
fn_native[0] = '\0'; |
| 863 |
fn_internal[0] = '\0'; |
| 864 |
while (vallen != 0) |
| 865 |
{ |
| 866 |
char *id; |
| 867 |
size_t idlen; |
| 868 |
char qu; |
| 869 |
|
| 870 |
|
| 871 |
if (*val == '#') |
| 872 |
break; |
| 873 |
|
| 874 |
|
| 875 |
for (id = val ; vallen > 0 && isalpha(*val) ; ++val, --vallen) ; |
| 876 |
idlen = val - id; |
| 877 |
|
| 878 |
|
| 879 |
if (id_matches(id, idlen, "native")) |
| 880 |
dst = fn_native; |
| 881 |
else if (id_matches(id, idlen, "internal")) |
| 882 |
dst = fn_internal; |
| 883 |
else |
| 884 |
{ |
| 885 |
printf("%s: line %d: expected 'internal' or 'native', " |
| 886 |
"found '%.*s'\n", infile, linenum, idlen, id); |
| 887 |
return; |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
if (*dst != '\0') |
| 892 |
{ |
| 893 |
printf("%s: line %d: '%.*s' specified more than once\n", |
| 894 |
infile, linenum, idlen, id); |
| 895 |
return; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
while (vallen > 0 && isspace(*val)) |
| 900 |
++val, --vallen; |
| 901 |
|
| 902 |
|
| 903 |
if (vallen == 0 || *val != '=') |
| 904 |
{ |
| 905 |
printf("%s: line %d: expected '=' after '%.*s'\n", |
| 906 |
infile, linenum, idlen, id); |
| 907 |
return; |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
++val, --vallen; |
| 912 |
while (vallen > 0 && isspace(*val)) |
| 913 |
++val, --vallen; |
| 914 |
|
| 915 |
|
| 916 |
if (vallen == 0) |
| 917 |
{ |
| 918 |
printf("%s: line %d: expected filename after '='\n", |
| 919 |
infile, linenum); |
| 920 |
return; |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
if (*val == '"' || *val == '\'') |
| 925 |
{ |
| 926 |
|
| 927 |
qu = *val; |
| 928 |
|
| 929 |
|
| 930 |
++val, --vallen; |
| 931 |
} |
| 932 |
else |
| 933 |
{ |
| 934 |
|
| 935 |
qu = '\0'; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
for ( ; vallen > 0 ; ++val, --vallen) |
| 940 |
{ |
| 941 |
|
| 942 |
if (qu != '\0' && *val == qu) |
| 943 |
{ |
| 944 |
|
| 945 |
++val; |
| 946 |
--vallen; |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
if (vallen > 1 && *(val+1) == qu) |
| 953 |
{ |
| 954 |
|
| 955 |
} |
| 956 |
else |
| 957 |
{ |
| 958 |
|
| 959 |
break; |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
*dst++ = *val; |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
*dst = '\0'; |
| 969 |
|
| 970 |
|
| 971 |
while (vallen > 0 && isspace(*val)) |
| 972 |
++val, --vallen; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
if (fn_internal[0] == '\0' || fn_native[0] == '\0') |
| 977 |
{ |
| 978 |
printf("%s: line %d: must specify both 'native' and 'internal'" |
| 979 |
" with 'unicode'\n", infile, linenum); |
| 980 |
return; |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
load_unicode_file(fn_internal, map_internal, infile, linenum); |
| 985 |
load_unicode_file(fn_native, map_native, infile, linenum); |
| 986 |
|
| 987 |
|
| 988 |
gen_unicode_mapping(map_native, map_internal, input_map, input_map_set, |
| 989 |
output_map, output_map_set); |
| 990 |
gen_unicode_mapping(map_internal, map_native, output_map, output_map_set, |
| 991 |
input_map, input_map_set); |
| 992 |
|
| 993 |
|
| 994 |
gen_unicode_html_mapping(map_native, entity_first, entity_last); |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
int main(int argc, char **argv) |
| 1002 |
{ |
| 1003 |
int curarg; |
| 1004 |
unsigned char input_map[256]; |
| 1005 |
unsigned char output_map[256]; |
| 1006 |
unsigned char input_map_set[256]; |
| 1007 |
unsigned char output_map_set[256]; |
| 1008 |
unsigned char *p; |
| 1009 |
int i; |
| 1010 |
osfildef *fp; |
| 1011 |
char *infile; |
| 1012 |
char *outfile; |
| 1013 |
int linenum; |
| 1014 |
static char sig[] = CMAP_SIG_S100; |
| 1015 |
int strict_mode = FALSE; |
| 1016 |
char id[5]; |
| 1017 |
char ldesc[CMAP_LDESC_MAX_LEN + 1]; |
| 1018 |
size_t len; |
| 1019 |
unsigned char lenbuf[2]; |
| 1020 |
char *sys_info; |
| 1021 |
entity_map_t *entity_first; |
| 1022 |
entity_map_t *entity_last; |
| 1023 |
|
| 1024 |
|
| 1025 |
memset(id, 0, sizeof(id)); |
| 1026 |
ldesc[0] = '\0'; |
| 1027 |
sys_info = 0; |
| 1028 |
|
| 1029 |
|
| 1030 |
entity_first = entity_last = 0; |
| 1031 |
|
| 1032 |
|
| 1033 |
for (curarg = 1 ; curarg < argc && argv[curarg][0] == '-' ; ++curarg) |
| 1034 |
{ |
| 1035 |
if (!stricmp(argv[curarg], "-strict")) |
| 1036 |
{ |
| 1037 |
|
| 1038 |
strict_mode = TRUE; |
| 1039 |
} |
| 1040 |
else |
| 1041 |
{ |
| 1042 |
|
| 1043 |
curarg = argc; |
| 1044 |
break; |
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
if (curarg + 1 >= argc) |
| 1050 |
{ |
| 1051 |
printf("usage: mkchrtab [options] <source> <dest>\n" |
| 1052 |
" <source> is the input file\n" |
| 1053 |
" <dest> is the output file\n" |
| 1054 |
"Options:\n" |
| 1055 |
" -strict warn if any codes 128-255 are unassigned\n"); |
| 1056 |
#if 0 |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
printf("\n" |
| 1064 |
"The source file contains one entry per line, as follows:\n" |
| 1065 |
"\n" |
| 1066 |
"Set the internal character set identifier, which can be up " |
| 1067 |
"to four letters long\n" |
| 1068 |
"(note that the mapping file MUST contain an ID entry):\n" |
| 1069 |
" ID = id\n" |
| 1070 |
"\n"); |
| 1071 |
printf("Set the internal character set's full display name:\n" |
| 1072 |
" LDESC = full name of character set\n" |
| 1073 |
"\n" |
| 1074 |
"Set system-dependent extra information (the meaning varies " |
| 1075 |
"by system):\n" |
| 1076 |
" EXTRA_SYSTEM_INFO = info-string\n" |
| 1077 |
"\n" |
| 1078 |
"Set the native default character:\n" |
| 1079 |
" NATIVE_DEFAULT = charval\n" |
| 1080 |
"Set the internal default character:\n" |
| 1081 |
" INTERNAL_DEFAULT = charval\n"); |
| 1082 |
printf("Load Unicode mapping files:\n" |
| 1083 |
" UNICODE NATIVE=native-mapping INTERNAL=internal-mapping\n" |
| 1084 |
"\n" |
| 1085 |
"Reversibly map a native character code to an internal code:\n" |
| 1086 |
" native <-> internal\n" |
| 1087 |
"\n" |
| 1088 |
"Map a native code to an internal code, and map the internal " |
| 1089 |
"code back\nto a different native code:\n" |
| 1090 |
" native -> internal -> native\n" |
| 1091 |
"\n" |
| 1092 |
"Map a native code to an internal code, where the internal " |
| 1093 |
"code is already\nmapped to a native code by a previous line:\n" |
| 1094 |
" native -> internal\n" |
| 1095 |
"\n"); |
| 1096 |
printf("Map an internal code to a native code, where the native " |
| 1097 |
"code is already\nmapped to an internal code by a previous " |
| 1098 |
"line:\n" |
| 1099 |
" native <- internal\n" |
| 1100 |
"\n" |
| 1101 |
"Map an HTML entity name to a native code or string:\n" |
| 1102 |
" &entity = internal-code [internal-code ...]\n" |
| 1103 |
"\n" |
| 1104 |
"Numbers can be specified in decimal (default), octal (by " |
| 1105 |
"prefixing the number\nwith a zero, as in '037'), or hex (by " |
| 1106 |
"prefixing the number with '0x', as in\n'0xb2'). A number " |
| 1107 |
"can also be entered as a character by enclosing the\n" |
| 1108 |
"character in single quotes.\n" |
| 1109 |
"\n" |
| 1110 |
"Blank lines and lines starting with a pound sign ('#') are " |
| 1111 |
"ignored.\n"); |
| 1112 |
#endif |
| 1113 |
os_term(OSEXFAIL); |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
infile = argv[curarg]; |
| 1118 |
outfile = argv[curarg + 1]; |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
for (p = input_map, i = 0 ; i < sizeof(input_map)/sizeof(input_map[0]) ; |
| 1125 |
++i, ++p) |
| 1126 |
*p = (unsigned char)i; |
| 1127 |
|
| 1128 |
for (p = output_map, i = 0 ; |
| 1129 |
i < sizeof(output_map)/sizeof(output_map[0]) ; ++i, ++p) |
| 1130 |
*p = (unsigned char)i; |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
for (i = 0 ; i < sizeof(input_map_set)/sizeof(input_map_set[0]) ; ++i) |
| 1140 |
input_map_set[i] = output_map_set[i] = FALSE; |
| 1141 |
|
| 1142 |
|
| 1143 |
fp = osfoprs(infile, OSFTTEXT); |
| 1144 |
if (fp == 0) |
| 1145 |
{ |
| 1146 |
printf("error: unable to open input file \"%s\"\n", infile); |
| 1147 |
os_term(OSEXFAIL); |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
for (linenum = 1 ; ; ++linenum) |
| 1152 |
{ |
| 1153 |
char buf[256]; |
| 1154 |
char *p; |
| 1155 |
unsigned int n1, n2, n3; |
| 1156 |
int set_input; |
| 1157 |
int set_output; |
| 1158 |
|
| 1159 |
|
| 1160 |
set_input = set_output = TRUE; |
| 1161 |
|
| 1162 |
|
| 1163 |
if (osfgets(buf, sizeof(buf), fp) == 0) |
| 1164 |
break; |
| 1165 |
|
| 1166 |
|
| 1167 |
for (p = buf ; isspace(*p) ; ++p) ; |
| 1168 |
|
| 1169 |
|
| 1170 |
if (*p == '\0' || *p == '\n' || *p == '\r' || *p == '#') |
| 1171 |
continue; |
| 1172 |
|
| 1173 |
|
| 1174 |
if (isalpha(*p) || *p == '_') |
| 1175 |
{ |
| 1176 |
char *sp; |
| 1177 |
char *val; |
| 1178 |
size_t vallen; |
| 1179 |
size_t idlen; |
| 1180 |
|
| 1181 |
|
| 1182 |
for (sp = p ; isalpha(*sp) || *sp == '_' ; ++sp) ; |
| 1183 |
idlen = sp - p; |
| 1184 |
|
| 1185 |
|
| 1186 |
for (val = sp ; isspace(*val) ; ++val) ; |
| 1187 |
if (*val == '=') |
| 1188 |
{ |
| 1189 |
|
| 1190 |
for (++val ; isspace(*val) ; ++val) ; |
| 1191 |
|
| 1192 |
|
| 1193 |
for (sp = val ; *sp != '\n' && *sp != '\r' && *sp != '\0' ; |
| 1194 |
++sp) ; |
| 1195 |
|
| 1196 |
|
| 1197 |
vallen = sp - val; |
| 1198 |
} |
| 1199 |
else |
| 1200 |
{ |
| 1201 |
|
| 1202 |
val = 0; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
if (id_matches(p, idlen, "id")) |
| 1207 |
{ |
| 1208 |
|
| 1209 |
if (val == 0) |
| 1210 |
goto val_required; |
| 1211 |
|
| 1212 |
|
| 1213 |
if (vallen > 4) |
| 1214 |
{ |
| 1215 |
printf("%s: line %d: ID too long - no more than four " |
| 1216 |
"characters are allowed\n", infile, linenum); |
| 1217 |
} |
| 1218 |
else |
| 1219 |
{ |
| 1220 |
|
| 1221 |
memcpy(id, val, vallen); |
| 1222 |
id[vallen] = '\0'; |
| 1223 |
} |
| 1224 |
} |
| 1225 |
else if (id_matches(p, idlen, "ldesc")) |
| 1226 |
{ |
| 1227 |
|
| 1228 |
if (val == 0) |
| 1229 |
goto val_required; |
| 1230 |
|
| 1231 |
|
| 1232 |
if (vallen > sizeof(ldesc) - 1) |
| 1233 |
{ |
| 1234 |
printf("%s: line %d: LDESC too long - no more than %u " |
| 1235 |
"characters are allowed\n", infile, linenum, |
| 1236 |
sizeof(ldesc) - 1); |
| 1237 |
} |
| 1238 |
else |
| 1239 |
{ |
| 1240 |
|
| 1241 |
memcpy(ldesc, val, vallen); |
| 1242 |
ldesc[vallen] = '\0'; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
else if (id_matches(p, idlen, "extra_system_info")) |
| 1246 |
{ |
| 1247 |
|
| 1248 |
if (val == 0) |
| 1249 |
goto val_required; |
| 1250 |
|
| 1251 |
|
| 1252 |
sys_info = (char *)malloc(vallen + 1); |
| 1253 |
memcpy(sys_info, val, vallen); |
| 1254 |
sys_info[vallen] = '\0'; |
| 1255 |
} |
| 1256 |
else if (id_matches(p, idlen, "native_default")) |
| 1257 |
{ |
| 1258 |
unsigned int nval; |
| 1259 |
int i; |
| 1260 |
|
| 1261 |
|
| 1262 |
if (val == 0) |
| 1263 |
goto val_required; |
| 1264 |
|
| 1265 |
|
| 1266 |
if (read_number(&nval, &val, infile, linenum, TRUE)) |
| 1267 |
continue; |
| 1268 |
|
| 1269 |
|
| 1270 |
for (i = 128 ; i < 256 ; ++i) |
| 1271 |
{ |
| 1272 |
|
| 1273 |
if (!output_map_set[i]) |
| 1274 |
output_map[i] = nval; |
| 1275 |
} |
| 1276 |
} |
| 1277 |
else if (id_matches(p, idlen, "internal_default")) |
| 1278 |
{ |
| 1279 |
unsigned int nval; |
| 1280 |
int i; |
| 1281 |
|
| 1282 |
|
| 1283 |
if (val == 0) |
| 1284 |
goto val_required; |
| 1285 |
|
| 1286 |
|
| 1287 |
if (read_number(&nval, &val, infile, linenum, TRUE)) |
| 1288 |
continue; |
| 1289 |
|
| 1290 |
|
| 1291 |
for (i = 128 ; i < 256 ; ++i) |
| 1292 |
{ |
| 1293 |
|
| 1294 |
if (!input_map_set[i]) |
| 1295 |
input_map[i] = nval; |
| 1296 |
} |
| 1297 |
} |
| 1298 |
else if (id_matches(p, idlen, "unicode")) |
| 1299 |
{ |
| 1300 |
|
| 1301 |
for (p += idlen ; isspace(*p) ; ++p) ; |
| 1302 |
|
| 1303 |
|
| 1304 |
parse_unicode_files(p, strlen(p), infile, linenum, |
| 1305 |
input_map, input_map_set, |
| 1306 |
output_map, output_map_set, |
| 1307 |
&entity_first, &entity_last); |
| 1308 |
} |
| 1309 |
else |
| 1310 |
{ |
| 1311 |
|
| 1312 |
printf("%s: line %d: invalid directive '%.*s'\n", |
| 1313 |
infile, linenum, idlen, p); |
| 1314 |
} |
| 1315 |
|
| 1316 |
|
| 1317 |
continue; |
| 1318 |
|
| 1319 |
|
| 1320 |
val_required: |
| 1321 |
printf("%s: line %d: '=' required with directive '%.*s'\n", |
| 1322 |
infile, linenum, idlen, p); |
| 1323 |
continue; |
| 1324 |
} |
| 1325 |
|
| 1326 |
|
| 1327 |
if (*p == '&') |
| 1328 |
{ |
| 1329 |
entity_map_t *mapp; |
| 1330 |
|
| 1331 |
|
| 1332 |
++p; |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
mapp = parse_entity(p, infile, linenum); |
| 1339 |
if (mapp != 0) |
| 1340 |
{ |
| 1341 |
if (entity_last == 0) |
| 1342 |
entity_first = mapp; |
| 1343 |
else |
| 1344 |
entity_last->nxt = mapp; |
| 1345 |
entity_last = mapp; |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
continue; |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
if (read_number(&n1, &p, infile, linenum, TRUE)) |
| 1354 |
continue; |
| 1355 |
|
| 1356 |
|
| 1357 |
if (*p == '<') |
| 1358 |
{ |
| 1359 |
|
| 1360 |
if (*(p+1) == '-' && *(p+2) != '>') |
| 1361 |
{ |
| 1362 |
|
| 1363 |
p += 2; |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
if (read_number(&n2, &p, infile, linenum, TRUE)) |
| 1373 |
continue; |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
n3 = n1; |
| 1382 |
set_input = FALSE; |
| 1383 |
} |
| 1384 |
else if (*(p+1) == '-' && *(p+2) == '>') |
| 1385 |
{ |
| 1386 |
|
| 1387 |
p += 3; |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
n3 = n1; |
| 1395 |
if (read_number(&n2, &p, infile, linenum, TRUE)) |
| 1396 |
continue; |
| 1397 |
} |
| 1398 |
else |
| 1399 |
{ |
| 1400 |
printf("%s: line %d: invalid operator - expected <->\n", |
| 1401 |
infile, linenum); |
| 1402 |
continue; |
| 1403 |
} |
| 1404 |
} |
| 1405 |
else if (*p == '-') |
| 1406 |
{ |
| 1407 |
|
| 1408 |
if (*(p+1) != '>') |
| 1409 |
{ |
| 1410 |
printf("%s: line %d: invalid operator - expected ->\n", |
| 1411 |
infile, linenum); |
| 1412 |
continue; |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
p += 2; |
| 1417 |
|
| 1418 |
|
| 1419 |
if (read_number(&n2, &p, infile, linenum, TRUE)) |
| 1420 |
continue; |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
if (*p == '-') |
| 1428 |
{ |
| 1429 |
|
| 1430 |
if (*(p+1) != '>') |
| 1431 |
{ |
| 1432 |
printf("%s: line %d: invalid operator - expected ->\n", |
| 1433 |
infile, linenum); |
| 1434 |
continue; |
| 1435 |
} |
| 1436 |
|
| 1437 |
|
| 1438 |
p += 2; |
| 1439 |
|
| 1440 |
|
| 1441 |
if (read_number(&n3, &p, infile, linenum, TRUE)) |
| 1442 |
continue; |
| 1443 |
} |
| 1444 |
else |
| 1445 |
{ |
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
set_output = FALSE; |
| 1451 |
} |
| 1452 |
} |
| 1453 |
else |
| 1454 |
{ |
| 1455 |
printf("%s: line %d: invalid operator - expected " |
| 1456 |
"-> or <-> or <-\n", |
| 1457 |
infile, linenum); |
| 1458 |
continue; |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
if (*p != '\0' && *p != '\n' && *p != '\r' && *p != '#') |
| 1463 |
printf("%s: line %d: extra characters at end of line ignored\n", |
| 1464 |
infile, linenum); |
| 1465 |
|
| 1466 |
|
| 1467 |
if (set_input) |
| 1468 |
{ |
| 1469 |
|
| 1470 |
if (input_map_set[n1]) |
| 1471 |
printf("%s: line %d: warning - native character %u has " |
| 1472 |
"already been\n mapped to internal value %u\n", |
| 1473 |
infile, linenum, n1, input_map[n1]); |
| 1474 |
|
| 1475 |
|
| 1476 |
input_map[n1] = n2; |
| 1477 |
|
| 1478 |
|
| 1479 |
input_map_set[n1] = TRUE; |
| 1480 |
} |
| 1481 |
|
| 1482 |
|
| 1483 |
if (set_output) |
| 1484 |
{ |
| 1485 |
|
| 1486 |
if (output_map_set[n2]) |
| 1487 |
printf("%s: line %d: warning - internal character %u has " |
| 1488 |
"already been\n mapped to native value %u\n", |
| 1489 |
infile, linenum, n2, input_map[n2]); |
| 1490 |
|
| 1491 |
|
| 1492 |
output_map[n2] = n3; |
| 1493 |
|
| 1494 |
|
| 1495 |
output_map_set[n2] = TRUE; |
| 1496 |
} |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
osfcls(fp); |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
if (id[0] == '\0') |
| 1506 |
{ |
| 1507 |
printf("Error: No ID was specified. An ID is required.\n"); |
| 1508 |
os_term(OSEXFAIL); |
| 1509 |
} |
| 1510 |
else if (ldesc[0] == '\0') |
| 1511 |
{ |
| 1512 |
printf("Error: No LDESC was specified. An LDESC is required.\n"); |
| 1513 |
os_term(OSEXFAIL); |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
fp = osfopwb(outfile, OSFTCMAP); |
| 1518 |
if (fp == 0) |
| 1519 |
{ |
| 1520 |
printf("error: unable to open output file \"%s\"\n", outfile); |
| 1521 |
os_term(OSEXFAIL); |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
if (osfwb(fp, sig, sizeof(sig))) |
| 1526 |
printf("error writing signature to output file\n"); |
| 1527 |
|
| 1528 |
|
| 1529 |
len = strlen(ldesc) + 1; |
| 1530 |
oswp2(lenbuf, len); |
| 1531 |
if (osfwb(fp, id, 4) |
| 1532 |
|| osfwb(fp, lenbuf, 2) |
| 1533 |
|| osfwb(fp, ldesc, len)) |
| 1534 |
printf("error writing ID information to output file\n"); |
| 1535 |
|
| 1536 |
|
| 1537 |
if (osfwb(fp, input_map, sizeof(input_map)) |
| 1538 |
|| osfwb(fp, output_map, sizeof(output_map))) |
| 1539 |
printf("error writing character maps to output file\n"); |
| 1540 |
|
| 1541 |
|
| 1542 |
if (sys_info != 0) |
| 1543 |
{ |
| 1544 |
|
| 1545 |
len = strlen(sys_info) + 1; |
| 1546 |
oswp2(lenbuf, len); |
| 1547 |
if (osfwb(fp, "SYSI", 4) |
| 1548 |
|| osfwb(fp, lenbuf, 2) |
| 1549 |
|| osfwb(fp, sys_info, len)) |
| 1550 |
printf("error writing EXTRA_SYSTEM_INFO to output file\n"); |
| 1551 |
|
| 1552 |
|
| 1553 |
free(sys_info); |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
if (entity_first != 0) |
| 1560 |
{ |
| 1561 |
entity_map_t *entp; |
| 1562 |
entity_map_t *next_entity; |
| 1563 |
char lenbuf[2]; |
| 1564 |
char cvalbuf[2]; |
| 1565 |
|
| 1566 |
|
| 1567 |
if (osfwb(fp, "ENTY", 4)) |
| 1568 |
printf("error writing entity marker to output file\n"); |
| 1569 |
|
| 1570 |
|
| 1571 |
for (entp = entity_first ; entp != 0 ; entp = next_entity) |
| 1572 |
{ |
| 1573 |
|
| 1574 |
oswp2(lenbuf, entp->exp_len); |
| 1575 |
oswp2(cvalbuf, entp->html_char); |
| 1576 |
if (osfwb(fp, lenbuf, 2) |
| 1577 |
|| osfwb(fp, cvalbuf, 2) |
| 1578 |
|| osfwb(fp, entp->expansion, entp->exp_len)) |
| 1579 |
{ |
| 1580 |
printf("error writing entity mapping to output file\n"); |
| 1581 |
break; |
| 1582 |
} |
| 1583 |
|
| 1584 |
|
| 1585 |
next_entity = entp->nxt; |
| 1586 |
|
| 1587 |
|
| 1588 |
free(entp); |
| 1589 |
} |
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
oswp2(lenbuf, 0); |
| 1596 |
oswp2(cvalbuf, 0); |
| 1597 |
if (osfwb(fp, lenbuf, 2) |
| 1598 |
|| osfwb(fp, cvalbuf, 2)) |
| 1599 |
printf("error writing entity list end marker to output file\n"); |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
if (osfwb(fp, "$EOF", 4)) |
| 1604 |
printf("error writing end-of-file marker to output file\n"); |
| 1605 |
|
| 1606 |
|
| 1607 |
osfcls(fp); |
| 1608 |
|
| 1609 |
|
| 1610 |
if (strict_mode) |
| 1611 |
{ |
| 1612 |
int in_cnt, out_cnt; |
| 1613 |
int cnt; |
| 1614 |
|
| 1615 |
|
| 1616 |
for (i = 128, in_cnt = out_cnt = 0 ; i < 256 ; ++i) |
| 1617 |
{ |
| 1618 |
if (!input_map_set[i]) |
| 1619 |
++in_cnt; |
| 1620 |
if (!output_map_set[i]) |
| 1621 |
++out_cnt; |
| 1622 |
} |
| 1623 |
|
| 1624 |
|
| 1625 |
if (in_cnt != 0) |
| 1626 |
{ |
| 1627 |
printf("\nUnassigned native -> internal mappings:\n "); |
| 1628 |
for (i = 128, cnt = 0 ; i < 256 ; ++i) |
| 1629 |
{ |
| 1630 |
if (!input_map_set[i]) |
| 1631 |
{ |
| 1632 |
|
| 1633 |
if (cnt >= 16) |
| 1634 |
{ |
| 1635 |
printf("\n "); |
| 1636 |
cnt = 0; |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
printf("%3d ", i); |
| 1641 |
++cnt; |
| 1642 |
} |
| 1643 |
} |
| 1644 |
printf("\n"); |
| 1645 |
} |
| 1646 |
|
| 1647 |
|
| 1648 |
if (out_cnt != 0) |
| 1649 |
{ |
| 1650 |
printf("\nUnassigned internal -> native mappings:\n "); |
| 1651 |
for (i = 128, cnt = 0 ; i < 256 ; ++i) |
| 1652 |
{ |
| 1653 |
if (!output_map_set[i]) |
| 1654 |
{ |
| 1655 |
|
| 1656 |
if (cnt >= 16) |
| 1657 |
{ |
| 1658 |
printf("\n "); |
| 1659 |
cnt = 0; |
| 1660 |
} |
| 1661 |
|
| 1662 |
|
| 1663 |
printf("%3d ", i); |
| 1664 |
++cnt; |
| 1665 |
} |
| 1666 |
} |
| 1667 |
printf("\n"); |
| 1668 |
} |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
os_term(OSEXSUCC); |
| 1673 |
return OSEXSUCC; |
| 1674 |
} |
| 1675 |
|