Source:SLASH'EM 0.0.7E7F2/pager.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to pager.c from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/pager.c#line123]], for example.

The latest source code for vanilla NetHack is at Source code.


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.    /*	SCCS Id: @(#)pager.c	3.4	2003/08/13	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    /* This file contains the command routines dowhatis() and dohelp() and */
6.    /* a few other help related facilities */
7.    
8.    #include "hack.h"
9.    #include "dlb.h"
10.   
11.   STATIC_DCL boolean FDECL(is_swallow_sym, (int));
12.   STATIC_DCL int FDECL(append_str, (char *, const char *));
13.   STATIC_DCL struct permonst * FDECL(lookat, (int, int, char *, char *));
14.   STATIC_DCL void FDECL(checkfile,
15.   		      (char *,struct permonst *,BOOLEAN_P,BOOLEAN_P));
16.   STATIC_DCL int FDECL(do_look, (BOOLEAN_P));
17.   STATIC_DCL boolean FDECL(help_menu, (int *));
18.   #ifdef PORT_HELP
19.   extern void NDECL(port_help);
20.   #endif
21.   
22.   /* Returns "true" for characters that could represent a monster's stomach. */
23.   STATIC_OVL boolean
24.   is_swallow_sym(c)
25.   int c;
26.   {
27.       int i;
28.       for (i = S_sw_tl; i <= S_sw_br; i++)
29.   	if ((int)showsyms[i] == c) return TRUE;
30.       return FALSE;
31.   }
32.   
33.   /*
34.    * Append new_str to the end of buf if new_str doesn't already exist as
35.    * a substring of buf.  Return 1 if the string was appended, 0 otherwise.
36.    * It is expected that buf is of size BUFSZ.
37.    */
38.   STATIC_OVL int
39.   append_str(buf, new_str)
40.       char *buf;
41.       const char *new_str;
42.   {
43.       int space_left;	/* space remaining in buf */
44.   
45.       if (strstri(buf, new_str)) return 0;
46.   
47.       space_left = BUFSZ - strlen(buf) - 1;
48.       (void) strncat(buf, " or ", space_left);
49.       (void) strncat(buf, new_str, space_left - 4);
50.       return 1;
51.   }
52.   
53.   /*
54.    * Return the name of the glyph found at (x,y).
55.    * If not hallucinating and the glyph is a monster, also monster data.
56.    */
57.   STATIC_OVL struct permonst *
58.   lookat(x, y, buf, monbuf)
59.       int x, y;
60.       char *buf, *monbuf;
61.   {
62.       register struct monst *mtmp = (struct monst *) 0;
63.       struct permonst *pm = (struct permonst *) 0;
64.       int glyph;
65.   
66.       buf[0] = monbuf[0] = 0;
67.       glyph = glyph_at(x,y);
68.       if (u.ux == x && u.uy == y && senseself()) {
69.   	char race[QBUFSZ];
70.   
71.   	/* if not polymorphed, show both the role and the race */
72.   	race[0] = 0;
73.   	if (!Upolyd) {
74.   	    Sprintf(race, "%s ", urace.adj);
75.   	}
76.   
77.   	Sprintf(buf, "%s%s%s called %s",
78.   		Invis ? "invisible " : "",
79.   		race,
80.   		mons[u.umonnum].mname,
81.   		plname);
82.   	/* file lookup can't distinguish between "gnomish wizard" monster
83.   	   and correspondingly named player character, always picking the
84.   	   former; force it to find the general "wizard" entry instead */
85.   	if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
86.   	    pm = &mons[PM_WIZARD];
87.   
88.   #if 0
89.   	char race[QBUFSZ], role[QBUFSZ];
90.   
91.   	/* if not polymorphed, show both the role and the race */
92.   	role[0] = 0;
93.   	race[0] = 0;
94.   	
95.   	if (!Upolyd) {
96.   	    Sprintf(race, "%s ", urace.adj);
97.   	    Sprintf(role, "%s ", urole.name);
98.   	} else Sprintf(race, "%s ", mons[u.umonnum].mname);
99.   
100.  	Sprintf(buf, "%s%s%s called %s",
101.  		Invis ? "invisible " : "",
102.  		race,
103.  		role,
104.  		plname);
105.  #endif
106.  
107.  
108.  #ifdef STEED
109.  	if (u.usteed) {
110.  	    char steedbuf[BUFSZ];
111.  
112.  	    Sprintf(steedbuf, ", mounted on %s", y_monnam(u.usteed));
113.  	    /* assert((sizeof buf >= strlen(buf)+strlen(steedbuf)+1); */
114.  	    Strcat(buf, steedbuf);
115.  	}
116.  #endif
117.  	/* When you see yourself normally, no explanation is appended
118.  	   (even if you could also see yourself via other means).
119.  	   Sensing self while blind or swallowed is treated as if it
120.  	   were by normal vision (cf canseeself()). */
121.  	if ((Invisible || u.uundetected) && !Blind && !u.uswallow) {
122.  	    unsigned how = 0;
123.  
124.  	    if (Infravision)	 how |= 1;
125.  	    if (Unblind_telepat) how |= 2;
126.  	    if (Detect_monsters) how |= 4;
127.  
128.  	    if (how)
129.  		Sprintf(eos(buf), " [seen: %s%s%s%s%s]",
130.  			(how & 1) ? "infravision" : "",
131.  			/* add comma if telep and infrav */
132.  			((how & 3) > 2) ? ", " : "",
133.  			(how & 2) ? "telepathy" : "",
134.  			/* add comma if detect and (infrav or telep or both) */
135.  			((how & 7) > 4) ? ", " : "",
136.  			(how & 4) ? "monster detection" : "");
137.  	}
138.      } else if (u.uswallow) {
139.  	/* all locations when swallowed other than the hero are the monster */
140.  	Sprintf(buf, "interior of %s",
141.  				    Blind ? "a monster" : a_monnam(u.ustuck));
142.  	pm = u.ustuck->data;
143.      } else if (glyph_is_monster(glyph)) {
144.  	bhitpos.x = x;
145.  	bhitpos.y = y;
146.  	mtmp = m_at(x,y);
147.  	if (mtmp != (struct monst *) 0) {
148.  	    char *name, monnambuf[BUFSZ];
149.  	    boolean accurate = !Hallucination;
150.  
151.  	    if (mtmp->data == &mons[PM_COYOTE] && accurate)
152.  		name = coyotename(mtmp, monnambuf);
153.  	    else
154.  		name = distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
155.  
156.  	    pm = mtmp->data;
157.  	    Sprintf(buf, "%s%s%s",
158.  		    (mtmp->mx != x || mtmp->my != y) ?
159.  			((mtmp->isshk && accurate)
160.  				? "tail of " : "tail of a ") : "",
161.  		    (mtmp->mtame && accurate) ? "tame " :
162.  		    (mtmp->mpeaceful && accurate) ? "peaceful " : "",
163.  		    name);
164.  	    if (u.ustuck == mtmp)
165.  		Strcat(buf, (Upolyd && sticks(youmonst.data)) ?
166.  			", being held" : ", holding you");
167.  	    if (mtmp->mleashed)
168.  		Strcat(buf, ", leashed to you");
169.  
170.  	    if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
171.  		struct trap *t = t_at(mtmp->mx, mtmp->my);
172.  		int tt = t ? t->ttyp : NO_TRAP;
173.  
174.  		/* newsym lets you know of the trap, so mention it here */
175.  		if (tt == BEAR_TRAP || tt == PIT ||
176.  			tt == SPIKED_PIT || tt == WEB)
177.  		    Sprintf(eos(buf), ", trapped in %s",
178.  			    an(defsyms[trap_to_defsym(tt)].explanation));
179.  	    }
180.  
181.  	    {
182.  		int ways_seen = 0, normal = 0, xraydist;
183.  		boolean useemon = (boolean) canseemon(mtmp);
184.  
185.  		xraydist = (u.xray_range<0) ? -1 : u.xray_range * u.xray_range;
186.  		/* normal vision */
187.  		if ((mtmp->wormno ? worm_known(mtmp) : cansee(mtmp->mx, mtmp->my)) &&
188.  			mon_visible(mtmp) && !mtmp->minvis) {
189.  		    ways_seen++;
190.  		    normal++;
191.  		}
192.  		/* see invisible */
193.  		if (useemon && mtmp->minvis)
194.  		    ways_seen++;
195.  		/* infravision */
196.  		if ((!mtmp->minvis || See_invisible) && see_with_infrared(mtmp))
197.  		    ways_seen++;
198.  		/* telepathy */
199.  		if (tp_sensemon(mtmp))
200.  		    ways_seen++;
201.  		/* xray */
202.  		if (useemon && xraydist > 0 &&
203.  			distu(mtmp->mx, mtmp->my) <= xraydist)
204.  		    ways_seen++;
205.  		if (Detect_monsters)
206.  		    ways_seen++;
207.  		if (MATCH_WARN_OF_MON(mtmp))
208.  		    ways_seen++;
209.  
210.  		if (ways_seen > 1 || !normal) {
211.  		    if (normal) {
212.  			Strcat(monbuf, "normal vision");
213.  			/* can't actually be 1 yet here */
214.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
215.  		    }
216.  		    if (useemon && mtmp->minvis) {
217.  			Strcat(monbuf, "see invisible");
218.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
219.  		    }
220.  		    if ((!mtmp->minvis || See_invisible) &&
221.  			    see_with_infrared(mtmp)) {
222.  			Strcat(monbuf, "infravision");
223.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
224.  		    }
225.  		    if (tp_sensemon(mtmp)) {
226.  			Strcat(monbuf, "telepathy");
227.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
228.  		    }
229.  		    if (useemon && xraydist > 0 &&
230.  			    distu(mtmp->mx, mtmp->my) <= xraydist) {
231.  			/* Eyes of the Overworld */
232.  			Strcat(monbuf, "astral vision");
233.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
234.  		    }
235.  		    if (Detect_monsters) {
236.  			Strcat(monbuf, "monster detection");
237.  			if (ways_seen-- > 1) Strcat(monbuf, ", ");
238.  		    }
239.  		    if (MATCH_WARN_OF_MON(mtmp)) {
240.  		    	char wbuf[BUFSZ];
241.  			if (Hallucination)
242.  				Strcat(monbuf, "paranoid delusion");
243.  			else {
244.  				Sprintf(wbuf, "warned of %s",
245.  					makeplural(mtmp->data->mname));
246.  		    		Strcat(monbuf, wbuf);
247.  		    	}
248.  		    	if (ways_seen-- > 1) Strcat(monbuf, ", ");
249.  		    }
250.  		}
251.  	    }
252.  	}
253.      }
254.      else if (glyph_is_object(glyph)) {
255.  	struct obj *otmp = vobj_at(x,y);
256.  
257.  	if (!otmp || otmp->otyp != glyph_to_obj(glyph)) {
258.  	    if (glyph_to_obj(glyph) != STRANGE_OBJECT) {
259.  		otmp = mksobj(glyph_to_obj(glyph), FALSE, FALSE);
260.  		if (otmp->oclass == COIN_CLASS)
261.  		    otmp->quan = 2L; /* to force pluralization */
262.  		else if (otmp->otyp == SLIME_MOLD)
263.  		    otmp->spe = current_fruit;	/* give the fruit a type */
264.  		Strcpy(buf, distant_name(otmp, xname));
265.  		dealloc_obj(otmp);
266.  	    }
267.  	} else
268.  	    Strcpy(buf, distant_name(otmp, xname));
269.  
270.  	if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
271.  	    Strcat(buf, " embedded in stone");
272.  	else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
273.  	    Strcat(buf, " embedded in a wall");
274.  	else if (closed_door(x,y))
275.  	    Strcat(buf, " embedded in a door");
276.  	else if (is_pool(x,y))
277.  	    Strcat(buf, " in water");
278.  	else if (is_lava(x,y))
279.  	    Strcat(buf, " in molten lava");	/* [can this ever happen?] */
280.      } else if (glyph_is_trap(glyph)) {
281.  	int tnum = what_trap(glyph_to_trap(glyph));
282.  	Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation);
283.      } else if(!glyph_is_cmap(glyph)) {
284.  	Strcpy(buf,"dark part of a room");
285.      } else switch(glyph_to_cmap(glyph)) {
286.      case S_altar:
287.  	if(!In_endgame(&u.uz))
288.  	    Sprintf(buf, "%s altar",
289.  		align_str(Amask2align(levl[x][y].altarmask & ~AM_SHRINE)));
290.  	else Sprintf(buf, "aligned altar");
291.  	break;
292.      case S_ndoor:
293.  	if (is_drawbridge_wall(x, y) >= 0)
294.  	    Strcpy(buf,"open drawbridge portcullis");
295.  	else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
296.  	    Strcpy(buf,"broken door");
297.  	else
298.  	    Strcpy(buf,"doorway");
299.  	break;
300.      case S_cloud:
301.  	Strcpy(buf, Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
302.  	break;
303.      case S_water:
304.      case S_pool:
305.  	Strcpy(buf, level.flags.lethe? "sparkling water" : "water");
306.  	break;
307.      default:
308.  	Strcpy(buf,defsyms[glyph_to_cmap(glyph)].explanation);
309.  	break;
310.      }
311.  
312.      return ((pm && !Hallucination) ? pm : (struct permonst *) 0);
313.  }
314.  
315.  /*
316.   * Look in the "data" file for more info.  Called if the user typed in the
317.   * whole name (user_typed_name == TRUE), or we've found a possible match
318.   * with a character/glyph and flags.help is TRUE.
319.   *
320.   * NOTE: when (user_typed_name == FALSE), inp is considered read-only and
321.   *	 must not be changed directly, e.g. via lcase(). We want to force
322.   *	 lcase() for data.base lookup so that we can have a clean key.
323.   *	 Therefore, we create a copy of inp _just_ for data.base lookup.
324.   */
325.  STATIC_OVL void
326.  checkfile(inp, pm, user_typed_name, without_asking)
327.      char *inp;
328.      struct permonst *pm;
329.      boolean user_typed_name, without_asking;
330.  {
331.      dlb *fp;
332.      char buf[BUFSZ], newstr[BUFSZ];
333.      char *ep, *dbase_str;
334.      long txt_offset;
335.      int chk_skip;
336.      boolean found_in_file = FALSE, skipping_entry = FALSE;
337.  
338.      fp = dlb_fopen_area(NH_DATAAREA, NH_DATAFILE, "r");
339.      if (!fp) {
340.  	pline("Cannot open data file!");
341.  	return;
342.      }
343.  
344.      /* To prevent the need for entries in data.base like *ngel to account
345.       * for Angel and angel, make the lookup string the same for both
346.       * user_typed_name and picked name.
347.       */
348.      if (pm != (struct permonst *) 0 && !user_typed_name)
349.  	dbase_str = strcpy(newstr, pm->mname);
350.      else dbase_str = strcpy(newstr, inp);
351.      (void) lcase(dbase_str);
352.  
353.      if (!strncmp(dbase_str, "interior of ", 12))
354.  	dbase_str += 12;
355.      if (!strncmp(dbase_str, "a ", 2))
356.  	dbase_str += 2;
357.      else if (!strncmp(dbase_str, "an ", 3))
358.  	dbase_str += 3;
359.      else if (!strncmp(dbase_str, "the ", 4))
360.  	dbase_str += 4;
361.      if (!strncmp(dbase_str, "tame ", 5))
362.  	dbase_str += 5;
363.      else if (!strncmp(dbase_str, "peaceful ", 9))
364.  	dbase_str += 9;
365.      if (!strncmp(dbase_str, "invisible ", 10))
366.  	dbase_str += 10;
367.      if (!strncmp(dbase_str, "statue of ", 10))
368.  	dbase_str[6] = '\0';
369.      else if (!strncmp(dbase_str, "figurine of ", 12))
370.  	dbase_str[8] = '\0';
371.  
372.      /* Make sure the name is non-empty. */
373.      if (*dbase_str) {
374.  	/* adjust the input to remove "named " and convert to lower case */
375.  	char *alt = 0;	/* alternate description */
376.  
377.  	if ((ep = strstri(dbase_str, " named ")) != 0)
378.  	    alt = ep + 7;
379.  	else
380.  	    ep = strstri(dbase_str, " called ");
381.  	if (!ep) ep = strstri(dbase_str, ", ");
382.  	if (ep && ep > dbase_str) *ep = '\0';
383.  
384.  	/*
385.  	 * If the object is named, then the name is the alternate description;
386.  	 * otherwise, the result of makesingular() applied to the name is. This
387.  	 * isn't strictly optimal, but named objects of interest to the user
388.  	 * will usually be found under their name, rather than under their
389.  	 * object type, so looking for a singular form is pointless.
390.  	 */
391.  
392.  	if (!alt)
393.  	    alt = makesingular(dbase_str);
394.  	else
395.  	    if (user_typed_name)
396.  		(void) lcase(alt);
397.  
398.  	/* skip first record; read second */
399.  	txt_offset = 0L;
400.  	if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
401.  	    impossible("can't read 'data' file");
402.  	    (void) dlb_fclose(fp);
403.  	    return;
404.  	} else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0)
405.  	    goto bad_data_file;
406.  
407.  	/* look for the appropriate entry */
408.  	while (dlb_fgets(buf,BUFSZ,fp)) {
409.  	    if (*buf == '.') break;  /* we passed last entry without success */
410.  
411.  	    if (digit(*buf)) {
412.  		/* a number indicates the end of current entry */
413.  		skipping_entry = FALSE;
414.  	    } else if (!skipping_entry) {
415.  		if (!(ep = index(buf, '\n'))) goto bad_data_file;
416.  		*ep = 0;
417.  		/* if we match a key that begins with "~", skip this entry */
418.  		chk_skip = (*buf == '~') ? 1 : 0;
419.  		if (pmatch(&buf[chk_skip], dbase_str) ||
420.  			(alt && pmatch(&buf[chk_skip], alt))) {
421.  		    if (chk_skip) {
422.  			skipping_entry = TRUE;
423.  			continue;
424.  		    } else {
425.  			found_in_file = TRUE;
426.  			break;
427.  		    }
428.  		}
429.  	    }
430.  	}
431.      }
432.  
433.      if(found_in_file) {
434.  	long entry_offset;
435.  	int  entry_count;
436.  	int  i;
437.  
438.  	/* skip over other possible matches for the info */
439.  	do {
440.  	    if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file;
441.  	} while (!digit(*buf));
442.  	if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) {
443.  bad_data_file:	impossible("'data' file in wrong format");
444.  		(void) dlb_fclose(fp);
445.  		return;
446.  	}
447.  
448.  	if (user_typed_name || without_asking || yn("More info?") == 'y') {
449.  	    winid datawin;
450.  
451.  	    if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) {
452.  		pline("? Seek error on 'data' file!");
453.  		(void) dlb_fclose(fp);
454.  		return;
455.  	    }
456.  	    datawin = create_nhwindow(NHW_MENU);
457.  	    for (i = 0; i < entry_count; i++) {
458.  		if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file;
459.  		if ((ep = index(buf, '\n')) != 0) *ep = 0;
460.  		if (index(buf+1, '\t') != 0) (void) tabexpand(buf+1);
461.  		putstr(datawin, 0, buf+1);
462.  	    }
463.  	    display_nhwindow(datawin, FALSE);
464.  	    destroy_nhwindow(datawin);
465.  	}
466.      } else if (user_typed_name)
467.  	pline("I don't have any information on those things.");
468.  
469.      (void) dlb_fclose(fp);
470.  }
471.  
472.  /* getpos() return values */
473.  #define LOOK_TRADITIONAL	0	/* '.' -- ask about "more info?" */
474.  #define LOOK_QUICK		1	/* ',' -- skip "more info?" */
475.  #define LOOK_ONCE		2	/* ';' -- skip and stop looping */
476.  #define LOOK_VERBOSE		3	/* ':' -- show more info w/o asking */
477.  
478.  /* also used by getpos hack in do_name.c */
479.  const char what_is_an_unknown_object[] = "an unknown object";
480.  
481.  STATIC_OVL int
482.  do_look(quick)
483.      boolean quick;	/* use cursor && don't search for "more info" */
484.  {
485.      char    out_str[BUFSZ], look_buf[BUFSZ];
486.      const char *x_str, *firstmatch = 0;
487.      struct permonst *pm = 0;
488.      int     i, ans = 0;
489.      int     sym;		/* typed symbol or converted glyph */
490.      int	    found;		/* count of matching syms found */
491.      coord   cc;			/* screen pos of unknown glyph */
492.      boolean save_verbose;	/* saved value of flags.verbose */
493.      boolean from_screen;	/* question from the screen */
494.      boolean need_to_look;	/* need to get explan. from glyph */
495.      boolean hit_trap;		/* true if found trap explanation */
496.      int skipped_venom;		/* non-zero if we ignored "splash of venom" */
497.      static const char *mon_interior = "the interior of a monster";
498.  
499.      if (quick) {
500.  	from_screen = TRUE;	/* yes, we want to use the cursor */
501.      } else {
502.  	i = ynq("Specify unknown object by cursor?");
503.  	if (i == 'q') return 0;
504.  	from_screen = (i == 'y');
505.      }
506.  
507.      if (from_screen) {
508.  	cc.x = u.ux;
509.  	cc.y = u.uy;
510.  	sym = 0;		/* gcc -Wall lint */
511.      } else {
512.  	getlin("Specify what? (type the word)", out_str);
513.  	if (out_str[0] == '\0' || out_str[0] == '\033')
514.  	    return 0;
515.  
516.  	if (out_str[1]) {	/* user typed in a complete string */
517.  	    checkfile(out_str, pm, TRUE, TRUE);
518.  	    return 0;
519.  	}
520.  	sym = out_str[0];
521.      }
522.  
523.      /* Save the verbose flag, we change it later. */
524.      save_verbose = flags.verbose;
525.      flags.verbose = flags.verbose && !quick;
526.      /*
527.       * The user typed one letter, or we're identifying from the screen.
528.       */
529.      do {
530.  	/* Reset some variables. */
531.  	need_to_look = FALSE;
532.  	pm = (struct permonst *)0;
533.  	skipped_venom = 0;
534.  	found = 0;
535.  	out_str[0] = '\0';
536.  
537.  	if (from_screen) {
538.  	    int glyph;	/* glyph at selected position */
539.  
540.  	    if (flags.verbose)
541.  		pline("Please move the cursor to %s.",
542.  		       what_is_an_unknown_object);
543.  	    else
544.  		pline("Pick an object.");
545.  
546.  	    ans = getpos(&cc, quick, what_is_an_unknown_object);
547.  	    if (ans < 0 || cc.x < 0) {
548.  		flags.verbose = save_verbose;
549.  		return 0;	/* done */
550.  	    }
551.  	    flags.verbose = FALSE;	/* only print long question once */
552.  
553.  	    /* Convert the glyph at the selected position to a symbol. */
554.  	    glyph = glyph_at(cc.x,cc.y);
555.  	    if (glyph_is_cmap(glyph)) {
556.  		sym = showsyms[glyph_to_cmap(glyph)];
557.  	    } else if (glyph_is_trap(glyph)) {
558.  		sym = showsyms[trap_to_defsym(glyph_to_trap(glyph))];
559.  	    } else if (glyph_is_object(glyph)) {
560.  		sym = oc_syms[(int)objects[glyph_to_obj(glyph)].oc_class];
561.  		if (sym == '`' && iflags.bouldersym && (int)glyph_to_obj(glyph) == BOULDER)
562.  			sym = iflags.bouldersym;
563.  	    } else if (glyph_is_monster(glyph)) {
564.  		/* takes care of pets, detected, ridden, and regular mons */
565.  		sym = monsyms[(int)mons[glyph_to_mon(glyph)].mlet];
566.  	    } else if (glyph_is_swallow(glyph)) {
567.  		sym = showsyms[glyph_to_swallow(glyph)+S_sw_tl];
568.  	    } else if (glyph_is_invisible(glyph)) {
569.  		sym = DEF_INVISIBLE;
570.  	    } else if (glyph_is_warning(glyph)) {
571.  		sym = glyph_to_warning(glyph);
572.  	    	sym = warnsyms[sym];
573.  	    } else {
574.  		impossible("do_look:  bad glyph %d at (%d,%d)",
575.  						glyph, (int)cc.x, (int)cc.y);
576.  		sym = ' ';
577.  	    }
578.  	}
579.  
580.  	/*
581.  	 * Check all the possibilities, saving all explanations in a buffer.
582.  	 * When all have been checked then the string is printed.
583.  	 */
584.  
585.  	/* Check for monsters */
586.  	for (i = 0; i < MAXMCLASSES; i++) {
587.  	    if (sym == (from_screen ? monsyms[i] : def_monsyms[i]) &&
588.  		monexplain[i]) {
589.  		need_to_look = TRUE;
590.  		if (!found) {
591.  		    Sprintf(out_str, "%c       %s", sym, an(monexplain[i]));
592.  		    firstmatch = monexplain[i];
593.  		    found++;
594.  		} else {
595.  		    found += append_str(out_str, an(monexplain[i]));
596.  		}
597.  	    }
598.  	}
599.  	/* handle '@' as a special case if it refers to you and you're
600.  	   playing a character which isn't normally displayed by that
601.  	   symbol; firstmatch is assumed to already be set for '@' */
602.  	if ((from_screen ?
603.  		(sym == monsyms[S_HUMAN] && cc.x == u.ux && cc.y == u.uy) :
604.  		(sym == def_monsyms[S_HUMAN] && !iflags.showrace)) &&
605.  	    !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd)
606.  	    found += append_str(out_str, "you");	/* tack on "or you" */
607.  
608.  	/*
609.  	 * Special case: if identifying from the screen, and we're swallowed,
610.  	 * and looking at something other than our own symbol, then just say
611.  	 * "the interior of a monster".
612.  	 */
613.  	if (u.uswallow && from_screen && is_swallow_sym(sym)) {
614.  	    if (!found) {
615.  		Sprintf(out_str, "%c       %s", sym, mon_interior);
616.  		firstmatch = mon_interior;
617.  	    } else {
618.  		found += append_str(out_str, mon_interior);
619.  	    }
620.  	    need_to_look = TRUE;
621.  	}
622.  
623.  	/* Now check for objects */
624.  	for (i = 1; i < MAXOCLASSES; i++) {
625.  	    if (sym == (from_screen ? oc_syms[i] : def_oc_syms[i])) {
626.  		need_to_look = TRUE;
627.  		if (from_screen && i == VENOM_CLASS) {
628.  		    skipped_venom++;
629.  		    continue;
630.  		}
631.  		if (!found) {
632.  		    Sprintf(out_str, "%c       %s", sym, an(objexplain[i]));
633.  		    firstmatch = objexplain[i];
634.  		    found++;
635.  		} else {
636.  		    found += append_str(out_str, an(objexplain[i]));
637.  		}
638.  	    }
639.  	}
640.  
641.  	if (sym == DEF_INVISIBLE) {
642.  	    if (!found) {
643.  		Sprintf(out_str, "%c       %s", sym, an(invisexplain));
644.  		firstmatch = invisexplain;
645.  		found++;
646.  	    } else {
647.  		found += append_str(out_str, an(invisexplain));
648.  	    }
649.  	}
650.  
651.  #define is_cmap_trap(i) ((i) >= S_arrow_trap && (i) <= S_polymorph_trap)
652.  #define is_cmap_drawbridge(i) ((i) >= S_vodbridge && (i) <= S_hcdbridge)
653.  
654.  	/* Now check for graphics symbols */
655.  	for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) {
656.  	    x_str = defsyms[i].explanation;
657.  	    if (sym == (from_screen ? showsyms[i] : defsyms[i].sym) && *x_str) {
658.  		/* avoid "an air", "a water", or "a floor of a room" */
659.  		int article = (i == S_room) ? 2 :		/* 2=>"the" */
660.  			      !(strcmp(x_str, "air") == 0 ||	/* 1=>"an"  */
661.  				strcmp(x_str, "water") == 0);	/* 0=>(none)*/
662.  
663.  		if (!found) {
664.  		    if (is_cmap_trap(i)) {
665.  			Sprintf(out_str, "%c       a trap", sym);
666.  			hit_trap = TRUE;
667.  		    } else if (level.flags.lethe && !strcmp(x_str, "water")) {
668.  			Sprintf(out_str, "%c       sparkling water", sym);
669.  		    } else {
670.  			Sprintf(out_str, "%c       %s", sym,
671.  				article == 2 ? the(x_str) :
672.  				article == 1 ? an(x_str) : x_str);
673.  		    }
674.  		    firstmatch = x_str;
675.  		    found++;
676.  		} else if (!u.uswallow && !(hit_trap && is_cmap_trap(i)) &&
677.  			   !(found >= 3 && is_cmap_drawbridge(i))) {
678.  		    if (level.flags.lethe && !strcmp(x_str, "water"))
679.  			found += append_str(out_str, "sparkling water");
680.  		    else
681.  		    	found += append_str(out_str,
682.  					article == 2 ? the(x_str) :
683.  					article == 1 ? an(x_str) : x_str);
684.  		    if (is_cmap_trap(i)) hit_trap = TRUE;
685.  		}
686.  
687.  		if (i == S_altar || is_cmap_trap(i))
688.  		    need_to_look = TRUE;
689.  	    }
690.  	}
691.  
692.  	/* Now check for warning symbols */
693.  	for (i = 1; i < WARNCOUNT; i++) {
694.  	    x_str = def_warnsyms[i].explanation;
695.  	    if (sym == (from_screen ? warnsyms[i] : def_warnsyms[i].sym)) {
696.  		if (!found) {
697.  			Sprintf(out_str, "%c       %s",
698.  				sym, def_warnsyms[i].explanation);
699.  			firstmatch = def_warnsyms[i].explanation;
700.  			found++;
701.  		} else {
702.  			found += append_str(out_str, def_warnsyms[i].explanation);
703.  		}
704.  		/* Kludge: warning trumps boulders on the display.
705.  		   Reveal the boulder too or player can get confused */
706.  		if (from_screen && sobj_at(BOULDER, cc.x, cc.y))
707.  			Strcat(out_str, " co-located with a boulder");
708.  		break;	/* out of for loop*/
709.  	    }
710.  	}
711.      
712.  	/* if we ignored venom and list turned out to be short, put it back */
713.  	if (skipped_venom && found < 2) {
714.  	    x_str = objexplain[VENOM_CLASS];
715.  	    if (!found) {
716.  		Sprintf(out_str, "%c       %s", sym, an(x_str));
717.  		firstmatch = x_str;
718.  		found++;
719.  	    } else {
720.  		found += append_str(out_str, an(x_str));
721.  	    }
722.  	}
723.  
724.  	/* handle optional boulder symbol as a special case */ 
725.  	if (iflags.bouldersym && sym == iflags.bouldersym) {
726.  	    if (!found) {
727.  		firstmatch = "boulder";
728.  		Sprintf(out_str, "%c       %s", sym, an(firstmatch));
729.  		found++;
730.  	    } else {
731.  		found += append_str(out_str, "boulder");
732.  	    }
733.  	}
734.  	
735.  	/*
736.  	 * If we are looking at the screen, follow multiple possibilities or
737.  	 * an ambiguous explanation by something more detailed.
738.  	 */
739.  	if (from_screen) {
740.  	    if (found > 1 || need_to_look) {
741.  		char monbuf[BUFSZ];
742.  		char temp_buf[BUFSZ];
743.  
744.  		pm = lookat(cc.x, cc.y, look_buf, monbuf);
745.  		firstmatch = look_buf;
746.  		if (*firstmatch) {
747.  		    Sprintf(temp_buf, " (%s)", firstmatch);
748.  		    (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1);
749.  		    found = 1;	/* we have something to look up */
750.  		}
751.  		if (monbuf[0]) {
752.  		    Sprintf(temp_buf, " [seen: %s]", monbuf);
753.  		    (void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1);
754.  		}
755.  #ifdef WIZARD
756.  		if (wizard && pm) {
757.  		    struct monst *mtmp = m_at(cc.x, cc.y);
758.  		    if (mtmp && mtmp->oldmonnm != monsndx(pm)) {
759.  			Sprintf(temp_buf, " [polymorphed from a %s]",
760.  				mons[mtmp->oldmonnm].mname);
761.  			(void)strncat(out_str, temp_buf, BUFSZ-strlen(out_str)-1);
762.  		    }
763.  		}
764.  #endif
765.  	    }
766.  	}
767.  
768.  	/* Finally, print out our explanation. */
769.  	if (found) {
770.  	    pline("%s", out_str);
771.  	    /* check the data file for information about this thing */
772.  	    if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE &&
773.  			(ans == LOOK_VERBOSE || (flags.help && !quick))) {
774.  		char temp_buf[BUFSZ];
775.  		Strcpy(temp_buf, level.flags.lethe 
776.  					&& !strcmp(firstmatch, "water")?
777.  				"lethe" : firstmatch);
778.  		checkfile(temp_buf, pm, FALSE, (boolean)(ans == LOOK_VERBOSE));
779.  	    }
780.  	} else {
781.  	    pline("I've never heard of such things.");
782.  	}
783.  
784.      } while (from_screen && !quick && ans != LOOK_ONCE);
785.  
786.      flags.verbose = save_verbose;
787.      return 0;
788.  }
789.  
790.  
791.  int
792.  dowhatis()
793.  {
794.  	return do_look(FALSE);
795.  }
796.  
797.  int
798.  doquickwhatis()
799.  {
800.  	return do_look(TRUE);
801.  }
802.  
803.  int
804.  doidtrap()
805.  {
806.  	register struct trap *trap;
807.  	int x, y, tt;
808.  
809.  	if (!getdir("^")) return 0;
810.  	x = u.ux + u.dx;
811.  	y = u.uy + u.dy;
812.  	for (trap = ftrap; trap; trap = trap->ntrap)
813.  	    if (trap->tx == x && trap->ty == y) {
814.  		if (!trap->tseen) break;
815.  		tt = trap->ttyp;
816.  		if (u.dz) {
817.  		    if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE) :
818.  			    tt == ROCKTRAP) break;
819.  		}
820.  		tt = what_trap(tt);
821.  		pline("That is %s%s%s.",
822.  		      an(defsyms[trap_to_defsym(tt)].explanation),
823.  		      !trap->madeby_u ? "" : (tt == WEB) ? " woven" :
824.  			  /* trap doors & spiked pits can't be made by
825.  			     player, and should be considered at least
826.  			     as much "set" as "dug" anyway */
827.  			  (tt == HOLE || tt == PIT) ? " dug" : " set",
828.  		      !trap->madeby_u ? "" : " by you");
829.  		return 0;
830.  	    }
831.  	pline("I can't see a trap there.");
832.  	return 0;
833.  }
834.  
835.  char *
836.  dowhatdoes_core(q, cbuf)
837.  char q;
838.  char *cbuf;
839.  {
840.  	dlb *fp;
841.  	char bufr[BUFSZ];
842.  	register char *buf = &bufr[6], *ep, ctrl, meta;
843.  
844.  	fp = dlb_fopen_area(NH_CMDHELPAREA, NH_CMDHELPFILE, "r");
845.  	if (!fp) {
846.  		pline("Cannot open data file!");
847.  		return 0;
848.  	}
849.  
850.    	ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0);
851.  	meta = ((0x80 & q) ? (0x7f & q) : 0);
852.  	while(dlb_fgets(buf,BUFSZ-6,fp)) {
853.  	    if ((ctrl && *buf=='^' && *(buf+1)==ctrl) ||
854.  		(meta && *buf=='M' && *(buf+1)=='-' && *(buf+2)==meta) ||
855.  		*buf==q) {
856.  		if ((ep = index(buf, '\n')) != 0) *ep = 0;
857.  #ifdef MSDOS
858.  		if ((ep = index(buf, '\r')) != 0) *ep = 0;
859.  #endif
860.  		if (ctrl && buf[2] == '\t'){
861.  			buf = bufr + 1;
862.  			(void) strncpy(buf, "^?      ", 8);
863.  			buf[1] = ctrl;
864.  		} else if (meta && buf[3] == '\t'){
865.  			buf = bufr + 2;
866.  			(void) strncpy(buf, "M-?     ", 8);
867.  			buf[2] = meta;
868.  		} else if(buf[1] == '\t'){
869.  			buf = bufr;
870.  			buf[0] = q;
871.  			(void) strncpy(buf+1, "       ", 7);
872.  		}
873.  		(void) dlb_fclose(fp);
874.  		Strcpy(cbuf, buf);
875.  		return cbuf;
876.  	    }
877.  	}
878.  	(void) dlb_fclose(fp);
879.  	return (char *)0;
880.  }
881.  
882.  int
883.  dowhatdoes()
884.  {
885.  	char bufr[BUFSZ];
886.  	char q, *reslt;
887.  
888.  #if defined(UNIX) || defined(VMS)
889.  	introff();
890.  #endif
891.  	q = yn_function("What command?", (char *)0, '\0');
892.  #if defined(UNIX) || defined(VMS)
893.  	intron();
894.  #endif
895.  	reslt = dowhatdoes_core(q, bufr);
896.  	if (reslt)
897.  		pline("%s", reslt);
898.  	else
899.  		pline("I've never heard of such commands.");
900.  	return 0;
901.  }
902.  
903.  /* data for help_menu() */
904.  static const char *help_menu_items[] = {
905.  /* 0*/	"Long description of the game and commands.",
906.  /* 1*/	"List of game commands.",
907.  /* 2*/	"Concise history of Slash'EM.",
908.  /* 3*/	"Info on a character in the game display.",
909.  /* 4*/	"Info on what a given key does.",
910.  /* 5*/	"List of game options.",
911.  /* 6*/	"Longer explanation of game options.",
912.  /* 7*/	"List of extended commands.",
913.  /* 8*/	"The NetHack license.",
914.  #ifndef MAC
915.  /*WAC Add access to txt guidebook*/
916.  /* 9*/  "The Slash'EM Guidebook.",
917.  #endif
918.  #ifdef PORT_HELP
919.  	"%s-specific help and commands.",
920.  #endif
921.  #ifdef WIZARD
922.  	"List of wizard-mode commands.",
923.  #endif
924.  	"",
925.  	(char *)0
926.  };
927.  
928.  enum {
929.    LICENSE_SLOT=8,
930.  #ifndef MAC
931.    GUIDEBOOK_SLOT,
932.  #endif
933.  #ifdef PORT_HELP
934.    PORT_HELP_ID,
935.  #endif
936.  #ifdef WIZARD
937.    WIZHLP_SLOT,
938.  #endif
939.    NULL_SLOT
940.  };
941.  
942.  STATIC_OVL boolean
943.  help_menu(sel)
944.  	int *sel;
945.  {
946.  	winid tmpwin = create_nhwindow(NHW_MENU);
947.  #ifdef PORT_HELP
948.  	char helpbuf[QBUFSZ];
949.  #endif
950.  	int i, n;
951.  	menu_item *selected;
952.  	anything any;
953.  
954.  	any.a_void = 0;		/* zero all bits */
955.  	start_menu(tmpwin);
956.  #ifdef WIZARD
957.  	if (!wizard) help_menu_items[WIZHLP_SLOT] = "",
958.  		     help_menu_items[WIZHLP_SLOT+1] = (char *)0;
959.  #endif
960.  	for (i = 0; help_menu_items[i]; i++)
961.  #ifdef PORT_HELP
962.  	    /* port-specific line has a %s in it for the PORT_ID */
963.  	    if (help_menu_items[i][0] == '%') {
964.  		Sprintf(helpbuf, help_menu_items[i], PORT_ID);
965.  		any.a_int = PORT_HELP_ID + 1;
966.  		add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
967.  			 helpbuf, MENU_UNSELECTED);
968.  	    } else
969.  #endif
970.  	    {
971.  		any.a_int = (*help_menu_items[i]) ? i+1 : 0;
972.  		add_menu(tmpwin, NO_GLYPH, &any, 0, 0,
973.  			ATR_NONE, help_menu_items[i], MENU_UNSELECTED);
974.  	    }
975.  	end_menu(tmpwin, "Select one item:");
976.  	n = select_menu(tmpwin, PICK_ONE, &selected);
977.  	destroy_nhwindow(tmpwin);
978.  	if (n > 0) {
979.  	    *sel = selected[0].item.a_int - 1;
980.  	    free((genericptr_t)selected);
981.  	    return TRUE;
982.  	}
983.  	return FALSE;
984.  }
985.  
986.  int
987.  dohelp()
988.  {
989.  	int sel = 0;
990.  
991.  	if (help_menu(&sel)) {
992.  		switch (sel) {
993.  			case  0:  display_file_area(NH_HELP_AREA, NH_HELP, TRUE);
994.  				  break;
995.  			case  1:  display_file_area(NH_SHELP_AREA, NH_SHELP, TRUE);
996.  				  break;
997.  			case  2:  (void) dohistory();  break;
998.  			case  3:  (void) dowhatis();  break;
999.  			case  4:  (void) dowhatdoes();  break;
1000. 			case  5:  option_help();  break;
1001. 			case  6:  display_file_area(NH_OPTIONAREA,
1002. 				    NH_OPTIONFILE, TRUE);
1003. 				  break;
1004. 			case  7:  (void) doextlist();  break;
1005. 			case  8:  display_file_area(NH_LICENSE_AREA,
1006. 				    NH_LICENSE, TRUE);
1007. 				  break;
1008. #ifndef MAC
1009. /*WAC add guidebook.*/
1010.                         case  GUIDEBOOK_SLOT:  display_file_area(NH_GUIDEBOOK_AREA,
1011. 				    NH_GUIDEBOOK, TRUE);
1012. 				  break;
1013. #endif
1014. #ifdef PORT_HELP
1015. 			case PORT_HELP_ID:  port_help();  break;
1016. #endif
1017. #ifdef WIZARD
1018.                         case  WIZHLP_SLOT:  display_file_area(NH_DEBUGHELP_AREA,
1019. 				    NH_DEBUGHELP, TRUE);
1020. 				  break;
1021. #endif
1022. 		}
1023. 	}
1024. 	return 0;
1025. }
1026. 
1027. int
1028. dohistory()
1029. {
1030. 	display_file_area(NH_HISTORY_AREA, NH_HISTORY, TRUE);
1031. 	return 0;
1032. }
1033. 
1034. /*pager.c*/