Source:NetHack 3.6.2/src/mail.c
Jump to navigation
Jump to search
Below is the full text to mail.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/mail.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 mail.c $NHDT-Date: 1545597424 2018/12/23 20:37:04 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.39 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. #ifdef MAIL 9. #ifdef SIMPLE_MAIL 10. # include <fcntl.h> 11. # include <errno.h> 12. #endif /* SIMPLE_MAIL */ 13. #include "mail.h" 14. 15. /* 16. * Notify user when new mail has arrived. Idea by Merlyn Leroy. 17. * 18. * The mail daemon can move with less than usual restraint. It can: 19. * - move diagonally from a door 20. * - use secret and closed doors 21. * - run through a monster ("Gangway!", etc.) 22. * - run over pools & traps 23. * 24. * Possible extensions: 25. * - Open the file MAIL and do fstat instead of stat for efficiency. 26. * (But sh uses stat, so this cannot be too bad.) 27. * - Examine the mail and produce a scroll of mail named "From somebody". 28. * - Invoke MAILREADER in such a way that only this single mail is read. 29. * - Do something to the text when the scroll is enchanted or cancelled. 30. * - Make the daemon always appear at a stairwell, and have it find a 31. * path to the hero. 32. * 33. * Note by Olaf Seibert: On the Amiga, we usually don't get mail. So we go 34. * through most of the effects at 'random' moments. 35. * Note by Paul Winner: The MSDOS port also 'fakes' the mail daemon at 36. * random intervals. 37. */ 38. 39. STATIC_DCL boolean FDECL(md_start, (coord *)); 40. STATIC_DCL boolean FDECL(md_stop, (coord *, coord *)); 41. STATIC_DCL boolean FDECL(md_rush, (struct monst *, int, int)); 42. STATIC_DCL void FDECL(newmail, (struct mail_info *)); 43. 44. extern char *viz_rmin, *viz_rmax; /* line-of-sight limits (vision.c) */ 45. 46. #if !defined(UNIX) && !defined(VMS) 47. int mustgetmail = -1; 48. #endif 49. 50. #ifdef UNIX 51. #include <sys/stat.h> 52. #include <pwd.h> 53. /* DON'T trust all Unices to declare getpwuid() in <pwd.h> */ 54. #if !defined(_BULL_SOURCE) && !defined(__sgi) && !defined(_M_UNIX) 55. #if !defined(SUNOS4) && !(defined(ULTRIX) && defined(__GNUC__)) 56. /* DO trust all SVR4 to typedef uid_t in <sys/types.h> (probably to a long) */ 57. #if defined(POSIX_TYPES) || defined(SVR4) || defined(HPUX) 58. extern struct passwd *FDECL(getpwuid, (uid_t)); 59. #else 60. extern struct passwd *FDECL(getpwuid, (int)); 61. #endif 62. #endif 63. #endif 64. static struct stat omstat, nmstat; 65. static char *mailbox = (char *) 0; 66. static long laststattime; 67. 68. #if !defined(MAILPATH) && defined(AMS) /* Just a placeholder for AMS */ 69. #define MAILPATH "/dev/null" 70. #endif 71. #if !defined(MAILPATH) && (defined(LINUX) || defined(__osf__)) 72. #define MAILPATH "/var/spool/mail/" 73. #endif 74. #if !defined(MAILPATH) && defined(__FreeBSD__) 75. #define MAILPATH "/var/mail/" 76. #endif 77. #if !defined(MAILPATH) && (defined(BSD) || defined(ULTRIX)) 78. #define MAILPATH "/usr/spool/mail/" 79. #endif 80. #if !defined(MAILPATH) && (defined(SYSV) || defined(HPUX)) 81. #define MAILPATH "/usr/mail/" 82. #endif 83. 84. void 85. free_maildata() 86. { 87. if (mailbox) 88. free((genericptr_t) mailbox), mailbox = (char *) 0; 89. } 90. 91. void 92. getmailstatus() 93. { 94. if (mailbox) { 95. ; /* no need to repeat the setup */ 96. } else if ((mailbox = nh_getenv("MAIL")) != 0) { 97. mailbox = dupstr(mailbox); 98. #ifdef MAILPATH 99. } else { 100. #ifdef AMS 101. struct passwd ppasswd; 102. 103. (void) memcpy(&ppasswd, getpwuid(getuid()), sizeof (struct passwd)); 104. if (ppasswd.pw_dir) { 105. /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */ 106. mailbox = (char *) alloc((unsigned) (strlen(ppasswd.pw_dir) 107. + sizeof AMS_MAILBOX)); 108. Strcpy(mailbox, ppasswd.pw_dir); 109. Strcat(mailbox, AMS_MAILBOX); 110. } 111. #else 112. const char *pw_name = getpwuid(getuid())->pw_name; 113. 114. /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */ 115. mailbox = (char *) alloc((unsigned) (strlen(pw_name) 116. + sizeof MAILPATH)); 117. Strcpy(mailbox, MAILPATH); 118. Strcat(mailbox, pw_name); 119. #endif /* AMS */ 120. #endif /* MAILPATH */ 121. } 122. 123. debugpline3("mailbox=%c%s%c", 124. mailbox ? '\"' : '<', 125. mailbox ? mailbox : "null", 126. mailbox ? '\"' : '>'); 127. 128. if (mailbox && stat(mailbox, &omstat)) { 129. #ifdef PERMANENT_MAILBOX 130. pline("Cannot get status of MAIL=\"%s\".", mailbox); 131. free_maildata(); /* set 'mailbox' to Null */ 132. #else 133. omstat.st_mtime = 0; 134. #endif 135. } 136. } 137. #endif /* UNIX */ 138. 139. /* 140. * Pick coordinates for a starting position for the mail daemon. Called 141. * from newmail() and newphone(). 142. */ 143. STATIC_OVL boolean 144. md_start(startp) 145. coord *startp; 146. { 147. coord testcc; /* scratch coordinates */ 148. int row; /* current row we are checking */ 149. int lax; /* if TRUE, pick a position in sight. */ 150. int dd; /* distance to current point */ 151. int max_distance; /* max distance found so far */ 152. 153. /* 154. * If blind and not telepathic, then it doesn't matter what we pick --- 155. * the hero is not going to see it anyway. So pick a nearby position. 156. */ 157. if (Blind && !Blind_telepat) { 158. if (!enexto(startp, u.ux, u.uy, (struct permonst *) 0)) 159. return FALSE; /* no good positions */ 160. return TRUE; 161. } 162. 163. /* 164. * Arrive at an up or down stairwell if it is in line of sight from the 165. * hero. 166. */ 167. if (couldsee(upstair.sx, upstair.sy)) { 168. startp->x = upstair.sx; 169. startp->y = upstair.sy; 170. return TRUE; 171. } 172. if (couldsee(dnstair.sx, dnstair.sy)) { 173. startp->x = dnstair.sx; 174. startp->y = dnstair.sy; 175. return TRUE; 176. } 177. 178. /* 179. * Try to pick a location out of sight next to the farthest position away 180. * from the hero. If this fails, try again, just picking the farthest 181. * position that could be seen. What we really ought to be doing is 182. * finding a path from a stairwell... 183. * 184. * The arrays viz_rmin[] and viz_rmax[] are set even when blind. These 185. * are the LOS limits for each row. 186. */ 187. lax = 0; /* be picky */ 188. max_distance = -1; 189. retry: 190. for (row = 0; row < ROWNO; row++) { 191. if (viz_rmin[row] < viz_rmax[row]) { 192. /* There are valid positions on this row. */ 193. dd = distu(viz_rmin[row], row); 194. if (dd > max_distance) { 195. if (lax) { 196. max_distance = dd; 197. startp->y = row; 198. startp->x = viz_rmin[row]; 199. 200. } else if (enexto(&testcc, (xchar) viz_rmin[row], row, 201. (struct permonst *) 0) 202. && !cansee(testcc.x, testcc.y) 203. && couldsee(testcc.x, testcc.y)) { 204. max_distance = dd; 205. *startp = testcc; 206. } 207. } 208. dd = distu(viz_rmax[row], row); 209. if (dd > max_distance) { 210. if (lax) { 211. max_distance = dd; 212. startp->y = row; 213. startp->x = viz_rmax[row]; 214. 215. } else if (enexto(&testcc, (xchar) viz_rmax[row], row, 216. (struct permonst *) 0) 217. && !cansee(testcc.x, testcc.y) 218. && couldsee(testcc.x, testcc.y)) { 219. max_distance = dd; 220. *startp = testcc; 221. } 222. } 223. } 224. } 225. 226. if (max_distance < 0) { 227. if (!lax) { 228. lax = 1; /* just find a position */ 229. goto retry; 230. } 231. return FALSE; 232. } 233. 234. return TRUE; 235. } 236. 237. /* 238. * Try to choose a stopping point as near as possible to the starting 239. * position while still adjacent to the hero. If all else fails, try 240. * enexto(). Use enexto() as a last resort because enexto() chooses 241. * its point randomly, which is not what we want. 242. */ 243. STATIC_OVL boolean 244. md_stop(stopp, startp) 245. coord *stopp; /* stopping position (we fill it in) */ 246. coord *startp; /* starting position (read only) */ 247. { 248. int x, y, distance, min_distance = -1; 249. 250. for (x = u.ux - 1; x <= u.ux + 1; x++) 251. for (y = u.uy - 1; y <= u.uy + 1; y++) { 252. if (!isok(x, y) || (x == u.ux && y == u.uy)) 253. continue; 254. 255. if (accessible(x, y) && !MON_AT(x, y)) { 256. distance = dist2(x, y, startp->x, startp->y); 257. if (min_distance < 0 || distance < min_distance 258. || (distance == min_distance && rn2(2))) { 259. stopp->x = x; 260. stopp->y = y; 261. min_distance = distance; 262. } 263. } 264. } 265. 266. /* If we didn't find a good spot, try enexto(). */ 267. if (min_distance < 0 && !enexto(stopp, u.ux, u.uy, &mons[PM_MAIL_DAEMON])) 268. return FALSE; 269. 270. return TRUE; 271. } 272. 273. /* Let the mail daemon have a larger vocabulary. */ 274. static NEARDATA const char *mail_text[] = { "Gangway!", "Look out!", 275. "Pardon me!" }; 276. #define md_exclamations() (mail_text[rn2(3)]) 277. 278. /* 279. * Make the mail daemon run through the dungeon. The daemon will run over 280. * any monsters that are in its path, but will replace them later. Return 281. * FALSE if the md gets stuck in a position where there is a monster. Return 282. * TRUE otherwise. 283. */ 284. STATIC_OVL boolean 285. md_rush(md, tx, ty) 286. struct monst *md; 287. register int tx, ty; /* destination of mail daemon */ 288. { 289. struct monst *mon; /* displaced monster */ 290. register int dx, dy; /* direction counters */ 291. int fx = md->mx, fy = md->my; /* current location */ 292. int nfx = fx, nfy = fy, /* new location */ 293. d1, d2; /* shortest distances */ 294. 295. /* 296. * It is possible that the monster at (fx,fy) is not the md when: 297. * the md rushed the hero and failed, and is now starting back. 298. */ 299. if (m_at(fx, fy) == md) { 300. remove_monster(fx, fy); /* pick up from orig position */ 301. newsym(fx, fy); 302. } 303. 304. /* 305. * At the beginning and exit of this loop, md is not placed in the 306. * dungeon. 307. */ 308. while (1) { 309. /* Find a good location next to (fx,fy) closest to (tx,ty). */ 310. d1 = dist2(fx, fy, tx, ty); 311. for (dx = -1; dx <= 1; dx++) 312. for (dy = -1; dy <= 1; dy++) 313. if ((dx || dy) && isok(fx + dx, fy + dy) 314. && !IS_STWALL(levl[fx + dx][fy + dy].typ)) { 315. d2 = dist2(fx + dx, fy + dy, tx, ty); 316. if (d2 < d1) { 317. d1 = d2; 318. nfx = fx + dx; 319. nfy = fy + dy; 320. } 321. } 322. 323. /* Break if the md couldn't find a new position. */ 324. if (nfx == fx && nfy == fy) 325. break; 326. 327. fx = nfx; /* this is our new position */ 328. fy = nfy; 329. 330. /* Break if the md reaches its destination. */ 331. if (fx == tx && fy == ty) 332. break; 333. 334. if ((mon = m_at(fx, fy)) != 0) /* save monster at this position */ 335. verbalize1(md_exclamations()); 336. else if (fx == u.ux && fy == u.uy) 337. verbalize("Excuse me."); 338. 339. if (mon) 340. remove_monster(fx, fy); 341. place_monster(md, fx, fy); /* put md down */ 342. newsym(fx, fy); /* see it */ 343. flush_screen(0); /* make sure md shows up */ 344. delay_output(); /* wait a little bit */ 345. 346. /* Remove md from the dungeon. Restore original mon, if necessary. */ 347. remove_monster(fx, fy); 348. if (mon) { 349. if ((mon->mx != fx) || (mon->my != fy)) 350. place_worm_seg(mon, fx, fy); 351. else 352. place_monster(mon, fx, fy); 353. } 354. newsym(fx, fy); 355. } 356. 357. /* 358. * Check for a monster at our stopping position (this is possible, but 359. * very unlikely). If one exists, then have the md leave in disgust. 360. */ 361. if ((mon = m_at(fx, fy)) != 0) { 362. remove_monster(fx, fy); 363. place_monster(md, fx, fy); /* display md with text below */ 364. newsym(fx, fy); 365. verbalize("This place's too crowded. I'm outta here."); 366. remove_monster(fx, fy); 367. 368. if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */ 369. place_worm_seg(mon, fx, fy); 370. else 371. place_monster(mon, fx, fy); 372. 373. newsym(fx, fy); 374. return FALSE; 375. } 376. 377. place_monster(md, fx, fy); /* place at final spot */ 378. newsym(fx, fy); 379. flush_screen(0); 380. delay_output(); /* wait a little bit */ 381. 382. return TRUE; 383. } 384. 385. /* Deliver a scroll of mail. */ 386. /*ARGSUSED*/ 387. STATIC_OVL void 388. newmail(info) 389. struct mail_info *info; 390. { 391. struct monst *md; 392. coord start, stop; 393. boolean message_seen = FALSE; 394. 395. /* Try to find good starting and stopping places. */ 396. if (!md_start(&start) || !md_stop(&stop, &start)) 397. goto give_up; 398. 399. /* Make the daemon. Have it rush towards the hero. */ 400. if (!(md = makemon(&mons[PM_MAIL_DAEMON], start.x, start.y, NO_MM_FLAGS))) 401. goto give_up; 402. if (!md_rush(md, stop.x, stop.y)) 403. goto go_back; 404. 405. message_seen = TRUE; 406. verbalize("%s, %s! %s.", Hello(md), plname, info->display_txt); 407. 408. if (info->message_typ) { 409. struct obj *obj = mksobj(SCR_MAIL, FALSE, FALSE); 410. 411. if (info->object_nam) 412. obj = oname(obj, info->object_nam); 413. if (info->response_cmd) 414. new_omailcmd(obj, info->response_cmd); 415. 416. if (distu(md->mx, md->my) > 2) 417. verbalize("Catch!"); 418. display_nhwindow(WIN_MESSAGE, FALSE); 419. obj = hold_another_object(obj, "Oops!", (const char *) 0, 420. (const char *) 0); 421. nhUse(obj); 422. } 423. 424. go_back: 425. /* zip back to starting location */ 426. if (!md_rush(md, start.x, start.y)) 427. md->mx = md->my = 0; /* for mongone, md is not on map */ 428. mongone(md); 429. 430. give_up: 431. /* deliver some classes of messages even if no daemon ever shows up */ 432. if (!message_seen && info->message_typ == MSG_OTHER) 433. pline("Hark! \"%s.\"", info->display_txt); 434. } 435. 436. #if !defined(UNIX) && !defined(VMS) 437. 438. void 439. ckmailstatus() 440. { 441. if (u.uswallow || !flags.biff) 442. return; 443. if (mustgetmail < 0) { 444. #if defined(AMIGA) || defined(MSDOS) || defined(TOS) 445. mustgetmail = (moves < 2000) ? (100 + rn2(2000)) : (2000 + rn2(3000)); 446. #endif 447. return; 448. } 449. if (--mustgetmail <= 0) { 450. static struct mail_info deliver = { 451. MSG_MAIL, "I have some mail for you", 0, 0 452. }; 453. newmail(&deliver); 454. mustgetmail = -1; 455. } 456. } 457. 458. /*ARGSUSED*/ 459. void 460. readmail(otmp) 461. struct obj *otmp UNUSED; 462. { 463. static char *junk[] = { 464. NULL, /* placeholder for "Report bugs to <devteam@nethack.org>.", */ 465. "Please disregard previous letter.", "Welcome to NetHack.", 466. #ifdef AMIGA 467. "Only Amiga makes it possible.", "CATS have all the answers.", 468. #endif 469. "This mail complies with the Yendorian Anti-Spam Act (YASA)", 470. "Please find enclosed a small token to represent your Owlbear", 471. "**FR33 P0T10N 0F FULL H34L1NG**", 472. "Please return to sender (Asmodeus)", 473. "Buy a potion of gain level for only $19.99! Guaranteed to be blessed!", 474. "Invitation: Visit the NetHack web site at http://www.nethack.org!" 475. }; 476. 477. /* XXX replace with more general substitution code and add local 478. * contact message. Also use DEVTEAM_URL */ 479. if (junk[0] == NULL) { 480. #define BUGS_FORMAT "Report bugs to <%s>." 481. /* +2 from '%s' suffices as substitute for usual +1 for terminator */ 482. junk[0] = (char *) alloc(strlen(BUGS_FORMAT) + strlen(DEVTEAM_EMAIL)); 483. Sprintf(junk[0], BUGS_FORMAT, DEVTEAM_EMAIL); 484. #undef BUGS_FORMAT 485. } 486. if (Blind) { 487. pline("Unfortunately you cannot see what it says."); 488. } else 489. pline("It reads: \"%s\"", junk[rn2(SIZE(junk))]); 490. } 491. 492. #endif /* !UNIX && !VMS */ 493. 494. #ifdef UNIX 495. 496. void 497. ckmailstatus() 498. { 499. ck_server_admin_msg(); 500. 501. if (!mailbox || u.uswallow || !flags.biff 502. #ifdef MAILCKFREQ 503. || moves < laststattime + MAILCKFREQ 504. #endif 505. ) 506. return; 507. 508. laststattime = moves; 509. if (stat(mailbox, &nmstat)) { 510. #ifdef PERMANENT_MAILBOX 511. pline("Cannot get status of MAIL=\"%s\" anymore.", mailbox); 512. free_maildata(); 513. #else 514. nmstat.st_mtime = 0; 515. #endif 516. } else if (nmstat.st_mtime > omstat.st_mtime) { 517. if (nmstat.st_size) { 518. static struct mail_info deliver = { 519. #ifndef NO_MAILREADER 520. MSG_MAIL, "I have some mail for you", 521. #else 522. /* suppress creation and delivery of scroll of mail */ 523. MSG_OTHER, "You have some mail in the outside world", 524. #endif 525. 0, 0 526. }; 527. newmail(&deliver); 528. } 529. getmailstatus(); /* might be too late ... */ 530. } 531. } 532. 533. #if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG) 534. void 535. read_simplemail(mbox, adminmsg) 536. char *mbox; 537. boolean adminmsg; 538. { 539. FILE* mb = fopen(mbox, "r"); 540. char curline[128], *msg; 541. boolean seen_one_already = FALSE; 542. #ifdef SIMPLE_MAIL 543. struct flock fl = { 0 }; 544. #endif 545. const char *msgfrom = adminmsg 546. ? "The voice of %s booms through the caverns:" 547. : "This message is from '%s'."; 548. 549. if (!mb) 550. goto bail; 551. 552. #ifdef SIMPLE_MAIL 553. fl.l_type = F_RDLCK; 554. fl.l_whence = SEEK_SET; 555. fl.l_start = 0; 556. fl.l_len = 0; 557. errno = 0; 558. #endif 559. 560. /* Allow this call to block. */ 561. if (!adminmsg 562. #ifdef SIMPLE_MAIL 563. && fcntl (fileno (mb), F_SETLKW, &fl) == -1 564. #endif 565. ) 566. goto bail; 567. 568. while (fgets(curline, 128, mb) != NULL) { 569. if (!adminmsg) { 570. #ifdef SIMPLE_MAIL 571. fl.l_type = F_UNLCK; 572. fcntl (fileno(mb), F_UNLCK, &fl); 573. #endif 574. pline("There is a%s message on this scroll.", 575. seen_one_already ? "nother" : ""); 576. } 577. msg = strchr(curline, ':'); 578. 579. if (!msg) 580. goto bail; 581. 582. *msg = '\0'; 583. msg++; 584. msg[strlen(msg) - 1] = '\0'; /* kill newline */ 585. 586. pline(msgfrom, curline); 587. if (adminmsg) 588. verbalize(msg); 589. else 590. pline("It reads: \"%s\".", msg); 591. 592. seen_one_already = TRUE; 593. #ifdef SIMPLE_MAIL 594. errno = 0; 595. if (!adminmsg) { 596. fl.l_type = F_RDLCK; 597. fcntl(fileno(mb), F_SETLKW, &fl); 598. } 599. #endif 600. } 601. 602. #ifdef SIMPLE_MAIL 603. if (!adminmsg) { 604. fl.l_type = F_UNLCK; 605. fcntl(fileno(mb), F_UNLCK, &fl); 606. } 607. #endif 608. fclose(mb); 609. if (adminmsg) 610. display_nhwindow(WIN_MESSAGE, TRUE); 611. else 612. unlink(mailbox); 613. return; 614. bail: 615. /* bail out _professionally_ */ 616. if (!adminmsg) 617. pline("It appears to be all gibberish."); 618. } 619. #endif /* SIMPLE_MAIL */ 620. 621. void 622. ck_server_admin_msg() 623. { 624. #ifdef SERVER_ADMIN_MSG 625. static struct stat ost,nst; 626. static long lastchk = 0; 627. 628. if (moves < lastchk + SERVER_ADMIN_MSG_CKFREQ) return; 629. lastchk = moves; 630. 631. if (!stat(SERVER_ADMIN_MSG, &nst)) { 632. if (nst.st_mtime > ost.st_mtime) 633. read_simplemail(SERVER_ADMIN_MSG, TRUE); 634. ost.st_mtime = nst.st_mtime; 635. } 636. #endif /* SERVER_ADMIN_MSG */ 637. } 638. 639. /*ARGSUSED*/ 640. void 641. readmail(otmp) 642. struct obj *otmp UNUSED; 643. { 644. #ifdef DEF_MAILREADER /* This implies that UNIX is defined */ 645. register const char *mr = 0; 646. #endif /* DEF_MAILREADER */ 647. #ifdef SIMPLE_MAIL 648. read_simplemail(mailbox, FALSE); 649. return; 650. #endif /* SIMPLE_MAIL */ 651. #ifdef DEF_MAILREADER /* This implies that UNIX is defined */ 652. if (iflags.debug_fuzzer) 653. return; 654. display_nhwindow(WIN_MESSAGE, FALSE); 655. if (!(mr = nh_getenv("MAILREADER"))) 656. mr = DEF_MAILREADER; 657. 658. if (child(1)) { 659. (void) execl(mr, mr, (char *) 0); 660. nh_terminate(EXIT_FAILURE); 661. } 662. #else 663. #ifndef AMS /* AMS mailboxes are directories */ 664. display_file(mailbox, TRUE); 665. #endif /* AMS */ 666. #endif /* DEF_MAILREADER */ 667. 668. /* get new stat; not entirely correct: there is a small time 669. window where we do not see new mail */ 670. getmailstatus(); 671. } 672. 673. #endif /* UNIX */ 674. 675. #ifdef VMS 676. 677. extern NDECL(struct mail_info *parse_next_broadcast); 678. 679. volatile int broadcasts = 0; 680. 681. void 682. ckmailstatus() 683. { 684. struct mail_info *brdcst; 685. 686. if (iflags.debug_fuzzer) 687. return; 688. if (u.uswallow || !flags.biff) 689. return; 690. 691. while (broadcasts > 0) { /* process all trapped broadcasts [until] */ 692. broadcasts--; 693. if ((brdcst = parse_next_broadcast()) != 0) { 694. newmail(brdcst); 695. break; /* only handle one real message at a time */ 696. } 697. } 698. } 699. 700. void 701. readmail(otmp) 702. struct obj *otmp; 703. { 704. #ifdef SHELL /* can't access mail reader without spawning subprocess */ 705. const char *txt, *cmd; 706. char *p, buf[BUFSZ] = DUMMY, qbuf[BUFSZ]; 707. int len; 708. 709. /* there should be a command in OMAILCMD */ 710. if (has_oname(otmp)) 711. txt = ONAME(otmp); 712. else 713. txt = ""; 714. len = strlen(txt); 715. if (has_omailcmd(otmp)) 716. cmd = OMAILCMD(otmp); 717. if (!cmd || !*cmd) 718. cmd = "SPAWN"; 719. 720. Sprintf(qbuf, "System command (%s)", cmd); 721. getlin(qbuf, buf); 722. if (*buf != '\033') { 723. for (p = eos(buf); p > buf; *p = '\0') 724. if (*--p != ' ') 725. break; /* strip trailing spaces */ 726. if (*buf) 727. cmd = buf; /* use user entered command */ 728. if (!strcmpi(cmd, "SPAWN") || !strcmp(cmd, "!")) 729. cmd = (char *) 0; /* interactive escape */ 730. 731. vms_doshell(cmd, TRUE); 732. (void) sleep(1); 733. } 734. #else 735. nhUse(otmp); 736. #endif /* SHELL */ 737. } 738. 739. #endif /* VMS */ 740. #endif /* MAIL */ 741. 742. /*mail.c*/