Source:NetHack 3.6.6/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 3.6.6. To link to a particular line, write [[Source:NetHack 3.6.6/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 3.6	pager.c	$NHDT-Date: 1574722864 2019/11/25 23:01:04 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.162 $ */
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. /* This file contains the command routines dowhatis() and dohelp() and */
7. /* a few other help related facilities */
8. 
9. #include "hack.h"
10. #include "dlb.h"
11. 
12. STATIC_DCL boolean FDECL(is_swallow_sym, (int));
13. STATIC_DCL int FDECL(append_str, (char *, const char *));
14. STATIC_DCL void FDECL(look_at_object, (char *, int, int, int));
15. STATIC_DCL void FDECL(look_at_monster, (char *, char *,
16.                                         struct monst *, int, int));
17. STATIC_DCL struct permonst *FDECL(lookat, (int, int, char *, char *));
18. STATIC_DCL void FDECL(checkfile, (char *, struct permonst *,
19.                                   BOOLEAN_P, BOOLEAN_P, char *));
20. STATIC_DCL void FDECL(look_all, (BOOLEAN_P,BOOLEAN_P));
21. STATIC_DCL void FDECL(do_supplemental_info, (char *, struct permonst *,
22.                                              BOOLEAN_P));
23. STATIC_DCL void NDECL(whatdoes_help);
24. STATIC_DCL void NDECL(docontact);
25. STATIC_DCL void NDECL(dispfile_help);
26. STATIC_DCL void NDECL(dispfile_shelp);
27. STATIC_DCL void NDECL(dispfile_optionfile);
28. STATIC_DCL void NDECL(dispfile_license);
29. STATIC_DCL void NDECL(dispfile_debughelp);
30. STATIC_DCL void NDECL(hmenu_doextversion);
31. STATIC_DCL void NDECL(hmenu_dohistory);
32. STATIC_DCL void NDECL(hmenu_dowhatis);
33. STATIC_DCL void NDECL(hmenu_dowhatdoes);
34. STATIC_DCL void NDECL(hmenu_doextlist);
35. #ifdef PORT_HELP
36. extern void NDECL(port_help);
37. #endif
38. 
39. /* Returns "true" for characters that could represent a monster's stomach. */
40. STATIC_OVL boolean
41. is_swallow_sym(c)
42. int c;
43. {
44.     int i;
45. 
46.     for (i = S_sw_tl; i <= S_sw_br; i++)
47.         if ((int) showsyms[i] == c)
48.             return TRUE;
49.     return FALSE;
50. }
51. 
52. /*
53.  * Append new_str to the end of buf if new_str doesn't already exist as
54.  * a substring of buf.  Return 1 if the string was appended, 0 otherwise.
55.  * It is expected that buf is of size BUFSZ.
56.  */
57. STATIC_OVL int
58. append_str(buf, new_str)
59. char *buf;
60. const char *new_str;
61. {
62.     int space_left; /* space remaining in buf */
63. 
64.     if (strstri(buf, new_str))
65.         return 0;
66. 
67.     space_left = BUFSZ - strlen(buf) - 1;
68.     if (space_left < 1)
69.         return 0;
70.     (void) strncat(buf, " or ", space_left);
71.     (void) strncat(buf, new_str, space_left - 4);
72.     return 1;
73. }
74. 
75. /* shared by monster probing (via query_objlist!) as well as lookat() */
76. char *
77. self_lookat(outbuf)
78. char *outbuf;
79. {
80.     char race[QBUFSZ];
81. 
82.     /* include race with role unless polymorphed */
83.     race[0] = '\0';
84.     if (!Upolyd)
85.         Sprintf(race, "%s ", urace.adj);
86.     Sprintf(outbuf, "%s%s%s called %s",
87.             /* being blinded may hide invisibility from self */
88.             (Invis && (senseself() || !Blind)) ? "invisible " : "", race,
89.             mons[u.umonnum].mname, plname);
90.     if (u.usteed)
91.         Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed));
92.     if (u.uundetected || (Upolyd && U_AP_TYPE))
93.         mhidden_description(&youmonst, FALSE, eos(outbuf));
94.     return outbuf;
95. }
96. 
97. /* describe a hidden monster; used for look_at during extended monster
98.    detection and for probing; also when looking at self */
99. void
100. mhidden_description(mon, altmon, outbuf)
101. struct monst *mon;
102. boolean altmon; /* for probing: if mimicking a monster, say so */
103. char *outbuf;
104. {
105.     struct obj *otmp;
106.     boolean fakeobj, isyou = (mon == &youmonst);
107.     int x = isyou ? u.ux : mon->mx, y = isyou ? u.uy : mon->my,
108.         glyph = (level.flags.hero_memory && !isyou) ? levl[x][y].glyph
109.                                                     : glyph_at(x, y);
110. 
111.     *outbuf = '\0';
112.     if (M_AP_TYPE(mon) == M_AP_FURNITURE
113.         || M_AP_TYPE(mon) == M_AP_OBJECT) {
114.         Strcpy(outbuf, ", mimicking ");
115.         if (M_AP_TYPE(mon) == M_AP_FURNITURE) {
116.             Strcat(outbuf, an(defsyms[mon->mappearance].explanation));
117.         } else if (M_AP_TYPE(mon) == M_AP_OBJECT
118.                    /* remembered glyph, not glyph_at() which is 'mon' */
119.                    && glyph_is_object(glyph)) {
120.  objfrommap:
121.             otmp = (struct obj *) 0;
122.             fakeobj = object_from_map(glyph, x, y, &otmp);
123.             Strcat(outbuf, (otmp && otmp->otyp != STRANGE_OBJECT)
124.                               ? ansimpleoname(otmp)
125.                               : an(obj_descr[STRANGE_OBJECT].oc_name));
126.             if (fakeobj) {
127.                 otmp->where = OBJ_FREE; /* object_from_map set to OBJ_FLOOR */
128.                 dealloc_obj(otmp);
129.             }
130.         } else {
131.             Strcat(outbuf, something);
132.         }
133.     } else if (M_AP_TYPE(mon) == M_AP_MONSTER) {
134.         if (altmon)
135.             Sprintf(outbuf, ", masquerading as %s",
136.                     an(mons[mon->mappearance].mname));
137.     } else if (isyou ? u.uundetected : mon->mundetected) {
138.         Strcpy(outbuf, ", hiding");
139.         if (hides_under(mon->data)) {
140.             Strcat(outbuf, " under ");
141.             /* remembered glyph, not glyph_at() which is 'mon' */
142.             if (glyph_is_object(glyph))
143.                 goto objfrommap;
144.             Strcat(outbuf, something);
145.         } else if (is_hider(mon->data)) {
146.             Sprintf(eos(outbuf), " on the %s",
147.                     (is_flyer(mon->data) || mon->data->mlet == S_PIERCER)
148.                        ? "ceiling"
149.                        : surface(x, y)); /* trapper */
150.         } else {
151.             if (mon->data->mlet == S_EEL && is_pool(x, y))
152.                 Strcat(outbuf, " in murky water");
153.         }
154.     }
155. }
156. 
157. /* extracted from lookat(); also used by namefloorobj() */
158. boolean
159. object_from_map(glyph, x, y, obj_p)
160. int glyph, x, y;
161. struct obj **obj_p;
162. {
163.     boolean fakeobj = FALSE, mimic_obj = FALSE;
164.     struct monst *mtmp;
165.     struct obj *otmp;
166.     int glyphotyp = glyph_to_obj(glyph);
167. 
168.     *obj_p = (struct obj *) 0;
169.     /* TODO: check inside containers in case glyph came from detection */
170.     if ((otmp = sobj_at(glyphotyp, x, y)) == 0)
171.         for (otmp = level.buriedobjlist; otmp; otmp = otmp->nobj)
172.             if (otmp->ox == x && otmp->oy == y && otmp->otyp == glyphotyp)
173.                 break;
174. 
175.     /* there might be a mimic here posing as an object */
176.     mtmp = m_at(x, y);
177.     if (mtmp && is_obj_mappear(mtmp, (unsigned) glyphotyp)) {
178.         otmp = 0;
179.         mimic_obj = TRUE;
180.     } else
181.         mtmp = 0;
182. 
183.     if (!otmp || otmp->otyp != glyphotyp) {
184.         /* this used to exclude STRANGE_OBJECT; now caller deals with it */
185.         otmp = mksobj(glyphotyp, FALSE, FALSE);
186.         if (!otmp)
187.             return FALSE;
188.         fakeobj = TRUE;
189.         if (otmp->oclass == COIN_CLASS)
190.             otmp->quan = 2L; /* to force pluralization */
191.         else if (otmp->otyp == SLIME_MOLD)
192.             otmp->spe = context.current_fruit; /* give it a type */
193.         if (mtmp && has_mcorpsenm(mtmp)) { /* mimic as corpse/statue */
194.             if (otmp->otyp == SLIME_MOLD)
195.                 /* override context.current_fruit to avoid
196.                      look, use 'O' to make new named fruit, look again
197.                    giving different results when current_fruit changes */
198.                 otmp->spe = MCORPSENM(mtmp);
199.             else
200.                 otmp->corpsenm = MCORPSENM(mtmp);
201.         } else if (otmp->otyp == CORPSE && glyph_is_body(glyph)) {
202.             otmp->corpsenm = glyph - GLYPH_BODY_OFF;
203.         } else if (otmp->otyp == STATUE && glyph_is_statue(glyph)) {
204.             otmp->corpsenm = glyph - GLYPH_STATUE_OFF;
205.         }
206.         if (otmp->otyp == LEASH)
207.             otmp->leashmon = 0;
208.         /* extra fields needed for shop price with doname() formatting */
209.         otmp->where = OBJ_FLOOR;
210.         otmp->ox = x, otmp->oy = y;
211.         otmp->no_charge = (otmp->otyp == STRANGE_OBJECT && costly_spot(x, y));
212.     }
213.     /* if located at adjacent spot, mark it as having been seen up close
214.        (corpse type will be known even if dknown is 0, so we don't need a
215.        touch check for cockatrice corpse--we're looking without touching) */
216.     if (otmp && distu(x, y) <= 2 && !Blind && !Hallucination
217.         /* redundant: we only look for an object which matches current
218.            glyph among floor and buried objects; when !Blind, any buried
219.            object's glyph will have been replaced by whatever is present
220.            on the surface as soon as we moved next to its spot */
221.         && (fakeobj || otmp->where == OBJ_FLOOR) /* not buried */
222.         /* terrain mode views what's already known, doesn't learn new stuff */
223.         && !iflags.terrainmode) /* so don't set dknown when in terrain mode */
224.         otmp->dknown = 1; /* if a pile, clearly see the top item only */
225.     if (fakeobj && mtmp && mimic_obj &&
226.         (otmp->dknown || (M_AP_FLAG(mtmp) & M_AP_F_DKNOWN))) {
227.             mtmp->m_ap_type |= M_AP_F_DKNOWN;
228.             otmp->dknown = 1;
229.     }
230.     *obj_p = otmp;
231.     return fakeobj; /* when True, caller needs to dealloc *obj_p */
232. }
233. 
234. STATIC_OVL void
235. look_at_object(buf, x, y, glyph)
236. char *buf; /* output buffer */
237. int x, y, glyph;
238. {
239.     struct obj *otmp = 0;
240.     boolean fakeobj = object_from_map(glyph, x, y, &otmp);
241. 
242.     if (otmp) {
243.         Strcpy(buf, (otmp->otyp != STRANGE_OBJECT)
244.                      ? distant_name(otmp, otmp->dknown ? doname_with_price
245.                                                        : doname_vague_quan)
246.                      : obj_descr[STRANGE_OBJECT].oc_name);
247.         if (fakeobj) {
248.             otmp->where = OBJ_FREE; /* object_from_map set it to OBJ_FLOOR */
249.             dealloc_obj(otmp), otmp = 0;
250.         }
251.     } else
252.         Strcpy(buf, something); /* sanity precaution */
253. 
254.     if (otmp && otmp->where == OBJ_BURIED)
255.         Strcat(buf, " (buried)");
256.     else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
257.         Strcat(buf, " embedded in stone");
258.     else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
259.         Strcat(buf, " embedded in a wall");
260.     else if (closed_door(x, y))
261.         Strcat(buf, " embedded in a door");
262.     else if (is_pool(x, y))
263.         Strcat(buf, " in water");
264.     else if (is_lava(x, y))
265.         Strcat(buf, " in molten lava"); /* [can this ever happen?] */
266.     return;
267. }
268. 
269. STATIC_OVL void
270. look_at_monster(buf, monbuf, mtmp, x, y)
271. char *buf, *monbuf; /* buf: output, monbuf: optional output */
272. struct monst *mtmp;
273. int x, y;
274. {
275.     char *name, monnambuf[BUFSZ];
276.     boolean accurate = !Hallucination;
277. 
278.     name = (mtmp->data == &mons[PM_COYOTE] && accurate)
279.               ? coyotename(mtmp, monnambuf)
280.               : distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
281.     Sprintf(buf, "%s%s%s",
282.             (mtmp->mx != x || mtmp->my != y)
283.                 ? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ")
284.                 : "",
285.             (mtmp->mtame && accurate)
286.                 ? "tame "
287.                 : (mtmp->mpeaceful && accurate)
288.                     ? "peaceful "
289.                     : "",
290.             name);
291.     if (u.ustuck == mtmp) {
292.         if (u.uswallow || iflags.save_uswallow) /* monster detection */
293.             Strcat(buf, is_animal(mtmp->data)
294.                           ? ", swallowing you" : ", engulfing you");
295.         else
296.             Strcat(buf, (Upolyd && sticks(youmonst.data))
297.                           ? ", being held" : ", holding you");
298.     }
299.     if (mtmp->mleashed)
300.         Strcat(buf, ", leashed to you");
301. 
302.     if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
303.         struct trap *t = t_at(mtmp->mx, mtmp->my);
304.         int tt = t ? t->ttyp : NO_TRAP;
305. 
306.         /* newsym lets you know of the trap, so mention it here */
307.         if (tt == BEAR_TRAP || is_pit(tt) || tt == WEB) {
308.             Sprintf(eos(buf), ", trapped in %s",
309.                     an(defsyms[trap_to_defsym(tt)].explanation));
310.             t->tseen = 1;
311.         }
312.     }
313. 
314.     /* we know the hero sees a monster at this location, but if it's shown
315.        due to persistant monster detection he might remember something else */
316.     if (mtmp->mundetected || M_AP_TYPE(mtmp))
317.         mhidden_description(mtmp, FALSE, eos(buf));
318. 
319.     if (monbuf) {
320.         unsigned how_seen = howmonseen(mtmp);
321. 
322.         monbuf[0] = '\0';
323.         if (how_seen != 0 && how_seen != MONSEEN_NORMAL) {
324.             if (how_seen & MONSEEN_NORMAL) {
325.                 Strcat(monbuf, "normal vision");
326.                 how_seen &= ~MONSEEN_NORMAL;
327.                 /* how_seen can't be 0 yet... */
328.                 if (how_seen)
329.                     Strcat(monbuf, ", ");
330.             }
331.             if (how_seen & MONSEEN_SEEINVIS) {
332.                 Strcat(monbuf, "see invisible");
333.                 how_seen &= ~MONSEEN_SEEINVIS;
334.                 if (how_seen)
335.                     Strcat(monbuf, ", ");
336.             }
337.             if (how_seen & MONSEEN_INFRAVIS) {
338.                 Strcat(monbuf, "infravision");
339.                 how_seen &= ~MONSEEN_INFRAVIS;
340.                 if (how_seen)
341.                     Strcat(monbuf, ", ");
342.             }
343.             if (how_seen & MONSEEN_TELEPAT) {
344.                 Strcat(monbuf, "telepathy");
345.                 how_seen &= ~MONSEEN_TELEPAT;
346.                 if (how_seen)
347.                     Strcat(monbuf, ", ");
348.             }
349.             if (how_seen & MONSEEN_XRAYVIS) {
350.                 /* Eyes of the Overworld */
351.                 Strcat(monbuf, "astral vision");
352.                 how_seen &= ~MONSEEN_XRAYVIS;
353.                 if (how_seen)
354.                     Strcat(monbuf, ", ");
355.             }
356.             if (how_seen & MONSEEN_DETECT) {
357.                 Strcat(monbuf, "monster detection");
358.                 how_seen &= ~MONSEEN_DETECT;
359.                 if (how_seen)
360.                     Strcat(monbuf, ", ");
361.             }
362.             if (how_seen & MONSEEN_WARNMON) {
363.                 if (Hallucination) {
364.                     Strcat(monbuf, "paranoid delusion");
365.                 } else {
366.                     unsigned long mW = (context.warntype.obj
367.                                         | context.warntype.polyd),
368.                                   m2 = mtmp->data->mflags2;
369.                     const char *whom = ((mW & M2_HUMAN & m2) ? "human"
370.                                         : (mW & M2_ELF & m2) ? "elf"
371.                                           : (mW & M2_ORC & m2) ? "orc"
372.                                             : (mW & M2_DEMON & m2) ? "demon"
373.                                               : mtmp->data->mname);
374. 
375.                     Sprintf(eos(monbuf), "warned of %s", makeplural(whom));
376.                 }
377.                 how_seen &= ~MONSEEN_WARNMON;
378.                 if (how_seen)
379.                     Strcat(monbuf, ", ");
380.             }
381.             /* should have used up all the how_seen bits by now */
382.             if (how_seen) {
383.                 impossible("lookat: unknown method of seeing monster");
384.                 Sprintf(eos(monbuf), "(%u)", how_seen);
385.             }
386.         } /* seen by something other than normal vision */
387.     } /* monbuf is non-null */
388. }
389. 
390. /*
391.  * Return the name of the glyph found at (x,y).
392.  * If not hallucinating and the glyph is a monster, also monster data.
393.  */
394. STATIC_OVL struct permonst *
395. lookat(x, y, buf, monbuf)
396. int x, y;
397. char *buf, *monbuf;
398. {
399.     struct monst *mtmp = (struct monst *) 0;
400.     struct permonst *pm = (struct permonst *) 0;
401.     int glyph;
402. 
403.     buf[0] = monbuf[0] = '\0';
404.     glyph = glyph_at(x, y);
405.     if (u.ux == x && u.uy == y && canspotself()
406.         && !(iflags.save_uswallow &&
407.              glyph == mon_to_glyph(u.ustuck, rn2_on_display_rng))
408.         && (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) {
409.         /* fill in buf[] */
410.         (void) self_lookat(buf);
411. 
412.         /* file lookup can't distinguish between "gnomish wizard" monster
413.            and correspondingly named player character, always picking the
414.            former; force it to find the general "wizard" entry instead */
415.         if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
416.             pm = &mons[PM_WIZARD];
417. 
418.         /* When you see yourself normally, no explanation is appended
419.            (even if you could also see yourself via other means).
420.            Sensing self while blind or swallowed is treated as if it
421.            were by normal vision (cf canseeself()). */
422.         if ((Invisible || u.uundetected) && !Blind
423.             && !(u.uswallow || iflags.save_uswallow)) {
424.             unsigned how = 0;
425. 
426.             if (Infravision)
427.                 how |= 1;
428.             if (Unblind_telepat)
429.                 how |= 2;
430.             if (Detect_monsters)
431.                 how |= 4;
432. 
433.             if (how)
434.                 Sprintf(eos(buf), " [seen: %s%s%s%s%s]",
435.                         (how & 1) ? "infravision" : "",
436.                         /* add comma if telep and infrav */
437.                         ((how & 3) > 2) ? ", " : "",
438.                         (how & 2) ? "telepathy" : "",
439.                         /* add comma if detect and (infrav or telep or both) */
440.                         ((how & 7) > 4) ? ", " : "",
441.                         (how & 4) ? "monster detection" : "");
442.         }
443.     } else if (u.uswallow) {
444.         /* when swallowed, we're only called for spots adjacent to hero,
445.            and blindness doesn't prevent hero from feeling what holds him */
446.         Sprintf(buf, "interior of %s", a_monnam(u.ustuck));
447.         pm = u.ustuck->data;
448.     } else if (glyph_is_monster(glyph)) {
449.         bhitpos.x = x;
450.         bhitpos.y = y;
451.         if ((mtmp = m_at(x, y)) != 0) {
452.             look_at_monster(buf, monbuf, mtmp, x, y);
453.             pm = mtmp->data;
454.         } else if (Hallucination) {
455.             /* 'monster' must actually be a statue */
456.             Strcpy(buf, rndmonnam((char *) 0));
457.         }
458.     } else if (glyph_is_object(glyph)) {
459.         look_at_object(buf, x, y, glyph); /* fill in buf[] */
460.     } else if (glyph_is_trap(glyph)) {
461.         int tnum = what_trap(glyph_to_trap(glyph), rn2_on_display_rng);
462. 
463.         /* Trap detection displays a bear trap at locations having
464.          * a trapped door or trapped container or both.
465.          * TODO: we should create actual trap types for doors and
466.          * chests so that they can have their own glyphs and tiles.
467.          */
468.         if (trapped_chest_at(tnum, x, y))
469.             Strcpy(buf, "trapped chest"); /* might actually be a large box */
470.         else if (trapped_door_at(tnum, x, y))
471.             Strcpy(buf, "trapped door"); /* not "trap door"... */
472.         else
473.             Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation);
474.     } else if (glyph_is_warning(glyph)) {
475.         int warnindx = glyph_to_warning(glyph);
476. 
477.         Strcpy(buf, def_warnsyms[warnindx].explanation);
478.     } else if (!glyph_is_cmap(glyph)) {
479.         Strcpy(buf, "unexplored area");
480.     } else {
481.         int amsk;
482.         aligntyp algn;
483. 
484.         switch (glyph_to_cmap(glyph)) {
485.         case S_altar:
486.             amsk = ((mtmp = m_at(x, y)) != 0 && has_mcorpsenm(mtmp)
487.                     && M_AP_TYPE(mtmp) == M_AP_FURNITURE
488.                     && mtmp->mappearance == S_altar) ? MCORPSENM(mtmp)
489.                    : levl[x][y].altarmask;
490.             algn = Amask2align(amsk & ~AM_SHRINE);
491.             Sprintf(buf, "%s %saltar",
492.                     /* like endgame high priests, endgame high altars
493.                        are only recognizable when immediately adjacent */
494.                     (Is_astralevel(&u.uz) && distu(x, y) > 2)
495.                         ? "aligned"
496.                         : align_str(algn),
497.                     ((amsk & AM_SHRINE) != 0
498.                      && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)))
499.                         ? "high "
500.                         : "");
501.             break;
502.         case S_ndoor:
503.             if (is_drawbridge_wall(x, y) >= 0)
504.                 Strcpy(buf, "open drawbridge portcullis");
505.             else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
506.                 Strcpy(buf, "broken door");
507.             else
508.                 Strcpy(buf, "doorway");
509.             break;
510.         case S_cloud:
511.             Strcpy(buf,
512.                    Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
513.             break;
514.         case S_stone:
515.             if (!levl[x][y].seenv) {
516.                 Strcpy(buf, "unexplored");
517.                 break;
518.             } else if (Underwater && !Is_waterlevel(&u.uz)) {
519.                 /* "unknown" == previously mapped but not visible when
520.                    submerged; better terminology appreciated... */
521.                 Strcpy(buf, (distu(x, y) <= 2) ? "land" : "unknown");
522.                 break;
523.             } else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) {
524.                 Strcpy(buf, "stone");
525.                 break;
526.             }
527.             /*FALLTHRU*/
528.         default:
529.             Strcpy(buf, defsyms[glyph_to_cmap(glyph)].explanation);
530.             break;
531.         }
532.     }
533.     return (pm && !Hallucination) ? pm : (struct permonst *) 0;
534. }
535. 
536. /*
537.  * Look in the "data" file for more info.  Called if the user typed in the
538.  * whole name (user_typed_name == TRUE), or we've found a possible match
539.  * with a character/glyph and flags.help is TRUE.
540.  *
541.  * NOTE: when (user_typed_name == FALSE), inp is considered read-only and
542.  *       must not be changed directly, e.g. via lcase(). We want to force
543.  *       lcase() for data.base lookup so that we can have a clean key.
544.  *       Therefore, we create a copy of inp _just_ for data.base lookup.
545.  */
546. STATIC_OVL void
547. checkfile(inp, pm, user_typed_name, without_asking, supplemental_name)
548. char *inp;
549. struct permonst *pm;
550. boolean user_typed_name, without_asking;
551. char *supplemental_name;
552. {
553.     dlb *fp;
554.     char buf[BUFSZ], newstr[BUFSZ], givenname[BUFSZ];
555.     char *ep, *dbase_str;
556.     unsigned long txt_offset = 0L;
557.     winid datawin = WIN_ERR;
558. 
559.     fp = dlb_fopen(DATAFILE, "r");
560.     if (!fp) {
561.         pline("Cannot open 'data' file!");
562.         return;
563.     }
564.     /* If someone passed us garbage, prevent fault. */
565.     if (!inp || strlen(inp) > (BUFSZ - 1)) {
566.         impossible("bad do_look buffer passed (%s)!",
567.                    !inp ? "null" : "too long");
568.         goto checkfile_done;
569.     }
570. 
571.     /* To prevent the need for entries in data.base like *ngel to account
572.      * for Angel and angel, make the lookup string the same for both
573.      * user_typed_name and picked name.
574.      */
575.     if (pm != (struct permonst *) 0 && !user_typed_name)
576.         dbase_str = strcpy(newstr, pm->mname);
577.     else
578.         dbase_str = strcpy(newstr, inp);
579.     (void) lcase(dbase_str);
580. 
581.     /*
582.      * TODO:
583.      * The switch from xname() to doname_vague_quan() in look_at_obj()
584.      * had the unintendded side-effect of making names picked from
585.      * pointing at map objects become harder to simplify for lookup.
586.      * We should split the prefix and suffix handling used by wish
587.      * parsing and also wizmode monster generation out into separate
588.      * routines and use those routines here.  This currently lacks
589.      * erosion handling and probably lots of other bits and pieces
590.      * that wishing already understands and most of this duplicates
591.      * stuff already done for wish handling or monster generation.
592.      */
593.     if (!strncmp(dbase_str, "interior of ", 12))
594.         dbase_str += 12;
595.     if (!strncmp(dbase_str, "a ", 2))
596.         dbase_str += 2;
597.     else if (!strncmp(dbase_str, "an ", 3))
598.         dbase_str += 3;
599.     else if (!strncmp(dbase_str, "the ", 4))
600.         dbase_str += 4;
601.     else if (!strncmp(dbase_str, "some ", 5))
602.         dbase_str += 5;
603.     else if (digit(*dbase_str)) {
604.         /* remove count prefix ("2 ya") which can come from looking at map */
605.         while (digit(*dbase_str))
606.             ++dbase_str;
607.         if (*dbase_str == ' ')
608.             ++dbase_str;
609.     }
610.     if (!strncmp(dbase_str, "pair of ", 8))
611.         dbase_str += 8;
612.     if (!strncmp(dbase_str, "tame ", 5))
613.         dbase_str += 5;
614.     else if (!strncmp(dbase_str, "peaceful ", 9))
615.         dbase_str += 9;
616.     if (!strncmp(dbase_str, "invisible ", 10))
617.         dbase_str += 10;
618.     if (!strncmp(dbase_str, "saddled ", 8))
619.         dbase_str += 8;
620.     if (!strncmp(dbase_str, "blessed ", 8))
621.         dbase_str += 8;
622.     else if (!strncmp(dbase_str, "uncursed ", 9))
623.         dbase_str += 9;
624.     else if (!strncmp(dbase_str, "cursed ", 7))
625.         dbase_str += 7;
626.     if (!strncmp(dbase_str, "empty ", 6))
627.         dbase_str += 6;
628.     if (!strncmp(dbase_str, "partly used ", 12))
629.         dbase_str += 12;
630.     else if (!strncmp(dbase_str, "partly eaten ", 13))
631.         dbase_str += 13;
632.     if (!strncmp(dbase_str, "statue of ", 10))
633.         dbase_str[6] = '\0';
634.     else if (!strncmp(dbase_str, "figurine of ", 12))
635.         dbase_str[8] = '\0';
636.     /* remove enchantment ("+0 aklys"); [for 3.6.0 and earlier, this wasn't
637.        needed because looking at items on the map used xname() rather than
638.        doname() hence known enchantment was implicitly suppressed] */
639.     if (*dbase_str && index("+-", dbase_str[0]) && digit(dbase_str[1])) {
640.         ++dbase_str; /* skip sign */
641.         while (digit(*dbase_str))
642.             ++dbase_str;
643.         if (*dbase_str == ' ')
644.             ++dbase_str;
645.     }
646.     /* "towel", "wet towel", and "moist towel" share one data.base entry;
647.        for "wet towel", we keep prefix so that the prompt will ask about
648.        "wet towel"; for "moist towel", we also want to ask about "wet towel".
649.        (note: strncpy() only terminates output string if the specified
650.        count is bigger than the length of the substring being copied) */
651.     if (!strncmp(dbase_str, "moist towel", 11))
652.         (void) strncpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */
653. 
654.     /* Make sure the name is non-empty. */
655.     if (*dbase_str) {
656.         long pass1offset = -1L;
657.         int chk_skip, pass = 1;
658.         boolean yes_to_moreinfo, found_in_file, pass1found_in_file,
659.                 skipping_entry;
660.         char *sp, *ap, *alt = 0; /* alternate description */
661. 
662.         /* adjust the input to remove "named " and "called " */
663.         if ((ep = strstri(dbase_str, " named ")) != 0) {
664.             alt = ep + 7;
665.             if ((ap = strstri(dbase_str, " called ")) != 0 && ap < ep)
666.                 ep = ap; /* "named" is alt but truncate at "called" */
667.         } else if ((ep = strstri(dbase_str, " called ")) != 0) {
668.             copynchars(givenname, ep + 8, BUFSZ - 1);
669.             alt = givenname;
670.             if (supplemental_name && (sp = strstri(inp, " called ")) != 0)
671.                 copynchars(supplemental_name, sp + 8, BUFSZ - 1);
672.         } else
673.             ep = strstri(dbase_str, ", ");
674.         if (ep && ep > dbase_str)
675.             *ep = '\0';
676.         /* remove article from 'alt' name ("a pair of lenses named
677.            The Eyes of the Overworld" simplified above to "lenses named
678.            The Eyes of the Overworld", now reduced to "The Eyes of the
679.            Overworld", skip "The" as with base name processing) */
680.         if (alt && (!strncmpi(alt, "a ", 2)
681.                     || !strncmpi(alt, "an ", 3)
682.                     || !strncmpi(alt, "the ", 4)))
683.             alt = index(alt, ' ') + 1;
684.         /* remove charges or "(lit)" or wizmode "(N aum)" */
685.         if ((ep = strstri(dbase_str, " (")) != 0 && ep > dbase_str)
686.             *ep = '\0';
687.         if (alt && (ap = strstri(alt, " (")) != 0 && ap > alt)
688.             *ap = '\0';
689. 
690.         /*
691.          * If the object is named, then the name is the alternate description;
692.          * otherwise, the result of makesingular() applied to the name is.
693.          * This isn't strictly optimal, but named objects of interest to the
694.          * user will usually be found under their name, rather than under
695.          * their object type, so looking for a singular form is pointless.
696.          */
697.         if (!alt)
698.             alt = makesingular(dbase_str);
699. 
700.         pass1found_in_file = FALSE;
701.         for (pass = !strcmp(alt, dbase_str) ? 0 : 1; pass >= 0; --pass) {
702.             found_in_file = skipping_entry = FALSE;
703.             txt_offset = 0L;
704.             if (dlb_fseek(fp, txt_offset, SEEK_SET) < 0 ) {
705.                 impossible("can't get to start of 'data' file");
706.                 goto checkfile_done;
707.             }
708.             /* skip first record; read second */
709.             if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
710.                 impossible("can't read 'data' file");
711.                 goto checkfile_done;
712.             } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1
713.                        || txt_offset == 0L)
714.                 goto bad_data_file;
715. 
716.             /* look for the appropriate entry */
717.             while (dlb_fgets(buf, BUFSZ, fp)) {
718.                 if (*buf == '.')
719.                     break; /* we passed last entry without success */
720. 
721.                 if (digit(*buf)) {
722.                     /* a number indicates the end of current entry */
723.                     skipping_entry = FALSE;
724.                 } else if (!skipping_entry) {
725.                     if (!(ep = index(buf, '\n')))
726.                         goto bad_data_file;
727.                     (void) strip_newline((ep > buf) ? ep - 1 : ep);
728.                     /* if we match a key that begins with "~", skip
729.                        this entry */
730.                     chk_skip = (*buf == '~') ? 1 : 0;
731.                     if ((pass == 0 && pmatch(&buf[chk_skip], dbase_str))
732.                         || (pass == 1 && alt && pmatch(&buf[chk_skip], alt))) {
733.                         if (chk_skip) {
734.                             skipping_entry = TRUE;
735.                             continue;
736.                         } else {
737.                             found_in_file = TRUE;
738.                             if (pass == 1)
739.                                 pass1found_in_file = TRUE;
740.                             break;
741.                         }
742.                     }
743.                 }
744.             }
745.             if (found_in_file) {
746.                 long entry_offset, fseekoffset;
747.                 int entry_count;
748.                 int i;
749. 
750.                 /* skip over other possible matches for the info */
751.                 do {
752.                     if (!dlb_fgets(buf, BUFSZ, fp))
753.                         goto bad_data_file;
754.                 } while (!digit(*buf));
755.                 if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2)
756.                     goto bad_data_file;
757.                 fseekoffset = (long) txt_offset + entry_offset;
758.                 if (pass == 1)
759.                     pass1offset = fseekoffset;
760.                 else if (fseekoffset == pass1offset)
761.                     goto checkfile_done;
762. 
763.                 yes_to_moreinfo = FALSE;
764.                 if (!user_typed_name && !without_asking) {
765.                     char *entrytext = pass ? alt : dbase_str;
766.                     char question[QBUFSZ];
767. 
768.                     Strcpy(question, "More info about \"");
769.                     /* +2 => length of "\"?" */
770.                     copynchars(eos(question), entrytext,
771.                                (int) (sizeof question - 1
772.                                       - (strlen(question) + 2)));
773.                     Strcat(question, "\"?");
774.                     if (yn(question) == 'y')
775.                         yes_to_moreinfo = TRUE;
776.                 }
777. 
778.                 if (user_typed_name || without_asking || yes_to_moreinfo) {
779.                     if (dlb_fseek(fp, fseekoffset, SEEK_SET) < 0) {
780.                         pline("? Seek error on 'data' file!");
781.                         goto checkfile_done;
782.                     }
783.                     datawin = create_nhwindow(NHW_MENU);
784.                     for (i = 0; i < entry_count; i++) {
785.                         if (!dlb_fgets(buf, BUFSZ, fp))
786.                             goto bad_data_file;
787.                         (void) strip_newline(buf);
788.                         if (index(buf + 1, '\t') != 0)
789.                             (void) tabexpand(buf + 1);
790.                         putstr(datawin, 0, buf + 1);
791.                     }
792.                     display_nhwindow(datawin, FALSE);
793.                     destroy_nhwindow(datawin), datawin = WIN_ERR;
794.                 }
795.             } else if (user_typed_name && pass == 0 && !pass1found_in_file)
796.                 pline("I don't have any information on those things.");
797.         }
798.     }
799.     goto checkfile_done; /* skip error feedback */
800. 
801.  bad_data_file:
802.     impossible("'data' file in wrong format or corrupted");
803.  checkfile_done:
804.     if (datawin != WIN_ERR)
805.         destroy_nhwindow(datawin);
806.     (void) dlb_fclose(fp);
807.     return;
808. }
809. 
810. int
811. do_screen_description(cc, looked, sym, out_str, firstmatch, for_supplement)
812. coord cc;
813. boolean looked;
814. int sym;
815. char *out_str;
816. const char **firstmatch;
817. struct permonst **for_supplement;
818. {
819.     static const char mon_interior[] = "the interior of a monster",
820.                       unreconnoitered[] = "unreconnoitered";
821.     static char look_buf[BUFSZ];
822.     char prefix[BUFSZ];
823.     int i, alt_i, j, glyph = NO_GLYPH,
824.         skipped_venom = 0, found = 0; /* count of matching syms found */
825.     boolean hit_trap, need_to_look = FALSE,
826.             submerged = (Underwater && !Is_waterlevel(&u.uz));
827.     const char *x_str;
828.     nhsym tmpsym;
829. 
830.     if (looked) {
831.         int oc;
832.         unsigned os;
833. 
834.         glyph = glyph_at(cc.x, cc.y);
835.         /* Convert glyph at selected position to a symbol for use below. */
836.         (void) mapglyph(glyph, &sym, &oc, &os, cc.x, cc.y, 0);
837. 
838.         Sprintf(prefix, "%s        ", encglyph(glyph));
839.     } else
840.         Sprintf(prefix, "%c        ", sym);
841. 
842.     /*
843.      * Check all the possibilities, saving all explanations in a buffer.
844.      * When all have been checked then the string is printed.
845.      */
846. 
847.     /*
848.      * Handle restricted vision range (limited to adjacent spots when
849.      * swallowed or underwater) cases first.
850.      *
851.      * 3.6.0 listed anywhere on map, other than self, as "interior
852.      * of a monster" when swallowed, and non-adjacent water or
853.      * non-water anywhere as "dark part of a room" when underwater.
854.      * "unreconnoitered" is an attempt to convey "even if you knew
855.      * what was there earlier, you don't know what is there in the
856.      * current circumstance".
857.      *
858.      * (Note: 'self' will always be visible when swallowed so we don't
859.      * need special swallow handling for <ux,uy>.
860.      * Another note: for '#terrain' without monsters, u.uswallow and
861.      * submerged will always both be False and skip this code.)
862.      */
863.     x_str = 0;
864.     if (!looked) {
865.         ; /* skip special handling */
866.     } else if (((u.uswallow || submerged) && distu(cc.x, cc.y) > 2)
867.                /* detection showing some category, so mostly background */
868.                || ((iflags.terrainmode & (TER_DETECT | TER_MAP)) == TER_DETECT
869.                    && glyph == cmap_to_glyph(S_stone))) {
870.         x_str = unreconnoitered;
871.         need_to_look = FALSE;
872.     } else if (is_swallow_sym(sym)) {
873.         x_str = mon_interior;
874.         need_to_look = TRUE; /* for specific monster type */
875.     }
876.     if (x_str) {
877.         /* we know 'found' is zero here, but guard against some other
878.            special case being inserted ahead of us someday */
879.         if (!found) {
880.             Sprintf(out_str, "%s%s", prefix, x_str);
881.             *firstmatch = x_str;
882.             found++;
883.         } else {
884.             found += append_str(out_str, x_str); /* not 'an(x_str)' */
885.         }
886.         /* for is_swallow_sym(), we want to list the current symbol's
887.            other possibilities (wand for '/', throne for '\\', &c) so
888.            don't jump to the end for the x_str==mon_interior case */
889.         if (x_str == unreconnoitered)
890.             goto didlook;
891.     }
892.  check_monsters:
893.     /* Check for monsters */
894.     if (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0) {
895.         for (i = 1; i < MAXMCLASSES; i++) {
896.             if (sym == (looked ? showsyms[i + SYM_OFF_M] : def_monsyms[i].sym)
897.                 && def_monsyms[i].explain && *def_monsyms[i].explain) {
898.                 need_to_look = TRUE;
899.                 if (!found) {
900.                     Sprintf(out_str, "%s%s",
901.                             prefix, an(def_monsyms[i].explain));
902.                     *firstmatch = def_monsyms[i].explain;
903.                     found++;
904.                 } else {
905.                     found += append_str(out_str, an(def_monsyms[i].explain));
906.                 }
907.             }
908.         }
909.         /* handle '@' as a special case if it refers to you and you're
910.            playing a character which isn't normally displayed by that
911.            symbol; firstmatch is assumed to already be set for '@' */
912.         if ((looked ? (sym == showsyms[S_HUMAN + SYM_OFF_M]
913.                        && cc.x == u.ux && cc.y == u.uy)
914.                     : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace))
915.             && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd)
916.             found += append_str(out_str, "you"); /* tack on "or you" */
917.     }
918. 
919.     /* Now check for objects */
920.     if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) {
921.         for (i = 1; i < MAXOCLASSES; i++) {
922.             if (sym == (looked ? showsyms[i + SYM_OFF_O]
923.                                : def_oc_syms[i].sym)
924.                 || (looked && i == ROCK_CLASS && glyph_is_statue(glyph))) {
925.                 need_to_look = TRUE;
926.                 if (looked && i == VENOM_CLASS) {
927.                     skipped_venom++;
928.                     continue;
929.                 }
930.                 if (!found) {
931.                     Sprintf(out_str, "%s%s",
932.                             prefix, an(def_oc_syms[i].explain));
933.                     *firstmatch = def_oc_syms[i].explain;
934.                     found++;
935.                 } else {
936.                     found += append_str(out_str, an(def_oc_syms[i].explain));
937.                 }
938.             }
939.         }
940.     }
941. 
942.     if (sym == DEF_INVISIBLE) {
943.         extern const char altinvisexplain[]; /* drawing.c */
944.         /* for active clairvoyance, use alternate "unseen creature" */
945.         boolean usealt = (EDetect_monsters & I_SPECIAL) != 0L;
946.         const char *unseen_explain = !usealt ? invisexplain : altinvisexplain;
947. 
948.         if (!found) {
949.             Sprintf(out_str, "%s%s", prefix, an(unseen_explain));
950.             *firstmatch = unseen_explain;
951.             found++;
952.         } else {
953.             found += append_str(out_str, an(unseen_explain));
954.         }
955.     }
956. 
957.     /* Now check for graphics symbols */
958.     alt_i = (sym == (looked ? showsyms[0] : defsyms[0].sym)) ? 0 : (2 + 1);
959.     for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) {
960.         /* when sym is the default background character, we process
961.            i == 0 three times: unexplored, stone, dark part of a room */
962.         if (alt_i < 2) {
963.             x_str = !alt_i++ ? "unexplored" : submerged ? "unknown" : "stone";
964.             i = 0; /* for second iteration, undo loop increment */
965.             /* alt_i is now 1 or 2 */
966.         } else {
967.             if (alt_i++ == 2)
968.                 i = 0; /* undo loop increment */
969.             x_str = defsyms[i].explanation;
970.             if (submerged && !strcmp(x_str, defsyms[0].explanation))
971.                 x_str = "land"; /* replace "dark part of a room" */
972.             /* alt_i is now 3 or more and no longer of interest */
973.         }
974.         if (sym == (looked ? showsyms[i] : defsyms[i].sym) && *x_str) {
975.             /* avoid "an unexplored", "an stone", "an air", "a water",
976.                "a floor of a room", "a dark part of a room";
977.                article==2 => "the", 1 => "an", 0 => (none) */
978.             int article = strstri(x_str, " of a room") ? 2
979.                           : !(alt_i <= 2
980.                               || strcmp(x_str, "air") == 0
981.                               || strcmp(x_str, "land") == 0
982.                               || strcmp(x_str, "water") == 0);
983. 
984.             if (!found) {
985.                 if (is_cmap_trap(i)) {
986.                     Sprintf(out_str, "%sa trap", prefix);
987.                     hit_trap = TRUE;
988.                 } else {
989.                     Sprintf(out_str, "%s%s", prefix,
990.                             article == 2 ? the(x_str)
991.                             : article == 1 ? an(x_str) : x_str);
992.                 }
993.                 *firstmatch = x_str;
994.                 found++;
995.             } else if (!(hit_trap && is_cmap_trap(i))
996.                        && !(found >= 3 && is_cmap_drawbridge(i))
997.                        /* don't mention vibrating square outside of Gehennom
998.                           unless this happens to be one (hallucination?) */
999.                        && (i != S_vibrating_square || Inhell
1000.                            || (looked && glyph_is_trap(glyph)
1001.                                && glyph_to_trap(glyph) == VIBRATING_SQUARE))) {
1002.                 found += append_str(out_str, (article == 2) ? the(x_str)
1003.                                              : (article == 1) ? an(x_str)
1004.                                                : x_str);
1005.                 if (is_cmap_trap(i))
1006.                     hit_trap = TRUE;
1007.             }
1008. 
1009.             if (i == S_altar || is_cmap_trap(i))
1010.                 need_to_look = TRUE;
1011.         }
1012.     }
1013. 
1014.     /* Now check for warning symbols */
1015.     for (i = 1; i < WARNCOUNT; i++) {
1016.         x_str = def_warnsyms[i].explanation;
1017.         if (sym == (looked ? warnsyms[i] : def_warnsyms[i].sym)) {
1018.             if (!found) {
1019.                 Sprintf(out_str, "%s%s", prefix, def_warnsyms[i].explanation);
1020.                 *firstmatch = def_warnsyms[i].explanation;
1021.                 found++;
1022.             } else {
1023.                 found += append_str(out_str, def_warnsyms[i].explanation);
1024.             }
1025.             /* Kludge: warning trumps boulders on the display.
1026.                Reveal the boulder too or player can get confused */
1027.             if (looked && sobj_at(BOULDER, cc.x, cc.y))
1028.                 Strcat(out_str, " co-located with a boulder");
1029.             break; /* out of for loop*/
1030.         }
1031.     }
1032. 
1033.     /* if we ignored venom and list turned out to be short, put it back */
1034.     if (skipped_venom && found < 2) {
1035.         x_str = def_oc_syms[VENOM_CLASS].explain;
1036.         if (!found) {
1037.             Sprintf(out_str, "%s%s", prefix, an(x_str));
1038.             *firstmatch = x_str;
1039.             found++;
1040.         } else {
1041.             found += append_str(out_str, an(x_str));
1042.         }
1043.     }
1044. 
1045.     /* Finally, handle some optional overriding symbols */
1046.     for (j = SYM_OFF_X; j < SYM_MAX; ++j) {
1047.         if (j == (SYM_INVISIBLE + SYM_OFF_X))
1048.             continue;       /* already handled above */
1049.         tmpsym = Is_rogue_level(&u.uz) ? ov_rogue_syms[j]
1050.                                        : ov_primary_syms[j];
1051.         if (tmpsym && sym == tmpsym) {
1052.             switch (j) {
1053.             case SYM_BOULDER + SYM_OFF_X:
1054.                 if (!found) {
1055.                     *firstmatch = "boulder";
1056.                     Sprintf(out_str, "%s%s", prefix, an(*firstmatch));
1057.                     found++;
1058.                 } else {
1059.                     found += append_str(out_str, "boulder");
1060.                 }
1061.                 break;
1062.             case SYM_PET_OVERRIDE + SYM_OFF_X:
1063.                 if (looked) {
1064.                     int oc = 0;
1065.                     unsigned os = 0;
1066. 
1067.                     /* convert to symbol without override in effect */
1068.                     (void) mapglyph(glyph, &sym, &oc, &os,
1069.                                     cc.x, cc.y, MG_FLAG_NOOVERRIDE);
1070.                     goto check_monsters;
1071.                 }
1072.                 break;
1073.             case SYM_HERO_OVERRIDE + SYM_OFF_X:
1074.                 sym = showsyms[S_HUMAN + SYM_OFF_M];
1075.                 goto check_monsters;
1076.             }
1077.         }
1078.     }
1079. #if 0
1080.     /* handle optional boulder symbol as a special case */
1081.     if (o_syms[SYM_BOULDER + SYM_OFF_X]
1082.         && sym == o_syms[SYM_BOULDER + SYM_OFF_X]) {
1083.         if (!found) {
1084.             *firstmatch = "boulder";
1085.             Sprintf(out_str, "%s%s", prefix, an(*firstmatch));
1086.             found++;
1087.         } else {
1088.             found += append_str(out_str, "boulder");
1089.         }
1090.     }
1091. #endif
1092. 
1093.     /*
1094.      * If we are looking at the screen, follow multiple possibilities or
1095.      * an ambiguous explanation by something more detailed.
1096.      */
1097. 
1098.     if (found > 4)
1099.         /* 3.6.3: this used to be "That can be many things" (without prefix)
1100.            which turned it into a sentence that lacked its terminating period;
1101.            we could add one below but reinstating the prefix here is better */
1102.         Sprintf(out_str, "%scan be many things", prefix);
1103. 
1104.  didlook:
1105.     if (looked) {
1106.         struct permonst *pm = (struct permonst *)0;
1107. 
1108.         if (found > 1 || need_to_look) {
1109.             char monbuf[BUFSZ];
1110.             char temp_buf[BUFSZ];
1111. 
1112.             pm = lookat(cc.x, cc.y, look_buf, monbuf);
1113.             if (pm && for_supplement)
1114.                 *for_supplement = pm;
1115.             *firstmatch = look_buf;
1116.             if (*(*firstmatch)) {
1117.                 Sprintf(temp_buf, " (%s)", *firstmatch);
1118.                 (void) strncat(out_str, temp_buf,
1119.                                BUFSZ - strlen(out_str) - 1);
1120.                 found = 1; /* we have something to look up */
1121.             }
1122.             if (monbuf[0]) {
1123.                 Sprintf(temp_buf, " [seen: %s]", monbuf);
1124.                 (void) strncat(out_str, temp_buf,
1125.                                BUFSZ - strlen(out_str) - 1);
1126.             }
1127.         }
1128.     }
1129. 
1130.     return found;
1131. }
1132. 
1133. /* also used by getpos hack in do_name.c */
1134. const char what_is_an_unknown_object[] = "an unknown object";
1135. 
1136. int
1137. do_look(mode, click_cc)
1138. int mode;
1139. coord *click_cc;
1140. {
1141.     boolean quick = (mode == 1); /* use cursor; don't search for "more info" */
1142.     boolean clicklook = (mode == 2); /* right mouse-click method */
1143.     char out_str[BUFSZ] = DUMMY;
1144.     const char *firstmatch = 0;
1145.     struct permonst *pm = 0, *supplemental_pm = 0;
1146.     int i = '\0', ans = 0;
1147.     int sym;              /* typed symbol or converted glyph */
1148.     int found;            /* count of matching syms found */
1149.     coord cc;             /* screen pos of unknown glyph */
1150.     boolean save_verbose; /* saved value of flags.verbose */
1151.     boolean from_screen;  /* question from the screen */
1152. 
1153.     cc.x = 0;
1154.     cc.y = 0;
1155. 
1156.     if (!clicklook) {
1157.         if (quick) {
1158.             from_screen = TRUE; /* yes, we want to use the cursor */
1159.             i = 'y';
1160.         } else {
1161.             menu_item *pick_list = (menu_item *) 0;
1162.             winid win;
1163.             anything any;
1164. 
1165.             any = zeroany;
1166.             win = create_nhwindow(NHW_MENU);
1167.             start_menu(win);
1168.             any.a_char = '/';
1169.             /* 'y' and 'n' to keep backwards compatibility with previous
1170.                versions: "Specify unknown object by cursor?" */
1171.             add_menu(win, NO_GLYPH, &any,
1172.                      flags.lootabc ? 0 : any.a_char, 'y', ATR_NONE,
1173.                      "something on the map", MENU_UNSELECTED);
1174.             any.a_char = 'i';
1175.             add_menu(win, NO_GLYPH, &any,
1176.                      flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1177.                      "something you're carrying", MENU_UNSELECTED);
1178.             any.a_char = '?';
1179.             add_menu(win, NO_GLYPH, &any,
1180.                      flags.lootabc ? 0 : any.a_char, 'n', ATR_NONE,
1181.                      "something else (by symbol or name)", MENU_UNSELECTED);
1182.             if (!u.uswallow && !Hallucination) {
1183.                 any = zeroany;
1184.                 add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
1185.                          "", MENU_UNSELECTED);
1186.                 /* these options work sensibly for the swallowed case,
1187.                    but there's no reason for the player to use them then;
1188.                    objects work fine when hallucinating, but screen
1189.                    symbol/monster class letter doesn't match up with
1190.                    bogus monster type, so suppress when hallucinating */
1191.                 any.a_char = 'm';
1192.                 add_menu(win, NO_GLYPH, &any,
1193.                          flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1194.                          "nearby monsters", MENU_UNSELECTED);
1195.                 any.a_char = 'M';
1196.                 add_menu(win, NO_GLYPH, &any,
1197.                          flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1198.                          "all monsters shown on map", MENU_UNSELECTED);
1199.                 any.a_char = 'o';
1200.                 add_menu(win, NO_GLYPH, &any,
1201.                          flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1202.                          "nearby objects", MENU_UNSELECTED);
1203.                 any.a_char = 'O';
1204.                 add_menu(win, NO_GLYPH, &any,
1205.                          flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
1206.                          "all objects shown on map", MENU_UNSELECTED);
1207.             }
1208.             end_menu(win, "What do you want to look at:");
1209.             if (select_menu(win, PICK_ONE, &pick_list) > 0) {
1210.                 i = pick_list->item.a_char;
1211.                 free((genericptr_t) pick_list);
1212.             }
1213.             destroy_nhwindow(win);
1214.         }
1215. 
1216.         switch (i) {
1217.         default:
1218.         case 'q':
1219.             return 0;
1220.         case 'y':
1221.         case '/':
1222.             from_screen = TRUE;
1223.             sym = 0;
1224.             cc.x = u.ux;
1225.             cc.y = u.uy;
1226.             break;
1227.         case 'i':
1228.           {
1229.             char invlet;
1230.             struct obj *invobj;
1231. 
1232.             invlet = display_inventory((const char *) 0, TRUE);
1233.             if (!invlet || invlet == '\033')
1234.                 return 0;
1235.             *out_str = '\0';
1236.             for (invobj = invent; invobj; invobj = invobj->nobj)
1237.                 if (invobj->invlet == invlet) {
1238.                     strcpy(out_str, singular(invobj, xname));
1239.                     break;
1240.                 }
1241.             if (*out_str)
1242.                 checkfile(out_str, pm, TRUE, TRUE, (char *) 0);
1243.             return 0;
1244.           }
1245.         case '?':
1246.             from_screen = FALSE;
1247.             getlin("Specify what? (type the word)", out_str);
1248.             if (strcmp(out_str, " ")) /* keep single space as-is */
1249.                 /* remove leading and trailing whitespace and
1250.                    condense consecutive internal whitespace */
1251.                 mungspaces(out_str);
1252.             if (out_str[0] == '\0' || out_str[0] == '\033')
1253.                 return 0;
1254. 
1255.             if (out_str[1]) { /* user typed in a complete string */
1256.                 checkfile(out_str, pm, TRUE, TRUE, (char *) 0);
1257.                 return 0;
1258.             }
1259.             sym = out_str[0];
1260.             break;
1261.         case 'm':
1262.             look_all(TRUE, TRUE); /* list nearby monsters */
1263.             return 0;
1264.         case 'M':
1265.             look_all(FALSE, TRUE); /* list all monsters */
1266.             return 0;
1267.         case 'o':
1268.             look_all(TRUE, FALSE); /* list nearby objects */
1269.             return 0;
1270.         case 'O':
1271.             look_all(FALSE, FALSE); /* list all objects */
1272.             return 0;
1273.         }
1274.     } else { /* clicklook */
1275.         cc.x = click_cc->x;
1276.         cc.y = click_cc->y;
1277.         sym = 0;
1278.         from_screen = FALSE;
1279.     }
1280. 
1281.     /* Save the verbose flag, we change it later. */
1282.     save_verbose = flags.verbose;
1283.     flags.verbose = flags.verbose && !quick;
1284.     /*
1285.      * The user typed one letter, or we're identifying from the screen.
1286.      */
1287.     do {
1288.         /* Reset some variables. */
1289.         pm = (struct permonst *) 0;
1290.         found = 0;
1291.         out_str[0] = '\0';
1292. 
1293.         if (from_screen || clicklook) {
1294.             if (from_screen) {
1295.                 if (flags.verbose)
1296.                     pline("Please move the cursor to %s.",
1297.                           what_is_an_unknown_object);
1298.                 else
1299.                     pline("Pick an object.");
1300. 
1301.                 ans = getpos(&cc, quick, what_is_an_unknown_object);
1302.                 if (ans < 0 || cc.x < 0)
1303.                     break; /* done */
1304.                 flags.verbose = FALSE; /* only print long question once */
1305.             }
1306.         }
1307. 
1308.         found = do_screen_description(cc, (from_screen || clicklook), sym,
1309.                                       out_str, &firstmatch, &supplemental_pm);
1310. 
1311.         /* Finally, print out our explanation. */
1312.         if (found) {
1313.             /* use putmixed() because there may be an encoded glyph present */
1314.             putmixed(WIN_MESSAGE, 0, out_str);
1315. #ifdef DUMPLOG
1316.             {
1317.                 char dmpbuf[BUFSZ];
1318. 
1319.                 /* putmixed() bypasses pline() so doesn't write to DUMPLOG;
1320.                    tty puts it into ^P recall, so it ought to be there;
1321.                    DUMPLOG is plain text, so override graphics character;
1322.                    at present, force space, but we ought to use defsyms[]
1323.                    value for the glyph the graphics character came from */
1324.                 (void) decode_mixed(dmpbuf, out_str);
1325.                 if (dmpbuf[0] < ' ' || dmpbuf[0] >= 127) /* ASCII isprint() */
1326.                     dmpbuf[0] = ' ';
1327.                 dumplogmsg(dmpbuf);
1328.             }
1329. #endif
1330. 
1331.             /* check the data file for information about this thing */
1332.             if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE
1333.                 && (ans == LOOK_VERBOSE || (flags.help && !quick))
1334.                 && !clicklook) {
1335.                 char temp_buf[BUFSZ], supplemental_name[BUFSZ];
1336. 
1337.                 supplemental_name[0] = '\0';
1338.                 Strcpy(temp_buf, firstmatch);
1339.                 checkfile(temp_buf, pm, FALSE,
1340.                           (boolean) (ans == LOOK_VERBOSE), supplemental_name);
1341.                 if (supplemental_pm)
1342.                     do_supplemental_info(supplemental_name, supplemental_pm,
1343.                                          (boolean) (ans == LOOK_VERBOSE));
1344.             }
1345.         } else {
1346.             pline("I've never heard of such things.");
1347.         }
1348.     } while (from_screen && !quick && ans != LOOK_ONCE && !clicklook);
1349. 
1350.     flags.verbose = save_verbose;
1351.     return 0;
1352. }
1353. 
1354. STATIC_OVL void
1355. look_all(nearby, do_mons)
1356. boolean nearby; /* True => within BOLTLIM, False => entire map */
1357. boolean do_mons; /* True => monsters, False => objects */
1358. {
1359.     winid win;
1360.     int x, y, lo_x, lo_y, hi_x, hi_y, glyph, count = 0;
1361.     char lookbuf[BUFSZ], outbuf[BUFSZ];
1362. 
1363.     win = create_nhwindow(NHW_TEXT);
1364.     lo_y = nearby ? max(u.uy - BOLT_LIM, 0) : 0;
1365.     lo_x = nearby ? max(u.ux - BOLT_LIM, 1) : 1;
1366.     hi_y = nearby ? min(u.uy + BOLT_LIM, ROWNO - 1) : ROWNO - 1;
1367.     hi_x = nearby ? min(u.ux + BOLT_LIM, COLNO - 1) : COLNO - 1;
1368.     for (y = lo_y; y <= hi_y; y++) {
1369.         for (x = lo_x; x <= hi_x; x++) {
1370.             lookbuf[0] = '\0';
1371.             glyph = glyph_at(x, y);
1372.             if (do_mons) {
1373.                 if (glyph_is_monster(glyph)) {
1374.                     struct monst *mtmp;
1375. 
1376.                     bhitpos.x = x; /* [is this actually necessary?] */
1377.                     bhitpos.y = y;
1378.                     if (x == u.ux && y == u.uy && canspotself()) {
1379.                         (void) self_lookat(lookbuf);
1380.                         ++count;
1381.                     } else if ((mtmp = m_at(x, y)) != 0) {
1382.                         look_at_monster(lookbuf, (char *) 0, mtmp, x, y);
1383.                         ++count;
1384.                     }
1385.                 } else if (glyph_is_invisible(glyph)) {
1386.                     /* remembered, unseen, creature */
1387.                     Strcpy(lookbuf, invisexplain);
1388.                     ++count;
1389.                 } else if (glyph_is_warning(glyph)) {
1390.                     int warnindx = glyph_to_warning(glyph);
1391. 
1392.                     Strcpy(lookbuf, def_warnsyms[warnindx].explanation);
1393.                     ++count;
1394.                 }
1395.             } else { /* !do_mons */
1396.                 if (glyph_is_object(glyph)) {
1397.                     look_at_object(lookbuf, x, y, glyph);
1398.                     ++count;
1399.                 }
1400.             }
1401.             if (*lookbuf) {
1402.                 char coordbuf[20], which[12], cmode;
1403. 
1404.                 cmode = (iflags.getpos_coords != GPCOORDS_NONE)
1405.                            ? iflags.getpos_coords : GPCOORDS_MAP;
1406.                 if (count == 1) {
1407.                     Strcpy(which, do_mons ? "monsters" : "objects");
1408.                     if (nearby)
1409.                         Sprintf(outbuf, "%s currently shown near %s:",
1410.                                 upstart(which),
1411.                                 (cmode != GPCOORDS_COMPASS)
1412.                                   ? coord_desc(u.ux, u.uy, coordbuf, cmode)
1413.                                   : !canspotself() ? "your position" : "you");
1414.                     else
1415.                         Sprintf(outbuf, "All %s currently shown on the map:",
1416.                                 which);
1417.                     putstr(win, 0, outbuf);
1418.                     putstr(win, 0, "");
1419.                 }
1420.                 /* prefix: "coords  C  " where 'C' is mon or obj symbol */
1421.                 Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s  "
1422.                                   : (cmode == GPCOORDS_MAP) ? "%8s  "
1423.                                       : "%12s  ",
1424.                         coord_desc(x, y, coordbuf, cmode));
1425.                 Sprintf(eos(outbuf), "%s  ", encglyph(glyph));
1426.                 /* guard against potential overflow */
1427.                 lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0';
1428.                 Strcat(outbuf, lookbuf);
1429.                 putmixed(win, 0, outbuf);
1430.             }
1431.         }
1432.     }
1433.     if (count)
1434.         display_nhwindow(win, TRUE);
1435.     else
1436.         pline("No %s are currently shown %s.",
1437.               do_mons ? "monsters" : "objects",
1438.               nearby ? "nearby" : "on the map");
1439.     destroy_nhwindow(win);
1440. }
1441. 
1442. static const char *suptext1[] = {
1443.     "%s is a member of a marauding horde of orcs",
1444.     "rumored to have brutally attacked and plundered",
1445.     "the ordinarily sheltered town that is located ",
1446.     "deep within The Gnomish Mines.",
1447.     "",
1448.     "The members of that vicious horde proudly and ",
1449.     "defiantly acclaim their allegiance to their",
1450.     "leader %s in their names.",
1451.     (char *) 0,
1452. };
1453. 
1454. static const char *suptext2[] = {
1455.     "\"%s\" is the common dungeon name of",
1456.     "a nefarious orc who is known to acquire property",
1457.     "from thieves and sell it off for profit.",
1458.     "",
1459.     "The perpetrator was last seen hanging around the",
1460.     "stairs leading to the Gnomish Mines.",
1461.     (char *) 0,
1462. };
1463. 
1464. STATIC_OVL void
1465. do_supplemental_info(name, pm, without_asking)
1466. char *name;
1467. struct permonst *pm;
1468. boolean without_asking;
1469. {
1470.     const char **textp;
1471.     winid datawin = WIN_ERR;
1472.     char *entrytext = name, *bp = (char *) 0, *bp2 = (char *) 0;
1473.     char question[QBUFSZ];
1474.     boolean yes_to_moreinfo = FALSE;
1475.     boolean is_marauder = (name && pm && is_orc(pm));
1476. 
1477.     /*
1478.      * Provide some info on some specific things
1479.      * meant to support in-game mythology, and not
1480.      * available from data.base or other sources.
1481.      */
1482.     if (is_marauder && (strlen(name) < (BUFSZ - 1))) {
1483.         char fullname[BUFSZ];
1484. 
1485.         bp = strstri(name, " of ");
1486.         bp2 = strstri(name, " the Fence");
1487. 
1488.         if (bp || bp2) {
1489.             Strcpy(fullname, name);
1490.             if (!without_asking) {
1491.                 Strcpy(question, "More info about \"");
1492.                 /* +2 => length of "\"?" */
1493.                 copynchars(eos(question), entrytext,
1494.                     (int) (sizeof question - 1 - (strlen(question) + 2)));
1495.                 Strcat(question, "\"?");
1496.                 if (yn(question) == 'y')
1497.                 yes_to_moreinfo = TRUE;
1498.             }
1499.             if (yes_to_moreinfo) {
1500.                 int i, subs = 0;
1501.                 const char *gang = (char *) 0;
1502. 
1503.                 if (bp) {
1504.                     textp = suptext1;
1505.                     gang = bp + 4;
1506.                     *bp = '\0';
1507.                 } else {
1508.                     textp = suptext2;
1509.                     gang = "";
1510.                 }
1511.                 datawin = create_nhwindow(NHW_MENU);
1512.                 for (i = 0; textp[i]; i++) {
1513.                     char buf[BUFSZ];
1514.                     const char *txt;
1515. 
1516.                     if (strstri(textp[i], "%s") != 0) {
1517.                         Sprintf(buf, textp[i], subs++ ? gang : fullname);
1518.                         txt = buf;
1519.                     } else
1520.                         txt = textp[i];
1521.                     putstr(datawin, 0, txt);
1522.                 }
1523.                 display_nhwindow(datawin, FALSE);
1524.                 destroy_nhwindow(datawin), datawin = WIN_ERR;
1525.             }
1526.         }
1527.     }
1528. }
1529. 
1530. /* the '/' command */
1531. int
1532. dowhatis()
1533. {
1534.     return do_look(0, (coord *) 0);
1535. }
1536. 
1537. /* the ';' command */
1538. int
1539. doquickwhatis()
1540. {
1541.     return do_look(1, (coord *) 0);
1542. }
1543. 
1544. /* the '^' command */
1545. int
1546. doidtrap()
1547. {
1548.     register struct trap *trap;
1549.     int x, y, tt, glyph;
1550. 
1551.     if (!getdir("^"))
1552.         return 0;
1553.     x = u.ux + u.dx;
1554.     y = u.uy + u.dy;
1555. 
1556.     /* check fake bear trap from confused gold detection */
1557.     glyph = glyph_at(x, y);
1558.     if (glyph_is_trap(glyph) && (tt = glyph_to_trap(glyph)) == BEAR_TRAP) {
1559.         boolean chesttrap = trapped_chest_at(tt, x, y);
1560. 
1561.         if (chesttrap || trapped_door_at(tt, x, y)) {
1562.             pline("That is a trapped %s.", chesttrap ? "chest" : "door");
1563.             return 0; /* trap ID'd, but no time elapses */
1564.         }
1565.     }
1566. 
1567.     for (trap = ftrap; trap; trap = trap->ntrap)
1568.         if (trap->tx == x && trap->ty == y) {
1569.             if (!trap->tseen)
1570.                 break;
1571.             tt = trap->ttyp;
1572.             if (u.dz) {
1573.                 if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
1574.                     break;
1575.             }
1576.             tt = what_trap(tt, rn2_on_display_rng);
1577.             pline("That is %s%s%s.",
1578.                   an(defsyms[trap_to_defsym(tt)].explanation),
1579.                   !trap->madeby_u
1580.                      ? ""
1581.                      : (tt == WEB)
1582.                         ? " woven"
1583.                         /* trap doors & spiked pits can't be made by
1584.                            player, and should be considered at least
1585.                            as much "set" as "dug" anyway */
1586.                         : (tt == HOLE || tt == PIT)
1587.                            ? " dug"
1588.                            : " set",
1589.                   !trap->madeby_u ? "" : " by you");
1590.             return 0;
1591.         }
1592.     pline("I can't see a trap there.");
1593.     return 0;
1594. }
1595. 
1596. /*
1597.     Implements a rudimentary if/elif/else/endif interpretor and use
1598.     conditionals in dat/cmdhelp to describe what command each keystroke
1599.     currently invokes, so that there isn't a lot of "(debug mode only)"
1600.     and "(if number_pad is off)" cluttering the feedback that the user
1601.     sees.  (The conditionals add quite a bit of clutter to the raw data
1602.     but users don't see that.  number_pad produces a lot of conditional
1603.     commands:  basic letters vs digits, 'g' vs 'G' for '5', phone
1604.     keypad vs normal layout of digits, and QWERTZ keyboard swap between
1605.     y/Y/^Y/M-y/M-Y/M-^Y and z/Z/^Z/M-z/M-Z/M-^Z.)
1606. 
1607.     The interpretor understands
1608.      '&#' for comment,
1609.      '&? option' for 'if' (also '&? !option'
1610.                            or '&? option=value[,value2,...]'
1611.                            or '&? !option=value[,value2,...]'),
1612.      '&: option' for 'elif' (with argument variations same as 'if';
1613.                              any number of instances for each 'if'),
1614.      '&:' for 'else' (also '&: #comment';
1615.                       0 or 1 instance for a given 'if'), and
1616.      '&.' for 'endif' (also '&. #comment'; required for each 'if').
1617. 
1618.     The option handling is a bit of a mess, with no generality for
1619.     which options to deal with and only a comma separated list of
1620.     integer values for the '=value' part.  number_pad is the only
1621.     supported option that has a value; the few others (wizard/debug,
1622.     rest_on_space, #if SHELL, #if SUSPEND) are booleans.
1623. */
1624. 
1625. STATIC_DCL void
1626. whatdoes_help()
1627. {
1628.     dlb *fp;
1629.     char *p, buf[BUFSZ];
1630.     winid tmpwin;
1631. 
1632.     fp = dlb_fopen(KEYHELP, "r");
1633.     if (!fp) {
1634.         pline("Cannot open \"%s\" data file!", KEYHELP);
1635.         display_nhwindow(WIN_MESSAGE, TRUE);
1636.         return;
1637.     }
1638.     tmpwin = create_nhwindow(NHW_TEXT);
1639.     while (dlb_fgets(buf, (int) sizeof buf, fp)) {
1640.         if (*buf == '#')
1641.             continue;
1642.         for (p = buf; *p; p++)
1643.             if (*p != ' ' && *p != '\t')
1644.                 break;
1645.         putstr(tmpwin, 0, p);
1646.     }
1647.     (void) dlb_fclose(fp);
1648.     display_nhwindow(tmpwin, TRUE);
1649.     destroy_nhwindow(tmpwin);
1650. }
1651. 
1652. #if 0
1653. #define WD_STACKLIMIT 5
1654. struct wd_stack_frame {
1655.     Bitfield(active, 1);
1656.     Bitfield(been_true, 1);
1657.     Bitfield(else_seen, 1);
1658. };
1659. 
1660. STATIC_DCL boolean FDECL(whatdoes_cond, (char *, struct wd_stack_frame *,
1661.                                          int *, int));
1662. 
1663. STATIC_OVL boolean
1664. whatdoes_cond(buf, stack, depth, lnum)
1665. char *buf;
1666. struct wd_stack_frame *stack;
1667. int *depth, lnum;
1668. {
1669.     const char badstackfmt[] = "cmdhlp: too many &%c directives at line %d.";
1670.     boolean newcond, neg, gotopt;
1671.     char *p, *q, act = buf[1];
1672.     int np = 0;
1673. 
1674.     newcond = (act == '?' || !stack[*depth].been_true);
1675.     buf += 2;
1676.     mungspaces(buf);
1677.     if (act == '#' || *buf == '#' || !*buf || !newcond) {
1678.         gotopt = (*buf && *buf != '#');
1679.         *buf = '\0';
1680.         neg = FALSE; /* lint suppression */
1681.         p = q = (char *) 0;
1682.     } else {
1683.         gotopt = TRUE;
1684.         if ((neg = (*buf == '!')) != 0)
1685.             if (*++buf == ' ')
1686.                 ++buf;
1687.         p = index(buf, '='), q = index(buf, ':');
1688.         if (!p || (q && q < p))
1689.             p = q;
1690.         if (p) { /* we have a value specified */
1691.             /* handle a space before or after (or both) '=' (or ':') */
1692.             if (p > buf && p[-1] == ' ')
1693.                 p[-1] = '\0'; /* end of keyword in buf[] */
1694.             *p++ = '\0'; /* terminate keyword, advance to start of value */
1695.             if (*p == ' ')
1696.                 p++;
1697.         }
1698.     }
1699.     if (*buf && (act == '?' || act == ':')) {
1700.         if (!strcmpi(buf, "number_pad")) {
1701.             if (!p) {
1702.                 newcond = iflags.num_pad;
1703.             } else {
1704.                 /* convert internal encoding (separate yes/no and 0..3)
1705.                    back to user-visible one (-1..4) */
1706.                 np = iflags.num_pad ? (1 + iflags.num_pad_mode) /* 1..4 */
1707.                                     : (-1 * iflags.num_pad_mode); /* -1..0 */
1708.                 newcond = FALSE;
1709.                 for (; p; p = q) {
1710.                     q = index(p, ',');
1711.                     if (q)
1712.                         *q++ = '\0';
1713.                     if (atoi(p) == np) {
1714.                         newcond = TRUE;
1715.                         break;
1716.                     }
1717.                 }
1718.             }
1719.         } else if (!strcmpi(buf, "rest_on_space")) {
1720.             newcond = flags.rest_on_space;
1721.         } else if (!strcmpi(buf, "debug") || !strcmpi(buf, "wizard")) {
1722.             newcond = flags.debug; /* == wizard */
1723.         } else if (!strcmpi(buf, "shell")) {
1724. #ifdef SHELL
1725.             /* should we also check sysopt.shellers? */
1726.             newcond = TRUE;
1727. #else
1728.             newcond = FALSE;
1729. #endif
1730.         } else if (!strcmpi(buf, "suspend")) {
1731. #ifdef SUSPEND
1732.             /* sysopt.shellers is also used for dosuspend()... */
1733.             newcond = TRUE;
1734. #else
1735.             newcond = FALSE;
1736. #endif
1737.         } else {
1738.             impossible(
1739.                 "cmdhelp: unrecognized &%c conditional at line %d: \"%.20s\"",
1740.                        act, lnum, buf);
1741.             neg = FALSE;
1742.         }
1743.         /* this works for number_pad too: &? !number_pad:-1,0
1744.            would be true for 1..4 after negation */
1745.         if (neg)
1746.             newcond = !newcond;
1747.     }
1748.     switch (act) {
1749.     default:
1750.     case '#': /* comment */
1751.         break;
1752.     case '.': /* endif */
1753.         if (--*depth < 0) {
1754.             impossible(badstackfmt, '.', lnum);
1755.             *depth = 0;
1756.         }
1757.         break;
1758.     case ':': /* else or elif */
1759.         if (*depth == 0 || stack[*depth].else_seen) {
1760.             impossible(badstackfmt, ':', lnum);
1761.             *depth = 1; /* so that stack[*depth - 1] is a valid access */
1762.         }
1763.         if (stack[*depth].active || stack[*depth].been_true
1764.             || !stack[*depth - 1].active)
1765.             stack[*depth].active = 0;
1766.         else if (newcond)
1767.             stack[*depth].active = stack[*depth].been_true = 1;
1768.         if (!gotopt)
1769.             stack[*depth].else_seen = 1;
1770.         break;
1771.     case '?': /* if */
1772.         if (++*depth >= WD_STACKLIMIT) {
1773.             impossible(badstackfmt, '?', lnum);
1774.             *depth = WD_STACKLIMIT - 1;
1775.         }
1776.         stack[*depth].active = (newcond && stack[*depth - 1].active) ? 1 : 0;
1777.         stack[*depth].been_true = stack[*depth].active;
1778.         stack[*depth].else_seen = 0;
1779.         break;
1780.     }
1781.     return stack[*depth].active ? TRUE : FALSE;
1782. }
1783. #endif /* 0 */
1784. 
1785. char *
1786. dowhatdoes_core(q, cbuf)
1787. char q;
1788. char *cbuf;
1789. {
1790.     char buf[BUFSZ];
1791. #if 0
1792.     dlb *fp;
1793.     struct wd_stack_frame stack[WD_STACKLIMIT];
1794.     boolean cond;
1795.     int ctrl, meta, depth = 0, lnum = 0;
1796. #endif /* 0 */
1797.     const char *ec_desc;
1798. 
1799.     if ((ec_desc = key2extcmddesc(q)) != NULL) {
1800.         char keybuf[QBUFSZ];
1801. 
1802.         Sprintf(buf, "%-8s%s.", key2txt(q, keybuf), ec_desc);
1803.         Strcpy(cbuf, buf);
1804.         return cbuf;
1805.     }
1806.     return 0;
1807. #if 0
1808.     fp = dlb_fopen(CMDHELPFILE, "r");
1809.     if (!fp) {
1810.         pline("Cannot open \"%s\" data file!", CMDHELPFILE);
1811.         return 0;
1812.     }
1813. 
1814.     meta = (0x80 & (uchar) q) != 0;
1815.     if (meta)
1816.         q &= 0x7f;
1817.     ctrl = (0x1f & (uchar) q) == (uchar) q;
1818.     if (ctrl)
1819.         q |= 0x40; /* NUL -> '@', ^A -> 'A', ... ^Z -> 'Z', ^[ -> '[', ... */
1820.     else if (q == 0x7f)
1821.         ctrl = 1, q = '?';
1822. 
1823.     (void) memset((genericptr_t) stack, 0, sizeof stack);
1824.     cond = stack[0].active = 1;
1825.     while (dlb_fgets(buf, sizeof buf, fp)) {
1826.         ++lnum;
1827.         if (buf[0] == '&' && buf[1] && index("?:.#", buf[1])) {
1828.             cond = whatdoes_cond(buf, stack, &depth, lnum);
1829.             continue;
1830.         }
1831.         if (!cond)
1832.             continue;
1833.         if (meta ? (buf[0] == 'M' && buf[1] == '-'
1834.                     && (ctrl ? buf[2] == '^' && highc(buf[3]) == q
1835.                              : buf[2] == q))
1836.                  : (ctrl ? buf[0] == '^' && highc(buf[1]) == q
1837.                          : buf[0] == q)) {
1838.             (void) strip_newline(buf);
1839.             if (index(buf, '\t'))
1840.                 (void) tabexpand(buf);
1841.             if (meta && ctrl && buf[4] == ' ') {
1842.                 (void) strncpy(buf, "M-^?    ", 8);
1843.                 buf[3] = q;
1844.             } else if (meta && buf[3] == ' ') {
1845.                 (void) strncpy(buf, "M-?     ", 8);
1846.                 buf[2] = q;
1847.             } else if (ctrl && buf[2] == ' ') {
1848.                 (void) strncpy(buf, "^?      ", 8);
1849.                 buf[1] = q;
1850.             } else if (buf[1] == ' ') {
1851.                 (void) strncpy(buf, "?       ", 8);
1852.                 buf[0] = q;
1853.             }
1854.             (void) dlb_fclose(fp);
1855.             Strcpy(cbuf, buf);
1856.             return cbuf;
1857.         }
1858.     }
1859.     (void) dlb_fclose(fp);
1860.     if (depth != 0)
1861.         impossible("cmdhelp: mismatched &? &: &. conditionals.");
1862.     return (char *) 0;
1863. #endif /* 0 */
1864. }
1865. 
1866. int
1867. dowhatdoes()
1868. {
1869.     static boolean once = FALSE;
1870.     char bufr[BUFSZ];
1871.     char q, *reslt;
1872. 
1873.     if (!once) {
1874.         pline("Ask about '&' or '?' to get more info.%s",
1875. #ifdef ALTMETA
1876.               iflags.altmeta ? "  (For ESC, type it twice.)" :
1877. #endif
1878.               "");
1879.         once = TRUE;
1880.     }
1881. #if defined(UNIX) || defined(VMS)
1882.     introff(); /* disables ^C but not ^\ */
1883. #endif
1884.     q = yn_function("What command?", (char *) 0, '\0');
1885. #ifdef ALTMETA
1886.     if (q == '\033' && iflags.altmeta) {
1887.         /* in an ideal world, we would know whether another keystroke
1888.            was already pending, but this is not an ideal world...
1889.            if user typed ESC, we'll essentially hang until another
1890.            character is typed */
1891.         q = yn_function("]", (char *) 0, '\0');
1892.         if (q != '\033')
1893.             q = (char) ((uchar) q | 0200);
1894.     }
1895. #endif /*ALTMETA*/
1896. #if defined(UNIX) || defined(VMS)
1897.     intron(); /* reenables ^C */
1898. #endif
1899.     reslt = dowhatdoes_core(q, bufr);
1900.     if (reslt) {
1901.         if (q == '&' || q == '?')
1902.             whatdoes_help();
1903.         pline("%s", reslt);
1904.     } else {
1905.         pline("No such command '%s', char code %d (0%03o or 0x%02x).",
1906.               visctrl(q), (uchar) q, (uchar) q, (uchar) q);
1907.     }
1908.     return 0;
1909. }
1910. 
1911. STATIC_OVL void
1912. docontact(VOID_ARGS)
1913. {
1914.     winid cwin = create_nhwindow(NHW_TEXT);
1915.     char buf[BUFSZ];
1916. 
1917.     if (sysopt.support) {
1918.         /*XXX overflow possibilities*/
1919.         Sprintf(buf, "To contact local support, %s", sysopt.support);
1920.         putstr(cwin, 0, buf);
1921.         putstr(cwin, 0, "");
1922.     } else if (sysopt.fmtd_wizard_list) { /* formatted SYSCF WIZARDS */
1923.         Sprintf(buf, "To contact local support, contact %s.",
1924.                 sysopt.fmtd_wizard_list);
1925.         putstr(cwin, 0, buf);
1926.         putstr(cwin, 0, "");
1927.     }
1928.     putstr(cwin, 0, "To contact the NetHack development team directly,");
1929.     /*XXX overflow possibilities*/
1930.     Sprintf(buf, "see the 'Contact' form on our website or email <%s>.",
1931.             DEVTEAM_EMAIL);
1932.     putstr(cwin, 0, buf);
1933.     putstr(cwin, 0, "");
1934.     putstr(cwin, 0, "For more information on NetHack, or to report a bug,");
1935.     Sprintf(buf, "visit our website \"%s\".", DEVTEAM_URL);
1936.     putstr(cwin, 0, buf);
1937.     display_nhwindow(cwin, FALSE);
1938.     destroy_nhwindow(cwin);
1939. }
1940. 
1941. STATIC_OVL void
1942. dispfile_help(VOID_ARGS)
1943. {
1944.     display_file(HELP, TRUE);
1945. }
1946. 
1947. STATIC_OVL void
1948. dispfile_shelp(VOID_ARGS)
1949. {
1950.     display_file(SHELP, TRUE);
1951. }
1952. 
1953. STATIC_OVL void
1954. dispfile_optionfile(VOID_ARGS)
1955. {
1956.     display_file(OPTIONFILE, TRUE);
1957. }
1958. 
1959. STATIC_OVL void
1960. dispfile_license(VOID_ARGS)
1961. {
1962.     display_file(LICENSE, TRUE);
1963. }
1964. 
1965. STATIC_OVL void
1966. dispfile_debughelp(VOID_ARGS)
1967. {
1968.     display_file(DEBUGHELP, TRUE);
1969. }
1970. 
1971. STATIC_OVL void
1972. hmenu_doextversion(VOID_ARGS)
1973. {
1974.     (void) doextversion();
1975. }
1976. 
1977. STATIC_OVL void
1978. hmenu_dohistory(VOID_ARGS)
1979. {
1980.     (void) dohistory();
1981. }
1982. 
1983. STATIC_OVL void
1984. hmenu_dowhatis(VOID_ARGS)
1985. {
1986.     (void) dowhatis();
1987. }
1988. 
1989. STATIC_OVL void
1990. hmenu_dowhatdoes(VOID_ARGS)
1991. {
1992.     (void) dowhatdoes();
1993. }
1994. 
1995. STATIC_OVL void
1996. hmenu_doextlist(VOID_ARGS)
1997. {
1998.     (void) doextlist();
1999. }
2000. 
2001. void
2002. domenucontrols(VOID_ARGS)
2003. {
2004.     winid cwin = create_nhwindow(NHW_TEXT);
2005.     show_menu_controls(cwin, FALSE);
2006.     display_nhwindow(cwin, FALSE);
2007.     destroy_nhwindow(cwin);
2008. }
2009. 
2010. /* data for dohelp() */
2011. static struct {
2012.     void NDECL((*f));
2013.     const char *text;
2014. } help_menu_items[] = {
2015.     { hmenu_doextversion, "About NetHack (version information)." },
2016.     { dispfile_help, "Long description of the game and commands." },
2017.     { dispfile_shelp, "List of game commands." },
2018.     { hmenu_dohistory, "Concise history of NetHack." },
2019.     { hmenu_dowhatis, "Info on a character in the game display." },
2020.     { hmenu_dowhatdoes, "Info on what a given key does." },
2021.     { option_help, "List of game options." },
2022.     { dispfile_optionfile, "Longer explanation of game options." },
2023.     { dokeylist, "Full list of keyboard commands" },
2024.     { hmenu_doextlist, "List of extended commands." },
2025.     { domenucontrols, "List menu control keys" },
2026.     { dispfile_license, "The NetHack license." },
2027.     { docontact, "Support information." },
2028. #ifdef PORT_HELP
2029.     { port_help, "%s-specific help and commands." },
2030. #endif
2031.     { dispfile_debughelp, "List of wizard-mode commands." },
2032.     { (void NDECL((*))) 0, (char *) 0 }
2033. };
2034. 
2035. /* the '?' command */
2036. int
2037. dohelp()
2038. {
2039.     winid tmpwin = create_nhwindow(NHW_MENU);
2040.     char helpbuf[QBUFSZ];
2041.     int i, n;
2042.     menu_item *selected;
2043.     anything any;
2044.     int sel;
2045. 
2046.     any = zeroany; /* zero all bits */
2047.     start_menu(tmpwin);
2048. 
2049.     for (i = 0; help_menu_items[i].text; i++) {
2050.         if (!wizard && help_menu_items[i].f == dispfile_debughelp)
2051.             continue;
2052.         if (help_menu_items[i].text[0] == '%') {
2053.             Sprintf(helpbuf, help_menu_items[i].text, PORT_ID);
2054.         } else {
2055.             Strcpy(helpbuf, help_menu_items[i].text);
2056.         }
2057.         any.a_int = i + 1;
2058.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
2059.                  helpbuf, MENU_UNSELECTED);
2060.     }
2061.     end_menu(tmpwin, "Select one item:");
2062.     n = select_menu(tmpwin, PICK_ONE, &selected);
2063.     destroy_nhwindow(tmpwin);
2064.     if (n > 0) {
2065.         sel = selected[0].item.a_int - 1;
2066.         free((genericptr_t) selected);
2067.         (void) (*help_menu_items[sel].f)();
2068.     }
2069.     return 0;
2070. }
2071. 
2072. /* the 'V' command; also a choice for '?' */
2073. int
2074. dohistory()
2075. {
2076.     display_file(HISTORY, TRUE);
2077.     return 0;
2078. }
2079. 
2080. /*pager.c*/