Source:NetHack 5.0.0/src/pager.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to pager.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/pager.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	pager.c	$NHDT-Date: 1774846177 2026/03/29 20:49:37 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.296 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2018. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. /*
7.  * This file contains the command routines dowhatis() and dohelp() and
8.  * a few other help related facilities such as data.base lookup.
9.  */
10. 
11. #include "hack.h"
12. #include "dlb.h"
13. 
14. staticfn boolean is_swallow_sym(int);
15. staticfn int append_str(char *, const char *) NONNULLPTRS;
16. staticfn void trap_description(char *, int, coordxy, coordxy) NONNULLARG1;
17. staticfn void look_at_object(char *, coordxy, coordxy, int) NONNULLARG1;
18. staticfn void look_at_monster(char *, char *, struct monst *,
19.                                                coordxy, coordxy) NONNULLARG13;
20. /* lookat() can return Null */
21. staticfn struct permonst *lookat(coordxy, coordxy, char *, char *) NONNULLPTRS;
22. staticfn boolean checkfile(char *, struct permonst *, unsigned,
23.                                                             char *) NO_NNARGS;
24. staticfn int add_cmap_descr(int, int, int, int, coord,
25.                           const char *, const char *,
26.                           boolean *, const char **, char *) NONNULLPTRS;
27. staticfn void look_region_nearby(coordxy *, coordxy *, coordxy *, coordxy *,
28.                                boolean) NONNULLPTRS;
29. staticfn void look_all(boolean, boolean);
30. staticfn void look_traps(boolean);
31. staticfn void look_engrs(boolean);
32. staticfn void do_supplemental_info(char *, struct permonst *,
33.                                                          boolean) NONNULLPTRS;
34. staticfn void whatdoes_help(void);
35. staticfn void docontact(void);
36. staticfn void dispfile_help(void);
37. staticfn void dispfile_shelp(void);
38. staticfn void dispfile_optionfile(void);
39. staticfn void dispfile_optmenu(void);
40. staticfn void dispfile_license(void);
41. staticfn void dispfile_debughelp(void);
42. staticfn void dispfile_usagehelp(void);
43. staticfn void hmenu_doextversion(void);
44. staticfn void hmenu_dohistory(void);
45. staticfn void hmenu_dowhatis(void);
46. staticfn void hmenu_dowhatdoes(void);
47. staticfn void hmenu_doextlist(void);
48. staticfn void domenucontrols(void);
49. #ifdef PORT_HELP
50. extern void port_help(void);
51. #endif
52. staticfn char *setopt_cmd(char *) NONNULL NONNULLARG1;
53. staticfn boolean add_quoted_engraving(coordxy, coordxy, char *, boolean)
54.                                                                   NONNULLARG3;
55. 
56. enum checkfileflags {
57.     chkfilNone     = 0,
58.     chkfilUsrTyped = 1,
59.     chkfilDontAsk  = 2,
60.     chkfilIaCheck  = 4,
61. };
62. 
63. static const char invisexplain[] = "remembered, unseen, creature",
64.            altinvisexplain[] = "unseen creature"; /* for clairvoyance */
65. 
66. /* Returns "true" for characters that could represent a monster's stomach. */
67. staticfn boolean
68. is_swallow_sym(int c)
69. {
70.     int i;
71. 
72.     for (i = S_sw_tl; i <= S_sw_br; i++)
73.         if ((int) gs.showsyms[i] == c)
74.             return TRUE;
75.     return FALSE;
76. }
77. 
78. /* Append " or "+new_str to the end of buf if new_str doesn't already exist
79.    as a substring of buf.  Return 1 if the string was appended, 0 otherwise.
80.    It is expected that buf is of size BUFSZ. */
81. staticfn int
82. append_str(char *buf, const char *new_str)
83. {
84.     static const char sep[] = " or ";
85.     size_t oldlen, space_left;
86. 
87.     if (strstri(buf, new_str))
88.         return 0; /* already present */
89. 
90.     oldlen = strlen(buf);
91.     if (oldlen >= BUFSZ - 1) {
92.         if (oldlen > BUFSZ - 1)
93.             impossible("append_str: 'buf' contains %lu characters.",
94.                        (unsigned long) oldlen);
95.         return 0; /* no space available */
96.     }
97. 
98.     /* some space available, but not necessarily enough for full append */
99.     space_left = BUFSZ - 1 - oldlen;  /* space remaining in buf */
100.     (void) strncat(buf, sep, space_left);
101.     if (space_left > sizeof sep - 1)
102.         (void) strncat(buf, new_str, space_left - (sizeof sep - 1));
103.     return 1; /* something was appended, possibly just part of " or " */
104. }
105. 
106. /* shared by monster probing (via query_objlist!) as well as lookat() */
107. char *
108. self_lookat(char *outbuf)
109. {
110.     char race[QBUFSZ], trapbuf[QBUFSZ];
111. 
112.     /* include race with role unless polymorphed */
113.     race[0] = '\0';
114.     if (!Upolyd)
115.         Sprintf(race, "%s ", gu.urace.adj);
116.     Sprintf(outbuf, "%s%s%s called %s",
117.             /* being blinded may hide invisibility from self */
118.             (Invis && (senseself() || !Blind)) ? "invisible " : "", race,
119.             pmname(&mons[u.umonnum], Ugender), svp.plname);
120.     if (u.usteed)
121.         Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed));
122.     if (u.uundetected || (Upolyd && U_AP_TYPE)
123.         || visible_region_at(u.ux, u.uy))
124.         mhidden_description(&gy.youmonst,
125.                             MHID_PREFIX | MHID_ARTICLE | MHID_REGION,
126.                             eos(outbuf));
127.     if (Punished)
128.         Sprintf(eos(outbuf), ", chained to %s",
129.                 uball ? ansimpleoname(uball) : "nothing?");
130.     if (u.utrap) /* bear trap, pit, web, in-floor, in-lava, tethered */
131.         Sprintf(eos(outbuf), ", %s", trap_predicament(trapbuf, 0, FALSE));
132.     return outbuf;
133. }
134. 
135. /* format a description of 'mon's health for look_at_monster(), done_in_by();
136.    result isn't Healer-specific (not trained for arbitrary creatures) */
137. char *
138. monhealthdescr(struct monst *mon, boolean addspace, char *outbuf)
139. {
140. #if 0   /* [disable this for the time being] */
141.     int mhp_max = max(mon->mhpmax, 1), /* bullet proofing */
142.         pct = (mon->mhp * 100) / mhp_max;
143. 
144.     if (mon->mhp >= mhp_max)
145.         Strcpy(outbuf, "uninjured");
146.     else if (mon->mhp <= 1 || pct < 5)
147.         Sprintf(outbuf, "%s%s", (mon->mhp > 0) ? "nearly " : "",
148.                 !nonliving(mon->data) ? "deceased" : "defunct");
149.     else
150.         Sprintf(outbuf, "%swounded",
151.                 (pct >= 95) ? "barely "
152.                 : (pct >= 80) ? "slightly "
153.                   : (pct < 20) ? "heavily "
154.                     : "");
155.     if (addspace)
156.         (void) strkitten(outbuf, ' ');
157. #else
158.     nhUse(mon);
159.     nhUse(addspace);
160.     *outbuf = '\0';
161. #endif
162.     return outbuf;
163. }
164. 
165. /* copy a trap's description into outbuf[] */
166. staticfn void
167. trap_description(char *outbuf, int tnum, coordxy x, coordxy y)
168. {
169.     /*
170.      * Trap detection used to display a bear trap at locations having
171.      * a trapped door or trapped container or both.  They're semi-real
172.      * traps now (defined trap types but not part of ftrap chain).
173.      */
174.     if (trapped_chest_at(tnum, x, y))
175.         Strcpy(outbuf, "trapped chest"); /* might actually be a large box */
176.     else if (trapped_door_at(tnum, x, y))
177.         Strcpy(outbuf, "trapped door"); /* not "trap door"... */
178.     else
179.         Strcpy(outbuf, trapname(tnum, FALSE));
180.     return;
181. }
182. 
183. /* describe a hidden monster; used for look_at during extended monster
184.    detection and for probing; also when looking at self and camera feedback */
185. void
186. mhidden_description(
187.     struct monst *mon,   /* hidden monster to describe */
188.     unsigned mhid_flags, /* controls optional aspects of description */
189.     char *outbuf)        /* output buffer */
190. {
191.     struct obj *otmp;
192.     const char *what;
193.     NhRegion *reg;
194.     size_t buflen;
195.     boolean incl_prefix = (mhid_flags & MHID_PREFIX) != 0,
196.             incl_article = (mhid_flags & MHID_ARTICLE) != 0,
197.             show_altmon = (mhid_flags & MHID_ALTMON) != 0,
198.             force_region = (mhid_flags & MHID_REGION) != 0;
199.     boolean fakeobj, isyou = (mon == &gy.youmonst);
200.     coordxy x = isyou ? u.ux : mon->mx, y = isyou ? u.uy : mon->my;
201.     int glyph = (svl.level.flags.hero_memory && !isyou) ? levl[x][y].glyph
202.                                                        : glyph_at(x, y);
203. 
204.     *outbuf = '\0';
205.     if (M_AP_TYPE(mon) == M_AP_FURNITURE
206.         || M_AP_TYPE(mon) == M_AP_OBJECT) {
207.         if (incl_prefix)
208.             Strcpy(outbuf, ", mimicking ");
209.         if (M_AP_TYPE(mon) == M_AP_FURNITURE) {
210.             what = defsyms[mon->mappearance].explanation;
211.             if (incl_article)
212.                 what = an(what);
213.             Strcat(outbuf, what);
214.         } else if (M_AP_TYPE(mon) == M_AP_OBJECT
215.                    /* remembered glyph, not glyph_at() which is 'mon' */
216.                    && glyph_is_object(glyph)) {
217.  objfrommap:
218.             otmp = (struct obj *) 0;
219.             fakeobj = object_from_map(glyph, x, y, &otmp);
220.             what = (otmp && otmp->otyp != STRANGE_OBJECT)
221.                    ? simpleonames(otmp)
222.                    : obj_descr[STRANGE_OBJECT].oc_name;
223.             if (incl_article && (!otmp || otmp->quan == 1L))
224.                 what = an(what);
225.             Strcat(outbuf, what);
226. 
227.             if (fakeobj && otmp) {
228.                 otmp->where = OBJ_FREE; /* object_from_map set to OBJ_FLOOR */
229.                 dealloc_obj(otmp); /* has no contents */
230.             }
231.         } else {
232.             Strcat(outbuf, something);
233.         }
234.     } else if (M_AP_TYPE(mon) == M_AP_MONSTER) {
235.         if (show_altmon) {
236.             if (incl_prefix)
237.                 Strcat(outbuf, ", masquerading as ");
238.             what = pmname(&mons[mon->mappearance], Mgender(mon));
239.             if (incl_prefix)
240.                 what = an(what);
241.             Strcat(outbuf, what);
242.         }
243.     } else if (isyou ? u.uundetected : mon->mundetected) {
244.         Strcpy(outbuf, ", hiding");
245.         if (hides_under(mon->data)) {
246.             Strcat(outbuf, " under ");
247.             /* remembered glyph, not glyph_at() which is 'mon' */
248.             if (glyph_is_object(glyph))
249.                 goto objfrommap;
250.             Strcat(outbuf, something);
251.         } else if (is_hider(mon->data)) {
252.             Sprintf(eos(outbuf), " on the %s",
253.                     ceiling_hider(mon->data) ? "ceiling"
254.                        : surface(x, y)); /* trapper */
255.         } else {
256.             if (mon->data->mlet == S_EEL && is_pool(x, y))
257.                 Strcat(outbuf, " in murky water");
258.         }
259.     }
260. 
261.     /* FIXME: <x,y> isn't right when looking at long worm tails */
262.     if ((reg = visible_region_at(x, y)) != 0
263.         && (buflen = strlen(outbuf)) < BUFSZ - 1) {
264.         int r = (u.xray_range > 1) ? u.xray_range : 1;
265. 
266.         /* at present, hero must be next to the monster; being able to see
267.            from the hero's spot to the monster's spot would be much better,
268.            but a visible region marks all its spots as can't-be-seen, so
269.            this monster's spot is !cansee and !couldsee [maybe we need an
270.            additional vision bit for "hero's side of edge of gas cloud"?] */
271.         if (distu(x, y) <= r * (r + 1) || force_region) {
272.             int rglyph = reg->glyph;
273.             boolean poison_gas = (glyph_is_cmap(rglyph)
274.                                   && glyph_to_cmap(rglyph) == S_poisoncloud);
275. 
276.             Snprintf(eos(outbuf), BUFSZ - buflen, ", in a cloud of %s",
277.                      poison_gas ? "poison gas" : "vapor");
278.         }
279.     }
280. }
281. 
282. /* extracted from lookat(); also used by namefloorobj() */
283. boolean
284. object_from_map(
285.     int glyph,
286.     coordxy x, coordxy y,
287.     struct obj **obj_p)
288. {
289.     boolean fakeobj = FALSE, mimic_obj = FALSE;
290.     struct monst *mtmp;
291.     struct obj *otmp;
292.     int glyphotyp = glyph_is_object(glyph) ? glyph_to_obj(glyph)
293.                     /* if not an object, probably a detected chest trap */
294.                     : glyph_is_cmap(glyph) /* assume trapped chest|door */
295.                       ? (sobj_at(CHEST, x, y) ? CHEST : LARGE_BOX)
296.                       : STRANGE_OBJECT;
297. 
298.     *obj_p = (struct obj *) 0;
299.     /* TODO: check inside containers in case glyph came from detection */
300.     if ((otmp = sobj_at(glyphotyp, x, y)) == 0)
301.         for (otmp = svl.level.buriedobjlist; otmp; otmp = otmp->nobj)
302.             if (otmp->ox == x && otmp->oy == y && otmp->otyp == glyphotyp)
303.                 break;
304. 
305.     /* there might be a mimic here posing as an object */
306.     mtmp = m_at(x, y);
307.     if (mtmp && is_obj_mappear(mtmp, (unsigned) glyphotyp)) {
308.         otmp = 0;
309.         mimic_obj = TRUE;
310.     } else
311.         mtmp = 0;
312. 
313.     if (!otmp || otmp->otyp != glyphotyp) {
314.         /* this used to exclude STRANGE_OBJECT; now caller deals with it */
315.         if (OBJ_NAME(objects[glyphotyp])) {
316.             /* map shows a regular object, but one that's not actually here */
317.             otmp = mksobj(glyphotyp, FALSE, FALSE);
318.         } else {
319.             /* map shows a non-item that holds an extra object type (shown
320.                on map due to hallucination) for a name which might have been
321.                shuffled into play but wasn't (or was shuffled out of play);
322.                pick another item that is a regular one in same object class */
323.             otmp = mkobj(objects[glyphotyp].oc_class, FALSE);
324.             /* mkobj() doesn't provide any no-init option; however, there
325.                aren't any extra tool items (or statues) so we won't get here
326.                for tools and don't need to check for and delete container
327.                contents or extinguish lights on the temporary object */
328.         }
329.         /* even though we pass False for mksobj()'s 'init' arg, corpse-rot,
330.            egg-hatch, and figurine-transform timers get initialized */
331.         if (otmp->timed)
332.             obj_stop_timers(otmp);
333.         fakeobj = TRUE;
334.         if (otmp->oclass == COIN_CLASS)
335.             otmp->quan = 2L; /* to force pluralization */
336.         else if (otmp->otyp == SLIME_MOLD)
337.             otmp->spe = svc.context.current_fruit; /* give it a type */
338.         if (mtmp && has_mcorpsenm(mtmp)) { /* mimic as corpse/statue */
339.             if (otmp->otyp == SLIME_MOLD)
340.                 /* override svc.context.current_fruit to avoid
341.                      look, use 'O' to make new named fruit, look again
342.                    giving different results when current_fruit changes */
343.                 otmp->spe = MCORPSENM(mtmp);
344.             else
345.                 otmp->corpsenm = MCORPSENM(mtmp);
346.         } else if (otmp->otyp == CORPSE && glyph_is_body(glyph)) {
347.             otmp->corpsenm = glyph_to_body_corpsenm(glyph);
348.         } else if (otmp->otyp == STATUE && glyph_is_statue(glyph)) {
349.             otmp->corpsenm = glyph_to_statue_corpsenm(glyph);
350.         }
351.         if (otmp->otyp == LEASH)
352.             otmp->leashmon = 0;
353.         /* extra fields needed for shop price with doname() formatting */
354.         otmp->where = OBJ_FLOOR;
355.         otmp->ox = x, otmp->oy = y;
356.         otmp->no_charge = (otmp->otyp == STRANGE_OBJECT && costly_spot(x, y));
357.     }
358.     /* if located at adjacent spot, mark it as having been seen up close
359.        (corpse type will be known even if dknown is 0, so we don't need a
360.        touch check for cockatrice corpse--we're looking without touching) */
361.     if (otmp && next2u(x, y) && !Blind && !Hallucination
362.         /* redundant: we only look for an object which matches current
363.            glyph among floor and buried objects; when !Blind, any buried
364.            object's glyph will have been replaced by whatever is present
365.            on the surface as soon as we moved next to its spot */
366.         && (fakeobj || otmp->where == OBJ_FLOOR) /* not buried */
367.         /* terrain mode views what's already known, doesn't learn new stuff */
368.         && !iflags.terrainmode) /* so don't set dknown when in terrain mode */
369.         observe_object(otmp); /* if a pile, clearly see the top item only */
370.     if (fakeobj && mtmp && mimic_obj
371.         && (otmp->dknown || (M_AP_FLAG(mtmp) & M_AP_F_DKNOWN))) {
372.         mtmp->m_ap_type |= M_AP_F_DKNOWN;
373.         observe_object(otmp);
374.     }
375.     *obj_p = otmp;
376.     return fakeobj; /* when True, caller needs to dealloc *obj_p */
377. }
378. 
379. staticfn void
380. look_at_object(
381.     char *buf, /* output buffer */
382.     coordxy x, coordxy y,
383.     int glyph)
384. {
385.     struct obj *otmp = 0;
386.     boolean fakeobj = object_from_map(glyph, x, y, &otmp);
387. 
388.     if (otmp) {
389.         Strcpy(buf, (otmp->otyp != STRANGE_OBJECT)
390.                      ? distant_name(otmp, otmp->dknown ? doname_with_price
391.                                                        : doname_vague_quan)
392.                      : obj_descr[STRANGE_OBJECT].oc_name);
393.         if (fakeobj) {
394.             otmp->where = OBJ_FREE; /* object_from_map set it to OBJ_FLOOR */
395.             dealloc_obj(otmp), otmp = NULL; /* has no contents */
396.         }
397.     } else {
398.         Strcpy(buf, something); /* sanity precaution */
399.     }
400. 
401.     if (otmp && otmp->where == OBJ_BURIED)
402.         Strcat(buf, " (buried)");
403.     /* check TREE before STONE due to level.flags.arboreal */
404.     else if (IS_TREE(levl[x][y].typ))
405.         /* "dangling": "hanging" could imply that it's growing on this tree */
406.         Snprintf(eos(buf), BUFSZ - strlen(buf), " %s in a tree",
407.                  (otmp && is_treefruit(otmp)) ? "dangling" : "stuck");
408.     else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
409.         Strcat(buf, " embedded in stone");
410.     else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
411.         Strcat(buf, " embedded in a wall");
412.     else if (closed_door(x, y))
413.         Strcat(buf, " embedded in a door");
414.     else if (is_pool(x, y))
415.         Strcat(buf, " in water");
416.     else if (is_lava(x, y))
417.         Strcat(buf, " in molten lava"); /* [can this ever happen?] */
418.     return;
419. }
420. 
421. staticfn void
422. look_at_monster(
423.     char *buf, char *monbuf, /* buf: output, monbuf: optional output */
424.     struct monst *mtmp,
425.     coordxy x, coordxy y)
426. {
427.     char *name, monnambuf[BUFSZ], healthbuf[BUFSZ];
428.     boolean accurate = !Hallucination;
429. 
430.     name = (mtmp->data == &mons[PM_COYOTE] && accurate)
431.               ? coyotename(mtmp, monnambuf)
432.               : distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
433.     Sprintf(buf, "%s%s%s%s",
434.             (mtmp->mx != x || mtmp->my != y)
435.                 ? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ")
436.                 : "",
437.             accurate ? monhealthdescr(mtmp, TRUE, healthbuf) : "",
438.             (mtmp->mtame && accurate)
439.                 ? "tame "
440.                 : (mtmp->mpeaceful && accurate)
441.                     ? "peaceful "
442.                     : "",
443.             name);
444.     if (u.ustuck == mtmp) {
445.         if (u.uswallow || iflags.save_uswallow) /* monster detection */
446.             Strcat(buf, digests(mtmp->data) ? ", swallowing you"
447.                                             : ", engulfing you");
448.         else
449.             Strcat(buf, (Upolyd && sticks(gy.youmonst.data))
450.                           ? ", being held" : ", holding you");
451.     }
452.     /* if mtmp isn't able to move (other than because it is a type of
453.        monster that never moves), say so [excerpt from mstatusline() for
454.        stethoscope or wand of probing] */
455.     if (mtmp->mfrozen)
456.         /* unfortunately mfrozen covers temporary sleep and being busy
457.            (donning armor, for instance) as well as paralysis */
458.         Strcat(buf, ", can't move (paralyzed or sleeping or busy)");
459.     else if (mtmp->msleeping)
460.         /* sleeping for an indeterminate duration */
461.         Strcat(buf, ", asleep");
462.     else if ((mtmp->mstrategy & STRAT_WAITMASK) != 0)
463.         /* arbitrary reason why it isn't moving */
464.         Strcat(buf, ", meditating");
465. 
466.     if (mtmp->mleashed)
467.         Strcat(buf, ", leashed to you");
468.     if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
469.         struct trap *t = t_at(mtmp->mx, mtmp->my);
470.         int tt = t ? t->ttyp : NO_TRAP;
471. 
472.         /* newsym lets you know of the trap, so mention it here */
473.         if (tt == BEAR_TRAP || is_pit(tt) || tt == WEB) {
474.             Sprintf(eos(buf), ", trapped in %s", an(trapname(tt, FALSE)));
475.             t->tseen = 1;
476.         }
477.     }
478. 
479.     /* we know the hero sees a monster at this location, but if it's shown
480.        due to persistent monster detection he might remember something else */
481.     if (mtmp->mundetected || M_AP_TYPE(mtmp) || visible_region_at(x, y))
482.         mhidden_description(mtmp, MHID_PREFIX | MHID_ARTICLE | MHID_REGION,
483.                             eos(buf));
484. 
485.     if (monbuf) {
486.         unsigned how_seen = howmonseen(mtmp);
487. 
488.         monbuf[0] = '\0';
489.         if (how_seen != 0 && how_seen != MONSEEN_NORMAL) {
490.             if (how_seen & MONSEEN_NORMAL) {
491.                 Strcat(monbuf, "normal vision");
492.                 how_seen &= ~MONSEEN_NORMAL;
493.                 /* how_seen can't be 0 yet... */
494.                 if (how_seen)
495.                     Strcat(monbuf, ", ");
496.             }
497.             if (how_seen & MONSEEN_SEEINVIS) {
498.                 Strcat(monbuf, "see invisible");
499.                 how_seen &= ~MONSEEN_SEEINVIS;
500.                 if (how_seen)
501.                     Strcat(monbuf, ", ");
502.             }
503.             if (how_seen & MONSEEN_INFRAVIS) {
504.                 Strcat(monbuf, "infravision");
505.                 how_seen &= ~MONSEEN_INFRAVIS;
506.                 if (how_seen)
507.                     Strcat(monbuf, ", ");
508.             }
509.             if (how_seen & MONSEEN_TELEPAT) {
510.                 Strcat(monbuf, "telepathy");
511.                 how_seen &= ~MONSEEN_TELEPAT;
512.                 if (how_seen)
513.                     Strcat(monbuf, ", ");
514.             }
515.             if (how_seen & MONSEEN_XRAYVIS) {
516.                 /* Eyes of the Overworld */
517.                 Strcat(monbuf, "astral vision");
518.                 how_seen &= ~MONSEEN_XRAYVIS;
519.                 if (how_seen)
520.                     Strcat(monbuf, ", ");
521.             }
522.             if (how_seen & MONSEEN_DETECT) {
523.                 Strcat(monbuf, "monster detection");
524.                 how_seen &= ~MONSEEN_DETECT;
525.                 if (how_seen)
526.                     Strcat(monbuf, ", ");
527.             }
528.             if (how_seen & MONSEEN_WARNMON) {
529.                 if (Hallucination) {
530.                     Strcat(monbuf, "paranoid delusion");
531.                 } else {
532.                     unsigned long mW = (svc.context.warntype.obj
533.                                         | svc.context.warntype.polyd),
534.                                   m2 = mtmp->data->mflags2;
535.                     const char *whom = ((mW & M2_HUMAN & m2) ? "human"
536.                                         : (mW & M2_ELF & m2) ? "elf"
537.                                           : (mW & M2_ORC & m2) ? "orc"
538.                                             : (mW & M2_DEMON & m2) ? "demon"
539.                                               : pmname(mtmp->data,
540.                                                        Mgender(mtmp)));
541. 
542.                     Sprintf(eos(monbuf), "warned of %s", makeplural(whom));
543.                 }
544.                 how_seen &= ~MONSEEN_WARNMON;
545.                 if (how_seen)
546.                     Strcat(monbuf, ", ");
547.             }
548.             /* should have used up all the how_seen bits by now */
549.             if (how_seen) {
550.                 impossible("lookat: unknown method of seeing monster");
551.                 Sprintf(eos(monbuf), "(%u)", how_seen);
552.             }
553.         } /* seen by something other than normal vision */
554.     } /* monbuf is non-null */
555. }
556. 
557. /* describe a pool location's contents; might return a static buffer so
558.    caller should use it or copy it before calling waterbody_name() again
559.    [5.0: moved here from mkmaze.c] */
560. const char *
561. waterbody_name(coordxy x, coordxy y)
562. {
563.     static char pooltype[40];
564.     schar ltyp;
565.     boolean hallucinate = Hallucination && !program_state.gameover;
566. 
567.     if (!isok(x, y))
568.         return "drink"; /* should never happen */
569.     ltyp = SURFACE_AT(x, y);
570. 
571.     if (ltyp == LAVAPOOL) {
572.         Snprintf(pooltype, sizeof pooltype, "molten %s", hliquid("lava"));
573.         return pooltype;
574.     } else if (ltyp == ICE) {
575.         if (!hallucinate)
576.             return "ice";
577.         Snprintf(pooltype, sizeof pooltype, "frozen %s", hliquid("water"));
578.         return pooltype;
579.     } else if (ltyp == POOL) {
580.         Snprintf(pooltype, sizeof pooltype, "pool of %s", hliquid("water"));
581.         return pooltype;
582.     } else if (ltyp == MOAT) {
583.         /* a bit of extra flavor over general moat */
584.         if (hallucinate) {
585.             Snprintf(pooltype, sizeof pooltype, "deep %s", hliquid("water"));
586.             return pooltype;
587.         } else if (Is_medusa_level(&u.uz)) {
588.             /* somewhat iffy since ordinary stairs can take you beneath,
589.                but previous generic "water" was rather anti-climactic */
590.             return "shallow sea";
591.         } else if (Is_juiblex_level(&u.uz)) {
592.             return "swamp";
593.         } else if (Role_if(PM_SAMURAI) && Is_qstart(&u.uz)) {
594.             /* samurai quest home level has two isolated moat spots;
595.                they sound silly if farlook describes them as such */
596.             return "pond";
597.         } else {
598.             return "moat";
599.         }
600.     } else if (IS_WATERWALL(ltyp)) {
601.         if (Is_waterlevel(&u.uz))
602.             return "limitless water"; /* even if hallucinating */
603.         Snprintf(pooltype, sizeof pooltype, "wall of %s", hliquid("water"));
604.         return pooltype;
605.     } else if (ltyp == LAVAWALL) {
606.         Snprintf(pooltype, sizeof pooltype, "wall of %s", hliquid("lava"));
607.         return pooltype;
608.     }
609.     /* default; should be unreachable */
610.     return "water"; /* don't hallucinate this as some other liquid */
611. }
612. 
613. char *
614. ice_descr(coordxy x, coordxy y, char *outbuf)
615. {
616.     static const char *const icetyp[] = {
617.         "solid",    /* 0: not melting */
618.         "sturdy",   /* 1: more than 1000 turns left */
619.         "steady",   /* 2: 101..1000 turns left */
620.         "unsteady", /* 3:  51..100 turns left */
621.         "thin",     /* 4:  15..50 turns left */
622.         "slushy",   /* 5:   1..14 turns left; matches Warning on ice */
623.     };
624.     /* same formula as is used in distant_name() for objects */
625.     int r = (u.xray_range > 2) ? u.xray_range : 2,
626.         neardist = (r * r) * 2 - r; /* same as r*r + r*(r-1) */
627. 
628.     iflags.ice_rating = -1; /* secondary output, for 'mention_decor' */
629.     if (SURFACE_AT(x, y) != ICE) {
630.         Sprintf(outbuf, "[ice:%d?]", (int) levl[x][y].typ);
631.     } else if ((distu(x, y) > neardist
632.                 || (!cansee(x, y) && (!u_at(x, y) || Levitation)))
633.                && !gd.decor_levitate_override) { /* probe_decor(pickup.c) */
634.         Strcpy(outbuf, waterbody_name(x, y)); /* "ice" or "frozen <liquid>" */
635.     } else {
636.         long time_left = spot_time_left(x, y, MELT_ICE_AWAY);
637. 
638.         /* other, real ice thickness/strength terminology exists but seems
639.            to be too unfamiliar for nethack's use */
640.         iflags.ice_rating = !time_left ? 0                /* solid */
641.                             : (time_left > 1000L) ? 1     /* sturdy */
642.                               : (time_left > 100L) ? 2    /* steady */
643.                                 : (time_left > 50L) ? 3   /* unsteady */
644.                                   : (time_left > 14L) ? 4 /* thin */
645.                                     : 5;                  /* slushy */
646.         Sprintf(outbuf, "%s %s", icetyp[(int) iflags.ice_rating],
647.                 waterbody_name(x, y));
648.     }
649.     return outbuf;
650. }
651. 
652. /*
653.  * Return the name of the glyph found at (x,y).
654.  * If not hallucinating and the glyph is a monster, also monster data.
655.  */
656. staticfn struct permonst *
657. lookat(coordxy x, coordxy y, char *buf, char *monbuf)
658. {
659.     struct monst *mtmp = (struct monst *) 0;
660.     struct permonst *pm = (struct permonst *) 0;
661.     int glyph;
662. 
663.     buf[0] = monbuf[0] = '\0';
664.     glyph = glyph_at(x, y);
665.     if (u_at(x, y) && canspotself()
666.         && !(iflags.save_uswallow
667.              && glyph == mon_to_glyph(u.ustuck, rn2_on_display_rng))
668.         && (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) {
669.         /* fill in buf[] */
670.         (void) self_lookat(buf);
671. 
672.         /* file lookup can't distinguish between "gnomish wizard" monster
673.            and correspondingly named player character, always picking the
674.            former; force it to find the general "wizard" entry instead */
675.         if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
676.             pm = &mons[PM_WIZARD];
677. 
678.         /* When you see yourself normally, no explanation is appended
679.            (even if you could also see yourself via other means).
680.            Sensing self while blind or swallowed is treated as if it
681.            were by normal vision (cf canseeself()). */
682.         if ((Invisible || u.uundetected) && !Blind
683.             && !(u.uswallow || iflags.save_uswallow)) {
684.             unsigned how = 0;
685. 
686.             if (Infravision)
687.                 how |= 1;
688.             if (Unblind_telepat)
689.                 how |= 2;
690.             if (Detect_monsters)
691.                 how |= 4;
692. 
693.             if (how)
694.                 Sprintf(eos(buf), " [seen: %s%s%s%s%s]",
695.                         (how & 1) ? "infravision" : "",
696.                         /* add comma if telep and infrav */
697.                         ((how & 3) > 2) ? ", " : "",
698.                         (how & 2) ? "telepathy" : "",
699.                         /* add comma if detect and (infrav or telep or both) */
700.                         ((how & 7) > 4) ? ", " : "",
701.                         (how & 4) ? "monster detection" : "");
702.         }
703.     } else if (u.uswallow) {
704.         /* when swallowed, we're only called for spots adjacent to hero,
705.            and blindness doesn't prevent hero from feeling what holds him */
706.         Sprintf(buf, "interior of %s", mon_nam(u.ustuck));
707.         pm = u.ustuck->data;
708.     } else if (glyph_is_monster(glyph)) {
709.         if ((mtmp = m_at(x, y)) != 0) {
710.             look_at_monster(buf, monbuf, mtmp, x, y);
711.             pm = mtmp->data;
712.         } else if (Hallucination) {
713.             /* 'monster' must actually be a statue */
714.             Strcpy(buf, rndmonnam((char *) 0));
715.         }
716.     } else if (glyph_is_object(glyph)) {
717.         look_at_object(buf, x, y, glyph); /* fill in buf[] */
718.     } else if (glyph_is_trap(glyph)) {
719.         int tnum = glyph_to_trap(glyph);
720. 
721.         trap_description(buf, tnum, x, y);
722.     } else if (glyph_is_warning(glyph)) {
723.         int warnindx = glyph_to_warning(glyph);
724. 
725.         Strcpy(buf, def_warnsyms[warnindx].explanation);
726.     } else if (glyph_is_invisible(glyph)) {
727.         Strcpy(buf, invisexplain); /* redundant; handled by caller */
728.     } else if (glyph_is_nothing(glyph)) {
729.         Strcpy(buf, "dark part of a room");
730.     } else if (glyph_is_unexplored(glyph)) {
731.         if (Underwater && !Is_waterlevel(&u.uz)) {
732.             /* "unknown" == previously mapped but not visible when
733.                submerged; better terminology appreciated... */
734.             Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
735.         } else {
736.             Strcpy(buf, "unexplored area");
737.         }
738.     } else if (glyph_is_cmap(glyph)) {
739.         int amsk;
740.         aligntyp algn;
741.         short symidx = glyph_to_cmap(glyph);
742. 
743.         switch (symidx) {
744.         case S_altar:
745.             amsk = altarmask_at(x, y);
746.             algn = Amask2align(amsk & AM_MASK);
747.             Sprintf(buf, "%s %saltar",
748.                     /* like endgame high priests, endgame high altars
749.                        are only recognizable when immediately adjacent */
750.                     (Is_astralevel(&u.uz) && !next2u(x, y)
751.                      && (amsk & AM_SANCTUM))
752.                         ? "aligned"
753.                         : align_str(algn),
754.                     (amsk & AM_SANCTUM) ? "high " : "");
755.             break;
756.         case S_ndoor:
757.             if (is_drawbridge_wall(x, y) >= 0)
758.                 Strcpy(buf, "open drawbridge portcullis");
759.             else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
760.                 Strcpy(buf, "broken door");
761.             else
762.                 Strcpy(buf, "doorway");
763.             break;
764.         case S_cloud:
765.             Strcpy(buf,
766.                    Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
767.             break;
768.         case S_pool:
769.         case S_water: /* was Plane of Water, now that or "wall of water" */
770.         case S_lava:
771.         case S_lavawall:
772.         case S_ice: /* for hallucination; otherwise defsyms[] would be fine */
773.             Strcpy(buf, waterbody_name(x, y));
774.             break;
775.         case S_engroom:
776.         case S_engrcorr:
777.             Strcpy(buf, "engraving");
778.             break;
779.         case S_stone:
780.             if (!levl[x][y].seenv) {
781.                 Strcpy(buf, "unexplored");
782.                 break;
783.             } else if (Underwater && !Is_waterlevel(&u.uz)) {
784.                 /* "unknown" == previously mapped but not visible when
785.                    submerged; better terminology appreciated... */
786.                 Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
787.                 break;
788.             } else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) {
789.                 Strcpy(buf, "stone");
790.                 break;
791.             }
792.             FALLTHROUGH;
793.             /*FALLTHRU*/
794.         default:
795.             Strcpy(buf, defsyms[symidx].explanation);
796.             break;
797.         }
798.     } else { /* not mon, obj, trap, or cmap */
799.         Strcpy(buf, "unexplored area");
800.     }
801.     return (pm && !Hallucination) ? pm : (struct permonst *) 0;
802. }
803. 
804. /* used to decide whether the context-sensitive inventory action menu for
805.    item 'otmp' should include the "/ - look up this item" choice */
806. boolean
807. ia_checkfile(struct obj *otmp)
808. {
809.     char itemnam[BUFSZ];
810. 
811.     /* singular() of xname() of otmp is what "/i" looks up */
812.     Strcpy(itemnam, singular(otmp, xname));
813.     return checkfile(itemnam, (struct permonst *) 0,
814.                      chkfilIaCheck | chkfilDontAsk, (char *) 0);
815. }
816. 
817. /*
818.  * Look in the "data" file for more info.  Called if the user typed in the
819.  * whole name (user_typed_name == TRUE), or we've found a possible match
820.  * with a character/glyph and flags.help is TRUE.
821.  *
822.  * NOTE: when (user_typed_name == FALSE), inp is considered read-only and
823.  *       must not be changed directly, e.g. via lcase(). We want to force
824.  *       lcase() for data.base lookup so that we can have a clean key.
825.  *       Therefore, we create a copy of inp _just_ for data.base lookup.
826.  *
827.  * Returns True if an entry is found, False otherwise.
828.  */
829. staticfn boolean
830. checkfile(
831.     char *inp, /* string to look up */
832.     struct permonst *pm, /* monster type to look up (overrides 'inp') */
833.     unsigned chkflags,
834.     char *supplemental_name)
835. {
836.     dlb *fp;
837.     char buf[BUFSZ], newstr[BUFSZ], givenname[BUFSZ];
838.     char *ep, *dbase_str;
839.     boolean user_typed_name = (chkflags & chkfilUsrTyped) != 0,
840.             without_asking = (chkflags & chkfilDontAsk) != 0,
841.             ia_checking = (chkflags & chkfilIaCheck) != 0;
842.     unsigned long txt_offset = 0L;
843.     winid datawin = WIN_ERR;
844.     boolean res = FALSE;
845. 
846.     fp = dlb_fopen(DATAFILE, "r");
847.     if (!fp) {
848.         pline("Cannot open 'data' file!");
849.         return res;
850.     }
851.     /* If someone passed us garbage, prevent fault. */
852.     if (!inp || strlen(inp) > (BUFSZ - 1)) {
853.         impossible("bad do_look buffer passed (%s)!",
854.                    !inp ? "null" : "too long");
855.         goto checkfile_done;
856.     }
857. 
858.     /* To prevent the need for entries in data.base like *ngel to account
859.      * for Angel and angel, make the lookup string the same for both
860.      * user_typed_name and picked name.
861.      */
862.     if (pm != (struct permonst *) 0 && !user_typed_name)
863.         dbase_str = strcpy(newstr, pm->pmnames[NEUTRAL]);
864.     else
865.         dbase_str = strcpy(newstr, inp);
866.     (void) lcase(dbase_str);
867. 
868.     /*
869.      * TODO:
870.      * The switch from xname() to doname_vague_quan() in look_at_obj()
871.      * had the unintended side-effect of making names picked from
872.      * pointing at map objects become harder to simplify for lookup.
873.      * We should split the prefix and suffix handling used by wish
874.      * parsing and also wizmode monster generation out into separate
875.      * routines and use those routines here.  This currently lacks
876.      * erosion handling and probably lots of other bits and pieces
877.      * that wishing already understands and most of this duplicates
878.      * stuff already done for wish handling or monster generation.
879.      */
880.     if (!strncmp(dbase_str, "interior of ", 12))
881.         dbase_str += 12;
882.     if (!strncmp(dbase_str, "a ", 2))
883.         dbase_str += 2;
884.     else if (!strncmp(dbase_str, "an ", 3))
885.         dbase_str += 3;
886.     else if (!strncmp(dbase_str, "the ", 4))
887.         dbase_str += 4;
888.     else if (!strncmp(dbase_str, "some ", 5))
889.         dbase_str += 5;
890.     else if (digit(*dbase_str)) {
891.         /* remove count prefix ("2 ya") which can come from looking at map */
892.         while (digit(*dbase_str))
893.             ++dbase_str;
894.         if (*dbase_str == ' ')
895.             ++dbase_str;
896.     }
897.     if (!strncmp(dbase_str, "pair of ", 8))
898.         dbase_str += 8;
899.     if (!strncmp(dbase_str, "tame ", 5))
900.         dbase_str += 5;
901.     else if (!strncmp(dbase_str, "peaceful ", 9))
902.         dbase_str += 9;
903.     if (!strncmp(dbase_str, "invisible ", 10))
904.         dbase_str += 10;
905.     if (!strncmp(dbase_str, "saddled ", 8))
906.         dbase_str += 8;
907.     if (!strncmp(dbase_str, "blessed ", 8))
908.         dbase_str += 8;
909.     else if (!strncmp(dbase_str, "uncursed ", 9))
910.         dbase_str += 9;
911.     else if (!strncmp(dbase_str, "cursed ", 7))
912.         dbase_str += 7;
913.     if (!strncmp(dbase_str, "empty ", 6))
914.         dbase_str += 6;
915.     if (!strncmp(dbase_str, "partly used ", 12))
916.         dbase_str += 12;
917.     else if (!strncmp(dbase_str, "partly eaten ", 13))
918.         dbase_str += 13;
919.     if (!strncmp(dbase_str, "statue of ", 10))
920.         dbase_str[6] = '\0';
921.     else if (!strncmp(dbase_str, "figurine of ", 12))
922.         dbase_str[8] = '\0';
923.     /* remove enchantment ("+0 aklys"); [for 3.6.0 and earlier, this wasn't
924.        needed because looking at items on the map used xname() rather than
925.        doname() hence known enchantment was implicitly suppressed] */
926.     if (*dbase_str && strchr("+-", dbase_str[0]) && digit(dbase_str[1])) {
927.         ++dbase_str; /* skip sign */
928.         while (digit(*dbase_str))
929.             ++dbase_str;
930.         if (*dbase_str == ' ')
931.             ++dbase_str;
932.     }
933.     /* "towel", "wet towel", and "moist towel" share one data.base entry;
934.        for "wet towel", we keep prefix so that the prompt will ask about
935.        "wet towel"; for "moist towel", we also want to ask about "wet towel".
936.        (note: strncpy() only terminates output string if the specified
937.        count is bigger than the length of the substring being copied) */
938.     if (!strncmp(dbase_str, "moist towel", 11))
939.         memcpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */
940. 
941.     /* Make sure the name is non-empty. */
942.     if (*dbase_str) {
943.         long pass1offset = -1L;
944.         int chk_skip, pass = 1;
945.         boolean yes_to_moreinfo, found_in_file, pass1found_in_file,
946.                 skipping_entry;
947.         char *sp, *ap, *alt = 0; /* alternate description */
948. 
949.         /* adjust the input to remove "named " and "called " */
950.         if ((ep = strstri(dbase_str, " named ")) != 0) {
951.             alt = ep + 7;
952.             if ((ap = strstri(dbase_str, " called ")) != 0 && ap < ep)
953.                 ep = ap; /* "named" is alt but truncate at "called" */
954.         } else if ((ep = strstri(dbase_str, " called ")) != 0) {
955.             copynchars(givenname, ep + 8, BUFSZ - 1);
956.             alt = givenname;
957.             if (supplemental_name && (sp = strstri(inp, " called ")) != 0)
958.                 copynchars(supplemental_name, sp + 8, BUFSZ - 1);
959.         } else
960.             ep = strstri(dbase_str, ", ");
961.         if (ep && ep > dbase_str)
962.             *ep = '\0';
963.         /* remove article from 'alt' name ("a pair of lenses named
964.            The Eyes of the Overworld" simplified above to "lenses named
965.            The Eyes of the Overworld", now reduced to "The Eyes of the
966.            Overworld", skip "The" as with base name processing) */
967.         if (alt && (!strncmpi(alt, "a ", 2)
968.                     || !strncmpi(alt, "an ", 3)
969.                     || !strncmpi(alt, "the ", 4)))
970.             alt = strchr(alt, ' ') + 1;
971.         /* remove charges or "(lit)" or wizmode "(N aum)" */
972.         if ((ep = strstri(dbase_str, " (")) != 0 && ep > dbase_str)
973.             *ep = '\0';
974.         if (alt && (ap = strstri(alt, " (")) != 0 && ap > alt)
975.             *ap = '\0';
976. 
977.         /* If the object's name matches the player-specified fruitname,
978.            then "fruit" is the alternate description. We do this here so that
979.            if the fruit name is an extant object, looking at the fruit yields
980.            that object's description. */
981.         if (!alt && fruit_from_name(dbase_str, TRUE, (int *) 0))
982.             alt = strcpy(newstr, obj_descr[SLIME_MOLD].oc_name);
983.         /*
984.          * If the object is named, then the name is the alternate description;
985.          * otherwise, the result of makesingular() applied to the name is.
986.          * This isn't strictly optimal, but named objects of interest to the
987.          * user will usually be found under their name, rather than under
988.          * their object type, so looking for a singular form is pointless.
989.          */
990.         else if (!alt)
991.             alt = makesingular(dbase_str);
992. 
993.         pass1found_in_file = FALSE;
994.         for (pass = !strcmp(alt, dbase_str) ? 0 : 1; pass >= 0; --pass) {
995.             found_in_file = skipping_entry = FALSE;
996.             txt_offset = 0L;
997.             if (dlb_fseek(fp, txt_offset, SEEK_SET) < 0 ) {
998.                 impossible("can't get to start of 'data' file");
999.                 goto checkfile_done;
1000.             }
1001.             /* skip first record; read second */
1002.             if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
1003.                 impossible("can't read 'data' file");
1004.                 goto checkfile_done;
1005.             } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1
1006.                        || txt_offset == 0L)
1007.                 goto bad_data_file;
1008. 
1009.             /* look for the appropriate entry */
1010.             while (dlb_fgets(buf, BUFSZ, fp)) {
1011.                 if (*buf == '.')
1012.                     break; /* we passed last entry without success */
1013. 
1014.                 if (digit(*buf)) {
1015.                     /* a number indicates the end of current entry */
1016.                     skipping_entry = FALSE;
1017.                 } else if (!skipping_entry) {
1018.                     if (!(ep = strchr(buf, '\n')))
1019.                         goto bad_data_file;
1020.                     (void) strip_newline((ep > buf) ? ep - 1 : ep);
1021.                     /* if we match a key that begins with "~", skip
1022.                        this entry */
1023.                     chk_skip = (*buf == '~') ? 1 : 0;
1024.                     if ((pass == 0 && pmatch(&buf[chk_skip], dbase_str))
1025.                         || (pass == 1 && alt && pmatch(&buf[chk_skip], alt))) {
1026.                         if (chk_skip) {
1027.                             skipping_entry = TRUE;
1028.                             continue;
1029.                         } else {
1030.                             found_in_file = TRUE;
1031.                             if (pass == 1)
1032.                                 pass1found_in_file = TRUE;
1033.                             break;
1034.                         }
1035.                     }
1036.                 }
1037.             }
1038.             if (found_in_file) {
1039.                 long entry_offset, fseekoffset;
1040.                 int entry_count;
1041.                 int i;
1042. 
1043.                 /* skip over other possible matches for the info */
1044.                 do {
1045.                     if (!dlb_fgets(buf, BUFSZ, fp))
1046.                         goto bad_data_file;
1047.                 } while (!digit(*buf));
1048.                 if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2)
1049.                     goto bad_data_file;
1050.                 fseekoffset = (long) txt_offset + entry_offset;
1051.                 if (pass == 1)
1052.                     pass1offset = fseekoffset;
1053.                 else if (fseekoffset == pass1offset)
1054.                     goto checkfile_done;
1055. 
1056.                 yes_to_moreinfo = FALSE;
1057.                 if (!user_typed_name && !without_asking) {
1058.                     char *entrytext = pass ? alt : dbase_str;
1059.                     char question[QBUFSZ];
1060. 
1061.                     Strcpy(question, "More info about \"");
1062.                     /* +2 => length of "\"?" */
1063.                     copynchars(eos(question), entrytext,
1064.                                (int) (sizeof question - 1
1065.                                       - (strlen(question) + 2)));
1066.                     Strcat(question, "\"?");
1067.                     if (y_n(question) == 'y')
1068.                         yes_to_moreinfo = TRUE;
1069.                 }
1070. 
1071.                 if (user_typed_name || without_asking || yes_to_moreinfo) {
1072.                     if (dlb_fseek(fp, fseekoffset, SEEK_SET) < 0) {
1073.                         pline("? Seek error on 'data' file!");
1074.                         goto checkfile_done;
1075.                     }
1076.                     res = TRUE;
1077.                     if (ia_checking)
1078.                         goto checkfile_done;
1079. 
1080.                     datawin = create_nhwindow(NHW_MENU);
1081.                     for (i = 0; i < entry_count; i++) {
1082.                         /* room for 1-tab or 8-space prefix + BUFSZ-1 + \0 */
1083.                         char tabbuf[BUFSZ + 8], *tp;
1084. 
1085.                         if (!dlb_fgets(tabbuf, BUFSZ, fp))
1086.                             goto bad_data_file;
1087.                         tp = tabbuf;
1088.                         if (!strchr(tp, '\n'))
1089.                             goto bad_data_file;
1090.                         (void) strip_newline(tp);
1091.                         /* text in this file is indented with one tab but
1092.                            someone modifying it might use spaces instead */
1093.                         if (*tp == '\t') {
1094.                             ++tp;
1095.                         } else if (*tp == ' ') {
1096.                             /* remove up to 8 spaces (we expect 8-column
1097.                                tab stops but user might have them set at
1098.                                something else so we don't require it) */
1099.                             do {
1100.                                 ++tp;
1101.                             } while (tp < &tabbuf[8] && *tp == ' ');
1102.                         } else if (*tp) { /* empty lines are ok */
1103.                             goto bad_data_file;
1104.                         }
1105.                         /* if a tab after the leading one is found,
1106.                            convert tabs into spaces; the attributions
1107.                            at the end of quotes typically have them */
1108.                         if (strchr(tp, '\t') != 0)
1109.                             (void) tabexpand(tp);
1110.                         putstr(datawin, 0, tp);
1111.                     }
1112.                     display_nhwindow(datawin, FALSE);
1113.                     destroy_nhwindow(datawin), datawin = WIN_ERR;
1114.                 }
1115.             } else if (user_typed_name && pass == 0 && !pass1found_in_file) {
1116.                 pline("You don't have any information on those things.");
1117.             }
1118.         }
1119.     }
1120.     goto checkfile_done; /* skip error feedback */
1121. 
1122.  bad_data_file:
1123.     impossible("'data' file in wrong format or corrupted");
1124.  checkfile_done:
1125.     if (datawin != WIN_ERR)
1126.         destroy_nhwindow(datawin);
1127.     (void) dlb_fclose(fp);
1128.     return res;
1129. }
1130. 
1131. /* extracted from do_screen_description() */
1132. staticfn int
1133. add_cmap_descr(
1134.     int found,          /* number of matching descriptions so far */
1135.     int idx,            /* cmap index into defsyms[] */
1136.     int glyph,          /* map glyph of screen symbol being described;
1137.                          * anything other than NO_GLYPH implies 'looked' */
1138.     int article,        /* 0: (none), 1: a/an, 2: the */
1139.     coord cc,           /* map location */
1140.     const char *x_str,  /* description of defsyms[idx] */
1141.     const char *prefix, /* text to insert in front of first match */
1142.     boolean *hit_trap,  /* input/output: True if a trap has been described */
1143.     const char **firstmatch, /* output: pointer to 1st matching description */
1144.     char *out_str)      /* input/output: current description gets appended */
1145. {
1146.     char *mbuf = NULL;
1147.     const char *p;
1148.     int absidx = abs(idx);
1149. 
1150.     if (glyph == NO_GLYPH) {
1151.         /* use x_str [almost] as-is */
1152.         if (!strcmp(x_str, "water")) {
1153.             /* duplicate some transformations performed by waterbody_name() */
1154.             if (idx == S_pool)
1155.                 x_str = "pool of water";
1156.             else if (idx == S_water)
1157.                 x_str = !Is_waterlevel(&u.uz) ? "wall of water"
1158.                                               : "limitless water";
1159.         }
1160.         if (absidx == S_pool)
1161.             idx = S_pool;
1162.     } else if (absidx == S_pool || idx == S_water
1163.                || idx == S_lava || idx == S_lavawall || idx == S_ice) {
1164.         /* replace some descriptions (x_str) with waterbody_name() */
1165.         schar save_ltyp = levl[cc.x][cc.y].typ;
1166.         long save_prop = EHalluc_resistance;
1167. 
1168.         /* grab a scratch buffer we can safely return (via *firstmatch
1169.            when applicable) */
1170.         mbuf = mon_nam(&gy.youmonst);
1171. 
1172.         if (absidx == S_pool) {
1173.             levl[cc.x][cc.y].typ = (idx == S_pool) ? POOL : MOAT;
1174.             idx = S_pool; /* force fake negative moat value to be positive */
1175.         } else {
1176.             /* we might be examining a pool location but trying to match
1177.                water or lava; override the terrain with what we're matching
1178.                because that's what waterbody_name() bases its result on;
1179.                it's not pool so must be one of water/lava/ice to get here */
1180.             levl[cc.x][cc.y].typ = (idx == S_water) ? WATER
1181.                                    : (idx == S_lava) ? LAVAPOOL
1182.                                      : (idx == S_lavawall) ? LAVAWALL
1183.                                        : ICE;
1184.         }
1185.         EHalluc_resistance = 1;
1186.         Strcpy(mbuf, waterbody_name(cc.x, cc.y));
1187.         EHalluc_resistance = save_prop;
1188.         levl[cc.x][cc.y].typ = save_ltyp;
1189. 
1190.         /* shorten the feedback for farlook/quicklook: "pool or ..." */
1191.         if (!strcmp(mbuf, "pool of water"))
1192.             mbuf[4] = '\0';
1193.         else if (!strcmp(mbuf, "molten lava"))
1194.             Strcpy(mbuf, "lava");
1195.         x_str = mbuf;
1196.         /* avoid "an ice" and so forth; "a pool", "a moat", and
1197.            "a wall of ..." are grammatically correct but make
1198.            "a pool or a moat or a wall of water" become too verbose */
1199.         article = !(!strncmp(x_str, "water", 5)
1200.                     || !strncmp(x_str, "ice", 3)
1201.                     || !strncmp(x_str, "pool", 4)
1202.                     || !strncmp(x_str, "moat", 4)
1203.                     || !strncmp(x_str, "lava", 4)
1204.                     || !strncmp(x_str, "swamp", 5)
1205.                     || !strncmp(x_str, "molten", 6)
1206.                     || !strncmp(x_str, "shallow", 7)
1207.                     || !strncmp(x_str, "limitless", 9)
1208.                     || !strncmp(x_str, "wall of lava", 12)
1209.                     || !strncmp(x_str, "wall of water", 13)
1210.                     /* ice while hallucinating */
1211.                     || !strncmp(x_str, "frozen", 6)
1212.                     /* thawing ice ("solid ice", "thin ice", &c) */
1213.                     || ((p = strchr(x_str, ' ')) != 0 && !strcmpi(p, " ice"))
1214.                     );
1215.     }
1216. 
1217.     if (!found) {
1218.         /* this is the first match */
1219.         if (is_cmap_trap(idx) && idx != S_vibrating_square) {
1220.             Sprintf(out_str, "%sa trap", prefix);
1221.             *hit_trap = TRUE;
1222.         } else {
1223.             Sprintf(out_str, "%s%s", prefix, (article == 2) ? the(x_str)
1224.                                              : (article == 1) ? an(x_str)
1225.                                                : x_str);
1226.         }
1227.         *firstmatch = x_str;
1228.         found = 1;
1229.     } else if (!(*hit_trap && is_cmap_trap(idx))
1230.                && !(found >= 3 && is_cmap_drawbridge(idx))
1231.                /* don't mention vibrating square outside of Gehennom
1232.                   unless this happens to be one (hallucination?) */
1233.                && (idx != S_vibrating_square || Inhell
1234.                    || (glyph_is_trap(glyph)
1235.                        && glyph_to_trap(glyph) == VIBRATING_SQUARE))) {
1236.         /* append unless out_str already contains the string to append */
1237.         found += append_str(out_str, (article == 2) ? the(x_str)
1238.                                      : (article == 1) ? an(x_str)
1239.                                        : x_str);
1240.         if (is_cmap_trap(idx) && idx != S_vibrating_square)
1241.             *hit_trap = TRUE;
1242.     }
1243.     return found;
1244. }
1245. 
1246. int
1247. do_screen_description(
1248.     coord cc, boolean looked,
1249.     int sym, char *out_str,
1250.     const char **firstmatch,
1251.     struct permonst **for_supplement)
1252. {
1253.     static const char mon_interior[] = "the interior of a monster",
1254.                       unreconnoitered[] = "unreconnoitered";
1255.     static char look_buf[BUFSZ];
1256.     char prefix[BUFSZ];
1257.     int i, j, alt_i, glyph = NO_GLYPH,
1258.         skipped_venom = 0, found = 0; /* count of matching syms found */
1259.     boolean hit_trap, need_to_look = FALSE,
1260.             submerged = (Underwater && !Is_waterlevel(&u.uz)),
1261.             hallucinate = (Hallucination && !program_state.gameover);
1262.     const char *x_str;
1263.     nhsym tmpsym;
1264.     glyph_info glyphinfo = nul_glyphinfo;
1265. 
1266.     if (looked) {
1267.         glyph = glyph_at(cc.x, cc.y);
1268.         /* Convert glyph at selected position to a symbol for use below. */
1269.         map_glyphinfo(cc.x, cc.y, glyph, 0, &glyphinfo);
1270.         sym = glyphinfo.ttychar;
1271.         Sprintf(prefix, "%s        ", encglyph(glyphinfo.glyph));
1272.     } else
1273.         Sprintf(prefix, "%c        ", sym);
1274. 
1275.     /*
1276.      * Check all the possibilities, saving all explanations in a buffer.
1277.      * When all have been checked then the string is printed.
1278.      */
1279. 
1280.     /*
1281.      * Handle restricted vision range (limited to adjacent spots when
1282.      * swallowed or underwater) cases first.
1283.      *
1284.      * 3.6.0 listed anywhere on map, other than self, as "interior
1285.      * of a monster" when swallowed, and non-adjacent water or
1286.      * non-water anywhere as "dark part of a room" when underwater.
1287.      * "unreconnoitered" is an attempt to convey "even if you knew
1288.      * what was there earlier, you don't know what is there in the
1289.      * current circumstance".
1290.      *
1291.      * (Note: 'self' will always be visible when swallowed so we don't
1292.      * need special swallow handling for <ux,uy>.
1293.      * Another note: for '#terrain' without monsters, u.uswallow and
1294.      * submerged will always both be False and skip this code.)
1295.      */
1296.     x_str = 0;
1297.     if (!looked) {
1298.         ; /* skip special handling */
1299.     } else if (((u.uswallow || submerged) && !next2u(cc.x, cc.y))
1300.                /* detection showing some category, so mostly background */
1301.                || ((iflags.terrainmode & (TER_DETECT | TER_MAP)) == TER_DETECT
1302.                    && glyph == cmap_to_glyph(S_stone))) {
1303.         x_str = unreconnoitered;
1304.         need_to_look = FALSE;
1305.     } else if (is_swallow_sym(sym)) {
1306.         x_str = mon_interior;
1307.         need_to_look = TRUE; /* for specific monster type */
1308.     }
1309.     if (x_str) {
1310.         /* we know 'found' is zero here, but guard against some other
1311.            special case being inserted ahead of us someday */
1312.         if (!found) {
1313.             Sprintf(out_str, "%s%s", prefix, x_str);
1314.             *firstmatch = x_str;
1315.             found++;
1316.         } else {
1317.             found += append_str(out_str, x_str); /* not 'an(x_str)' */
1318.         }
1319.         /* for is_swallow_sym(), we want to list the current symbol's
1320.            other possibilities (wand for '/', throne for '\\', &c) so
1321.            don't jump to the end for the x_str==mon_interior case */
1322.         if (x_str == unreconnoitered)
1323.             goto didlook;
1324.     }
1325. 
1326.  check_monsters:
1327.     /* Check for monsters */
1328.     if (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0) {
1329.         for (i = 1; i < MAXMCLASSES; i++) {
1330.             if (i == S_invisible)  /* avoid matching on this */
1331.                 continue;
1332.             if (sym == (looked ? gs.showsyms[i + SYM_OFF_M]
1333.                                : def_monsyms[i].sym)
1334.                 && def_monsyms[i].explain && *def_monsyms[i].explain) {
1335.                 need_to_look = TRUE;
1336.                 if (!found) {
1337.                     Sprintf(out_str, "%s%s",
1338.                             prefix, an(def_monsyms[i].explain));
1339.                     *firstmatch = def_monsyms[i].explain;
1340.                     found++;
1341.                 } else {
1342.                     found += append_str(out_str, an(def_monsyms[i].explain));
1343.                 }
1344.             }
1345.         }
1346.         /* handle '@' as a special case if it refers to you and you're
1347.            playing a character which isn't normally displayed by that
1348.            symbol; firstmatch is assumed to already be set for '@' */
1349.         if ((looked ? (sym == gs.showsyms[S_HUMAN + SYM_OFF_M]
1350.                        && u_at(cc.x, cc.y))
1351.                     : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace))
1352.             && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd)
1353.             found += append_str(out_str, "you"); /* tack on "or you" */
1354.     }
1355. 
1356.     /* Now check for objects */
1357.     if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) {
1358.         const char *oc_ptr;
1359.         nhsym bouldersym;
1360. 
1361.         j = SYM_BOULDER + SYM_OFF_X;
1362.         bouldersym = Is_rogue_level(&u.uz) ? go.ov_rogue_syms[j]
1363.                                            : go.ov_primary_syms[j];
1364.         if (!bouldersym)
1365.             bouldersym = def_oc_syms[ROCK_CLASS].sym;
1366. 
1367.         for (i = 1; i < MAXOCLASSES; i++) {
1368.             if ((i != ROCK_CLASS)
1369.                 ? (sym == (looked ? gs.showsyms[i + SYM_OFF_O]
1370.                                   : def_oc_syms[i].sym))
1371.                 /* ROCK_CLASS is complicated; statues are displayed as the
1372.                    monster they depict rather than as S_rock; boulders might
1373.                    be displayed as a custom symbol rather than as S_rock */
1374.                 : (glyph_is_statue(glyph) || sym == bouldersym)) {
1375.                 oc_ptr = def_oc_syms[i].explain;
1376.                 /* for added fun, engravings are shown with the same symbol
1377.                    as S_rock which is why we want to shorten this */
1378.                 if (i == ROCK_CLASS && !strcmp(oc_ptr, "boulder or statue")) {
1379.                     if (sym == bouldersym)
1380.                         oc_ptr = "boulder"; /* discard "or statue" */
1381.                     else if (glyph_is_statue(glyph))
1382.                         oc_ptr = "statue"; /* discard "boulder or" */
1383.                     else if (looked)
1384.                         continue; /* discard both */
1385.                 }
1386.                 need_to_look = TRUE;
1387.                 if (looked && i == VENOM_CLASS) {
1388.                     skipped_venom++;
1389.                     continue;
1390.                 }
1391.                 if (!found) {
1392.                     Sprintf(out_str, "%s%s", prefix, an(oc_ptr));
1393.                     /* note: if the value assigned to *firstmatch ever
1394.                        becomes dynamically constructed, it will need to be
1395.                        copied into a static buffer; as of now, all alternate
1396.                        values are string literals and implicitly static */
1397.                     *firstmatch = oc_ptr;
1398.                     found++;
1399.                 } else {
1400.                     found += append_str(out_str, an(oc_ptr));
1401.                 }
1402.             }
1403.         }
1404.     }
1405. 
1406.     if (sym == DEF_INVISIBLE) {
1407.         /* for active clairvoyance, use alternate "unseen creature" */
1408.         boolean usealt = (EDetect_monsters & I_SPECIAL) != 0L;
1409.         const char *unseen_explain = (usealt || Blind) ? altinvisexplain
1410.                                                        : invisexplain;
1411. 
1412.         if (!found) {
1413.             Sprintf(out_str, "%s%s", prefix, an(unseen_explain));
1414.             *firstmatch = unseen_explain;
1415.             found++;
1416.         } else {
1417.             found += append_str(out_str, an(unseen_explain));
1418.         }
1419.     }
1420.     if ((glyph && glyph_is_nothing(glyph))
1421.         || (looked && sym == gs.showsyms[SYM_NOTHING + SYM_OFF_X])) {
1422.         x_str = "the dark part of a room";
1423.         if (!found) {
1424.             Sprintf(out_str, "%s%s", prefix, x_str);
1425.             *firstmatch = x_str;
1426.             found++;
1427.         } else {
1428.             found += append_str(out_str, x_str);
1429.         }
1430.     }
1431.     if ((glyph && glyph_is_unexplored(glyph))
1432.         || (looked && sym == gs.showsyms[SYM_UNEXPLORED + SYM_OFF_X])) {
1433.         x_str = "unexplored";
1434.         if (submerged)
1435.             x_str = "land"; /* replace "unexplored" */
1436.         if (!found) {
1437.             Sprintf(out_str, "%s%s", prefix, x_str);
1438.             *firstmatch = x_str;
1439.             found++;
1440.         } else {
1441.             found += append_str(out_str, x_str);
1442.         }
1443.     }
1444.     /* Now check for graphics symbols */
1445.     for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) {
1446.         /*
1447.          * Index hackery:  we want
1448.          *   "pool or moat or wall of water or lava or wall of lava"
1449.          * rather than
1450.          *   "pool or moat or lava or wall of lava or wall of water"
1451.          * but S_lava comes before S_water so 'i' reaches it sooner.
1452.          * Use 'alt_i' for the rest of the loop to behave as if their
1453.          * places were swapped.
1454.          * This was much simpler when it just exchanged water and lava.
1455.          * Now it rotates water to the first of (lava, lavawall, water)
1456.          * lava to the middle of (lava, lavawall, water), and lavawall
1457.          * to last of (lava, lavawall, water); other values are used
1458.          * as-is.
1459.          * If S_water (and corresponding tile) were renumbered, this
1460.          * hackery could go away.
1461.          */
1462.         alt_i = (i == S_lava) ? S_water /* do water first (of these 3) */
1463.                 : (i == S_lavawall) ? S_lava /* process lava second */
1464.                   : (i == S_water) ? S_lavawall /* and wall of lava third */
1465.                     : i; /* other; handle in defsyms[] order */
1466.         x_str = defsyms[alt_i].explanation;
1467.         /* cmap includes beams, shield effects, swallow boundaries, and
1468.            explosions; skip all of those */
1469.         if (!*x_str)
1470.             continue;
1471. 
1472.         if (sym == (looked ? gs.showsyms[alt_i] : defsyms[alt_i].sym)) {
1473.             int article; /* article==2 => "the", 1 => "an", 0 => (none) */
1474. 
1475.             /* check if dark part of a room was already included above */
1476.             if (alt_i == S_darkroom && glyph && glyph_is_nothing(glyph))
1477.                 continue;
1478. 
1479.             /* avoid "an unexplored", "an stone", "an air",
1480.                "a floor of a room", "a dark part of a room" */
1481.             article = strstri(x_str, " of a room") ? 2
1482.                       : !(alt_i == S_stone
1483.                           || strcmp(x_str, "air") == 0
1484.                           || strcmp(x_str, "land") == 0);
1485. 
1486.             found = add_cmap_descr(found, alt_i, glyph, article,
1487.                                    cc, x_str, prefix,
1488.                                    &hit_trap, firstmatch, out_str);
1489.             if (alt_i == S_pool) {
1490.                 /* "pool of water" and "moat" use the same symbol and glyph
1491.                    but have different descriptions; when handling pool, add
1492.                    it a second time for moat but pass an alternate symbol;
1493.                    skip incrementing 'found' to avoid "can be many things" */
1494.                 (void) add_cmap_descr(found, -S_pool, glyph, 1,
1495.                                       cc, "moat", prefix,
1496.                                       &hit_trap, firstmatch, out_str);
1497.                 need_to_look = TRUE;
1498.             }
1499. 
1500.             if (alt_i == S_altar || is_cmap_trap(alt_i)
1501.                 || (hallucinate && (alt_i == S_water /* S_pool already done */
1502.                                     || alt_i == S_lava
1503.                                     || alt_i == S_lavawall
1504.                                     || alt_i == S_ice))
1505.                 || alt_i == S_engroom || alt_i == S_engrcorr
1506.                 || alt_i == S_grave) /* 'need_to_look' to report engraving */
1507.                 need_to_look = TRUE;
1508.         }
1509.     }
1510. 
1511.     /* Now check for warning symbols */
1512.     for (i = 1; i < WARNCOUNT; i++) {
1513.         x_str = def_warnsyms[i].explanation;
1514.         if (sym == (looked ? gw.warnsyms[i] : def_warnsyms[i].sym)) {
1515.             if (!found) {
1516.                 Sprintf(out_str, "%s%s", prefix, x_str);
1517.                 *firstmatch = x_str;;
1518.                 found++;
1519.             } else {
1520.                 found += append_str(out_str, x_str);
1521.             }
1522.             /* Kludge: warning trumps boulders on the display.
1523.                Reveal the boulder too or player can get confused */
1524.             if (looked && sobj_at(BOULDER, cc.x, cc.y))
1525.                 Strcat(out_str, " co-located with a boulder");
1526.             break; /* out of for loop*/
1527.         }
1528.     }
1529. 
1530.     /* if we ignored venom and list turned out to be short, put it back */
1531.     if (skipped_venom && found < 2) {
1532.         x_str = def_oc_syms[VENOM_CLASS].explain;
1533.         if (!found) {
1534.             Sprintf(out_str, "%s%s", prefix, an(x_str));
1535.             *firstmatch = x_str;
1536.             found++;
1537.         } else {
1538.             found += append_str(out_str, an(x_str));
1539.         }
1540.     }
1541. 
1542.     /* Finally, handle some optional overriding symbols */
1543.     for (j = SYM_OFF_X; j < SYM_MAX; ++j) {
1544.         if (j == SYM_INVISIBLE + SYM_OFF_X || j == SYM_BOULDER + SYM_OFF_X)
1545.             continue;       /* already handled above */
1546.         tmpsym = Is_rogue_level(&u.uz) ? go.ov_rogue_syms[j]
1547.                                        : go.ov_primary_syms[j];
1548.         if (tmpsym && sym == tmpsym) {
1549.             switch (j) {
1550. #if 0
1551.             case SYM_BOULDER + SYM_OFF_X: {
1552.                 static const char boulder[] = "boulder";
1553. 
1554.                 if (!found) {
1555.                     *firstmatch = boulder;
1556.                     Sprintf(out_str, "%s%s", prefix, an(*firstmatch));
1557.                     found++;
1558.                 } else {
1559.                     found += append_str(out_str, boulder);
1560.                 }
1561.                 break;
1562.             }
1563. #endif
1564.             case SYM_PET_OVERRIDE + SYM_OFF_X:
1565.                 if (looked) {
1566.                     /* convert to symbol without override in effect */
1567.                     map_glyphinfo(cc.x, cc.y, glyph, MG_FLAG_NOOVERRIDE,
1568.                                   &glyphinfo);
1569.                     sym = glyphinfo.ttychar;
1570.                     goto check_monsters;
1571.                 }
1572.                 break;
1573.             case SYM_HERO_OVERRIDE + SYM_OFF_X:
1574.                 sym = gs.showsyms[S_HUMAN + SYM_OFF_M];
1575.                 goto check_monsters;
1576.             }
1577.         }
1578.     }
1579. 
1580.     /*
1581.      * If we are looking at the screen, follow multiple possibilities or
1582.      * an ambiguous explanation by something more detailed.
1583.      */
1584. 
1585.     if (found > 4)
1586.         /* 3.6.3: this used to be "That can be many things" (without prefix)
1587.            which turned it into a sentence that lacked its terminating period;
1588.            we could add one below but reinstating the prefix here is better */
1589.         Sprintf(out_str, "%scan be many things", prefix);
1590. 
1591.  didlook:
1592.     if (looked) {
1593.         struct permonst *pm = (struct permonst *) 0;
1594. 
1595.         if (found > 1 || need_to_look) {
1596.             char monbuf[BUFSZ];
1597.             char temp_buf[BUFSZ];
1598. 
1599.             pm = lookat(cc.x, cc.y, look_buf, monbuf);
1600.             if (pm && for_supplement)
1601.                 *for_supplement = pm;
1602.             if (!strcmp(look_buf, "ice"))
1603.                 (void) ice_descr(cc.x, cc.y, look_buf);
1604.             if (!strcmp(look_buf, "staircase down")
1605.                 && on_level(&u.uz, &qstart_level) && !ok_to_quest())
1606.                 Strcpy(look_buf, "blocked staircase down");
1607. 
1608.             if (look_buf[0] != '\0')
1609.                 *firstmatch = look_buf;
1610.             if (*(*firstmatch)) {
1611.                 Sprintf(temp_buf, " (%s", *firstmatch);
1612.                 (void) add_quoted_engraving(cc.x, cc.y, temp_buf, FALSE);
1613.                 Strcat(temp_buf, ")");
1614.                 (void) strncat(out_str, temp_buf,
1615.                                BUFSZ - strlen(out_str) - 1);
1616.                 found = 1; /* we have something to look up */
1617.             }
1618.             if (monbuf[0]) {
1619.                 Snprintf(temp_buf, sizeof temp_buf, " [seen: %s]", monbuf);
1620.                 (void) strncat(out_str, temp_buf,
1621.                                BUFSZ - strlen(out_str) - 1);
1622.             }
1623.         }
1624.     }
1625. 
1626.     return found;
1627. }
1628. 
1629. /* when farlook is reporting on an engraving, include its text */
1630. staticfn boolean
1631. add_quoted_engraving(
1632.     coordxy x, coordxy y,
1633.     char *buf,
1634.     boolean force) /* True: '/e' or '/E', False: '//' or ';' */
1635. {
1636.     char temp_buf[BUFSZ];
1637.     struct engr *ep = engr_at(x, y);
1638.     boolean floorengr = !strcmp(buf, " (engraving"),
1639.             headstone = !strcmp(buf, " (grave");
1640. 
1641.     /*
1642.      * If there is no engraving here, there's nothing to do; just return.
1643.      *
1644.      * When buf[] is " (engraving" or " (grave" then we're looking at an
1645.      * engraving and we'll add its text.  Caller supplies the closing paren.
1646.      *
1647.      * If buf[] contains anything else, we're looking at something (monster
1648.      * or object) that happens to be on top of an engraving, so we won't
1649.      * append the engraving text.
1650.      */
1651.     if (!ep)
1652.         return FALSE;
1653. 
1654.     if (!floorengr && !headstone && !force)
1655.         return FALSE;
1656. 
1657.     if (ep->eread)
1658.         Snprintf(temp_buf, sizeof temp_buf, " with %s: \"%s\"",
1659.                  headstone ? "headstone reading" : "remembered text",
1660.                  ep->engr_txt[remembered_text]);
1661.     else
1662.         Snprintf(temp_buf, sizeof temp_buf, " %s you haven't read",
1663.                  headstone ? "whose headstone" : "that");
1664. 
1665.     (void) strncat(buf, temp_buf, BUFSZ - strlen(buf) - 1);
1666.     return TRUE;
1667. }
1668. 
1669. /* also used by getpos hack in getpos.c */
1670. const char what_is_a_location[] = "a monster, object or location";
1671. 
1672. int
1673. do_look(int mode, coord *click_cc)
1674. {
1675.     boolean quick = (mode == 1); /* use cursor; don't search for "more info" */
1676.     boolean clicklook = (mode == 2); /* right mouse-click method */
1677.     char out_str[BUFSZ] = DUMMY;
1678.     struct _cmd_queue cq, *cmdq;
1679.     const char *firstmatch = 0;
1680.     struct permonst *pm = 0, *supplemental_pm = 0;
1681.     int i = '\0', ans = 0;
1682.     int sym;              /* typed symbol or converted glyph */
1683.     int found;            /* count of matching syms found */
1684.     coord cc;             /* screen pos of unknown glyph */
1685.     boolean save_verbose; /* saved value of flags.verbose */
1686.     boolean from_screen;  /* question from the screen */
1687.     int clr = NO_COLOR;
1688. 
1689.     cc.x = 0;
1690.     cc.y = 0;
1691. 
1692.     if ((cmdq = cmdq_pop()) != 0) {
1693.         cq = *cmdq;
1694.         free((genericptr_t) cmdq);
1695.         if (cq.typ == CMDQ_KEY)
1696.             i = cq.key;
1697.         else
1698.             cmdq_clear(CQ_CANNED);
1699.         goto dowhatiscmd;
1700.     }
1701. 
1702.     if (!clicklook) {
1703.         if (quick) {
1704.             i = 'y';
1705.         } else {
1706.             menu_item *pick_list = (menu_item *) 0;
1707.             winid win;
1708.             anything any;
1709. 
1710.             any = cg.zeroany;
1711.             win = create_nhwindow(NHW_MENU);
1712.             start_menu(win, MENU_BEHAVE_STANDARD);
1713. 
1714.             /*
1715.              * Originally this was just a y|n question about whether to
1716.              * use the cursor or to type a word.  When other choices were
1717.              * added, it was changed to be a menu.  Using 'y' and 'n' as
1718.              * unshown accelerators keeps backwards compatibility with
1719.              * the old y|n behavior.
1720.              *
1721.              * Initially the menu included a third choice and always used
1722.              * 'a', 'b', and 'c'.  Then it was changed to be controlled by
1723.              * the 'lootabc' option instead, defaulting to '/', 'i', '?'
1724.              * when that's false.  Eventually additional entries have been
1725.              * introduced.
1726.              *
1727.              * When lootabc is set, abandon the 'y'|'n' compatibility in
1728.              * favor of newer '/' and '?' compatibility instead.
1729.              */
1730. 
1731.             any.a_char = '/';
1732.             add_menu(win, &nul_glyphinfo, &any,
1733.                      flags.lootabc ? 0 : any.a_char,
1734.                      flags.lootabc ? '/' : 'y', ATR_NONE,
1735.                      clr, "something on the map", MENU_ITEMFLAGS_NONE);
1736.             any.a_char = 'i';
1737.             add_menu(win, &nul_glyphinfo, &any,
1738.                      /* [don't use 'i' as lootabc group accelerator because
1739.                         it will make the regular 'i' choice inaccessible] */
1740.                      flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1741.                      clr, "something you're carrying", MENU_ITEMFLAGS_NONE);
1742.             any.a_char = '?';
1743.             add_menu(win, &nul_glyphinfo, &any,
1744.                      flags.lootabc ? 0 : any.a_char,
1745.                      flags.lootabc ? '?' : 'n', ATR_NONE,
1746.                      clr, "something else (by symbol or name)",
1747.                      MENU_ITEMFLAGS_NONE);
1748.             if (!u.uswallow && !Hallucination) {
1749.                 any = cg.zeroany;
1750.                 add_menu_str(win, "");
1751.                 /* these options work sensibly for swallowed case, but
1752.                    there's no reason for player to use them then because
1753.                    the swallowed display hides all applicable targets;
1754.                    objects work fine when hallucinating, but screen
1755.                    symbol/monster class letter doesn't match up with
1756.                    bogus monster type, so suppress when hallucinating */
1757.                 any.a_char = 'm';
1758.                 add_menu(win, &nul_glyphinfo, &any,
1759.                          flags.lootabc ? 0 : any.a_char,
1760.                          flags.lootabc ? any.a_char : 0, ATR_NONE,
1761.                          clr, "nearby monsters", MENU_ITEMFLAGS_NONE);
1762.                 any.a_char = 'M';
1763.                 add_menu(win, &nul_glyphinfo, &any,
1764.                          flags.lootabc ? 0 : any.a_char,
1765.                          flags.lootabc ? any.a_char : 0, ATR_NONE,
1766.                          clr, "all monsters shown on map",
1767.                          MENU_ITEMFLAGS_NONE);
1768.                 any.a_char = 'o';
1769.                 add_menu(win, &nul_glyphinfo, &any,
1770.                          flags.lootabc ? 0 : any.a_char,
1771.                          flags.lootabc ? any.a_char : 0, ATR_NONE,
1772.                          clr, "nearby objects", MENU_ITEMFLAGS_NONE);
1773.                 any.a_char = 'O';
1774.                 add_menu(win, &nul_glyphinfo, &any,
1775.                          flags.lootabc ? 0 : any.a_char,
1776.                          flags.lootabc ? any.a_char : 0, ATR_NONE,
1777.                          clr, "all objects shown on map",
1778.                          MENU_ITEMFLAGS_NONE);
1779.                 any.a_char = 't';
1780.                 add_menu(win, &nul_glyphinfo, &any,
1781.                          flags.lootabc ? 0 : any.a_char,
1782.                          flags.lootabc ? any.a_char : '^', ATR_NONE,
1783.                          clr, "nearby traps", MENU_ITEMFLAGS_NONE);
1784.                 any.a_char = 'T';
1785.                 add_menu(win, &nul_glyphinfo, &any,
1786.                          flags.lootabc ? 0 : any.a_char,
1787.                          flags.lootabc ? any.a_char : '\"', ATR_NONE,
1788.                          clr, "all seen or remembered traps",
1789.                          MENU_ITEMFLAGS_NONE);
1790.                 any.a_char = 'e';
1791.                 add_menu(win, &nul_glyphinfo, &any,
1792.                          flags.lootabc ? 0 : any.a_char,
1793.                          /* [don't use 'e' as lootabc group accelerator] */
1794.                          flags.lootabc ? 0 : '`', ATR_NONE,
1795.                          clr, "nearby engravings", MENU_ITEMFLAGS_NONE);
1796.                 any.a_char = 'E';
1797.                 add_menu(win, &nul_glyphinfo, &any,
1798.                          flags.lootabc ? 0 : any.a_char,
1799.                          flags.lootabc ? any.a_char : '|', ATR_NONE,
1800.                          clr, "all seen or remembered engravings",
1801.                          MENU_ITEMFLAGS_NONE);
1802.             }
1803.             end_menu(win, "What do you want to look at:");
1804.             if (select_menu(win, PICK_ONE, &pick_list) > 0) {
1805.                 i = pick_list->item.a_char;
1806.                 free((genericptr_t) pick_list);
1807.             }
1808.             destroy_nhwindow(win);
1809.         }
1810. 
1811.  dowhatiscmd:
1812.         switch (i) {
1813.         default:
1814.         case 'q':
1815.             return ECMD_OK;
1816.         case 'y':
1817.         case '/':
1818.             from_screen = TRUE;
1819.             sym = 0;
1820.             cc.x = u.ux;
1821.             cc.y = u.uy;
1822.             break;
1823.         case 'i':
1824.           {
1825.             char invlet;
1826.             struct obj *invobj;
1827. 
1828.             invlet = display_inventory((const char *) 0, TRUE);
1829.             if (!invlet || invlet == '\033')
1830.                 return ECMD_OK;
1831.             *out_str = '\0';
1832.             for (invobj = gi.invent; invobj; invobj = invobj->nobj)
1833.                 if (invobj->invlet == invlet) {
1834.                     Strcpy(out_str, singular(invobj, xname));
1835.                     break;
1836.                 }
1837.             if (*out_str)
1838.                 (void) checkfile(out_str, pm, chkfilUsrTyped | chkfilDontAsk,
1839.                                  (char *) 0);
1840.             return ECMD_OK;
1841.           }
1842.         case '?':
1843.             from_screen = FALSE;
1844.             getlin("Specify what? (type the word)", out_str);
1845.             if (strcmp(out_str, " ")) /* keep single space as-is */
1846.                 /* remove leading and trailing whitespace and
1847.                    condense consecutive internal whitespace */
1848.                 mungspaces(out_str);
1849.             if (out_str[0] == '\0' || out_str[0] == '\033')
1850.                 return ECMD_OK;
1851. 
1852.             if (out_str[1]) { /* user typed in a complete string */
1853.                 (void) checkfile(out_str, pm,  chkfilUsrTyped | chkfilDontAsk,
1854.                                  (char *) 0);
1855.                 return ECMD_OK;
1856.             }
1857.             sym = out_str[0];
1858.             break;
1859.         case 'm':
1860.             look_all(TRUE, TRUE); /* list nearby monsters */
1861.             return ECMD_OK;
1862.         case 'M':
1863.             look_all(FALSE, TRUE); /* list all monsters */
1864.             return ECMD_OK;
1865.         case 'o':
1866.             look_all(TRUE, FALSE); /* list nearby objects */
1867.             return ECMD_OK;
1868.         case 'O':
1869.             look_all(FALSE, FALSE); /* list all objects */
1870.             return ECMD_OK;
1871.         case 't':
1872.             look_traps(TRUE); /* list nearby traps */
1873.             return ECMD_OK;
1874.         case 'T':
1875.             look_traps(FALSE); /* list all traps (visible or remembered) */
1876.             return ECMD_OK;
1877.         case 'e':
1878.             look_engrs(TRUE); /* list nearby engravings */
1879.             return ECMD_OK;
1880.         case 'E':
1881.             look_engrs(FALSE); /* list all engravings (visible|remembered) */
1882.             return ECMD_OK;
1883.         }
1884.     } else { /* clicklook */
1885.         cc.x = click_cc->x;
1886.         cc.y = click_cc->y;
1887.         sym = 0;
1888.         from_screen = FALSE;
1889.     }
1890. 
1891.     /* Save the verbose flag, we change it later. */
1892.     save_verbose = flags.verbose;
1893.     flags.verbose = flags.verbose && !quick;
1894.     /*
1895.      * The user typed one letter, or we're identifying from the screen.
1896.      */
1897.     do {
1898.         /* Reset some variables. */
1899.         pm = (struct permonst *) 0;
1900.         out_str[0] = '\0';
1901. 
1902.         if (from_screen || clicklook) {
1903.             if (from_screen) {
1904.                 if (flags.verbose)
1905.                     pline("Please move the cursor to %s.",
1906.                           what_is_a_location);
1907.                 else
1908.                     pline("Pick %s.", what_is_a_location);
1909. 
1910.                 ans = getpos(&cc, quick, what_is_a_location);
1911.                 if (ans < 0 || cc.x < 0)
1912.                     break; /* done */
1913.                 flags.verbose = FALSE; /* only print long question once */
1914.             }
1915.         }
1916. 
1917.         found = do_screen_description(cc, (from_screen || clicklook), sym,
1918.                                       out_str, &firstmatch, &supplemental_pm);
1919. 
1920.         /* Finally, print out our explanation. */
1921.         if (found) {
1922.             /* use putmixed() because there may be an encoded glyph present */
1923.             putmixed(WIN_MESSAGE, 0, out_str);
1924. #ifdef DUMPLOG_CORE
1925.             {
1926.                 char dmpbuf[BUFSZ];
1927. 
1928.                 /* putmixed() bypasses pline() so doesn't write to DUMPLOG;
1929.                    tty puts it into ^P recall, so it ought to be there;
1930.                    DUMPLOG is plain text, so override graphics character;
1931.                    at present, force space, but we ought to use defsyms[]
1932.                    value for the glyph the graphics character came from */
1933.                 (void) decode_mixed(dmpbuf, out_str);
1934.                 if (dmpbuf[0] < ' ' || dmpbuf[0] >= 127) /* ASCII isprint() */
1935.                     dmpbuf[0] = ' ';
1936.                 dumplogmsg(dmpbuf);
1937.             }
1938. #endif
1939. 
1940.             /* check the data file for information about this thing */
1941.             if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE
1942.                 && (ans == LOOK_VERBOSE || (flags.help && !quick))
1943.                 && !clicklook) {
1944.                 char temp_buf[BUFSZ], supplemental_name[BUFSZ];
1945. 
1946.                 supplemental_name[0] = '\0';
1947.                 Strcpy(temp_buf, firstmatch);
1948.                 (void) checkfile(temp_buf, pm,
1949.                                  (ans == LOOK_VERBOSE) ? chkfilDontAsk
1950.                                                        : chkfilNone,
1951.                                  supplemental_name);
1952.                 if (supplemental_pm)
1953.                     do_supplemental_info(supplemental_name, supplemental_pm,
1954.                                          (boolean) (ans == LOOK_VERBOSE));
1955.             }
1956.         } else {
1957.             pline("I've never heard of such things.");
1958.         }
1959.     } while (from_screen && !quick && ans != LOOK_ONCE && !clicklook);
1960. 
1961.     flags.verbose = save_verbose;
1962.     return ECMD_OK;
1963. }
1964. 
1965. staticfn void
1966. look_region_nearby(
1967.     coordxy *lo_x, coordxy *lo_y,
1968.     coordxy *hi_x, coordxy *hi_y, boolean nearby)
1969. {
1970.     *lo_y = nearby ? max(u.uy - BOLT_LIM, 0) : 0;
1971.     *lo_x = nearby ? max(u.ux - BOLT_LIM, 1) : 1;
1972.     *hi_y = nearby ? min(u.uy + BOLT_LIM, ROWNO - 1) : ROWNO - 1;
1973.     *hi_x = nearby ? min(u.ux + BOLT_LIM, COLNO - 1) : COLNO - 1;
1974. }
1975. 
1976. DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE is after do_supplemental_info() */
1977. 
1978. staticfn void
1979. look_all(
1980.     boolean nearby,  /* True => within BOLTLIM, False => entire map */
1981.     boolean do_mons) /* True => monsters, False => objects */
1982. {
1983.     winid win;
1984.     int glyph, count = 0;
1985.     coordxy x, y, lo_x, lo_y, hi_x, hi_y;
1986.     char lookbuf[BUFSZ], outbuf[BUFSZ];
1987. 
1988.     win = create_nhwindow(NHW_TEXT);
1989.     look_region_nearby(&lo_x, &lo_y, &hi_x, &hi_y, nearby);
1990.     for (y = lo_y; y <= hi_y; y++) {
1991.         for (x = lo_x; x <= hi_x; x++) {
1992.             lookbuf[0] = '\0';
1993.             glyph = glyph_at(x, y);
1994.             if (do_mons) {
1995.                 if (glyph_is_monster(glyph)) {
1996.                     struct monst *mtmp;
1997. 
1998.                     if (u_at(x, y) && canspotself()) {
1999.                         (void) self_lookat(lookbuf);
2000.                         ++count;
2001.                     } else if ((mtmp = m_at(x, y)) != 0) {
2002.                         look_at_monster(lookbuf, (char *) 0, mtmp, x, y);
2003.                         ++count;
2004.                     }
2005.                 } else if (glyph_is_invisible(glyph)) {
2006.                     /* remembered, unseen, creature */
2007.                     Strcpy(lookbuf, invisexplain);
2008.                     ++count;
2009.                 } else if (glyph_is_warning(glyph)) {
2010.                     int warnindx = glyph_to_warning(glyph);
2011. 
2012.                     Strcpy(lookbuf, def_warnsyms[warnindx].explanation);
2013.                     ++count;
2014.                 }
2015.             } else { /* !do_mons */
2016.                 if (glyph_is_object(glyph)) {
2017.                     look_at_object(lookbuf, x, y, glyph);
2018.                     ++count;
2019.                 }
2020.             }
2021.             if (*lookbuf) {
2022.                 char coordbuf[20], which[12], cmode;
2023. 
2024.                 cmode = (iflags.getpos_coords != GPCOORDS_NONE)
2025.                            ? iflags.getpos_coords : GPCOORDS_MAP;
2026.                 if (count == 1) {
2027.                     Strcpy(which, do_mons ? "monsters" : "objects");
2028.                     if (nearby)
2029.                         Sprintf(outbuf, "%s currently shown near %s:",
2030.                                 upstart(which),
2031.                                 (cmode != GPCOORDS_COMPASS)
2032.                                   ? coord_desc(u.ux, u.uy, coordbuf, cmode)
2033.                                   : !canspotself() ? "your position" : "you");
2034.                     else
2035.                         Sprintf(outbuf, "All %s currently shown on the map:",
2036.                                 which);
2037.                     putstr(win, 0, outbuf);
2038.                     /* hack alert! Qt watches a text window for any line
2039.                        with 4 consecutive spaces and renders the window
2040.                        in a fixed-width font it if finds at least one */
2041.                     putstr(win, 0, "    "); /* separator */
2042.                 }
2043.                 (void) coord_desc(x, y, coordbuf, cmode);
2044.                 /* this format wrinkle makes the commas of <x,y> line up;
2045.                    it isn't needed when all the y values have same number
2046.                    of digits but looks better when there is a mixture of 1
2047.                    and 2 digit values; done unconditionally because we
2048.                    would need two passes over the map to determine whether
2049.                    y width is uniform or a mixture; x width is not a factor
2050.                    because the result gets right-justified by %8s; adding
2051.                    a trailing space effectively pushes non-space text left */
2052.                 if (cmode == GPCOORDS_MAP && y < 10)
2053.                     (void) strkitten(coordbuf, ' ');
2054.                 /* prefix: "coords  C  " where 'C' is mon or obj symbol */
2055.                 Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s  "
2056.                                   : (cmode == GPCOORDS_MAP) ? "%8s  "
2057.                                       : "%12s  ",
2058.                         coordbuf);
2059.                 Sprintf(eos(outbuf), "%s  ", encglyph(glyph));
2060.                 /* guard against potential overflow */
2061.                 lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0';
2062.                 Strcat(outbuf, lookbuf);
2063.                 putmixed(win, 0, outbuf);
2064.             }
2065.         }
2066.     }
2067.     if (count)
2068.         display_nhwindow(win, TRUE);
2069.     else
2070.         pline("No %s are currently shown %s.",
2071.               do_mons ? "monsters" : "objects",
2072.               nearby ? "nearby" : "on the map");
2073.     destroy_nhwindow(win);
2074. }
2075. 
2076. /* give a /M style display of discovered traps, even when they're covered */
2077. staticfn void
2078. look_traps(boolean nearby)
2079. {
2080.     winid win;
2081.     struct trap *t;
2082.     int glyph, tnum, count = 0;
2083.     coordxy x, y, lo_x, lo_y, hi_x, hi_y;
2084.     char lookbuf[BUFSZ], outbuf[BUFSZ];
2085. 
2086.     win = create_nhwindow(NHW_TEXT);
2087.     look_region_nearby(&lo_x, &lo_y, &hi_x, &hi_y, nearby);
2088.     for (y = lo_y; y <= hi_y; y++) {
2089.         for (x = lo_x; x <= hi_x; x++) {
2090.             lookbuf[0] = '\0';
2091.             glyph = glyph_at(x, y);
2092.             if (glyph_is_trap(glyph)) {
2093.                 tnum = glyph_to_trap(glyph);
2094.                 trap_description(lookbuf, tnum, x, y);
2095.                 ++count;
2096.             } else if ((t = t_at(x, y)) != 0 && t->tseen
2097.                        /* can't use /" to track traps moved by bubbles or
2098.                           clouds except when hero has direct line of sight */
2099.                        && ((!Is_waterlevel(&u.uz) && !Is_airlevel(&u.uz))
2100.                            || couldsee(x, y))) {
2101.                 Strcpy(lookbuf, trapname(t->ttyp, FALSE));
2102.                 Sprintf(eos(lookbuf), ", obscured by %s", encglyph(glyph));
2103.                 glyph = trap_to_glyph(t);
2104.                 ++count;
2105.             }
2106.             if (*lookbuf) {
2107.                 char coordbuf[20], cmode;
2108. 
2109.                 cmode = (iflags.getpos_coords != GPCOORDS_NONE)
2110.                            ? iflags.getpos_coords : GPCOORDS_MAP;
2111.                 if (count == 1) {
2112.                     Sprintf(outbuf, "%sseen or remembered traps%s:",
2113.                             nearby ? "nearby " : "",
2114.                             nearby ? "" : " on this level");
2115.                     putstr(win, 0, upstart(outbuf));
2116.                     /* hack alert! Qt watches a text window for any line
2117.                        with 4 consecutive spaces and renders the window
2118.                        in a fixed-width font it if finds at least one */
2119.                     putstr(win, 0, "    "); /* separator */
2120.                 }
2121.                 /* prefix: "coords  C  " where 'C' is trap symbol */
2122.                 Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s  "
2123.                                   : (cmode == GPCOORDS_MAP) ? "%8s  "
2124.                                       : "%12s  ",
2125.                         coord_desc(x, y, coordbuf, cmode));
2126.                 Sprintf(eos(outbuf), "%s  ", encglyph(glyph));
2127.                 /* guard against potential overflow */
2128.                 lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0';
2129.                 Strcat(outbuf, lookbuf);
2130.                 putmixed(win, 0, outbuf);
2131.             }
2132.         }
2133.     }
2134.     if (count)
2135.         display_nhwindow(win, TRUE);
2136.     else
2137.         pline("No traps seen or remembered%s.", nearby ? " nearby" : "");
2138.     destroy_nhwindow(win);
2139. }
2140. 
2141. /* display of discovered engravings including headstones, even when they're
2142.    covered provided they've been read */
2143. staticfn void
2144. look_engrs(boolean nearby)
2145. {
2146.     winid win;
2147.     struct engr *e;
2148.     char lookbuf[BUFSZ], outbuf[BUFSZ];
2149.     coordxy x, y, lo_x, lo_y, hi_x, hi_y;
2150.     boolean is_headstone;
2151.     nhsym sym;
2152.     int glyph, count = 0;
2153. 
2154.     win = create_nhwindow(NHW_TEXT);
2155.     look_region_nearby(&lo_x, &lo_y, &hi_x, &hi_y, nearby);
2156.     /*assert(lo_x >= 1 && lo_y >= 0 && hi_x < MAXCO && hi_y < MAXLI);*/
2157.     for (y = lo_y; y <= hi_y; y++) {
2158.         for (x = lo_x; x <= hi_x; x++) {
2159.             lookbuf[0] = '\0';
2160.             if (!levl[x][y].seenv)
2161.                 continue;
2162.             /* this won't find remembered engravings which aren't there
2163.                anymore (in case the hero is unaware that they're gone;
2164.                scuffed away by monster movement or deleted during shop
2165.                or vault wall repair); not sure what to do about that */
2166.             e = engr_at(x, y);
2167.             if (!e)
2168.                 continue;
2169.             is_headstone = IS_GRAVE(svl.lastseentyp[x][y]);
2170.             Sprintf(lookbuf, " (%s", is_headstone ? "grave" : "engraving");
2171.             (void) add_quoted_engraving(x, y, lookbuf, TRUE);
2172.             /* the paren is used by farlook and add_quoted_engraving()
2173.                expected to see it; we don't want it here */
2174.             if (is_headstone) {
2175.                 (void) strsubst(lookbuf, "(grave with ", "");
2176.                 (void) strsubst(lookbuf, "(grave whose ", "");
2177.             } else {
2178.                 (void) strsubst(lookbuf, "(engraving with ", "");
2179.                 (void) strsubst(lookbuf, "(engraving ", "engraving ");
2180.             }
2181. 
2182.             glyph = glyph_at(x, y);
2183.             sym = glyph_is_cmap(glyph) ? glyph_to_cmap(glyph) : SYM_NOTHING;
2184.             if (is_cmap_engraving(sym) || sym == S_grave) {
2185.                 /* engraving or grave+headstone shown on the map */
2186.                 ++count;
2187.             } else {
2188.                 /* engraving or grave covered by object(s) */
2189.                 Snprintf(eos(lookbuf), sizeof lookbuf - strlen(lookbuf),
2190.                          ", obscured by %s", encglyph(glyph));
2191.                 glyph = is_headstone ? cmap_to_glyph(S_grave)
2192.                                      : engraving_to_glyph(e);
2193.                 ++count;
2194.             }
2195.             if (*lookbuf) { /* (redundant) */
2196.                 char coordbuf[20], cmode;
2197. 
2198.                 cmode = (iflags.getpos_coords != GPCOORDS_NONE)
2199.                            ? iflags.getpos_coords : GPCOORDS_MAP;
2200.                 if (count == 1) {
2201.                     Sprintf(outbuf, "%sseen or remembered engravings%s:",
2202.                             nearby ? "nearby " : "",
2203.                             nearby ? "" : " on this level");
2204.                     putstr(win, 0, upstart(outbuf));
2205.                     /* hack alert! Qt watches a text window for any line
2206.                        with 4 consecutive spaces and renders the window
2207.                        in a fixed-width font it if finds at least one */
2208.                     putstr(win, 0, "    "); /* separator */
2209.                 }
2210.                 /* prefix: "coords  C  " where 'C' is engrvng|grave symbol */
2211.                 Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s  "
2212.                                   : (cmode == GPCOORDS_MAP) ? "%8s  "
2213.                                       : "%12s  ",
2214.                         coord_desc(x, y, coordbuf, cmode));
2215.                 Sprintf(eos(outbuf), "%s ", encglyph(glyph));
2216.                 /* guard against potential overflow */
2217.                 lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0';
2218.                 Strcat(outbuf, lookbuf);
2219.                 putmixed(win, 0, outbuf);
2220.             }
2221.         }
2222.     }
2223.     if (count)
2224.         display_nhwindow(win, TRUE);
2225.     else
2226.         pline("No engravings seen or remembered%s.", nearby ? " nearby" : "");
2227.     destroy_nhwindow(win);
2228. }
2229. 
2230. static const char *suptext1[] = {
2231.     "%s is a member of a marauding horde of orcs",
2232.     "rumored to have brutally attacked and plundered",
2233.     "the ordinarily sheltered town that is located ",
2234.     "deep within The Gnomish Mines.",
2235.     "",
2236.     "The members of that vicious horde proudly and ",
2237.     "defiantly acclaim their allegiance to their",
2238.     "leader %s in their names.",
2239.     (char *) 0,
2240. };
2241. 
2242. static const char *suptext2[] = {
2243.     "\"%s\" is the common dungeon name of",
2244.     "a nefarious orc who is known to acquire property",
2245.     "from thieves and sell it off for profit.",
2246.     "",
2247.     "The perpetrator was last seen hanging around the",
2248.     "stairs leading to the Gnomish Mines.",
2249.     (char *) 0,
2250. };
2251. 
2252. staticfn void
2253. do_supplemental_info(
2254.     char *name,
2255.     struct permonst *pm,
2256.     boolean without_asking)
2257. {
2258.     const char **textp;
2259.     winid datawin = WIN_ERR;
2260.     char *entrytext = name, *bp = (char *) 0, *bp2 = (char *) 0;
2261.     char question[QBUFSZ];
2262.     boolean yes_to_moreinfo = FALSE;
2263.     boolean is_marauder = is_orc(pm);
2264. 
2265.     /*
2266.      * Provide some info on some specific things
2267.      * meant to support in-game mythology, and not
2268.      * available from data.base or other sources.
2269.      */
2270.     if (is_marauder && (strlen(name) < (BUFSZ - 1))) {
2271.         char fullname[BUFSZ];
2272. 
2273.         bp = strstri(name, " of ");
2274.         bp2 = strstri(name, " the Fence");
2275. 
2276.         if (bp || bp2) {
2277.             Strcpy(fullname, name);
2278.             if (!without_asking) {
2279.                 Strcpy(question, "More info about \"");
2280.                 /* +2 => length of "\"?" */
2281.                 copynchars(eos(question), entrytext,
2282.                         (int) (sizeof question - 1 - (strlen(question) + 2)));
2283.                 Strcat(question, "\"?");
2284.                 if (y_n(question) == 'y')
2285.                 yes_to_moreinfo = TRUE;
2286.             }
2287.             if (yes_to_moreinfo) {
2288.                 int i, subs = 0;
2289.                 const char *gang = (char *) 0;
2290. 
2291.                 if (bp) {
2292.                     textp = suptext1;
2293.                     gang = bp + 4;
2294.                     *bp = '\0';
2295.                 } else {
2296.                     textp = suptext2;
2297.                     gang = "";
2298.                 }
2299.                 datawin = create_nhwindow(NHW_MENU);
2300.                 for (i = 0; textp[i]; i++) {
2301.                     char buf[BUFSZ];
2302.                     const char *txt;
2303. 
2304.                     if (strstri(textp[i], "%s") != 0) {
2305.                         Sprintf(buf, textp[i], subs++ ? gang : fullname);
2306.                         txt = buf;
2307.                     } else
2308.                         txt = textp[i];
2309.                     putstr(datawin, 0, txt);
2310.                 }
2311.                 display_nhwindow(datawin, FALSE);
2312.                 destroy_nhwindow(datawin), datawin = WIN_ERR;
2313.             }
2314.         }
2315.     }
2316. }
2317. 
2318. RESTORE_WARNING_FORMAT_NONLITERAL
2319. 
2320. /* the #whatis command */
2321. int
2322. dowhatis(void)
2323. {
2324.     return do_look(0, (coord *) 0);
2325. }
2326. 
2327. /* the #glance command */
2328. int
2329. doquickwhatis(void)
2330. {
2331.     return do_look(1, (coord *) 0);
2332. }
2333. 
2334. /* the #showtrap command */
2335. int
2336. doidtrap(void)
2337. {
2338.     struct trap *trap;
2339.     int tt, glyph;
2340.     coordxy x, y;
2341. 
2342.     if (!getdir("^"))
2343.         return ECMD_CANCEL;
2344.     x = u.ux + u.dx;
2345.     y = u.uy + u.dy;
2346. 
2347.     /* trapped doors and chests used to be shown as fake bear traps;
2348.        they have their own trap types now but aren't part of the ftrap
2349.        chain; usually they revert to normal door or chest when the hero
2350.        sees them but player might be using '^' while the hero is blind */
2351.     glyph = glyph_at(x, y);
2352.     if (glyph_is_trap(glyph)
2353.         && ((tt = glyph_to_trap(glyph)) == BEAR_TRAP
2354.             || tt == TRAPPED_DOOR || tt == TRAPPED_CHEST)) {
2355.         boolean chesttrap = trapped_chest_at(tt, x, y);
2356. 
2357.         if (chesttrap || trapped_door_at(tt, x, y)) {
2358.             pline("That is a trapped %s.", chesttrap ? "chest" : "door");
2359.             return ECMD_OK; /* trap ID'd, but no time elapses */
2360.         }
2361.     }
2362. 
2363.     for (trap = gf.ftrap; trap; trap = trap->ntrap)
2364.         if (trap->tx == x && trap->ty == y) {
2365.             if (!trap->tseen)
2366.                 break;
2367.             tt = trap->ttyp;
2368.             if (u.dz) {
2369.                 if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
2370.                     break;
2371.             }
2372.             pline("That is %s%s%s.",
2373.                   an(trapname(tt, FALSE)),
2374.                   !trap->madeby_u
2375.                      ? ""
2376.                      : (tt == WEB)
2377.                         ? " woven"
2378.                         /* trap doors & spiked pits can't be made by
2379.                            player, and should be considered at least
2380.                            as much "set" as "dug" anyway */
2381.                         : (tt == HOLE || tt == PIT)
2382.                            ? " dug"
2383.                            : " set",
2384.                   !trap->madeby_u ? "" : " by you");
2385.             return ECMD_OK;
2386.         }
2387.     pline("I can't see a trap there.");
2388.     return ECMD_OK;
2389. }
2390. 
2391. /*
2392.     Implements a rudimentary if/elif/else/endif interpreter and use
2393.     conditionals in dat/cmdhelp to describe what command each keystroke
2394.     currently invokes, so that there isn't a lot of "(debug mode only)"
2395.     and "(if number_pad is off)" cluttering the feedback that the user
2396.     sees.  (The conditionals add quite a bit of clutter to the raw data
2397.     but users don't see that.  number_pad produces a lot of conditional
2398.     commands:  basic letters vs digits, 'g' vs 'G' for '5', phone
2399.     keypad vs normal layout of digits, and QWERTZ keyboard swap between
2400.     y/Y/^Y/M-y/M-Y/M-^Y and z/Z/^Z/M-z/M-Z/M-^Z.)
2401. 
2402.     The interpreter understands
2403.      '&#' for comment,
2404.      '&? option' for 'if' (also '&? !option'
2405.                            or '&? option=value[,value2,...]'
2406.                            or '&? !option=value[,value2,...]'),
2407.      '&: option' for 'elif' (with argument variations same as 'if';
2408.                              any number of instances for each 'if'),
2409.      '&:' for 'else' (also '&: #comment';
2410.                       0 or 1 instance for a given 'if'), and
2411.      '&.' for 'endif' (also '&. #comment'; required for each 'if').
2412. 
2413.     The option handling is a bit of a mess, with no generality for
2414.     which options to deal with and only a comma separated list of
2415.     integer values for the '=value' part.  number_pad is the only
2416.     supported option that has a value; the few others (wizard/debug,
2417.     rest_on_space, #if SHELL, #if SUSPEND) are booleans.
2418. */
2419. 
2420. staticfn void
2421. whatdoes_help(void)
2422. {
2423.     dlb *fp;
2424.     char *p, buf[BUFSZ];
2425.     winid tmpwin;
2426. 
2427.     fp = dlb_fopen(KEYHELP, "r");
2428.     if (!fp) {
2429.         pline("Cannot open \"%s\" data file!", KEYHELP);
2430.         display_nhwindow(WIN_MESSAGE, TRUE);
2431.         return;
2432.     }
2433.     tmpwin = create_nhwindow(NHW_TEXT);
2434.     while (dlb_fgets(buf, (int) sizeof buf, fp)) {
2435.         if (*buf == '#')
2436.             continue;
2437.         for (p = buf; *p; p++)
2438.             if (*p != ' ' && *p != '\t')
2439.                 break;
2440.         putstr(tmpwin, 0, p);
2441.     }
2442.     (void) dlb_fclose(fp);
2443.     display_nhwindow(tmpwin, TRUE);
2444.     destroy_nhwindow(tmpwin);
2445. }
2446. 
2447. #if 0
2448. #define WD_STACKLIMIT 5
2449. struct wd_stack_frame {
2450.     Bitfield(active, 1);
2451.     Bitfield(been_true, 1);
2452.     Bitfield(else_seen, 1);
2453. };
2454. 
2455. staticfn boolean whatdoes_cond(char *, struct wd_stack_frame *, int *, int);
2456. 
2457. staticfn boolean
2458. whatdoes_cond(char *buf, struct wd_stack_frame *stack, int *depth, int lnum)
2459. {
2460.     const char badstackfmt[] = "cmdhlp: too many &%c directives at line %d.";
2461.     boolean newcond, neg, gotopt;
2462.     char *p, *q, act = buf[1];
2463.     int np = 0;
2464. 
2465.     newcond = (act == '?' || !stack[*depth].been_true);
2466.     buf += 2;
2467.     mungspaces(buf);
2468.     if (act == '#' || *buf == '#' || !*buf || !newcond) {
2469.         gotopt = (*buf && *buf != '#');
2470.         *buf = '\0';
2471.         neg = FALSE; /* lint suppression */
2472.         p = q = (char *) 0;
2473.     } else {
2474.         gotopt = TRUE;
2475.         if ((neg = (*buf == '!')) != 0)
2476.             if (*++buf == ' ')
2477.                 ++buf;
2478.         p = strchr(buf, '='), q = strchr(buf, ':');
2479.         if (!p || (q && q < p))
2480.             p = q;
2481.         if (p) { /* we have a value specified */
2482.             /* handle a space before or after (or both) '=' (or ':') */
2483.             if (p > buf && p[-1] == ' ')
2484.                 p[-1] = '\0'; /* end of keyword in buf[] */
2485.             *p++ = '\0'; /* terminate keyword, advance to start of value */
2486.             if (*p == ' ')
2487.                 p++;
2488.         }
2489.     }
2490.     if (*buf && (act == '?' || act == ':')) {
2491.         if (!strcmpi(buf, "number_pad")) {
2492.             if (!p) {
2493.                 newcond = iflags.num_pad;
2494.             } else {
2495.                 /* convert internal encoding (separate yes/no and 0..3)
2496.                    back to user-visible one (-1..4) */
2497.                 np = iflags.num_pad ? (1 + iflags.num_pad_mode) /* 1..4 */
2498.                                     : (-1 * iflags.num_pad_mode); /* -1..0 */
2499.                 newcond = FALSE;
2500.                 for (; p; p = q) {
2501.                     q = strchr(p, ',');
2502.                     if (q)
2503.                         *q++ = '\0';
2504.                     if (atoi(p) == np) {
2505.                         newcond = TRUE;
2506.                         break;
2507.                     }
2508.                 }
2509.             }
2510.         } else if (!strcmpi(buf, "rest_on_space")) {
2511.             newcond = flags.rest_on_space;
2512.         } else if (!strcmpi(buf, "debug") || !strcmpi(buf, "wizard")) {
2513.             newcond = flags.debug; /* == wizard */
2514.         } else if (!strcmpi(buf, "shell")) {
2515. #ifdef SHELL
2516.             /* should we also check sysopt.shellers? */
2517.             newcond = TRUE;
2518. #else
2519.             newcond = FALSE;
2520. #endif
2521.         } else if (!strcmpi(buf, "suspend")) {
2522. #ifdef SUSPEND
2523.             /* sysopt.shellers is also used for dosuspend()... */
2524.             newcond = TRUE;
2525. #else
2526.             newcond = FALSE;
2527. #endif
2528.         } else {
2529.             impossible(
2530.                 "cmdhelp: unrecognized &%c conditional at line %d: \"%.20s\"",
2531.                        act, lnum, buf);
2532.             neg = FALSE;
2533.         }
2534.         /* this works for number_pad too: &? !number_pad:-1,0
2535.            would be true for 1..4 after negation */
2536.         if (neg)
2537.             newcond = !newcond;
2538.     }
2539.     switch (act) {
2540.     default:
2541.     case '#': /* comment */
2542.         break;
2543.     case '.': /* endif */
2544.         if (--*depth < 0) {
2545.             impossible(badstackfmt, '.', lnum);
2546.             *depth = 0;
2547.         }
2548.         break;
2549.     case ':': /* else or elif */
2550.         if (*depth == 0 || stack[*depth].else_seen) {
2551.             impossible(badstackfmt, ':', lnum);
2552.             *depth = 1; /* so that stack[*depth - 1] is a valid access */
2553.         }
2554.         if (stack[*depth].active || stack[*depth].been_true
2555.             || !stack[*depth - 1].active)
2556.             stack[*depth].active = 0;
2557.         else if (newcond)
2558.             stack[*depth].active = stack[*depth].been_true = 1;
2559.         if (!gotopt)
2560.             stack[*depth].else_seen = 1;
2561.         break;
2562.     case '?': /* if */
2563.         if (++*depth >= WD_STACKLIMIT) {
2564.             impossible(badstackfmt, '?', lnum);
2565.             *depth = WD_STACKLIMIT - 1;
2566.         }
2567.         stack[*depth].active = (newcond && stack[*depth - 1].active) ? 1 : 0;
2568.         stack[*depth].been_true = stack[*depth].active;
2569.         stack[*depth].else_seen = 0;
2570.         break;
2571.     }
2572.     return stack[*depth].active ? TRUE : FALSE;
2573. }
2574. #endif /* 0 */
2575. 
2576. char *
2577. dowhatdoes_core(char q, char *cbuf)
2578. {
2579.     char buf[BUFSZ];
2580. #if 0
2581.     dlb *fp;
2582.     struct wd_stack_frame stack[WD_STACKLIMIT];
2583.     boolean cond;
2584.     int ctrl, meta, depth = 0, lnum = 0;
2585. #endif /* 0 */
2586.     const char *ec_desc;
2587. 
2588.     if ((ec_desc = key2extcmddesc(q)) != NULL) {
2589.         char keybuf[QBUFSZ];
2590. 
2591.         /* note: if "%-8s" gets changed, the "%8.8s" in dowhatdoes() will
2592.            need a comparable change */
2593.         Sprintf(buf, "%-8s%s.", key2txt(q, keybuf), ec_desc);
2594.         Strcpy(cbuf, buf);
2595.         return cbuf;
2596.     }
2597.     return 0;
2598. #if 0
2599.     fp = dlb_fopen(CMDHELPFILE, "r");
2600.     if (!fp) {
2601.         pline("Cannot open \"%s\" data file!", CMDHELPFILE);
2602.         return 0;
2603.     }
2604. 
2605.     meta = (0x80 & (uchar) q) != 0;
2606.     if (meta)
2607.         q &= 0x7f;
2608.     ctrl = (0x1f & (uchar) q) == (uchar) q;
2609.     if (ctrl)
2610.         q |= 0x40; /* NUL -> '@', ^A -> 'A', ... ^Z -> 'Z', ^[ -> '[', ... */
2611.     else if (q == 0x7f)
2612.         ctrl = 1, q = '?';
2613. 
2614.     (void) memset((genericptr_t) stack, 0, sizeof stack);
2615.     cond = stack[0].active = 1;
2616.     while (dlb_fgets(buf, sizeof buf, fp)) {
2617.         ++lnum;
2618.         if (buf[0] == '&' && buf[1] && strchr("?:.#", buf[1])) {
2619.             cond = whatdoes_cond(buf, stack, &depth, lnum);
2620.             continue;
2621.         }
2622.         if (!cond)
2623.             continue;
2624.         if (meta ? (buf[0] == 'M' && buf[1] == '-'
2625.                     && (ctrl ? buf[2] == '^' && highc(buf[3]) == q
2626.                              : buf[2] == q))
2627.                  : (ctrl ? buf[0] == '^' && highc(buf[1]) == q
2628.                          : buf[0] == q)) {
2629.             (void) strip_newline(buf);
2630.             if (strchr(buf, '\t'))
2631.                 (void) tabexpand(buf);
2632.             if (meta && ctrl && buf[4] == ' ') {
2633.                 (void) strncpy(buf, "M-^?    ", 8);
2634.                 buf[3] = q;
2635.             } else if (meta && buf[3] == ' ') {
2636.                 (void) strncpy(buf, "M-?     ", 8);
2637.                 buf[2] = q;
2638.             } else if (ctrl && buf[2] == ' ') {
2639.                 (void) strncpy(buf, "^?      ", 8);
2640.                 buf[1] = q;
2641.             } else if (buf[1] == ' ') {
2642.                 (void) strncpy(buf, "?       ", 8);
2643.                 buf[0] = q;
2644.             }
2645.             (void) dlb_fclose(fp);
2646.             Strcpy(cbuf, buf);
2647.             return cbuf;
2648.         }
2649.     }
2650.     (void) dlb_fclose(fp);
2651.     if (depth != 0)
2652.         impossible("cmdhelp: mismatched &? &: &. conditionals.");
2653.     return (char *) 0;
2654. #endif /* 0 */
2655. }
2656. 
2657. /* the whatdoes command */
2658. int
2659. dowhatdoes(void)
2660. {
2661.     static boolean once = FALSE;
2662.     char bufr[BUFSZ];
2663.     char q, *reslt;
2664. 
2665.     if (!once) {
2666.         pline("Ask about '&' or '?' to get more info.%s",
2667. #ifdef ALTMETA
2668.               iflags.altmeta ? "  (For ESC, type it twice.)" :
2669. #endif
2670.               "");
2671.         once = TRUE;
2672.     }
2673. #if defined(UNIX) || defined(VMS)
2674.     introff(); /* disables ^C but not ^\ */
2675. #endif
2676.     q = yn_function("What command?", (char *) 0, '\0', TRUE);
2677. #ifdef ALTMETA
2678.     if (q == '\033' && iflags.altmeta) {
2679.         /* in an ideal world, we would know whether another keystroke
2680.            was already pending, but this is not an ideal world...
2681.            if user typed ESC, we'll essentially hang until another
2682.            character is typed */
2683.         q = yn_function("]", (char *) 0, '\0', TRUE);
2684.         if (q != '\033')
2685.             q = (char) ((uchar) q | 0200);
2686.     }
2687. #endif /*ALTMETA*/
2688. #if defined(UNIX) || defined(VMS)
2689.     intron(); /* reenables ^C */
2690. #endif
2691.     reslt = dowhatdoes_core(q, bufr);
2692.     if (reslt) {
2693.         char *p = strchr(reslt, '\n'); /* 'm' prefix has two lines of output */
2694. 
2695.         if (q == '&' || q == '?')
2696.             whatdoes_help();
2697.         if (!p) {
2698.             /* normal usage; 'reslt' starts with key, some indentation, and
2699.                then explanation followed by '.' for sentence punctuation */
2700.             pline("%s", reslt);
2701.         } else {
2702.             /* for 'm' prefix, where 'reslt' has an embedded newline to
2703.                indicate and separate two lines of output; we add a comma to
2704.                first line so that the combination is a complete sentence */
2705.             *p = '\0'; /* replace embedded newline with end of first line */
2706.             pline("%s,", reslt);
2707.             /* cheat by knowing how dowhatdoes_core() handles key portion */
2708.             pline("%8.8s%s", reslt, p + 1);
2709.         }
2710.     } else {
2711.         pline("No such command '%s', char code %d (0%03o or 0x%02x).",
2712.               visctrl(q), (uchar) q, (uchar) q, (uchar) q);
2713.     }
2714.     return ECMD_OK;
2715. }
2716. 
2717. staticfn void
2718. docontact(void)
2719. {
2720.     winid cwin = create_nhwindow(NHW_TEXT);
2721.     char buf[BUFSZ];
2722. 
2723.     if (sysopt.support) {
2724.         /*XXX overflow possibilities*/
2725.         Sprintf(buf, "To contact local support, %s", sysopt.support);
2726.         putstr(cwin, 0, buf);
2727.         putstr(cwin, 0, "");
2728.     } else if (sysopt.fmtd_wizard_list) { /* formatted SYSCF WIZARDS */
2729.         Sprintf(buf, "To contact local support, contact %s.",
2730.                 sysopt.fmtd_wizard_list);
2731.         putstr(cwin, 0, buf);
2732.         putstr(cwin, 0, "");
2733.     }
2734.     putstr(cwin, 0, "To contact the NetHack development team directly,");
2735.     /*XXX overflow possibilities*/
2736.     Sprintf(buf, "see the 'Contact' form on our website or email <%s>.",
2737.             DEVTEAM_EMAIL);
2738.     putstr(cwin, 0, buf);
2739.     putstr(cwin, 0, "");
2740.     putstr(cwin, 0, "For more information on NetHack, or to report a bug,");
2741.     Sprintf(buf, "visit our website \"%s\".", DEVTEAM_URL);
2742.     putstr(cwin, 0, buf);
2743.     display_nhwindow(cwin, FALSE);
2744.     destroy_nhwindow(cwin);
2745. }
2746. 
2747. staticfn void
2748. dispfile_help(void)
2749. {
2750.     display_file(HELP, TRUE);
2751. }
2752. 
2753. staticfn void
2754. dispfile_shelp(void)
2755. {
2756.     display_file(SHELP, TRUE);
2757. }
2758. 
2759. staticfn void
2760. dispfile_optionfile(void)
2761. {
2762.     display_file(OPTIONFILE, TRUE);
2763. }
2764. 
2765. staticfn void
2766. dispfile_optmenu(void)
2767. {
2768.     display_file(OPTMENUHELP, TRUE);
2769. }
2770. 
2771. staticfn void
2772. dispfile_license(void)
2773. {
2774.     display_file(LICENSE, TRUE);
2775. }
2776. 
2777. staticfn void
2778. dispfile_debughelp(void)
2779. {
2780.     display_file(DEBUGHELP, TRUE);
2781. }
2782. 
2783. staticfn void
2784. dispfile_usagehelp(void)
2785. {
2786.     display_file(USAGEHELP, TRUE);
2787. }
2788. 
2789. staticfn void
2790. hmenu_doextversion(void)
2791. {
2792.     (void) doextversion();
2793. }
2794. 
2795. staticfn void
2796. hmenu_dohistory(void)
2797. {
2798.     (void) dohistory();
2799. }
2800. 
2801. staticfn void
2802. hmenu_dowhatis(void)
2803. {
2804.     (void) dowhatis();
2805. }
2806. 
2807. staticfn void
2808. hmenu_dowhatdoes(void)
2809. {
2810.     (void) dowhatdoes();
2811. }
2812. 
2813. staticfn void
2814. hmenu_doextlist(void)
2815. {
2816.     (void) doextlist();
2817. }
2818. 
2819. staticfn void
2820. domenucontrols(void)
2821. {
2822.     winid cwin = create_nhwindow(NHW_TEXT);
2823. 
2824.     show_menu_controls(cwin, FALSE);
2825.     display_nhwindow(cwin, FALSE);
2826.     destroy_nhwindow(cwin);
2827. }
2828. 
2829. /* data for dohelp() */
2830. static const struct {
2831.     void (*f)(void);
2832.     const char *text;
2833. } help_menu_items[] = {
2834.     { hmenu_doextversion, "About NetHack (version information)." },
2835.     { dispfile_help, "Long description of the game and commands." },
2836.     { dispfile_shelp, "List of game commands." },
2837.     { hmenu_dohistory, "Concise history of NetHack." },
2838.     { hmenu_dowhatis, "Info on a character in the game display." },
2839.     { hmenu_dowhatdoes, "Info on what a given key does." },
2840.     { option_help, "List of game options." },
2841.     { dispfile_optionfile, "Longer explanation of game options." },
2842.     { dispfile_optmenu, "Using the %s command to set options." },
2843.     { dokeylist, "Full list of keyboard commands." },
2844.     { hmenu_doextlist, "List of extended commands." },
2845.     { domenucontrols, "List menu control keys." },
2846.     { dispfile_usagehelp, "Description of NetHack's command line." },
2847.     { dispfile_license, "The NetHack license." },
2848.     { docontact, "Support information." },
2849. #ifdef PORT_HELP
2850.     { port_help, "%s-specific help and commands." },
2851. #endif
2852.     { dispfile_debughelp, "List of wizard-mode commands." },
2853.     { (void (*)(void)) 0, (char *) 0 }
2854. };
2855. 
2856. DISABLE_WARNING_FORMAT_NONLITERAL
2857. 
2858. /* the #help command */
2859. int
2860. dohelp(void)
2861. {
2862.     winid tmpwin = create_nhwindow(NHW_MENU);
2863.     char helpbuf[QBUFSZ], tmpbuf[QBUFSZ];
2864.     int i, n;
2865.     menu_item *selected;
2866.     anything any;
2867.     int sel;
2868.     int clr = NO_COLOR;
2869. 
2870.     any = cg.zeroany; /* zero all bits */
2871.     start_menu(tmpwin, MENU_BEHAVE_STANDARD);
2872. 
2873.     for (i = 0; help_menu_items[i].text; i++) {
2874.         if (!wizard && help_menu_items[i].f == dispfile_debughelp)
2875.             continue;
2876.         if (sysopt.hideusage && help_menu_items[i].f == dispfile_usagehelp)
2877.             continue;
2878. 
2879.         if (help_menu_items[i].text[0] == '%') {
2880.             Sprintf(helpbuf, help_menu_items[i].text, PORT_ID);
2881.         } else if (help_menu_items[i].f == dispfile_optmenu) {
2882.             Sprintf(helpbuf, help_menu_items[i].text, setopt_cmd(tmpbuf));
2883.         } else {
2884.             Strcpy(helpbuf, help_menu_items[i].text);
2885.         }
2886.         any.a_int = i + 1;
2887.         add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr,
2888.                  helpbuf, MENU_ITEMFLAGS_NONE);
2889.     }
2890.     end_menu(tmpwin, "Select one item:");
2891.     n = select_menu(tmpwin, PICK_ONE, &selected);
2892.     destroy_nhwindow(tmpwin);
2893.     if (n > 0) {
2894.         sel = selected[0].item.a_int - 1;
2895.         free((genericptr_t) selected);
2896.         (void) (*help_menu_items[sel].f)();
2897.     }
2898.     return ECMD_OK;
2899. }
2900. 
2901. RESTORE_WARNING_FORMAT_NONLITERAL
2902. 
2903. /* format the key or extended command name of command used to set options;
2904.    normally 'O' but could be bound to something else, or not bound at all;
2905.    with the implementation of a simple options subset, now need 'mO' to get
2906.    the full options command; format it as 'm O' */
2907. staticfn char *
2908. setopt_cmd(char *outbuf)
2909. {
2910.     char cmdbuf[QBUFSZ];
2911.     const char *cmdnm;
2912.     char key;
2913. 
2914.     Strcpy(outbuf, "\'");
2915.     /* #optionsfull */
2916.     key = cmd_from_func(doset);
2917.     if (key) {
2918.         Strcat(outbuf, visctrl(key));
2919.     } else {
2920.         /* extended command name, with leading "#" */
2921.         cmdnm = cmdname_from_func(doset, cmdbuf, TRUE);
2922.         if (!cmdnm) /* paranoia */
2923.             cmdnm = "optionsfull";
2924.         Sprintf(eos(outbuf), "%s%.31s", (*cmdnm != '#') ? "#" : "", cmdnm);
2925. 
2926.         /* since there's no key bound to #optionsfull, include 'm O' */
2927.         Strcat(outbuf, "\' or \'");
2928.         /* m prefix plus #options */
2929.         key = cmd_from_func(do_reqmenu);
2930.         if (key) {
2931.             /* key for 'm' prefix */
2932.             Strcat(outbuf, visctrl(key));
2933.         } else {
2934.             /* extended command name for 'm' prefix */
2935.             cmdnm = cmdname_from_func(do_reqmenu, cmdbuf, TRUE);
2936.             if (!cmdnm)
2937.                 cmdnm = "reqmenu";
2938.             Sprintf(eos(outbuf), "%s%.31s", (*cmdnm != '#') ? "#" : "", cmdnm);
2939.         }
2940.         /* this is slightly iffy because the user shouldn't type <space> to
2941.            get the command we're describing, but it improves readability */
2942.         Strcat(outbuf, " ");
2943.         /* now #options, normally 'O' */
2944.         key = cmd_from_func(doset_simple);
2945.         if (key) {
2946.             Strcat(outbuf, visctrl(key));
2947.         } else {
2948.             /* extended command name */
2949.             cmdnm = cmdname_from_func(doset_simple, cmdbuf, TRUE);
2950.             if (!cmdnm) /* paranoia */
2951.                 cmdnm = "options";
2952.             Sprintf(eos(outbuf), "%s%.31s", (*cmdnm != '#') ? "#" : "", cmdnm);
2953.         }
2954.     }
2955.     Strcat(outbuf, "\'");
2956.     return outbuf;
2957. }
2958. 
2959. /* the 'V' command; also a choice for '?' */
2960. int
2961. dohistory(void)
2962. {
2963.     display_file(HISTORY, TRUE);
2964.     return ECMD_OK;
2965. }
2966. 
2967. /*pager.c*/