Source:NetHack 5.0.0/src/glyphs.c
Jump to navigation
Jump to search
Below is the full text to glyphs.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/glyphs.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 5.0 glyphs.c TODO: add NHDT branch/date/revision tags */ 2. /* Copyright (c) Michael Allison, 2021. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. extern const struct symparse loadsyms[]; 8. extern glyph_map glyphmap[MAX_GLYPH]; 9. extern struct enum_dump monsdump[]; 10. extern struct enum_dump objdump[]; 11. 12. #define Fprintf (void) fprintf 13. 14. enum reserved_activities { res_nothing, res_dump_glyphids, res_fill_cache }; 15. enum things_to_find { find_nothing, find_pm, find_oc, find_cmap, find_glyph }; 16. struct find_struct { 17. enum things_to_find findtype; 18. int val; 19. int loadsyms_offset; 20. int loadsyms_count; 21. int *extraval; 22. uint32 color; 23. const char *unicode_val; /* U+NNNN format */ 24. void (*callback)(int glyph, struct find_struct *); 25. enum reserved_activities restype; 26. genericptr_t reserved; 27. }; 28. static const struct find_struct zero_find = { 0 }; 29. struct glyphid_cache_t { 30. int glyphnum; 31. char *id; 32. }; 33. static struct glyphid_cache_t *glyphid_cache; 34. static unsigned glyphid_cache_lsize; 35. static size_t glyphid_cache_size; 36. static struct find_struct glyphcache_find, to_custom_symbol_find; 37. static const long nonzero_black = CLR_BLACK | NH_BASIC_COLOR; 38. 39. staticfn void init_glyph_cache(void); 40. staticfn void add_glyph_to_cache(int glyphnum, const char *id); 41. staticfn int find_glyph_in_cache(const char *id); 42. staticfn char *find_glyphid_in_cache_by_glyphnum(int glyphnum); 43. staticfn uint32 glyph_hash(const char *id); 44. staticfn void to_custom_symset_entry_callback(int glyph, 45. struct find_struct *findwhat); 46. staticfn int parse_id(const char *id, struct find_struct *findwhat); 47. staticfn int glyph_find_core(const char *id, struct find_struct *findwhat); 48. staticfn char *fix_glyphname(char *str); 49. staticfn void shuffle_customizations(void); 50. /* staticfn void purge_custom_entries(enum graphics_sets which_set); */ 51. 52. staticfn void 53. to_custom_symset_entry_callback( 54. int glyph, 55. struct find_struct *findwhat) 56. { 57. int idx = gs.symset_which_set; 58. #ifdef ENHANCED_SYMBOLS 59. uint8 utf8str[6] = { 0, 0, 0, 0, 0, 0 }; 60. int uval = 0; 61. #endif 62. 63. if (findwhat->extraval) 64. *findwhat->extraval = glyph; 65. 66. assert(idx >= 0 && idx < NUM_GRAPHICS); 67. #ifdef ENHANCED_SYMBOLS 68. if (findwhat->unicode_val) 69. uval = unicode_val(findwhat->unicode_val); 70. if (uval && unicodeval_to_utf8str(uval, utf8str, sizeof utf8str)) { 71. /* presently the customizations are affiliated with a particular 72. * symset but if we don't have any symset context, ignore it for now 73. * in order to avoid a segfault. 74. * FIXME: 75. * One future idea might be to store the U+ entries under "UTF8" 76. * and apply those customizations to any current symset if it has 77. * a UTF8 handler. Similar approach for unaffiliated glyph/symbols 78. * non-UTF color customizations 79. */ 80. if (gs.symset[idx].name) { 81. add_custom_urep_entry(gs.symset[idx].name, glyph, uval, 82. utf8str, gs.symset_which_set); 83. } else { 84. static int glyphnag = 0; 85. 86. if (!glyphnag++) 87. config_error_add("Unimplemented customization feature," 88. " ignoring for now"); 89. } 90. } 91. #endif 92. if (findwhat->color) { 93. if (gs.symset[idx].name) { 94. add_custom_nhcolor_entry(gs.symset[idx].name, glyph, 95. findwhat->color, gs.symset_which_set); 96. } else { 97. static int colornag = 0; 98. 99. if (!colornag++) 100. config_error_add("Unimplemented customization feature," 101. " ignoring for now"); 102. } 103. } 104. } 105. 106. /* 107. * Return value: 108. * 1 = success 109. * 0 = failure 110. */ 111. int 112. glyphrep_to_custom_map_entries( 113. const char *op, 114. int *glyphptr) 115. { 116. to_custom_symbol_find = zero_find; 117. char buf[BUFSZ], *c_glyphid, *c_unicode, *c_colorval, *cp; 118. int reslt = 0; 119. long rgb = 0L; 120. boolean slash = FALSE, colon = FALSE; 121. 122. if (!glyphid_cache) 123. reslt = 1; /* for debugger use only; no cache available */ 124. nhUse(reslt); 125. 126. Snprintf(buf, sizeof buf, "%s", op); 127. c_unicode = c_colorval = (char *) 0; 128. c_glyphid = cp = buf; 129. while (*cp) { 130. if (*cp == ':' || *cp == '/') { 131. if (*cp == ':') { 132. colon = TRUE; 133. *cp = '\0'; 134. } 135. if (*cp == '/') { 136. slash = TRUE; 137. *cp = '\0'; 138. } 139. } 140. cp++; 141. if (colon) { 142. c_unicode = cp; 143. colon = FALSE; 144. } 145. if (slash) { 146. c_colorval = cp; 147. slash = FALSE; 148. } 149. } 150. /* some sanity checks */ 151. if (c_glyphid && *c_glyphid == ' ') 152. c_glyphid++; 153. if (c_colorval && *c_colorval == ' ') 154. c_colorval++; 155. if (c_unicode && *c_unicode == ' ') { 156. while (*c_unicode == ' ') { 157. c_unicode++; 158. } 159. } 160. if (c_unicode && !*c_unicode) 161. c_unicode = 0; 162. 163. if ((c_colorval && (rgb = rgbstr_to_int32(c_colorval)) != -1L) 164. || !c_colorval) { 165. /* if the color 0 is an actual color, as opposed to just "not set" 166. we set a marker bit outside the 24-bit range to indicate a 167. valid color value 0. That allows valid color 0, but allows a 168. simple checking for 0 to detect "not set". The window port that 169. implements the color switch, needs to either check that bit 170. or appropriately mask colors with 0xFFFFFF. */ 171. to_custom_symbol_find.color = (rgb == -1 || !c_colorval) ? 0L 172. : (rgb == 0L) ? nonzero_black 173. : rgb; 174. } 175. if (c_unicode) 176. to_custom_symbol_find.unicode_val = c_unicode; 177. to_custom_symbol_find.extraval = glyphptr; 178. to_custom_symbol_find.callback = to_custom_symset_entry_callback; 179. reslt = glyph_find_core(c_glyphid, &to_custom_symbol_find); 180. return reslt; 181. } 182. 183. staticfn char * 184. fix_glyphname(char *str) 185. { 186. char *c; 187. 188. for (c = str; *c; c++) { 189. if (*c >= 'A' && *c <= 'Z') 190. *c += (char) ('a' - 'A'); 191. else if (*c >= '0' && *c <= '9') 192. ; 193. else if (*c < 'a' || *c > 'z') 194. *c = '_'; 195. } 196. return str; 197. } 198. 199. int 200. glyph_to_cmap(int glyph) 201. { 202. if (glyph == GLYPH_CMAP_STONE_OFF) 203. return S_stone; 204. else if (glyph_is_cmap_main(glyph)) 205. return (glyph - GLYPH_CMAP_MAIN_OFF) + S_vwall; 206. else if (glyph_is_cmap_mines(glyph)) 207. return (glyph - GLYPH_CMAP_MINES_OFF) + S_vwall; 208. else if (glyph_is_cmap_gehennom(glyph)) 209. return (glyph - GLYPH_CMAP_GEH_OFF) + S_vwall; 210. else if (glyph_is_cmap_knox(glyph)) 211. return (glyph - GLYPH_CMAP_KNOX_OFF) + S_vwall; 212. else if (glyph_is_cmap_sokoban(glyph)) 213. return (glyph - GLYPH_CMAP_SOKO_OFF) + S_vwall; 214. else if (glyph_is_cmap_a(glyph)) 215. return (glyph - GLYPH_CMAP_A_OFF) + S_ndoor; 216. else if (glyph_is_cmap_altar(glyph)) 217. return S_altar; 218. else if (glyph_is_cmap_b(glyph)) 219. return (glyph - GLYPH_CMAP_B_OFF) + S_grave; 220. else if (glyph_is_cmap_c(glyph)) 221. return (glyph - GLYPH_CMAP_C_OFF) + S_digbeam; 222. else if (glyph_is_cmap_zap(glyph)) 223. return ((glyph - GLYPH_ZAP_OFF) % 4) + S_vbeam; 224. else if (glyph_is_swallow(glyph)) 225. return glyph_to_swallow(glyph) + S_sw_tl; 226. else if (glyph_is_explosion(glyph)) 227. return glyph_to_explosion(glyph) + S_expl_tl; 228. else 229. return MAXPCHARS; /* MAXPCHARS is legal array index because 230. * of trailing fencepost entry */ 231. } 232. 233. staticfn int 234. glyph_find_core( 235. const char *id, 236. struct find_struct *findwhat) 237. { 238. int glyph; 239. boolean do_callback, end_find = FALSE; 240. 241. if (parse_id(id, findwhat)) { 242. if (findwhat->findtype == find_glyph) { 243. (*findwhat->callback)(findwhat->val, findwhat); 244. } else { 245. for (glyph = 0; glyph < MAX_GLYPH; ++glyph) { 246. do_callback = FALSE; 247. switch (findwhat->findtype) { 248. case find_cmap: 249. if (glyph_to_cmap(glyph) == findwhat->val) 250. do_callback = TRUE; 251. break; 252. case find_pm: 253. if (glyph_is_monster(glyph) 254. && mons[glyph_to_mon(glyph)].mlet 255. == findwhat->val) 256. do_callback = TRUE; 257. break; 258. case find_oc: 259. if (glyph_is_object(glyph) 260. && glyph_to_obj(glyph) == findwhat->val) 261. do_callback = TRUE; 262. break; 263. case find_glyph: 264. if (glyph == findwhat->val) { 265. do_callback = TRUE; 266. end_find = TRUE; 267. } 268. break; 269. case find_nothing: 270. default: 271. end_find = TRUE; 272. break; 273. } 274. if (do_callback) 275. (findwhat->callback)(glyph, findwhat); 276. if (end_find) 277. break; 278. } 279. } 280. return 1; 281. } 282. return 0; 283. } 284. 285. /* 286. When we start to process a config file or a symbol file, 287. that might have G_ entries, generating all 9000+ glyphid 288. for comparison repeatedly each time we encounter a G_ 289. entry to decipher, then comparing against them, is obviously 290. extremely performance-poor. 291. 292. Setting aside the "comparison" part for now (that has to be 293. done in some manner), we can likely do something about the 294. repeated "generation" of the names for parsing prior to the 295. actual comparison part by generating them once, ahead of the 296. bulk of the potential parsings. We can later free up 297. all the memory those names consumed once the bulk parsing is 298. over with. 299. */ 300. 301. 302. void 303. fill_glyphid_cache(void) 304. { 305. int reslt = 0; 306. 307. if (!glyphid_cache) { 308. init_glyph_cache(); 309. } 310. if (glyphid_cache) { 311. glyphcache_find = zero_find; 312. glyphcache_find.findtype = find_nothing; 313. glyphcache_find.reserved = (genericptr_t) glyphid_cache; 314. glyphcache_find.restype = res_fill_cache; 315. reslt = parse_id((char *) 0, &glyphcache_find); 316. if (!reslt) { 317. free_glyphid_cache(); 318. glyphid_cache = (struct glyphid_cache_t *) 0; 319. } 320. } 321. } 322. 323. /* 324. * The glyph ID cache is a simple double-hash table. 325. * The cache size is a power of two, and two hashes are derived from the 326. * cache ID. The first is a location in the table, and the second is an 327. * offset. On any collision, the second hash is added to the first until 328. * a match or an empty bucket is found. 329. * The second hash is an odd number, which is necessary and sufficient 330. * to traverse the entire table. 331. */ 332. 333. staticfn void 334. init_glyph_cache(void) 335. { 336. size_t glyph; 337. 338. /* Cache size of power of 2 not less than 2*MAX_GLYPH */ 339. glyphid_cache_lsize = 0; 340. glyphid_cache_size = 1; 341. while (glyphid_cache_size < 2*MAX_GLYPH) { 342. ++glyphid_cache_lsize; 343. glyphid_cache_size <<= 1; 344. } 345. 346. glyphid_cache = (struct glyphid_cache_t *) alloc( 347. glyphid_cache_size * sizeof (struct glyphid_cache_t)); 348. for (glyph = 0; glyph < glyphid_cache_size; ++glyph) { 349. glyphid_cache[glyph].glyphnum = 0; 350. glyphid_cache[glyph].id = (char *) 0; 351. } 352. } 353. 354. void 355. free_glyphid_cache(void) 356. { 357. size_t idx; 358. 359. if (!glyphid_cache) 360. return; 361. for (idx = 0; idx < glyphid_cache_size; ++idx) { 362. if (glyphid_cache[idx].id) { 363. free(glyphid_cache[idx].id); 364. glyphid_cache[idx].id = (char *) 0; 365. } 366. } 367. free(glyphid_cache); 368. glyphid_cache = (struct glyphid_cache_t *) 0; 369. } 370. 371. staticfn void 372. add_glyph_to_cache(int glyphnum, const char *id) 373. { 374. uint32 hash = glyph_hash(id); 375. size_t hash1 = (size_t) (hash & (glyphid_cache_size - 1)); 376. size_t hash2 = (size_t) 377. (((hash >> glyphid_cache_lsize) & (glyphid_cache_size - 1)) | 1); 378. size_t i = hash1; 379. 380. do { 381. if (glyphid_cache[i].id == NULL) { 382. /* Empty bucket found */ 383. glyphid_cache[i].id = dupstr(id); 384. glyphid_cache[i].glyphnum = glyphnum; 385. return; 386. } 387. /* For speed, assume that no ID occurs twice */ 388. i = (i + hash2) & (glyphid_cache_size - 1); 389. } while (i != hash1); 390. /* This should never happen */ 391. panic("glyphid_cache full"); 392. } 393. 394. staticfn int 395. find_glyph_in_cache(const char *id) 396. { 397. uint32 hash = glyph_hash(id); 398. size_t hash1 = (size_t) (hash & (glyphid_cache_size - 1)); 399. size_t hash2 = (size_t) 400. (((hash >> glyphid_cache_lsize) & (glyphid_cache_size - 1)) | 1); 401. size_t i = hash1; 402. 403. do { 404. if (glyphid_cache[i].id == NULL) { 405. /* Empty bucket found */ 406. return -1; 407. } 408. if (strcmpi(id, glyphid_cache[i].id) == 0) { 409. /* Match found */ 410. return glyphid_cache[i].glyphnum; 411. } 412. i = (i + hash2) & (glyphid_cache_size - 1); 413. } while (i != hash1); 414. return -1; 415. } 416. 417. staticfn char * 418. find_glyphid_in_cache_by_glyphnum(int glyphnum) 419. { 420. size_t idx; 421. 422. if (!glyphid_cache) 423. return (char *) 0; 424. for (idx = 0; idx < glyphid_cache_size; ++idx) { 425. if (glyphid_cache[idx].glyphnum == glyphnum 426. && glyphid_cache[idx].id != 0) { 427. /* Match found */ 428. return glyphid_cache[idx].id; 429. } 430. } 431. return (char *) 0; 432. } 433. 434. staticfn uint32 435. glyph_hash(const char *id) 436. { 437. uint32 hash = 0; 438. size_t i; 439. 440. for (i = 0; id[i] != '\0'; ++i) { 441. char ch = id[i]; 442. if ('A' <= ch && ch <= 'Z') { 443. ch += 'a' - 'A'; 444. } 445. hash = (hash << 1) | (hash >> 31); 446. hash ^= ch; 447. } 448. return hash; 449. } 450. 451. boolean 452. glyphid_cache_status(void) 453. { 454. return (glyphid_cache != 0); 455. } 456. 457. int 458. match_glyph(char *buf) 459. { 460. char workbuf[BUFSZ]; 461. 462. /* buf contains a G_ glyph reference, not an S_ symbol. 463. There could be an R-G-B color attached too. 464. Let's get a copy to work with. */ 465. Snprintf(workbuf, sizeof workbuf, "%s", buf); /* get a copy */ 466. return glyphrep(workbuf); 467. } 468. 469. int 470. glyphrep(const char *op) 471. { 472. int reslt = 0, glyph = NO_GLYPH; 473. 474. if (!glyphid_cache) 475. reslt = 1; /* for debugger use only; no cache available */ 476. nhUse(reslt); 477. reslt = glyphrep_to_custom_map_entries(op, &glyph); 478. if (reslt) 479. return 1; 480. return 0; 481. } 482. 483. int 484. add_custom_nhcolor_entry( 485. const char *customization_name, 486. int glyphidx, 487. uint32 nhcolor, 488. enum graphics_sets which_set) 489. { 490. struct symset_customization *gdc 491. = &gs.sym_customizations[which_set][custom_nhcolor]; 492. struct customization_detail *details, *newdetails = 0; 493. #if 0 494. static uint32 closecolor = 0; 495. static int clridx = 0; 496. #endif 497. 498. if (!gdc->details) { 499. gdc->customization_name = dupstr(customization_name); 500. gdc->custtype = custom_nhcolor; 501. gdc->details = 0; 502. gdc->details_end = 0; 503. } 504. details = find_matching_customization(customization_name, 505. custom_nhcolor, which_set); 506. if (details) { 507. while (details) { 508. if (details->content.ccolor.glyphidx == glyphidx) { 509. details->content.ccolor.nhcolor = nhcolor; 510. return 1; 511. } 512. details = details->next; 513. } 514. } 515. /* create new details entry */ 516. newdetails = (struct customization_detail *) alloc(sizeof *newdetails); 517. newdetails->content.urep.glyphidx = glyphidx; 518. newdetails->content.ccolor.nhcolor = nhcolor; 519. newdetails->next = (struct customization_detail *) 0; 520. if (gdc->details == NULL) { 521. gdc->details = newdetails; 522. } else { 523. gdc->details_end->next = newdetails; 524. } 525. gdc->details_end = newdetails; 526. gdc->count++; 527. return 1; 528. } 529. 530. void 531. apply_customizations( 532. enum graphics_sets which_set, 533. enum do_customizations docustomize) 534. { 535. glyph_map *gmap; 536. struct customization_detail *details; 537. struct symset_customization *sc; 538. boolean at_least_one = FALSE, 539. do_colors = ((docustomize & do_custom_colors) != 0), 540. do_symbols = ((docustomize & do_custom_symbols) != 0); 541. int custs; 542. 543. for (custs = 0; custs < (int) custom_count; ++custs) { 544. sc = &gs.sym_customizations[which_set][custs]; 545. if (sc->count && sc->details) { 546. at_least_one = TRUE; 547. /* These glyph customizations get applied to the glyphmap array, 548. not to symset entries */ 549. details = sc->details; 550. while (details) { 551. #ifdef ENHANCED_SYMBOLS 552. if (iflags.customsymbols && do_symbols) { 553. if (sc->custtype == custom_ureps) { 554. gmap = &glyphmap[details->content.urep.glyphidx]; 555. if (gs.symset[which_set].handling == H_UTF8) 556. (void) set_map_u(gmap, 557. details->content.urep.u.utf32ch, 558. details->content.urep.u.utf8str); 559. } 560. } 561. #endif 562. if (iflags.customcolors && do_colors) { 563. if (sc->custtype == custom_nhcolor) { 564. gmap = &glyphmap[details->content.ccolor.glyphidx]; 565. (void) set_map_customcolor(gmap, 566. details->content.ccolor.nhcolor); 567. } 568. } 569. details = details->next; 570. } 571. } 572. } 573. iflags.pending_customizations = at_least_one; 574. } 575. 576. /* Shuffle the customizations to match shuffled object descriptions, 577. * so a red potion isn't displayed with a blue customization, and so on. 578. */ 579. 580. void 581. maybe_shuffle_customizations(void) 582. { 583. if (iflags.pending_customizations) { 584. shuffle_customizations(); 585. iflags.pending_customizations = 0; 586. } 587. } 588. 589. #if 0 590. staticfn void 591. shuffle_customizations(void) 592. { 593. static const int offsets[2] = { GLYPH_OBJ_OFF, GLYPH_OBJ_PILETOP_OFF }; 594. int j; 595. 596. for (j = 0; j < SIZE(offsets); j++) { 597. glyph_map *obj_glyphs = glyphmap + offsets[j]; 598. int i; 599. struct unicode_representation *tmp_u[NUM_OBJECTS]; 600. int duplicate[NUM_OBJECTS]; 601. 602. for (i = 0; i < NUM_OBJECTS; i++) { 603. duplicate[i] = -1; 604. tmp_u[i] = (struct unicode_representation *) 0; 605. } 606. for (i = 0; i < NUM_OBJECTS; i++) { 607. int idx = objects[i].oc_descr_idx; 608. 609. /* 610. * Shuffling gem appearances can cause the same oc_descr_idx to 611. * appear more than once. Detect this condition and ensure that 612. * each pointer points to a unique allocation. 613. */ 614. if (duplicate[idx] >= 0) { 615. /* Current structure already appears in tmp_u */ 616. struct unicode_representation *other = tmp_u[duplicate[idx]]; 617. 618. tmp_u[i] = (struct unicode_representation *) 619. alloc(sizeof *tmp_u[i]); 620. *tmp_u[i] = *other; 621. if (other->utf8str != NULL) { 622. tmp_u[i]->utf8str = (uint8 *) 623. dupstr((const char *) other->utf8str); 624. } 625. } else { 626. tmp_u[i] = obj_glyphs[idx].u; 627. if (obj_glyphs[idx].u != NULL) { 628. duplicate[idx] = i; 629. obj_glyphs[idx].u = NULL; 630. } 631. } 632. } 633. for (i = 0; i < NUM_OBJECTS; i++) { 634. /* Some glyphmaps may not have been transferred */ 635. if (obj_glyphs[i].u != NULL) { 636. free(obj_glyphs[i].u->utf8str); 637. free(obj_glyphs[i].u); 638. } 639. obj_glyphs[i].u = tmp_u[i]; 640. } 641. } 642. } 643. 644. #else 645. staticfn void 646. shuffle_customizations(void) 647. { 648. static const int offsets[2] = { GLYPH_OBJ_OFF, GLYPH_OBJ_PILETOP_OFF }; 649. int j; 650. 651. for (j = 0; j < SIZE(offsets); j++) { 652. glyph_map *obj_glyphs = glyphmap + offsets[j]; 653. int i; 654. #ifdef ENHANCED_SYMBOLS 655. struct unicode_representation *tmp_u[NUM_OBJECTS]; 656. #endif 657. uint32 tmp_customcolor[NUM_OBJECTS]; 658. uint16 tmp_color256idx[NUM_OBJECTS]; 659. 660. int duplicate[NUM_OBJECTS]; 661. 662. for (i = 0; i < NUM_OBJECTS; i++) { 663. duplicate[i] = -1; 664. #ifdef ENHANCED_SYMBOLS 665. tmp_u[i] = (struct unicode_representation *) 0; 666. #endif 667. tmp_customcolor[i] = 0; 668. tmp_color256idx[i] = 0; 669. } 670. for (i = 0; i < NUM_OBJECTS; i++) { 671. int idx = objects[i].oc_descr_idx; 672. 673. /* 674. * Shuffling gem appearances can cause the same oc_descr_idx to 675. * appear more than once. Detect this condition and ensure that 676. * each pointer points to a unique allocation. 677. */ 678. if (duplicate[idx] >= 0) { 679. #ifdef ENHANCED_SYMBOLS 680. /* Current structure already appears in tmp_u */ 681. struct unicode_representation *other = tmp_u[duplicate[idx]]; 682. #endif 683. uint32 other_customcolor = tmp_customcolor[duplicate[idx]]; 684. uint16 other_color256idx = tmp_color256idx[duplicate[idx]]; 685. 686. tmp_customcolor[i] = other_customcolor; 687. tmp_color256idx[i] = other_color256idx; 688. #ifdef ENHANCED_SYMBOLS 689. if (other) { 690. tmp_u[i] = (struct unicode_representation *) alloc( 691. sizeof *tmp_u[i]); 692. *tmp_u[i] = *other; 693. if (other->utf8str != NULL) { 694. tmp_u[i]->utf8str = 695. (uint8 *) dupstr((const char *) other->utf8str); 696. } 697. } 698. #endif 699. } else { 700. tmp_customcolor[i] = obj_glyphs[idx].customcolor; 701. tmp_color256idx[i] = obj_glyphs[idx].color256idx; 702. #ifdef ENHANCED_SYMBOLS 703. tmp_u[i] = obj_glyphs[idx].u; 704. #endif 705. if ( 706. #ifdef ENHANCED_SYMBOLS 707. obj_glyphs[idx].u != NULL || 708. #endif 709. obj_glyphs[idx].customcolor != 0) { 710. duplicate[idx] = i; 711. #ifdef ENHANCED_SYMBOLS 712. obj_glyphs[idx].u = NULL; 713. #endif 714. obj_glyphs[idx].customcolor = 0; 715. obj_glyphs[idx].color256idx = 0; 716. } 717. } 718. } 719. for (i = 0; i < NUM_OBJECTS; i++) { 720. /* Some glyphmaps may not have been transferred */ 721. #ifdef ENHANCED_SYMBOLS 722. if (obj_glyphs[i].u != NULL) { 723. free(obj_glyphs[i].u->utf8str); 724. free(obj_glyphs[i].u); 725. } 726. obj_glyphs[i].u = tmp_u[i]; 727. #endif 728. obj_glyphs[i].customcolor = tmp_customcolor[i]; 729. obj_glyphs[i].color256idx = tmp_color256idx[i]; 730. } 731. } 732. } 733. #endif 734. 735. struct customization_detail * 736. find_matching_customization( 737. const char *customization_name, 738. enum customization_types custtype, 739. enum graphics_sets which_set) 740. { 741. struct symset_customization *gdc 742. = &gs.sym_customizations[which_set][custtype]; 743. 744. if ((gdc->custtype == custtype) && gdc->customization_name 745. && (strcmp(customization_name, gdc->customization_name) == 0)) 746. return gdc->details; 747. return (struct customization_detail *) 0; 748. } 749. 750. void 751. purge_all_custom_entries(void) 752. { 753. int i; 754. 755. for (i = 0; i < NUM_GRAPHICS + 1; ++i) { 756. purge_custom_entries(i); 757. } 758. } 759. 760. void 761. purge_custom_entries(enum graphics_sets which_set) 762. { 763. enum customization_types custtype; 764. struct symset_customization *gdc; 765. struct customization_detail *details, *next; 766. 767. for (custtype = custom_none; custtype < custom_count; ++custtype) { 768. gdc = &gs.sym_customizations[which_set][custtype]; 769. details = gdc->details; 770. while (details) { 771. next = details->next; 772. if (gdc->custtype == custom_ureps) { 773. if (details->content.urep.u.utf8str) 774. free(details->content.urep.u.utf8str); 775. details->content.urep.u.utf8str = (uint8 *) 0; 776. } else if (gdc->custtype == custom_symbols) { 777. details->content.sym.symparse = (struct symparse *) 0; 778. details->content.sym.val = 0; 779. } else if (gdc->custtype == custom_nhcolor) { 780. details->content.ccolor.nhcolor = 0; 781. details->content.ccolor.glyphidx = 0; 782. } 783. free(details); 784. details = next; 785. } 786. gdc->details = 0; 787. gdc->details_end = 0; 788. if (gdc->customization_name) { 789. free((genericptr_t) gdc->customization_name); 790. gdc->customization_name = 0; 791. } 792. gdc->count = 0; 793. } 794. } 795. 796. void 797. dump_all_glyphids(FILE *fp) 798. { 799. struct find_struct dump_glyphid_find = zero_find; 800. 801. dump_glyphid_find.findtype = find_nothing; 802. dump_glyphid_find.reserved = (genericptr_t) fp; 803. dump_glyphid_find.restype = res_dump_glyphids; 804. (void) parse_id((char *) 0, &dump_glyphid_find); 805. } 806. 807. void 808. wizcustom_glyphids(winid win) 809. { 810. int glyphnum; 811. char *id; 812. 813. if (!glyphid_cache) 814. return; 815. for (glyphnum = 0; glyphnum < MAX_GLYPH; ++glyphnum) { 816. id = find_glyphid_in_cache_by_glyphnum(glyphnum); 817. if (id) { 818. wizcustom_callback(win, glyphnum, id); 819. } 820. } 821. } 822. 823. staticfn int 824. parse_id( 825. const char *id, 826. struct find_struct *findwhat) 827. { 828. FILE *fp = (FILE *) 0; 829. int i = 0, j, mnum, glyph, 830. pm_offset = 0, oc_offset = 0, cmap_offset = 0, 831. pm_count = 0, oc_count = 0, cmap_count = 0; 832. boolean skip_base = FALSE, skip_this_one = FALSE, dump_ids = FALSE, 833. filling_cache = FALSE, is_S = FALSE, is_G = FALSE; 834. char buf[4][QBUFSZ]; 835. 836. if (findwhat->findtype == find_nothing && findwhat->restype) { 837. if (findwhat->restype == res_dump_glyphids) { 838. if (findwhat->reserved) { 839. fp = (FILE *) findwhat->reserved; 840. dump_ids = TRUE; 841. } else { 842. return 0; 843. } 844. } 845. if (findwhat->restype == res_fill_cache) { 846. if (findwhat->reserved 847. && findwhat->reserved == (genericptr_t) glyphid_cache) { 848. filling_cache = TRUE; 849. } else { 850. return 0; 851. } 852. } 853. } 854. 855. is_G = (id && id[0] == 'G' && id[1] == '_'); 856. is_S = (id && id[0] == 'S' && id[1] == '_'); 857. 858. if ((is_G && !glyphid_cache) || filling_cache || dump_ids || is_S) { 859. while (loadsyms[i].range) { 860. if (!pm_offset && loadsyms[i].range == SYM_MON) 861. pm_offset = i; 862. if (!pm_count && pm_offset && loadsyms[i].range != SYM_MON) 863. pm_count = i - pm_offset; 864. if (!oc_offset && loadsyms[i].range == SYM_OC) 865. oc_offset = i; 866. if (!oc_count && oc_offset && loadsyms[i].range != SYM_OC) 867. oc_count = i - oc_offset; 868. if (!cmap_offset && loadsyms[i].range == SYM_PCHAR) 869. cmap_offset = i; 870. if (!cmap_count && cmap_offset && loadsyms[i].range != SYM_PCHAR) 871. cmap_count = i - cmap_offset; 872. i++; 873. } 874. } 875. if (is_G || filling_cache || dump_ids) { 876. if (!filling_cache && id && glyphid_cache) { 877. int val = find_glyph_in_cache(id); 878. if (val >= 0) { 879. findwhat->findtype = find_glyph; 880. findwhat->val = val; 881. findwhat->loadsyms_offset = 0; 882. return 1; 883. } else { 884. return 0; 885. } 886. } else { 887. const char *buf2, *buf3, *buf4; 888. 889. /* individual matching glyph entries */ 890. for (glyph = 0; glyph < MAX_GLYPH; ++glyph) { 891. skip_base = FALSE; 892. skip_this_one = FALSE; 893. buf[0][0] = buf[1][0] = buf[2][0] = buf[3][0] = '\0'; 894. if (glyph_is_monster(glyph)) { 895. /* buf2 will hold the distinguishing prefix */ 896. /* buf3 will hold the base name */ 897. buf2 = ""; 898. buf3 = monsdump[glyph_to_mon(glyph)].nm; 899. 900. if (glyph_is_normal_male_monster(glyph)) { 901. buf2 = "male_"; 902. } else if (glyph_is_normal_female_monster(glyph)) { 903. buf2 = "female_"; 904. } else if (glyph_is_ridden_male_monster(glyph)) { 905. buf2 = "ridden_male_"; 906. } else if (glyph_is_ridden_female_monster(glyph)) { 907. buf2 = "ridden_female_"; 908. } else if (glyph_is_detected_male_monster(glyph)) { 909. buf2 = "detected_male_"; 910. } else if (glyph_is_detected_female_monster(glyph)) { 911. buf2 = "detected_female_"; 912. } else if (glyph_is_male_pet(glyph)) { 913. buf2 = "pet_male_"; 914. } else if (glyph_is_female_pet(glyph)) { 915. buf2 = "pet_female_"; 916. } 917. Strcpy(buf[0], "G_"); 918. Strcat(buf[0], buf2); 919. Strcat(buf[0], buf3); 920. } else if (glyph_is_body(glyph)) { 921. /* buf2 will hold the distinguishing prefix */ 922. /* buf3 will hold the base name */ 923. buf2 = glyph_is_body_piletop(glyph) 924. ? "piletop_body_" 925. : "body_"; 926. buf3 = monsdump[glyph_to_body_corpsenm(glyph)].nm; 927. Strcpy(buf[0], "G_"); 928. Strcat(buf[0], buf2); 929. Strcat(buf[0], buf3); 930. } else if (glyph_is_statue(glyph)) { 931. /* buf2 will hold the distinguishing prefix */ 932. /* buf3 will hold the base name */ 933. buf2 = glyph_is_fem_statue_piletop(glyph) 934. ? "piletop_statue_of_female_" 935. : glyph_is_fem_statue(glyph) 936. ? "statue_of_female_" 937. : glyph_is_male_statue_piletop(glyph) 938. ? "piletop_statue_of_male_" 939. : glyph_is_male_statue(glyph) 940. ? "statue_of_male_" 941. : ""; /* shouldn't happen */ 942. buf3 = monsdump[glyph_to_statue_corpsenm(glyph)].nm; 943. Strcpy(buf[0], "G_"); 944. Strcat(buf[0], buf2); 945. Strcat(buf[0], buf3); 946. } else if (glyph_is_object(glyph)) { 947. i = glyph_to_obj(glyph); 948. /* buf2 will hold the distinguishing prefix */ 949. /* buf3 will hold the base name */ 950. if (((i > SCR_STINKING_CLOUD) && (i < SCR_MAIL)) 951. || ((i > WAN_LIGHTNING) && (i < GOLD_PIECE))) 952. skip_this_one = TRUE; 953. if (!skip_this_one) { 954. if ((i >= WAN_LIGHT) && (i <= WAN_LIGHTNING)) 955. buf2 = "wand of "; 956. else if ((i >= SPE_DIG) && (i < SPE_BLANK_PAPER)) 957. buf2 = "spellbook of "; 958. else if ((i >= SCR_ENCHANT_ARMOR) 959. && (i <= SCR_STINKING_CLOUD)) 960. buf2 = "scroll of "; 961. else if ((i >= POT_GAIN_ABILITY) && (i <= POT_WATER)) 962. buf2 = (i == POT_WATER) ? "flask of n" 963. : "potion of "; 964. else if ((i >= RIN_ADORNMENT) 965. && (i <= RIN_PROTECTION_FROM_SHAPE_CHAN)) 966. buf2 = "ring of "; 967. else if (i == LAND_MINE) 968. buf2 = "unset "; 969. else 970. buf2 = ""; 971. buf3 = (i == SCR_BLANK_PAPER) ? "blank scroll" 972. : (i == SPE_BLANK_PAPER) ? "blank spellbook" 973. : (i == SLIME_MOLD) ? "slime mold" 974. : obj_descr[i].oc_name 975. ? obj_descr[i].oc_name 976. : obj_descr[i].oc_descr; 977. Strcpy(buf[0], "G_"); 978. if (glyph_is_normal_piletop_obj(glyph)) 979. Strcat(buf[0], "piletop_"); 980. Strcat(buf[0], buf2); 981. Strcat(buf[0], buf3); 982. } 983. } else if (glyph_is_cmap(glyph) || glyph_is_cmap_zap(glyph) 984. || glyph_is_swallow(glyph) 985. || glyph_is_explosion(glyph)) { 986. int cmap = -1; 987. 988. /* buf2 will hold the distinguishing prefix */ 989. /* buf3 will hold the base name */ 990. /* buf4 will hold the distinguishing suffix */ 991. buf2 = ""; 992. buf3 = ""; 993. buf4 = ""; 994. if (glyph == GLYPH_CMAP_OFF) { 995. cmap = S_stone; 996. buf3 = "stone substrate"; 997. skip_base = TRUE; 998. } else if (glyph_is_cmap_gehennom(glyph)) { 999. cmap = (glyph - GLYPH_CMAP_GEH_OFF) + S_vwall; 1000. buf4 = "_gehennom"; 1001. } else if (glyph_is_cmap_knox(glyph)) { 1002. cmap = (glyph - GLYPH_CMAP_KNOX_OFF) + S_vwall; 1003. buf4 = "_knox"; 1004. } else if (glyph_is_cmap_main(glyph)) { 1005. cmap = (glyph - GLYPH_CMAP_MAIN_OFF) + S_vwall; 1006. buf4 = "_main"; 1007. } else if (glyph_is_cmap_mines(glyph)) { 1008. cmap = (glyph - GLYPH_CMAP_MINES_OFF) + S_vwall; 1009. buf4 = "_mines"; 1010. } else if (glyph_is_cmap_sokoban(glyph)) { 1011. cmap = (glyph - GLYPH_CMAP_SOKO_OFF) + S_vwall; 1012. buf4 = "_sokoban"; 1013. } else if (glyph_is_cmap_a(glyph)) { 1014. cmap = (glyph - GLYPH_CMAP_A_OFF) + S_ndoor; 1015. } else if (glyph_is_cmap_altar(glyph)) { 1016. static const char *const altar_text[] = { 1017. "unaligned", "chaotic", "neutral", 1018. "lawful", "other", 1019. }; 1020. 1021. j = (glyph - GLYPH_ALTAR_OFF); 1022. cmap = S_altar; 1023. if (j != altar_other) { 1024. Snprintf(buf[2], sizeof buf[2], "%s_", 1025. altar_text[j]); 1026. buf2 = buf[2]; 1027. } else { 1028. buf3 = "altar other"; 1029. skip_base = TRUE; 1030. } 1031. } else if (glyph_is_cmap_b(glyph)) { 1032. cmap = (glyph - GLYPH_CMAP_B_OFF) + S_grave; 1033. } else if (glyph_is_cmap_zap(glyph)) { 1034. static const char *const zap_texts[] = { 1035. "missile", "fire", "frost", "sleep", 1036. "death", "lightning", "poison gas", "acid" 1037. }; 1038. 1039. j = (glyph - GLYPH_ZAP_OFF); 1040. cmap = (j % 4) + S_vbeam; 1041. Snprintf(buf[2], sizeof buf[2], "%s", 1042. loadsyms[cmap + cmap_offset].name + 2); 1043. Snprintf(buf[3], sizeof buf[3], "%s zap %s", 1044. zap_texts[j / 4], fix_glyphname(buf[2])); 1045. buf3 = buf[3]; 1046. buf2 = ""; 1047. skip_base = TRUE; 1048. } else if (glyph_is_cmap_c(glyph)) { 1049. cmap = (glyph - GLYPH_CMAP_C_OFF) + S_digbeam; 1050. } else if (glyph_is_swallow(glyph)) { 1051. static const char *const swallow_texts[] = { 1052. "top left", "top center", "top right", 1053. "middle left", "middle right", "bottom left", 1054. "bottom center", "bottom right", 1055. }; 1056. 1057. j = glyph - GLYPH_SWALLOW_OFF; 1058. cmap = glyph_to_swallow(glyph); 1059. mnum = j / ((S_sw_br - S_sw_tl) + 1); 1060. Strcpy(buf[3], "swallow "); 1061. Strcat(buf[3], monsdump[mnum].nm); 1062. Strcat(buf[3], " "); 1063. Strcat(buf[3], swallow_texts[cmap]); 1064. buf3 = buf[3]; 1065. skip_base = TRUE; 1066. } else if (glyph_is_explosion(glyph)) { 1067. static const char *const expl_type_texts[] = { 1068. "dark", "noxious", "muddy", "wet", 1069. "magical", "fiery", "frosty", 1070. }; 1071. static const char *const expl_texts[] = { 1072. "tl", "tc", "tr", "ml", "mc", 1073. "mr", "bl", "bc", "br", 1074. }; 1075. int expl; 1076. 1077. j = glyph - GLYPH_EXPLODE_OFF; 1078. expl = j / ((S_expl_br - S_expl_tl) + 1); 1079. cmap = glyph_to_explosion(glyph) + S_expl_tl; 1080. i = cmap - S_expl_tl; 1081. Snprintf(buf[2], sizeof buf[2], "%s ", 1082. expl_type_texts[expl]); 1083. buf2 = buf[2]; 1084. Snprintf(buf[3], sizeof buf[3], "%s%s", "expl_", 1085. expl_texts[i]); 1086. buf3 = buf[3]; 1087. skip_base = TRUE; 1088. } 1089. if (!skip_base) { 1090. if (cmap >= 0 && cmap < MAXPCHARS) { 1091. buf3 = loadsyms[cmap + cmap_offset].name + 2; 1092. } 1093. } 1094. Strcpy(buf[0], "G_"); 1095. Strcat(buf[0], buf2); 1096. Strcat(buf[0], buf3); 1097. Strcat(buf[0], buf4); 1098. } else if (glyph_is_invisible(glyph)) { 1099. Strcpy(buf[0], "G_invisible"); 1100. } else if (glyph_is_nothing(glyph)) { 1101. Strcpy(buf[0], "G_nothing"); 1102. } else if (glyph_is_unexplored(glyph)) { 1103. Strcpy(buf[0], "G_unexplored"); 1104. } else if (glyph_is_warning(glyph)) { 1105. j = glyph - GLYPH_WARNING_OFF; 1106. Snprintf(buf[0], sizeof buf[0], "G_%s%d", "warning", j); 1107. } 1108. if (memchr(buf[0], '\0', sizeof buf[0]) == NULL) 1109. panic("parse_id: buf[0] overflowed"); 1110. if (!skip_this_one) { 1111. fix_glyphname(buf[0]+2); 1112. if (dump_ids) { 1113. Fprintf(fp, "(%04d) %s\n", glyph, buf[0]); 1114. } else if (filling_cache) { 1115. add_glyph_to_cache(glyph, buf[0]); 1116. } else if (id) { 1117. if (!strcmpi(id, buf[0])) { 1118. findwhat->findtype = find_glyph; 1119. findwhat->val = glyph; 1120. findwhat->loadsyms_offset = 0; 1121. return 1; 1122. } 1123. } 1124. } 1125. } 1126. } /* not glyphid_cache */ 1127. } else if (is_S) { 1128. /* cmap entries */ 1129. for (i = 0; i < cmap_count; ++i) { 1130. if (!strcmpi(loadsyms[i + cmap_offset].name + 2, id + 2)) { 1131. findwhat->findtype = find_cmap; 1132. findwhat->val = i; 1133. findwhat->loadsyms_offset = i + cmap_offset; 1134. return 1; 1135. } 1136. } 1137. /* objclass entries */ 1138. for (i = 0; i < oc_count; ++i) { 1139. if (!strcmpi(loadsyms[i + oc_offset].name + 2, id + 2)) { 1140. findwhat->findtype = find_oc; 1141. findwhat->val = i; 1142. findwhat->loadsyms_offset = i + oc_offset; 1143. return 1; 1144. } 1145. } 1146. /* permonst entries */ 1147. for (i = 0; i <= pm_count; ++i) { 1148. if (!strcmpi(loadsyms[i + pm_offset].name + 2, id + 2)) { 1149. findwhat->findtype = find_pm; 1150. findwhat->val = i + 1; /* starts at 1 */ 1151. findwhat->loadsyms_offset = i + pm_offset; 1152. return 1; 1153. } 1154. } 1155. } 1156. if (dump_ids || filling_cache) 1157. return 1; 1158. findwhat->findtype = find_nothing; 1159. findwhat->val = 0; 1160. findwhat->loadsyms_offset = 0; 1161. return 0; 1162. } 1163. 1164. /* extern glyph_map glyphmap[MAX_GLYPH]; */ 1165. 1166. void 1167. clear_all_glyphmap_colors(void) 1168. { 1169. int glyph; 1170. 1171. for (glyph = 0; glyph < MAX_GLYPH; ++glyph) { 1172. if (glyphmap[glyph].customcolor) 1173. glyphmap[glyph].customcolor = 0; 1174. glyphmap[glyph].color256idx = 0; 1175. } 1176. } 1177. 1178. void 1179. reset_customcolors(void) 1180. { 1181. clear_all_glyphmap_colors(); 1182. apply_customizations(gc.currentgraphics, do_custom_colors); 1183. } 1184. 1185. /* not used yet */ 1186. 1187. #if 0 1188. staticfn struct customization_detail *find_display_sym_customization( 1189. const char *customization_name, const struct symparse *symparse, 1190. enum graphics_sets which_set); 1191. staticfn struct customization_detail *find_display_urep_customization( 1192. const char *customization_name, int glyphidx, 1193. enum graphics_sets which_set); 1194. 1195. struct customization_detail * 1196. find_display_sym_customization( 1197. const char *customization_name, 1198. const struct symparse *symparse, 1199. enum graphics_sets which_set) 1200. { 1201. struct symset_customization *gdc; 1202. struct customization_detail *symdetails; 1203. 1204. gdc = &gs.sym_customizations[which_set][custom_symbols]; 1205. if ((gdc->custtype == custom_symbols) 1206. && (strcmp(customization_name, gdc->customization_name) == 0)) { 1207. symdetails = gdc->details; 1208. while (symdetails) { 1209. if (symdetails->content.sym.symparse == symparse) 1210. return symdetails; 1211. symdetails = symdetails->next; 1212. } 1213. } 1214. return (struct customization_detail *) 0; 1215. } 1216. 1217. struct customization_detail * 1218. find_display_urep_customization( 1219. const char *customization_name, 1220. int glyphidx, 1221. enum graphics_sets which_set) 1222. { 1223. struct symset_customization *gdc = &gs.sym_customizations[which_set]; 1224. struct customization_detail *urepdetails; 1225. 1226. if ((gdc->custtype == custom_reps) 1227. || (strcmp(customization_name, gdc->customization_name) == 0)) { 1228. urepdetails = gdc->details; 1229. while (urepdetails) { 1230. if (urepdetails->content.urep.glyphidx == glyphidx) 1231. return urepdetails; 1232. urepdetails = urepdetails->next; 1233. } 1234. } 1235. return (struct customization_detail *) 0; 1236. } 1237. #endif /* 0 not used yet */ 1238. 1239. #ifdef TEST_GLYPHNAMES 1240. 1241. static struct { 1242. int idx; 1243. const char *nm1; 1244. const char *nm2; 1245. } cmapname[MAXPCHARS] = { 1246. #define PCHAR_TILES 1247. #include "defsym.h" 1248. #undef PCHAR_TILES 1249. }; 1250. 1251. void 1252. test_glyphnames(void) 1253. { 1254. int reslt; 1255. 1256. reslt = find_glyphs("G_potion_of_monster_detection"); 1257. reslt = find_glyphs("G_piletop_body_chickatrice"); 1258. reslt = find_glyphs("G_detected_male_homunculus"); 1259. reslt = find_glyphs("S_pool"); 1260. reslt = find_glyphs("S_dog"); 1261. reslt = glyphs_to_unicode("S_dog", "U+130E6", 0L); 1262. } 1263. 1264. staticfn void 1265. just_find_callback(int glyph UNUSED, struct find_struct *findwhat UNUSED) 1266. { 1267. return; 1268. } 1269. 1270. staticfn int 1271. find_glyphs(const char *id) 1272. { 1273. struct find_struct find_only = zero_find; 1274. 1275. find_only.unicode_val = 0; 1276. find_only.callback = just_find_callback; 1277. return glyph_find_core(id, &find_only); 1278. } 1279. 1280. staticfn void 1281. to_unicode_callback(int glyph UNUSED, struct find_struct *findwhat) 1282. { 1283. int uval; 1284. #ifdef NO_PARSING_SYMSET 1285. glyph_map *gm = &glyphmap[glyph]; 1286. #endif 1287. uint8 utf8str[6]; 1288. 1289. if (!findwhat->unicode_val) 1290. return; 1291. uval = unicode_val(findwhat->unicode_val); 1292. if (unicodeval_to_utf8str(uval, utf8str, sizeof utf8str)) { 1293. #ifdef NO_PARSING_SYMSET 1294. set_map_u(gm, uval, utf8str, 1295. (findwhat->color != 0L) ? findwhat->color : 0L); 1296. #else 1297. 1298. #endif 1299. } 1300. } 1301. 1302. int 1303. glyphs_to_unicode(const char *id, const char *unicode_val, long clr) 1304. { 1305. struct find_struct to_unicode = zero_find; 1306. 1307. to_unicode.unicode_val = unicode_val; 1308. to_unicode.callback = to_unicode_callback; 1309. /* if the color 0 is an actual color, as opposed to just "not set" 1310. we set a marker bit outside the 24-bit range to indicate a 1311. valid color value 0. That allows valid color 0, but allows a 1312. simple checking for 0 to detect "not set". The window port that 1313. implements the color switch, needs to either check that bit 1314. or appropriately mask colors with 0xFFFFFF. */ 1315. to_unicode.color = (clr == -1) ? 0L : (clr == 0L) ? nonzero_black : clr; 1316. return glyph_find_core(id, &to_unicode); 1317. } 1318. 1319. #endif /* SOME TEST STUFF */ 1320. 1321. /* glyphs.c */ 1322. 1323. 1324.