Source:NetHack 3.6.3/src/windows.c
Jump to navigation
Jump to search
Below is the full text to windows.c from the source code of NetHack 3.6.3. To link to a particular line, write [[Source:NetHack 3.6.3/src/windows.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 3.6 windows.c $NHDT-Date: 1575245096 2019/12/02 00:04:56 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.60 $ */ 2. /* Copyright (c) D. Cohrs, 1993. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. #ifdef TTY_GRAPHICS 7. #include "wintty.h" 8. #endif 9. #ifdef CURSES_GRAPHICS 10. extern struct window_procs curses_procs; 11. #endif 12. #ifdef X11_GRAPHICS 13. /* Cannot just blindly include winX.h without including all of X11 stuff 14. and must get the order of include files right. Don't bother. */ 15. extern struct window_procs X11_procs; 16. extern void FDECL(win_X11_init, (int)); 17. #endif 18. #ifdef QT_GRAPHICS 19. extern struct window_procs Qt_procs; 20. #endif 21. #ifdef GEM_GRAPHICS 22. #include "wingem.h" 23. #endif 24. #ifdef MAC 25. extern struct window_procs mac_procs; 26. #endif 27. #ifdef BEOS_GRAPHICS 28. extern struct window_procs beos_procs; 29. extern void FDECL(be_win_init, (int)); 30. FAIL /* be_win_init doesn't exist? XXX*/ 31. #endif 32. #ifdef AMIGA_INTUITION 33. extern struct window_procs amii_procs; 34. extern struct window_procs amiv_procs; 35. extern void FDECL(ami_wininit_data, (int)); 36. #endif 37. #ifdef WIN32_GRAPHICS 38. extern struct window_procs win32_procs; 39. #endif 40. #ifdef GNOME_GRAPHICS 41. #include "winGnome.h" 42. extern struct window_procs Gnome_procs; 43. #endif 44. #ifdef MSWIN_GRAPHICS 45. extern struct window_procs mswin_procs; 46. #endif 47. #ifdef WINCHAIN 48. extern struct window_procs chainin_procs; 49. extern void FDECL(chainin_procs_init, (int)); 50. extern void *FDECL(chainin_procs_chain, (int, int, void *, void *, void *)); 51. 52. extern struct chain_procs chainout_procs; 53. extern void FDECL(chainout_procs_init, (int)); 54. extern void *FDECL(chainout_procs_chain, (int, int, void *, void *, void *)); 55. 56. extern struct chain_procs trace_procs; 57. extern void FDECL(trace_procs_init, (int)); 58. extern void *FDECL(trace_procs_chain, (int, int, void *, void *, void *)); 59. #endif 60. 61. STATIC_DCL void FDECL(def_raw_print, (const char *s)); 62. STATIC_DCL void NDECL(def_wait_synch); 63. 64. #ifdef DUMPLOG 65. STATIC_DCL winid FDECL(dump_create_nhwindow, (int)); 66. STATIC_DCL void FDECL(dump_clear_nhwindow, (winid)); 67. STATIC_DCL void FDECL(dump_display_nhwindow, (winid, BOOLEAN_P)); 68. STATIC_DCL void FDECL(dump_destroy_nhwindow, (winid)); 69. STATIC_DCL void FDECL(dump_start_menu, (winid)); 70. STATIC_DCL void FDECL(dump_add_menu, (winid, int, const ANY_P *, CHAR_P, 71. CHAR_P, int, const char *, BOOLEAN_P)); 72. STATIC_DCL void FDECL(dump_end_menu, (winid, const char *)); 73. STATIC_DCL int FDECL(dump_select_menu, (winid, int, MENU_ITEM_P **)); 74. STATIC_DCL void FDECL(dump_putstr, (winid, int, const char *)); 75. #endif /* DUMPLOG */ 76. 77. #ifdef HANGUPHANDLING 78. volatile 79. #endif 80. NEARDATA struct window_procs windowprocs; 81. 82. #ifdef WINCHAIN 83. #define CHAINR(x) , x 84. #else 85. #define CHAINR(x) 86. #endif 87. 88. static struct win_choices { 89. struct window_procs *procs; 90. void FDECL((*ini_routine), (int)); /* optional (can be 0) */ 91. #ifdef WINCHAIN 92. void *FDECL((*chain_routine), (int, int, void *, void *, void *)); 93. #endif 94. } winchoices[] = { 95. #ifdef TTY_GRAPHICS 96. { &tty_procs, win_tty_init CHAINR(0) }, 97. #endif 98. #ifdef CURSES_GRAPHICS 99. { &curses_procs, 0 }, 100. #endif 101. #ifdef X11_GRAPHICS 102. { &X11_procs, win_X11_init CHAINR(0) }, 103. #endif 104. #ifdef QT_GRAPHICS 105. { &Qt_procs, 0 CHAINR(0) }, 106. #endif 107. #ifdef GEM_GRAPHICS 108. { &Gem_procs, win_Gem_init CHAINR(0) }, 109. #endif 110. #ifdef MAC 111. { &mac_procs, 0 CHAINR(0) }, 112. #endif 113. #ifdef BEOS_GRAPHICS 114. { &beos_procs, be_win_init CHAINR(0) }, 115. #endif 116. #ifdef AMIGA_INTUITION 117. { &amii_procs, 118. ami_wininit_data CHAINR(0) }, /* Old font version of the game */ 119. { &amiv_procs, 120. ami_wininit_data CHAINR(0) }, /* Tile version of the game */ 121. #endif 122. #ifdef WIN32_GRAPHICS 123. { &win32_procs, 0 CHAINR(0) }, 124. #endif 125. #ifdef GNOME_GRAPHICS 126. { &Gnome_procs, 0 CHAINR(0) }, 127. #endif 128. #ifdef MSWIN_GRAPHICS 129. { &mswin_procs, 0 CHAINR(0) }, 130. #endif 131. #ifdef WINCHAIN 132. { &chainin_procs, chainin_procs_init, chainin_procs_chain }, 133. { (struct window_procs *) &chainout_procs, chainout_procs_init, 134. chainout_procs_chain }, 135. 136. { (struct window_procs *) &trace_procs, trace_procs_init, 137. trace_procs_chain }, 138. #endif 139. { 0, 0 CHAINR(0) } /* must be last */ 140. }; 141. 142. #ifdef WINCHAIN 143. struct winlink { 144. struct winlink *nextlink; 145. struct win_choices *wincp; 146. void *linkdata; 147. }; 148. /* NB: this chain does not contain the terminal real window system pointer */ 149. 150. static struct winlink *chain = 0; 151. 152. static struct winlink * 153. wl_new() 154. { 155. struct winlink *wl = (struct winlink *) alloc(sizeof *wl); 156. 157. wl->nextlink = 0; 158. wl->wincp = 0; 159. wl->linkdata = 0; 160. 161. return wl; 162. } 163. 164. static void 165. wl_addhead(struct winlink *wl) 166. { 167. wl->nextlink = chain; 168. chain = wl; 169. } 170. 171. static void 172. wl_addtail(struct winlink *wl) 173. { 174. struct winlink *p = chain; 175. 176. if (!chain) { 177. chain = wl; 178. return; 179. } 180. while (p->nextlink) { 181. p = p->nextlink; 182. } 183. p->nextlink = wl; 184. return; 185. } 186. #endif /* WINCHAIN */ 187. 188. static struct win_choices *last_winchoice = 0; 189. 190. boolean 191. genl_can_suspend_no(VOID_ARGS) 192. { 193. return FALSE; 194. } 195. 196. boolean 197. genl_can_suspend_yes(VOID_ARGS) 198. { 199. return TRUE; 200. } 201. 202. STATIC_OVL 203. void 204. def_raw_print(s) 205. const char *s; 206. { 207. puts(s); 208. } 209. 210. STATIC_OVL 211. void 212. def_wait_synch(VOID_ARGS) 213. { 214. /* Config file error handling routines 215. * call wait_sync() without checking to 216. * see if it actually has a value, 217. * leading to spectacular violations 218. * when you try to execute address zero. 219. * The existence of this allows early 220. * processing to have something to execute 221. * even though it essentially does nothing 222. */ 223. return; 224. } 225. 226. #ifdef WINCHAIN 227. static struct win_choices * 228. win_choices_find(s) 229. const char *s; 230. { 231. register int i; 232. 233. for (i = 0; winchoices[i].procs; i++) { 234. if (!strcmpi(s, winchoices[i].procs->name)) { 235. return &winchoices[i]; 236. } 237. } 238. return (struct win_choices *) 0; 239. } 240. #endif 241. 242. void 243. choose_windows(s) 244. const char *s; 245. { 246. register int i; 247. 248. for (i = 0; winchoices[i].procs; i++) { 249. if ('+' == winchoices[i].procs->name[0]) 250. continue; 251. if ('-' == winchoices[i].procs->name[0]) 252. continue; 253. if (!strcmpi(s, winchoices[i].procs->name)) { 254. windowprocs = *winchoices[i].procs; 255. 256. if (last_winchoice && last_winchoice->ini_routine) 257. (*last_winchoice->ini_routine)(WININIT_UNDO); 258. if (winchoices[i].ini_routine) 259. (*winchoices[i].ini_routine)(WININIT); 260. last_winchoice = &winchoices[i]; 261. return; 262. } 263. } 264. 265. if (!windowprocs.win_raw_print) 266. windowprocs.win_raw_print = def_raw_print; 267. if (!windowprocs.win_wait_synch) 268. /* early config file error processing routines call this */ 269. windowprocs.win_wait_synch = def_wait_synch; 270. 271. if (!winchoices[0].procs) { 272. raw_printf("No window types?"); 273. nh_terminate(EXIT_FAILURE); 274. } 275. if (!winchoices[1].procs) { 276. config_error_add( 277. "Window type %s not recognized. The only choice is: %s", 278. s, winchoices[0].procs->name); 279. } else { 280. char buf[BUFSZ]; 281. boolean first = TRUE; 282. 283. buf[0] = '\0'; 284. for (i = 0; winchoices[i].procs; i++) { 285. if ('+' == winchoices[i].procs->name[0]) 286. continue; 287. if ('-' == winchoices[i].procs->name[0]) 288. continue; 289. Sprintf(eos(buf), "%s%s", 290. first ? "" : ", ", winchoices[i].procs->name); 291. first = FALSE; 292. } 293. config_error_add("Window type %s not recognized. Choices are: %s", 294. s, buf); 295. } 296. 297. if (windowprocs.win_raw_print == def_raw_print 298. || WINDOWPORT("safe-startup")) 299. nh_terminate(EXIT_SUCCESS); 300. } 301. 302. #ifdef WINCHAIN 303. void 304. addto_windowchain(s) 305. const char *s; 306. { 307. register int i; 308. 309. for (i = 0; winchoices[i].procs; i++) { 310. if ('+' != winchoices[i].procs->name[0]) 311. continue; 312. if (!strcmpi(s, winchoices[i].procs->name)) { 313. struct winlink *p = wl_new(); 314. 315. p->wincp = &winchoices[i]; 316. wl_addtail(p); 317. /* NB: The ini_routine() will be called during commit. */ 318. return; 319. } 320. } 321. 322. windowprocs.win_raw_print = def_raw_print; 323. 324. raw_printf("Window processor %s not recognized. Choices are:", s); 325. for (i = 0; winchoices[i].procs; i++) { 326. if ('+' != winchoices[i].procs->name[0]) 327. continue; 328. raw_printf(" %s", winchoices[i].procs->name); 329. } 330. 331. nh_terminate(EXIT_FAILURE); 332. } 333. 334. void 335. commit_windowchain() 336. { 337. struct winlink *p; 338. int n; 339. int wincap, wincap2; 340. 341. if (!chain) 342. return; 343. 344. /* Save wincap* from the real window system - we'll restore it below. */ 345. wincap = windowprocs.wincap; 346. wincap2 = windowprocs.wincap2; 347. 348. /* add -chainin at head and -chainout at tail */ 349. p = wl_new(); 350. p->wincp = win_choices_find("-chainin"); 351. if (!p->wincp) { 352. raw_printf("Can't locate processor '-chainin'"); 353. exit(EXIT_FAILURE); 354. } 355. wl_addhead(p); 356. 357. p = wl_new(); 358. p->wincp = win_choices_find("-chainout"); 359. if (!p->wincp) { 360. raw_printf("Can't locate processor '-chainout'"); 361. exit(EXIT_FAILURE); 362. } 363. wl_addtail(p); 364. 365. /* Now alloc() init() similar to Objective-C. */ 366. for (n = 1, p = chain; p; n++, p = p->nextlink) { 367. p->linkdata = (*p->wincp->chain_routine)(WINCHAIN_ALLOC, n, 0, 0, 0); 368. } 369. 370. for (n = 1, p = chain; p; n++, p = p->nextlink) { 371. if (p->nextlink) { 372. (void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata, 373. p->nextlink->wincp->procs, 374. p->nextlink->linkdata); 375. } else { 376. (void) (*p->wincp->chain_routine)(WINCHAIN_INIT, n, p->linkdata, 377. last_winchoice->procs, 0); 378. } 379. } 380. 381. /* Restore the saved wincap* values. We do it here to give the 382. * ini_routine()s a chance to change or check them. */ 383. chain->wincp->procs->wincap = wincap; 384. chain->wincp->procs->wincap2 = wincap2; 385. 386. /* Call the init procs. Do not re-init the terminal real win. */ 387. p = chain; 388. while (p->nextlink) { 389. if (p->wincp->ini_routine) { 390. (*p->wincp->ini_routine)(WININIT); 391. } 392. p = p->nextlink; 393. } 394. 395. /* Install the chain into window procs very late so ini_routine()s 396. * can raw_print on error. */ 397. windowprocs = *chain->wincp->procs; 398. 399. p = chain; 400. while (p) { 401. struct winlink *np = p->nextlink; 402. free(p); 403. p = np; /* assignment, not proof */ 404. } 405. } 406. #endif /* WINCHAIN */ 407. 408. /* 409. * tty_message_menu() provides a means to get feedback from the 410. * --More-- prompt; other interfaces generally don't need that. 411. */ 412. /*ARGSUSED*/ 413. char 414. genl_message_menu(let, how, mesg) 415. char let UNUSED; 416. int how UNUSED; 417. const char *mesg; 418. { 419. pline("%s", mesg); 420. return 0; 421. } 422. 423. /*ARGSUSED*/ 424. void 425. genl_preference_update(pref) 426. const char *pref UNUSED; 427. { 428. /* window ports are expected to provide 429. their own preference update routine 430. for the preference capabilities that 431. they support. 432. Just return in this genl one. */ 433. return; 434. } 435. 436. char * 437. genl_getmsghistory(init) 438. boolean init UNUSED; 439. { 440. /* window ports can provide 441. their own getmsghistory() routine to 442. preserve message history between games. 443. The routine is called repeatedly from 444. the core save routine, and the window 445. port is expected to successively return 446. each message that it wants saved, starting 447. with the oldest message first, finishing 448. with the most recent. 449. Return null pointer when finished. 450. */ 451. return (char *) 0; 452. } 453. 454. void 455. genl_putmsghistory(msg, is_restoring) 456. const char *msg; 457. boolean is_restoring; 458. { 459. /* window ports can provide 460. their own putmsghistory() routine to 461. load message history from a saved game. 462. The routine is called repeatedly from 463. the core restore routine, starting with 464. the oldest saved message first, and 465. finishing with the latest. 466. The window port routine is expected to 467. load the message recall buffers in such 468. a way that the ordering is preserved. 469. The window port routine should make no 470. assumptions about how many messages are 471. forthcoming, nor should it assume that 472. another message will follow this one, 473. so it should keep all pointers/indexes 474. intact at the end of each call. 475. */ 476. 477. /* this doesn't provide for reloading the message window with the 478. previous session's messages upon restore, but it does put the quest 479. message summary lines there by treating them as ordinary messages */ 480. if (!is_restoring) 481. pline("%s", msg); 482. return; 483. } 484. 485. #ifdef HANGUPHANDLING 486. /* 487. * Dummy windowing scheme used to replace current one with no-ops 488. * in order to avoid all terminal I/O after hangup/disconnect. 489. */ 490. 491. static int NDECL(hup_nhgetch); 492. static char FDECL(hup_yn_function, (const char *, const char *, CHAR_P)); 493. static int FDECL(hup_nh_poskey, (int *, int *, int *)); 494. static void FDECL(hup_getlin, (const char *, char *)); 495. static void FDECL(hup_init_nhwindows, (int *, char **)); 496. static void FDECL(hup_exit_nhwindows, (const char *)); 497. static winid FDECL(hup_create_nhwindow, (int)); 498. static int FDECL(hup_select_menu, (winid, int, MENU_ITEM_P **)); 499. static void FDECL(hup_add_menu, (winid, int, const anything *, CHAR_P, CHAR_P, 500. int, const char *, BOOLEAN_P)); 501. static void FDECL(hup_end_menu, (winid, const char *)); 502. static void FDECL(hup_putstr, (winid, int, const char *)); 503. static void FDECL(hup_print_glyph, (winid, XCHAR_P, XCHAR_P, int, int)); 504. static void FDECL(hup_outrip, (winid, int, time_t)); 505. static void FDECL(hup_curs, (winid, int, int)); 506. static void FDECL(hup_display_nhwindow, (winid, BOOLEAN_P)); 507. static void FDECL(hup_display_file, (const char *, BOOLEAN_P)); 508. #ifdef CLIPPING 509. static void FDECL(hup_cliparound, (int, int)); 510. #endif 511. #ifdef CHANGE_COLOR 512. static void FDECL(hup_change_color, (int, long, int)); 513. #ifdef MAC 514. static short FDECL(hup_set_font_name, (winid, char *)); 515. #endif 516. static char *NDECL(hup_get_color_string); 517. #endif /* CHANGE_COLOR */ 518. static void FDECL(hup_status_update, (int, genericptr_t, int, int, int, 519. unsigned long *)); 520. 521. static int NDECL(hup_int_ndecl); 522. static void NDECL(hup_void_ndecl); 523. static void FDECL(hup_void_fdecl_int, (int)); 524. static void FDECL(hup_void_fdecl_winid, (winid)); 525. static void FDECL(hup_void_fdecl_constchar_p, (const char *)); 526. 527. static struct window_procs hup_procs = { 528. "hup", 0L, 0L, 529. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 530. hup_init_nhwindows, 531. hup_void_ndecl, /* player_selection */ 532. hup_void_ndecl, /* askname */ 533. hup_void_ndecl, /* get_nh_event */ 534. hup_exit_nhwindows, hup_void_fdecl_constchar_p, /* suspend_nhwindows */ 535. hup_void_ndecl, /* resume_nhwindows */ 536. hup_create_nhwindow, hup_void_fdecl_winid, /* clear_nhwindow */ 537. hup_display_nhwindow, hup_void_fdecl_winid, /* destroy_nhwindow */ 538. hup_curs, hup_putstr, hup_putstr, /* putmixed */ 539. hup_display_file, hup_void_fdecl_winid, /* start_menu */ 540. hup_add_menu, hup_end_menu, hup_select_menu, genl_message_menu, 541. hup_void_ndecl, /* update_inventory */ 542. hup_void_ndecl, /* mark_synch */ 543. hup_void_ndecl, /* wait_synch */ 544. #ifdef CLIPPING 545. hup_cliparound, 546. #endif 547. #ifdef POSITIONBAR 548. (void FDECL((*), (char *))) hup_void_fdecl_constchar_p, 549. /* update_positionbar */ 550. #endif 551. hup_print_glyph, 552. hup_void_fdecl_constchar_p, /* raw_print */ 553. hup_void_fdecl_constchar_p, /* raw_print_bold */ 554. hup_nhgetch, hup_nh_poskey, hup_void_ndecl, /* nhbell */ 555. hup_int_ndecl, /* doprev_message */ 556. hup_yn_function, hup_getlin, hup_int_ndecl, /* get_ext_cmd */ 557. hup_void_fdecl_int, /* number_pad */ 558. hup_void_ndecl, /* delay_output */ 559. #ifdef CHANGE_COLOR 560. hup_change_color, 561. #ifdef MAC 562. hup_void_fdecl_int, /* change_background */ 563. hup_set_font_name, 564. #endif 565. hup_get_color_string, 566. #endif /* CHANGE_COLOR */ 567. hup_void_ndecl, /* start_screen */ 568. hup_void_ndecl, /* end_screen */ 569. hup_outrip, genl_preference_update, genl_getmsghistory, 570. genl_putmsghistory, 571. hup_void_ndecl, /* status_init */ 572. hup_void_ndecl, /* status_finish */ 573. genl_status_enablefield, hup_status_update, 574. genl_can_suspend_no, 575. }; 576. 577. static void FDECL((*previnterface_exit_nhwindows), (const char *)) = 0; 578. 579. /* hangup has occurred; switch to no-op user interface */ 580. void 581. nhwindows_hangup() 582. { 583. char *FDECL((*previnterface_getmsghistory), (BOOLEAN_P)) = 0; 584. 585. #ifdef ALTMETA 586. /* command processor shouldn't look for 2nd char after seeing ESC */ 587. iflags.altmeta = FALSE; 588. #endif 589. 590. /* don't call exit_nhwindows() directly here; if a hangup occurs 591. while interface code is executing, exit_nhwindows could knock 592. the interface's active data structures out from under itself */ 593. if (iflags.window_inited 594. && windowprocs.win_exit_nhwindows != hup_exit_nhwindows) 595. previnterface_exit_nhwindows = windowprocs.win_exit_nhwindows; 596. 597. /* also, we have to leave the old interface's getmsghistory() 598. in place because it will be called while saving the game */ 599. if (windowprocs.win_getmsghistory != hup_procs.win_getmsghistory) 600. previnterface_getmsghistory = windowprocs.win_getmsghistory; 601. 602. windowprocs = hup_procs; 603. 604. if (previnterface_getmsghistory) 605. windowprocs.win_getmsghistory = previnterface_getmsghistory; 606. } 607. 608. static void 609. hup_exit_nhwindows(lastgasp) 610. const char *lastgasp; 611. { 612. /* core has called exit_nhwindows(); call the previous interface's 613. shutdown routine now; xxx_exit_nhwindows() needs to call other 614. xxx_ routines directly rather than through windowprocs pointers */ 615. if (previnterface_exit_nhwindows) { 616. lastgasp = 0; /* don't want exit routine to attempt extra output */ 617. (*previnterface_exit_nhwindows)(lastgasp); 618. previnterface_exit_nhwindows = 0; 619. } 620. iflags.window_inited = 0; 621. } 622. 623. static int 624. hup_nhgetch(VOID_ARGS) 625. { 626. return '\033'; /* ESC */ 627. } 628. 629. /*ARGSUSED*/ 630. static char 631. hup_yn_function(prompt, resp, deflt) 632. const char *prompt UNUSED, *resp UNUSED; 633. char deflt; 634. { 635. if (!deflt) 636. deflt = '\033'; 637. return deflt; 638. } 639. 640. /*ARGSUSED*/ 641. static int 642. hup_nh_poskey(x, y, mod) 643. int *x UNUSED, *y UNUSED, *mod UNUSED; 644. { 645. return '\033'; 646. } 647. 648. /*ARGSUSED*/ 649. static void 650. hup_getlin(prompt, outbuf) 651. const char *prompt UNUSED; 652. char *outbuf; 653. { 654. Strcpy(outbuf, "\033"); 655. } 656. 657. /*ARGSUSED*/ 658. static void 659. hup_init_nhwindows(argc_p, argv) 660. int *argc_p UNUSED; 661. char **argv UNUSED; 662. { 663. iflags.window_inited = 1; 664. } 665. 666. /*ARGUSED*/ 667. static winid 668. hup_create_nhwindow(type) 669. int type UNUSED; 670. { 671. return WIN_ERR; 672. } 673. 674. /*ARGSUSED*/ 675. static int 676. hup_select_menu(window, how, menu_list) 677. winid window UNUSED; 678. int how UNUSED; 679. struct mi **menu_list UNUSED; 680. { 681. return -1; 682. } 683. 684. /*ARGSUSED*/ 685. static void 686. hup_add_menu(window, glyph, identifier, sel, grpsel, attr, txt, preselected) 687. winid window UNUSED; 688. int glyph UNUSED, attr UNUSED; 689. const anything *identifier UNUSED; 690. char sel UNUSED, grpsel UNUSED; 691. const char *txt UNUSED; 692. boolean preselected UNUSED; 693. { 694. return; 695. } 696. 697. /*ARGSUSED*/ 698. static void 699. hup_end_menu(window, prompt) 700. winid window UNUSED; 701. const char *prompt UNUSED; 702. { 703. return; 704. } 705. 706. /*ARGSUSED*/ 707. static void 708. hup_putstr(window, attr, text) 709. winid window UNUSED; 710. int attr UNUSED; 711. const char *text UNUSED; 712. { 713. return; 714. } 715. 716. /*ARGSUSED*/ 717. static void 718. hup_print_glyph(window, x, y, glyph, bkglyph) 719. winid window UNUSED; 720. xchar x UNUSED, y UNUSED; 721. int glyph UNUSED; 722. int bkglyph UNUSED; 723. { 724. return; 725. } 726. 727. /*ARGSUSED*/ 728. static void 729. hup_outrip(tmpwin, how, when) 730. winid tmpwin UNUSED; 731. int how UNUSED; 732. time_t when UNUSED; 733. { 734. return; 735. } 736. 737. /*ARGSUSED*/ 738. static void 739. hup_curs(window, x, y) 740. winid window UNUSED; 741. int x UNUSED, y UNUSED; 742. { 743. return; 744. } 745. 746. /*ARGSUSED*/ 747. static void 748. hup_display_nhwindow(window, blocking) 749. winid window UNUSED; 750. boolean blocking UNUSED; 751. { 752. return; 753. } 754. 755. /*ARGSUSED*/ 756. static void 757. hup_display_file(fname, complain) 758. const char *fname UNUSED; 759. boolean complain UNUSED; 760. { 761. return; 762. } 763. 764. #ifdef CLIPPING 765. /*ARGSUSED*/ 766. static void 767. hup_cliparound(x, y) 768. int x UNUSED, y UNUSED; 769. { 770. return; 771. } 772. #endif 773. 774. #ifdef CHANGE_COLOR 775. /*ARGSUSED*/ 776. static void 777. hup_change_color(color, rgb, reverse) 778. int color, reverse; 779. long rgb; 780. { 781. return; 782. } 783. 784. #ifdef MAC 785. /*ARGSUSED*/ 786. static short 787. hup_set_font_name(window, fontname) 788. winid window; 789. char *fontname; 790. { 791. return 0; 792. } 793. #endif /* MAC */ 794. 795. static char * 796. hup_get_color_string(VOID_ARGS) 797. { 798. return (char *) 0; 799. } 800. #endif /* CHANGE_COLOR */ 801. 802. /*ARGSUSED*/ 803. static void 804. hup_status_update(idx, ptr, chg, pc, color, colormasks) 805. int idx UNUSED; 806. genericptr_t ptr UNUSED; 807. int chg UNUSED, pc UNUSED, color UNUSED; 808. unsigned long *colormasks UNUSED; 809. 810. { 811. return; 812. } 813. 814. /* 815. * Non-specific stubs. 816. */ 817. 818. static int 819. hup_int_ndecl(VOID_ARGS) 820. { 821. return -1; 822. } 823. 824. static void 825. hup_void_ndecl(VOID_ARGS) 826. { 827. return; 828. } 829. 830. /*ARGUSED*/ 831. static void 832. hup_void_fdecl_int(arg) 833. int arg UNUSED; 834. { 835. return; 836. } 837. 838. /*ARGUSED*/ 839. static void 840. hup_void_fdecl_winid(window) 841. winid window UNUSED; 842. { 843. return; 844. } 845. 846. /*ARGUSED*/ 847. static void 848. hup_void_fdecl_constchar_p(string) 849. const char *string UNUSED; 850. { 851. return; 852. } 853. 854. #endif /* HANGUPHANDLING */ 855. 856. 857. /****************************************************************************/ 858. /* genl backward compat stuff */ 859. /****************************************************************************/ 860. 861. const char *status_fieldnm[MAXBLSTATS]; 862. const char *status_fieldfmt[MAXBLSTATS]; 863. char *status_vals[MAXBLSTATS]; 864. boolean status_activefields[MAXBLSTATS]; 865. NEARDATA winid WIN_STATUS; 866. 867. void 868. genl_status_init() 869. { 870. int i; 871. 872. for (i = 0; i < MAXBLSTATS; ++i) { 873. status_vals[i] = (char *) alloc(MAXCO); 874. *status_vals[i] = '\0'; 875. status_activefields[i] = FALSE; 876. status_fieldfmt[i] = (const char *) 0; 877. } 878. /* Use a window for the genl version; backward port compatibility */ 879. WIN_STATUS = create_nhwindow(NHW_STATUS); 880. display_nhwindow(WIN_STATUS, FALSE); 881. } 882. 883. void 884. genl_status_finish() 885. { 886. /* tear down routine */ 887. int i; 888. 889. /* free alloc'd memory here */ 890. for (i = 0; i < MAXBLSTATS; ++i) { 891. if (status_vals[i]) 892. free((genericptr_t) status_vals[i]), status_vals[i] = (char *) 0; 893. } 894. } 895. 896. void 897. genl_status_enablefield(fieldidx, nm, fmt, enable) 898. int fieldidx; 899. const char *nm; 900. const char *fmt; 901. boolean enable; 902. { 903. status_fieldfmt[fieldidx] = fmt; 904. status_fieldnm[fieldidx] = nm; 905. status_activefields[fieldidx] = enable; 906. } 907. 908. /* call once for each field, then call with BL_FLUSH to output the result */ 909. void 910. genl_status_update(idx, ptr, chg, percent, color, colormasks) 911. int idx; 912. genericptr_t ptr; 913. int chg UNUSED, percent UNUSED, color UNUSED; 914. unsigned long *colormasks UNUSED; 915. { 916. char newbot1[MAXCO], newbot2[MAXCO]; 917. long cond, *condptr = (long *) ptr; 918. register int i; 919. unsigned pass, lndelta; 920. enum statusfields idx1, idx2, *fieldlist; 921. char *nb, *text = (char *) ptr; 922. 923. static enum statusfields fieldorder[][15] = { 924. /* line one */ 925. { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, BL_ALIGN, 926. BL_SCORE, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, 927. BL_FLUSH }, 928. /* line two, default order */ 929. { BL_LEVELDESC, BL_GOLD, 930. BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX, BL_AC, 931. BL_XP, BL_EXP, BL_HD, 932. BL_TIME, 933. BL_HUNGER, BL_CAP, BL_CONDITION, 934. BL_FLUSH }, 935. /* move time to the end */ 936. { BL_LEVELDESC, BL_GOLD, 937. BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX, BL_AC, 938. BL_XP, BL_EXP, BL_HD, 939. BL_HUNGER, BL_CAP, BL_CONDITION, 940. BL_TIME, BL_FLUSH }, 941. /* move experience and time to the end */ 942. { BL_LEVELDESC, BL_GOLD, 943. BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX, BL_AC, 944. BL_HUNGER, BL_CAP, BL_CONDITION, 945. BL_XP, BL_EXP, BL_HD, BL_TIME, BL_FLUSH }, 946. /* move level description plus gold and experience and time to end */ 947. { BL_HP, BL_HPMAX, BL_ENE, BL_ENEMAX, BL_AC, 948. BL_HUNGER, BL_CAP, BL_CONDITION, 949. BL_LEVELDESC, BL_GOLD, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_FLUSH }, 950. }; 951. 952. /* in case interface is using genl_status_update() but has not 953. specified WC2_FLUSH_STATUS (status_update() for field values 954. is buffered so final BL_FLUSH is needed to produce output) */ 955. windowprocs.wincap2 |= WC2_FLUSH_STATUS; 956. 957. if (idx >= 0) { 958. if (!status_activefields[idx]) 959. return; 960. switch (idx) { 961. case BL_CONDITION: 962. cond = condptr ? *condptr : 0L; 963. nb = status_vals[idx]; 964. *nb = '\0'; 965. if (cond & BL_MASK_STONE) 966. Strcpy(nb = eos(nb), " Stone"); 967. if (cond & BL_MASK_SLIME) 968. Strcpy(nb = eos(nb), " Slime"); 969. if (cond & BL_MASK_STRNGL) 970. Strcpy(nb = eos(nb), " Strngl"); 971. if (cond & BL_MASK_FOODPOIS) 972. Strcpy(nb = eos(nb), " FoodPois"); 973. if (cond & BL_MASK_TERMILL) 974. Strcpy(nb = eos(nb), " TermIll"); 975. if (cond & BL_MASK_BLIND) 976. Strcpy(nb = eos(nb), " Blind"); 977. if (cond & BL_MASK_DEAF) 978. Strcpy(nb = eos(nb), " Deaf"); 979. if (cond & BL_MASK_STUN) 980. Strcpy(nb = eos(nb), " Stun"); 981. if (cond & BL_MASK_CONF) 982. Strcpy(nb = eos(nb), " Conf"); 983. if (cond & BL_MASK_HALLU) 984. Strcpy(nb = eos(nb), " Hallu"); 985. if (cond & BL_MASK_LEV) 986. Strcpy(nb = eos(nb), " Lev"); 987. if (cond & BL_MASK_FLY) 988. Strcpy(nb = eos(nb), " Fly"); 989. if (cond & BL_MASK_RIDE) 990. Strcpy(nb = eos(nb), " Ride"); 991. break; 992. default: 993. Sprintf(status_vals[idx], 994. status_fieldfmt[idx] ? status_fieldfmt[idx] : "%s", 995. text ? text : ""); 996. break; 997. } 998. return; /* processed one field other than BL_FLUSH */ 999. } /* (idx >= 0, thus not BL_FLUSH, BL_RESET, BL_CHARACTERISTICS) */ 1000. 1001. /* does BL_RESET require any specific code to ensure all fields ? */ 1002. 1003. if (!(idx == BL_FLUSH || idx == BL_RESET)) 1004. return; 1005. 1006. /* We've received BL_FLUSH; time to output the gathered data */ 1007. nb = newbot1; 1008. *nb = '\0'; 1009. /* BL_FLUSH is the only pseudo-index value we need to check for 1010. in the loop below because it is the only entry used to pad the 1011. end of the fieldorder array. We could stop on any 1012. negative (illegal) index, but this should be fine */ 1013. for (i = 0; (idx1 = fieldorder[0][i]) != BL_FLUSH; ++i) { 1014. if (status_activefields[idx1]) 1015. Strcpy(nb = eos(nb), status_vals[idx1]); 1016. } 1017. /* if '$' is encoded, buffer length of \GXXXXNNNN is 9 greater than 1018. single char; we want to subtract that 9 when checking display length */ 1019. lndelta = (status_activefields[BL_GOLD] 1020. && strstr(status_vals[BL_GOLD], "\\G")) ? 9 : 0; 1021. /* basic bot2 formats groups of second line fields into five buffers, 1022. then decides how to order those buffers based on comparing lengths 1023. of [sub]sets of them to the width of the map; we have more control 1024. here but currently emulate that behavior */ 1025. for (pass = 1; pass <= 4; pass++) { 1026. fieldlist = fieldorder[pass]; 1027. nb = newbot2; 1028. *nb = '\0'; 1029. for (i = 0; (idx2 = fieldlist[i]) != BL_FLUSH; ++i) { 1030. if (status_activefields[idx2]) { 1031. const char *val = status_vals[idx2]; 1032. 1033. switch (idx2) { 1034. case BL_HP: /* for pass 4, Hp comes first; mungspaces() 1035. will strip the unwanted leading spaces */ 1036. case BL_XP: case BL_HD: 1037. case BL_TIME: 1038. Strcpy(nb = eos(nb), " "); 1039. break; 1040. case BL_LEVELDESC: 1041. /* leveldesc has no leading space, so if we've moved 1042. it past the first position, provide one */ 1043. if (i != 0) 1044. Strcpy(nb = eos(nb), " "); 1045. break; 1046. /* 1047. * We want " hunger encumbrance conditions" 1048. * or " encumbrance conditions" 1049. * or " hunger conditions" 1050. * or " conditions" 1051. * 'hunger' is either " " or " hunger_text"; 1052. * 'encumbrance' is either " " or " encumbrance_text"; 1053. * 'conditions' is either "" or " cond1 cond2...". 1054. */ 1055. case BL_HUNGER: 1056. /* hunger==" " - keep it, end up with " "; 1057. hunger!=" " - insert space and get " hunger" */ 1058. if (strcmp(val, " ")) 1059. Strcpy(nb = eos(nb), " "); 1060. break; 1061. case BL_CAP: 1062. /* cap==" " - suppress it, retain " hunger" or " "; 1063. cap!=" " - use it, get " hunger cap" or " cap" */ 1064. if (!strcmp(val, " ")) 1065. ++val; 1066. break; 1067. default: 1068. break; 1069. } 1070. Strcpy(nb = eos(nb), val); /* status_vals[idx2] */ 1071. } /* status_activefields[idx2] */ 1072. 1073. if (idx2 == BL_CONDITION && pass < 4 1074. && strlen(newbot2) - lndelta > COLNO) 1075. break; /* switch to next order */ 1076. } /* i */ 1077. 1078. if (idx2 == BL_FLUSH) { /* made it past BL_CONDITION */ 1079. if (pass > 1) 1080. mungspaces(newbot2); 1081. break; 1082. } 1083. } /* pass */ 1084. curs(WIN_STATUS, 1, 0); 1085. putstr(WIN_STATUS, 0, newbot1); 1086. curs(WIN_STATUS, 1, 1); 1087. putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */ 1088. } 1089. 1090. STATIC_VAR struct window_procs dumplog_windowprocs_backup; 1091. STATIC_VAR FILE *dumplog_file; 1092. 1093. #ifdef DUMPLOG 1094. STATIC_VAR time_t dumplog_now; 1095. 1096. char * 1097. dump_fmtstr(fmt, buf, fullsubs) 1098. const char *fmt; 1099. char *buf; 1100. boolean fullsubs; /* True -> full substitution for file name, False -> 1101. * partial substitution for '--showpaths' feedback 1102. * where there's no game in progress when executed */ 1103. { 1104. const char *fp = fmt; 1105. char *bp = buf; 1106. int slen, len = 0; 1107. char tmpbuf[BUFSZ]; 1108. char verbuf[BUFSZ]; 1109. long uid; 1110. time_t now; 1111. 1112. now = dumplog_now; 1113. uid = (long) getuid(); 1114. 1115. /* 1116. * Note: %t and %T assume that time_t is a 'long int' number of 1117. * seconds since some epoch value. That's quite iffy.... The 1118. * unit of time might be different and the datum size might be 1119. * some variant of 'long long int'. [Their main purpose is to 1120. * construct a unique file name rather than record the date and 1121. * time; violating the 'long seconds since base-date' assumption 1122. * may or may not interfere with that usage.] 1123. */ 1124. 1125. while (fp && *fp && len < BUFSZ - 1) { 1126. if (*fp == '%') { 1127. fp++; 1128. switch (*fp) { 1129. default: 1130. goto finish; 1131. case '\0': /* fallthrough */ 1132. case '%': /* literal % */ 1133. Sprintf(tmpbuf, "%%"); 1134. break; 1135. case 't': /* game start, timestamp */ 1136. if (fullsubs) 1137. Sprintf(tmpbuf, "%lu", (unsigned long) ubirthday); 1138. else 1139. Strcpy(tmpbuf, "{game start cookie}"); 1140. break; 1141. case 'T': /* current time, timestamp */ 1142. if (fullsubs) 1143. Sprintf(tmpbuf, "%lu", (unsigned long) now); 1144. else 1145. Strcpy(tmpbuf, "{current time cookie}"); 1146. break; 1147. case 'd': /* game start, YYYYMMDDhhmmss */ 1148. if (fullsubs) 1149. Sprintf(tmpbuf, "%08ld%06ld", 1150. yyyymmdd(ubirthday), hhmmss(ubirthday)); 1151. else 1152. Strcpy(tmpbuf, "{game start date+time}"); 1153. break; 1154. case 'D': /* current time, YYYYMMDDhhmmss */ 1155. if (fullsubs) 1156. Sprintf(tmpbuf, "%08ld%06ld", yyyymmdd(now), hhmmss(now)); 1157. else 1158. Strcpy(tmpbuf, "{current date+time}"); 1159. break; 1160. case 'v': /* version, eg. "3.6.3-0" */ 1161. Sprintf(tmpbuf, "%s", version_string(verbuf)); 1162. break; 1163. case 'u': /* UID */ 1164. Sprintf(tmpbuf, "%ld", uid); 1165. break; 1166. case 'n': /* player name */ 1167. if (fullsubs) 1168. Sprintf(tmpbuf, "%s", *plname ? plname : "unknown"); 1169. else 1170. Strcpy(tmpbuf, "{hero name}"); 1171. break; 1172. case 'N': /* first character of player name */ 1173. if (fullsubs) 1174. Sprintf(tmpbuf, "%c", *plname ? *plname : 'u'); 1175. else 1176. Strcpy(tmpbuf, "{hero initial}"); 1177. break; 1178. } 1179. if (fullsubs) { 1180. /* replace potentially troublesome characters (including 1181. <space> even though it might be an acceptable file name 1182. character); user shouldn't be able to get ' ' or '/' 1183. or '\\' into plname[] but play things safe */ 1184. (void) strNsubst(tmpbuf, " ", "_", 0); 1185. (void) strNsubst(tmpbuf, "/", "_", 0); 1186. (void) strNsubst(tmpbuf, "\\", "_", 0); 1187. /* note: replacements are only done on field substitutions, 1188. not on the template (from sysconf or DUMPLOG_FILE) */ 1189. } 1190. 1191. slen = (int) strlen(tmpbuf); 1192. if (len + slen < BUFSZ - 1) { 1193. len += slen; 1194. Sprintf(bp, "%s", tmpbuf); 1195. bp += slen; 1196. if (*fp) 1197. fp++; 1198. } else 1199. break; 1200. } else { 1201. *bp = *fp; 1202. bp++; 1203. fp++; 1204. len++; 1205. } 1206. } 1207. finish: 1208. *bp = '\0'; 1209. return buf; 1210. } 1211. #endif /* DUMPLOG */ 1212. 1213. void 1214. dump_open_log(now) 1215. time_t now; 1216. { 1217. #ifdef DUMPLOG 1218. char buf[BUFSZ]; 1219. char *fname; 1220. 1221. dumplog_now = now; 1222. #ifdef SYSCF 1223. if (!sysopt.dumplogfile) 1224. return; 1225. fname = dump_fmtstr(sysopt.dumplogfile, buf, TRUE); 1226. #else 1227. fname = dump_fmtstr(DUMPLOG_FILE, buf, TRUE); 1228. #endif 1229. dumplog_file = fopen(fname, "w"); 1230. dumplog_windowprocs_backup = windowprocs; 1231. 1232. #else /*!DUMPLOG*/ 1233. nhUse(now); 1234. #endif /*?DUMPLOG*/ 1235. } 1236. 1237. void 1238. dump_close_log() 1239. { 1240. if (dumplog_file) { 1241. (void) fclose(dumplog_file); 1242. dumplog_file = (FILE *) 0; 1243. } 1244. } 1245. 1246. void 1247. dump_forward_putstr(win, attr, str, no_forward) 1248. winid win; 1249. int attr; 1250. const char *str; 1251. int no_forward; 1252. { 1253. if (dumplog_file) 1254. fprintf(dumplog_file, "%s\n", str); 1255. if (!no_forward) 1256. putstr(win, attr, str); 1257. } 1258. 1259. /*ARGSUSED*/ 1260. STATIC_OVL void 1261. dump_putstr(win, attr, str) 1262. winid win UNUSED; 1263. int attr UNUSED; 1264. const char *str; 1265. { 1266. if (dumplog_file) 1267. fprintf(dumplog_file, "%s\n", str); 1268. } 1269. 1270. STATIC_OVL winid 1271. dump_create_nhwindow(dummy) 1272. int dummy; 1273. { 1274. return dummy; 1275. } 1276. 1277. /*ARGUSED*/ 1278. STATIC_OVL void 1279. dump_clear_nhwindow(win) 1280. winid win UNUSED; 1281. { 1282. return; 1283. } 1284. 1285. /*ARGSUSED*/ 1286. STATIC_OVL void 1287. dump_display_nhwindow(win, p) 1288. winid win UNUSED; 1289. boolean p UNUSED; 1290. { 1291. return; 1292. } 1293. 1294. /*ARGUSED*/ 1295. STATIC_OVL void 1296. dump_destroy_nhwindow(win) 1297. winid win UNUSED; 1298. { 1299. return; 1300. } 1301. 1302. /*ARGUSED*/ 1303. STATIC_OVL void 1304. dump_start_menu(win) 1305. winid win UNUSED; 1306. { 1307. return; 1308. } 1309. 1310. /*ARGSUSED*/ 1311. STATIC_OVL void 1312. dump_add_menu(win, glyph, identifier, ch, gch, attr, str, preselected) 1313. winid win UNUSED; 1314. int glyph; 1315. const anything *identifier UNUSED; 1316. char ch; 1317. char gch UNUSED; 1318. int attr UNUSED; 1319. const char *str; 1320. boolean preselected UNUSED; 1321. { 1322. if (dumplog_file) { 1323. if (glyph == NO_GLYPH) 1324. fprintf(dumplog_file, " %s\n", str); 1325. else 1326. fprintf(dumplog_file, " %c - %s\n", ch, str); 1327. } 1328. } 1329. 1330. /*ARGSUSED*/ 1331. STATIC_OVL void 1332. dump_end_menu(win, str) 1333. winid win UNUSED; 1334. const char *str; 1335. { 1336. if (dumplog_file) { 1337. if (str) 1338. fprintf(dumplog_file, "%s\n", str); 1339. else 1340. fputs("\n", dumplog_file); 1341. } 1342. } 1343. 1344. STATIC_OVL int 1345. dump_select_menu(win, how, item) 1346. winid win UNUSED; 1347. int how UNUSED; 1348. menu_item **item; 1349. { 1350. *item = (menu_item *) 0; 1351. return 0; 1352. } 1353. 1354. void 1355. dump_redirect(onoff_flag) 1356. boolean onoff_flag; 1357. { 1358. if (dumplog_file) { 1359. if (onoff_flag) { 1360. windowprocs.win_create_nhwindow = dump_create_nhwindow; 1361. windowprocs.win_clear_nhwindow = dump_clear_nhwindow; 1362. windowprocs.win_display_nhwindow = dump_display_nhwindow; 1363. windowprocs.win_destroy_nhwindow = dump_destroy_nhwindow; 1364. windowprocs.win_start_menu = dump_start_menu; 1365. windowprocs.win_add_menu = dump_add_menu; 1366. windowprocs.win_end_menu = dump_end_menu; 1367. windowprocs.win_select_menu = dump_select_menu; 1368. windowprocs.win_putstr = dump_putstr; 1369. } else { 1370. windowprocs = dumplog_windowprocs_backup; 1371. } 1372. iflags.in_dumplog = onoff_flag; 1373. } else { 1374. iflags.in_dumplog = FALSE; 1375. } 1376. } 1377. 1378. #ifdef TTY_GRAPHICS 1379. #ifdef TEXTCOLOR 1380. #ifdef TOS 1381. extern const char *hilites[CLR_MAX]; 1382. #else 1383. extern NEARDATA char *hilites[CLR_MAX]; 1384. #endif 1385. #endif 1386. #endif 1387. 1388. int 1389. has_color(color) 1390. int color; 1391. { 1392. return (iflags.use_color && windowprocs.name 1393. && (windowprocs.wincap & WC_COLOR) && windowprocs.has_color[color] 1394. #ifdef TTY_GRAPHICS 1395. #if defined(TEXTCOLOR) && defined(TERMLIB) && !defined(NO_TERMS) 1396. && (hilites[color] != 0) 1397. #endif 1398. #endif 1399. ); 1400. } 1401. 1402. /*windows.c*/