Source:NetHack 3.6.0/src/pager.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to pager.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/pager.c#line123]], 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.

Top of file

  1.  /* NetHack 3.6	pager.c	$NHDT-Date: 1448482543 2015/11/25 20:15:43 $  $NHDT-Branch: master $:$NHDT-Revision: 1.86 $ */
  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 void FDECL(look_at_object, (char *, int, int, int));
  14.  STATIC_DCL void FDECL(look_at_monster, (char *, char *,
  15.                                          struct monst *, int, int));
  16.  STATIC_DCL struct permonst *FDECL(lookat, (int, int, char *, char *));
  17.  STATIC_DCL void FDECL(checkfile, (char *, struct permonst *,
  18.                                    BOOLEAN_P, BOOLEAN_P));
  19.  STATIC_DCL void FDECL(look_all, (BOOLEAN_P,BOOLEAN_P));
  20.  STATIC_DCL boolean FDECL(help_menu, (int *));
  21.  STATIC_DCL void NDECL(docontact);
  22.  #ifdef PORT_HELP
  23.  extern void NDECL(port_help);
  24.  #endif
  25.  

is_swallow_sym

  1.  /* Returns "true" for characters that could represent a monster's stomach. */
  2.  STATIC_OVL boolean
  3.  is_swallow_sym(c)
  4.  int c;
  5.  {
  6.      int i;
  7.  
  8.      for (i = S_sw_tl; i <= S_sw_br; i++)
  9.          if ((int) showsyms[i] == c)
  10.              return TRUE;
  11.      return FALSE;
  12.  }
  13.  

append_str

  1.  /*
  2.   * Append new_str to the end of buf if new_str doesn't already exist as
  3.   * a substring of buf.  Return 1 if the string was appended, 0 otherwise.
  4.   * It is expected that buf is of size BUFSZ.
  5.   */
  6.  STATIC_OVL int
  7.  append_str(buf, new_str)
  8.  char *buf;
  9.  const char *new_str;
  10.  {
  11.      int space_left; /* space remaining in buf */
  12.  
  13.      if (strstri(buf, new_str))
  14.          return 0;
  15.  
  16.      space_left = BUFSZ - strlen(buf) - 1;
  17.      (void) strncat(buf, " or ", space_left);
  18.      (void) strncat(buf, new_str, space_left - 4);
  19.      return 1;
  20.  }
  21.  

self_lookat

  1.  /* shared by monster probing (via query_objlist!) as well as lookat() */
  2.  char *
  3.  self_lookat(outbuf)
  4.  char *outbuf;
  5.  {
  6.      char race[QBUFSZ];
  7.  
  8.      /* include race with role unless polymorphed */
  9.      race[0] = '\0';
  10.      if (!Upolyd)
  11.          Sprintf(race, "%s ", urace.adj);
  12.      Sprintf(outbuf, "%s%s%s called %s",
  13.              /* being blinded may hide invisibility from self */
  14.              (Invis && (senseself() || !Blind)) ? "invisible " : "", race,
  15.              mons[u.umonnum].mname, plname);
  16.      if (u.usteed)
  17.          Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed));
  18.      return outbuf;
  19.  }
  20.  

object_from_map

  1.  /* extracted from lookat(); also used by namefloorobj() */
  2.  boolean
  3.  object_from_map(glyph, x, y, obj_p)
  4.  int glyph, x, y;
  5.  struct obj **obj_p;
  6.  {
  7.      boolean fakeobj = FALSE;
  8.      struct monst *mtmp;
  9.      struct obj *otmp = vobj_at(x, y);
  10.      int glyphotyp = glyph_to_obj(glyph);
  11.  
  12.      *obj_p = (struct obj *) 0;
  13.      /* there might be a mimic here posing as an object */
  14.      mtmp = m_at(x, y);
  15.      if (mtmp && is_obj_mappear(mtmp, (unsigned) glyphotyp))
  16.          otmp = 0;
  17.      else
  18.          mtmp = 0;
  19.  
  20.      if (!otmp || otmp->otyp != glyphotyp) {
  21.          /* this used to exclude STRANGE_OBJECT; now caller deals with it */
  22.          otmp = mksobj(glyphotyp, FALSE, FALSE);
  23.          if (!otmp)
  24.              return FALSE;
  25.          fakeobj = TRUE;
  26.          if (otmp->oclass == COIN_CLASS)
  27.              otmp->quan = 2L; /* to force pluralization */
  28.          else if (otmp->otyp == SLIME_MOLD)
  29.              otmp->spe = context.current_fruit; /* give it a type */
  30.          if (mtmp && has_mcorpsenm(mtmp)) /* mimic as corpse/statue */
  31.              otmp->corpsenm = MCORPSENM(mtmp);
  32.      }
  33.      /* if located at adjacent spot, mark it as having been seen up close */
  34.      if (otmp && distu(x, y) <= 2 && !Blind && !Hallucination)
  35.          otmp->dknown = 1;
  36.  
  37.      *obj_p = otmp;
  38.      return fakeobj; /* when True, caller needs to dealloc *obj_p */
  39.  }
  40.  

look_at_object

  1.  STATIC_OVL void
  2.  look_at_object(buf, x, y, glyph)
  3.  char *buf; /* output buffer */
  4.  int x, y, glyph;
  5.  {
  6.      struct obj *otmp = 0;
  7.      boolean fakeobj = object_from_map(glyph, x, y, &otmp);
  8.  
  9.      if (otmp) {
  10.          Strcpy(buf, (otmp->otyp != STRANGE_OBJECT)
  11.                       ? distant_name(otmp, xname)
  12.                       : obj_descr[STRANGE_OBJECT].oc_name);
  13.          if (fakeobj)
  14.              dealloc_obj(otmp), otmp = 0;
  15.      } else
  16.          Strcpy(buf, something); /* sanity precaution */
  17.  
  18.      if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
  19.          Strcat(buf, " embedded in stone");
  20.      else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
  21.          Strcat(buf, " embedded in a wall");
  22.      else if (closed_door(x, y))
  23.          Strcat(buf, " embedded in a door");
  24.      else if (is_pool(x, y))
  25.          Strcat(buf, " in water");
  26.      else if (is_lava(x, y))
  27.          Strcat(buf, " in molten lava"); /* [can this ever happen?] */
  28.      return;
  29.  }
  30.  

look_at_monster

  1.  STATIC_OVL void
  2.  look_at_monster(buf, monbuf, mtmp, x, y)
  3.  char *buf, *monbuf; /* buf: output, monbuf: optional output */
  4.  struct monst *mtmp;
  5.  int x, y;
  6.  {
  7.      char *name, monnambuf[BUFSZ];
  8.      boolean accurate = !Hallucination;
  9.  
  10.      if (mtmp->data == &mons[PM_COYOTE] && accurate)
  11.          name = coyotename(mtmp, monnambuf);
  12.      else
  13.          name = distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
  14.  
  15.      Sprintf(buf, "%s%s%s",
  16.              (mtmp->mx != x || mtmp->my != y)
  17.                  ? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ")
  18.                  : "",
  19.              (mtmp->mtame && accurate)
  20.                  ? "tame "
  21.                  : (mtmp->mpeaceful && accurate)
  22.                      ? "peaceful "
  23.                      : "",
  24.              name);
  25.      if (u.ustuck == mtmp)
  26.          Strcat(buf, (Upolyd && sticks(youmonst.data))
  27.                       ? ", being held" : ", holding you");
  28.      if (mtmp->mleashed)
  29.          Strcat(buf, ", leashed to you");
  30.  
  31.      if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
  32.          struct trap *t = t_at(mtmp->mx, mtmp->my);
  33.          int tt = t ? t->ttyp : NO_TRAP;
  34.  
  35.          /* newsym lets you know of the trap, so mention it here */
  36.          if (tt == BEAR_TRAP || tt == PIT || tt == SPIKED_PIT || tt == WEB)
  37.              Sprintf(eos(buf), ", trapped in %s",
  38.                      an(defsyms[trap_to_defsym(tt)].explanation));
  39.      }
  40.  
  41.      if (monbuf) {
  42.          unsigned how_seen = howmonseen(mtmp);
  43.  
  44.          monbuf[0] = '\0';
  45.          if (how_seen != 0 && how_seen != MONSEEN_NORMAL) {
  46.              if (how_seen & MONSEEN_NORMAL) {
  47.                  Strcat(monbuf, "normal vision");
  48.                  how_seen &= ~MONSEEN_NORMAL;
  49.                  /* how_seen can't be 0 yet... */
  50.                  if (how_seen)
  51.                      Strcat(monbuf, ", ");
  52.              }
  53.              if (how_seen & MONSEEN_SEEINVIS) {
  54.                  Strcat(monbuf, "see invisible");
  55.                  how_seen &= ~MONSEEN_SEEINVIS;
  56.                  if (how_seen)
  57.                      Strcat(monbuf, ", ");
  58.              }
  59.              if (how_seen & MONSEEN_INFRAVIS) {
  60.                  Strcat(monbuf, "infravision");
  61.                  how_seen &= ~MONSEEN_INFRAVIS;
  62.                  if (how_seen)
  63.                      Strcat(monbuf, ", ");
  64.              }
  65.              if (how_seen & MONSEEN_TELEPAT) {
  66.                  Strcat(monbuf, "telepathy");
  67.                  how_seen &= ~MONSEEN_TELEPAT;
  68.                  if (how_seen)
  69.                      Strcat(monbuf, ", ");
  70.              }
  71.              if (how_seen & MONSEEN_XRAYVIS) {
  72.                  /* Eyes of the Overworld */
  73.                  Strcat(monbuf, "astral vision");
  74.                  how_seen &= ~MONSEEN_XRAYVIS;
  75.                  if (how_seen)
  76.                      Strcat(monbuf, ", ");
  77.              }
  78.              if (how_seen & MONSEEN_DETECT) {
  79.                  Strcat(monbuf, "monster detection");
  80.                  how_seen &= ~MONSEEN_DETECT;
  81.                  if (how_seen)
  82.                      Strcat(monbuf, ", ");
  83.              }
  84.              if (how_seen & MONSEEN_WARNMON) {
  85.                  if (Hallucination)
  86.                      Strcat(monbuf, "paranoid delusion");
  87.                  else
  88.                      Sprintf(eos(monbuf), "warned of %s",
  89.                              makeplural(mtmp->data->mname));
  90.                  how_seen &= ~MONSEEN_WARNMON;
  91.                  if (how_seen)
  92.                      Strcat(monbuf, ", ");
  93.              }
  94.              /* should have used up all the how_seen bits by now */
  95.              if (how_seen) {
  96.                  impossible("lookat: unknown method of seeing monster");
  97.                  Sprintf(eos(monbuf), "(%u)", how_seen);
  98.              }
  99.          } /* seen by something other than normal vision */
  100.      } /* monbuf is non-null */
  101.  }
  102.  

lookat

  1.  /*
  2.   * Return the name of the glyph found at (x,y).
  3.   * If not hallucinating and the glyph is a monster, also monster data.
  4.   */
  5.  STATIC_OVL struct permonst *
  6.  lookat(x, y, buf, monbuf)
  7.  int x, y;
  8.  char *buf, *monbuf;
  9.  {
  10.      struct monst *mtmp = (struct monst *) 0;
  11.      struct permonst *pm = (struct permonst *) 0;
  12.      int glyph;
  13.  
  14.      buf[0] = monbuf[0] = '\0';
  15.      glyph = glyph_at(x, y);
  16.      if (u.ux == x && u.uy == y && canspotself()) {
  17.          /* fill in buf[] */
  18.          (void) self_lookat(buf);
  19.  
  20.          /* file lookup can't distinguish between "gnomish wizard" monster
  21.             and correspondingly named player character, always picking the
  22.             former; force it to find the general "wizard" entry instead */
  23.          if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
  24.              pm = &mons[PM_WIZARD];
  25.  
  26.          /* When you see yourself normally, no explanation is appended
  27.             (even if you could also see yourself via other means).
  28.             Sensing self while blind or swallowed is treated as if it
  29.             were by normal vision (cf canseeself()). */
  30.          if ((Invisible || u.uundetected) && !Blind && !u.uswallow) {
  31.              unsigned how = 0;
  32.  
  33.              if (Infravision)
  34.                  how |= 1;
  35.              if (Unblind_telepat)
  36.                  how |= 2;
  37.              if (Detect_monsters)
  38.                  how |= 4;
  39.  
  40.              if (how)
  41.                  Sprintf(
  42.                      eos(buf), " [seen: %s%s%s%s%s]",
  43.                      (how & 1) ? "infravision" : "",
  44.                      /* add comma if telep and infrav */
  45.                      ((how & 3) > 2) ? ", " : "", (how & 2) ? "telepathy" : "",
  46.                      /* add comma if detect and (infrav or telep or both) */
  47.                      ((how & 7) > 4) ? ", " : "",
  48.                      (how & 4) ? "monster detection" : "");
  49.          }
  50.      } else if (u.uswallow) {
  51.          /* all locations when swallowed other than the hero are the monster */
  52.          Sprintf(buf, "interior of %s",
  53.                  Blind ? "a monster" : a_monnam(u.ustuck));
  54.          pm = u.ustuck->data;
  55.      } else if (glyph_is_monster(glyph)) {
  56.          bhitpos.x = x;
  57.          bhitpos.y = y;
  58.          if ((mtmp = m_at(x, y)) != 0) {
  59.              look_at_monster(buf, monbuf, mtmp, x, y);
  60.              pm = mtmp->data;
  61.          }
  62.      } else if (glyph_is_object(glyph)) {
  63.          look_at_object(buf, x, y, glyph); /* fill in buf[] */
  64.      } else if (glyph_is_trap(glyph)) {
  65.          int tnum = what_trap(glyph_to_trap(glyph));
  66.  
  67.          Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation);
  68.      } else if (!glyph_is_cmap(glyph)) {
  69.          Strcpy(buf, "unexplored area");
  70.      } else
  71.          switch (glyph_to_cmap(glyph)) {
  72.          case S_altar:
  73.              Sprintf(buf, "%s %saltar",
  74.                      /* like endgame high priests, endgame high altars
  75.                         are only recognizable when immediately adjacent */
  76.                      (Is_astralevel(&u.uz) && distu(x, y) > 2)
  77.                          ? "aligned"
  78.                          : align_str(
  79.                                Amask2align(levl[x][y].altarmask & ~AM_SHRINE)),
  80.                      ((levl[x][y].altarmask & AM_SHRINE)
  81.                       && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)))
  82.                          ? "high "
  83.                          : "");
  84.              break;
  85.          case S_ndoor:
  86.              if (is_drawbridge_wall(x, y) >= 0)
  87.                  Strcpy(buf, "open drawbridge portcullis");
  88.              else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
  89.                  Strcpy(buf, "broken door");
  90.              else
  91.                  Strcpy(buf, "doorway");
  92.              break;
  93.          case S_cloud:
  94.              Strcpy(buf,
  95.                     Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
  96.              break;
  97.          case S_stone:
  98.              if (!levl[x][y].seenv) {
  99.                  Strcpy(buf, "unexplored");
  100.                  break;
  101.              } else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) {
  102.                  Strcpy(buf, "stone");
  103.                  break;
  104.              }
  105.              /*else FALLTHRU*/
  106.          default:
  107.              Strcpy(buf, defsyms[glyph_to_cmap(glyph)].explanation);
  108.              break;
  109.          }
  110.  
  111.      return (pm && !Hallucination) ? pm : (struct permonst *) 0;
  112.  }
  113.  

checkfile

  1.  /*
  2.   * Look in the "data" file for more info.  Called if the user typed in the
  3.   * whole name (user_typed_name == TRUE), or we've found a possible match
  4.   * with a character/glyph and flags.help is TRUE.
  5.   *
  6.   * NOTE: when (user_typed_name == FALSE), inp is considered read-only and
  7.   *       must not be changed directly, e.g. via lcase(). We want to force
  8.   *       lcase() for data.base lookup so that we can have a clean key.
  9.   *       Therefore, we create a copy of inp _just_ for data.base lookup.
  10.   */
  11.  STATIC_OVL void
  12.  checkfile(inp, pm, user_typed_name, without_asking)
  13.  char *inp;
  14.  struct permonst *pm;
  15.  boolean user_typed_name, without_asking;
  16.  {
  17.      dlb *fp;
  18.      char buf[BUFSZ], newstr[BUFSZ];
  19.      char *ep, *dbase_str;
  20.      unsigned long txt_offset = 0L;
  21.      int chk_skip;
  22.      boolean found_in_file = FALSE, skipping_entry = FALSE;
  23.      winid datawin = WIN_ERR;
  24.  
  25.      fp = dlb_fopen(DATAFILE, "r");
  26.      if (!fp) {
  27.          pline("Cannot open data file!");
  28.          return;
  29.      }
  30.  
  31.      /*
  32.       * If someone passed us garbage, prevent fault.
  33.       */
  34.      if (!inp || (inp && strlen(inp) > (BUFSZ - 1))) {
  35.          pline("bad do_look buffer passed!");
  36.          return;
  37.      }
  38.  
  39.      /* To prevent the need for entries in data.base like *ngel to account
  40.       * for Angel and angel, make the lookup string the same for both
  41.       * user_typed_name and picked name.
  42.       */
  43.      if (pm != (struct permonst *) 0 && !user_typed_name)
  44.          dbase_str = strcpy(newstr, pm->mname);
  45.      else
  46.          dbase_str = strcpy(newstr, inp);
  47.      (void) lcase(dbase_str);
  48.  
  49.      if (!strncmp(dbase_str, "interior of ", 12))
  50.          dbase_str += 12;
  51.      if (!strncmp(dbase_str, "a ", 2))
  52.          dbase_str += 2;
  53.      else if (!strncmp(dbase_str, "an ", 3))
  54.          dbase_str += 3;
  55.      else if (!strncmp(dbase_str, "the ", 4))
  56.          dbase_str += 4;
  57.      if (!strncmp(dbase_str, "tame ", 5))
  58.          dbase_str += 5;
  59.      else if (!strncmp(dbase_str, "peaceful ", 9))
  60.          dbase_str += 9;
  61.      if (!strncmp(dbase_str, "invisible ", 10))
  62.          dbase_str += 10;
  63.      if (!strncmp(dbase_str, "saddled ", 8))
  64.          dbase_str += 8;
  65.      if (!strncmp(dbase_str, "statue of ", 10))
  66.          dbase_str[6] = '\0';
  67.      else if (!strncmp(dbase_str, "figurine of ", 12))
  68.          dbase_str[8] = '\0';
  69.  
  70.      /* Make sure the name is non-empty. */
  71.      if (*dbase_str) {
  72.          /* adjust the input to remove "named " and convert to lower case */
  73.          char *alt = 0; /* alternate description */
  74.  
  75.          if ((ep = strstri(dbase_str, " named ")) != 0)
  76.              alt = ep + 7;
  77.          else
  78.              ep = strstri(dbase_str, " called ");
  79.          if (!ep)
  80.              ep = strstri(dbase_str, ", ");
  81.          if (ep && ep > dbase_str)
  82.              *ep = '\0';
  83.  
  84.          /*
  85.           * If the object is named, then the name is the alternate description;
  86.           * otherwise, the result of makesingular() applied to the name is.
  87.           * This
  88.           * isn't strictly optimal, but named objects of interest to the user
  89.           * will usually be found under their name, rather than under their
  90.           * object type, so looking for a singular form is pointless.
  91.           */
  92.          if (!alt)
  93.              alt = makesingular(dbase_str);
  94.  
  95.          /* skip first record; read second */
  96.          txt_offset = 0L;
  97.          if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
  98.              impossible("can't read 'data' file");
  99.              (void) dlb_fclose(fp);
  100.              return;
  101.          } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset == 0L)
  102.              goto bad_data_file;
  103.  
  104.          /* look for the appropriate entry */
  105.          while (dlb_fgets(buf, BUFSZ, fp)) {
  106.              if (*buf == '.')
  107.                  break; /* we passed last entry without success */
  108.  
  109.              if (digit(*buf)) {
  110.                  /* a number indicates the end of current entry */
  111.                  skipping_entry = FALSE;
  112.              } else if (!skipping_entry) {
  113.                  if (!(ep = index(buf, '\n')))
  114.                      goto bad_data_file;
  115.                  *ep = 0;
  116.                  /* if we match a key that begins with "~", skip this entry */
  117.                  chk_skip = (*buf == '~') ? 1 : 0;
  118.                  if (pmatch(&buf[chk_skip], dbase_str)
  119.                      || (alt && pmatch(&buf[chk_skip], alt))) {
  120.                      if (chk_skip) {
  121.                          skipping_entry = TRUE;
  122.                          continue;
  123.                      } else {
  124.                          found_in_file = TRUE;
  125.                          break;
  126.                      }
  127.                  }
  128.              }
  129.          }
  130.      }
  131.  
  132.      if (found_in_file) {
  133.          long entry_offset;
  134.          int entry_count;
  135.          int i;
  136.  
  137.          /* skip over other possible matches for the info */
  138.          do {
  139.              if (!dlb_fgets(buf, BUFSZ, fp))
  140.                  goto bad_data_file;
  141.          } while (!digit(*buf));
  142.          if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) {
  143.          bad_data_file:
  144.              impossible("'data' file in wrong format or corrupted");
  145.              /* window will exist if we came here from below via 'goto' */
  146.              if (datawin != WIN_ERR)
  147.                  destroy_nhwindow(datawin);
  148.              (void) dlb_fclose(fp);
  149.              return;
  150.          }
  151.  
  152.          if (user_typed_name || without_asking || yn("More info?") == 'y') {
  153.              if (dlb_fseek(fp, (long) txt_offset + entry_offset, SEEK_SET)
  154.                  < 0) {
  155.                  pline("? Seek error on 'data' file!");
  156.                  (void) dlb_fclose(fp);
  157.                  return;
  158.              }
  159.              datawin = create_nhwindow(NHW_MENU);
  160.              for (i = 0; i < entry_count; i++) {
  161.                  if (!dlb_fgets(buf, BUFSZ, fp))
  162.                      goto bad_data_file;
  163.                  if ((ep = index(buf, '\n')) != 0)
  164.                      *ep = 0;
  165.                  if (index(buf + 1, '\t') != 0)
  166.                      (void) tabexpand(buf + 1);
  167.                  putstr(datawin, 0, buf + 1);
  168.              }
  169.              display_nhwindow(datawin, FALSE);
  170.              destroy_nhwindow(datawin);
  171.          }
  172.      } else if (user_typed_name)
  173.          pline("I don't have any information on those things.");
  174.  
  175.      (void) dlb_fclose(fp);
  176.  }
  177.  

do_screen_description

  1.  int
  2.  do_screen_description(cc, looked, sym, out_str, firstmatch)
  3.  coord cc;
  4.  boolean looked;
  5.  int sym;
  6.  char *out_str;
  7.  const char **firstmatch;
  8.  {
  9.      boolean need_to_look = FALSE;
  10.      int glyph = NO_GLYPH;
  11.      static char look_buf[BUFSZ];
  12.      char prefix[BUFSZ];
  13.      int found = 0; /* count of matching syms found */
  14.      int i, alt_i;
  15.      int skipped_venom = 0;
  16.      boolean hit_trap;
  17.      const char *x_str;
  18.      static const char *mon_interior = "the interior of a monster";
  19.  
  20.      if (looked) {
  21.          int oc;
  22.          unsigned os;
  23.  
  24.          glyph = glyph_at(cc.x, cc.y);
  25.          /* Convert glyph at selected position to a symbol for use below. */
  26.          (void) mapglyph(glyph, &sym, &oc, &os, cc.x, cc.y);
  27.  
  28.          Sprintf(prefix, "%s        ", encglyph(glyph));
  29.      } else
  30.          Sprintf(prefix, "%c        ", sym);
  31.  
  32.      /*
  33.       * Check all the possibilities, saving all explanations in a buffer.
  34.       * When all have been checked then the string is printed.
  35.       */
  36.  
  37.      /*
  38.       * Special case: if identifying from the screen, and we're swallowed,
  39.       * and looking at something other than our own symbol, then just say
  40.       * "the interior of a monster".
  41.       */
  42.      if (u.uswallow && looked
  43.          && (is_swallow_sym(sym) || (int) showsyms[S_stone] == sym)) {
  44.          if (!found) {
  45.              Sprintf(out_str, "%s%s", prefix, mon_interior);
  46.              *firstmatch = mon_interior;
  47.          } else {
  48.              found += append_str(out_str, mon_interior);
  49.          }
  50.          need_to_look = TRUE;
  51.          goto didlook;
  52.      }
  53.  
  54.      /* Check for monsters */
  55.      for (i = 0; i < MAXMCLASSES; i++) {
  56.          if (sym == (looked ? showsyms[i + SYM_OFF_M] : def_monsyms[i].sym)
  57.              && def_monsyms[i].explain) {
  58.              need_to_look = TRUE;
  59.              if (!found) {
  60.                  Sprintf(out_str, "%s%s", prefix, an(def_monsyms[i].explain));
  61.                  *firstmatch = def_monsyms[i].explain;
  62.                  found++;
  63.              } else {
  64.                  found += append_str(out_str, an(def_monsyms[i].explain));
  65.              }
  66.          }
  67.      }
  68.      /* handle '@' as a special case if it refers to you and you're
  69.         playing a character which isn't normally displayed by that
  70.         symbol; firstmatch is assumed to already be set for '@' */
  71.      if ((looked ? (sym == showsyms[S_HUMAN + SYM_OFF_M]
  72.                     && cc.x == u.ux && cc.y == u.uy)
  73.                  : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace))
  74.          && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd)
  75.          found += append_str(out_str, "you"); /* tack on "or you" */
  76.  
  77.      /* Now check for objects */
  78.      for (i = 1; i < MAXOCLASSES; i++) {
  79.          if (sym == (looked ? showsyms[i + SYM_OFF_O] : def_oc_syms[i].sym)) {
  80.              need_to_look = TRUE;
  81.              if (looked && i == VENOM_CLASS) {
  82.                  skipped_venom++;
  83.                  continue;
  84.              }
  85.              if (!found) {
  86.                  Sprintf(out_str, "%s%s", prefix, an(def_oc_syms[i].explain));
  87.                  *firstmatch = def_oc_syms[i].explain;
  88.                  found++;
  89.              } else {
  90.                  found += append_str(out_str, an(def_oc_syms[i].explain));
  91.              }
  92.          }
  93.      }
  94.  
  95.      if (sym == DEF_INVISIBLE) {
  96.          if (!found) {
  97.              Sprintf(out_str, "%s%s", prefix, an(invisexplain));
  98.              *firstmatch = invisexplain;
  99.              found++;
  100.          } else {
  101.              found += append_str(out_str, an(invisexplain));
  102.          }
  103.      }
  104.  
  105.  #define is_cmap_trap(i) ((i) >= S_arrow_trap && (i) <= S_polymorph_trap)
  106.  #define is_cmap_drawbridge(i) ((i) >= S_vodbridge && (i) <= S_hcdbridge)
  107.  
  108.      /* Now check for graphics symbols */
  109.      alt_i = (sym == (looked ? showsyms[0] : defsyms[0].sym)) ? 0 : (2 + 1);
  110.      for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) {
  111.          /* when sym is the default background character, we process
  112.             i == 0 three times: unexplored, stone, dark part of a room */
  113.          if (alt_i < 2) {
  114.              x_str = !alt_i++ ? "unexplored" : "stone";
  115.              i = 0; /* for second iteration, undo loop increment */
  116.              /* alt_i is now 1 or 2 */
  117.          } else {
  118.              if (alt_i++ == 2)
  119.                  i = 0; /* undo loop increment */
  120.              x_str = defsyms[i].explanation;
  121.              /* alt_i is now 3 or more and no longer of interest */
  122.          }
  123.          if (sym == (looked ? showsyms[i] : defsyms[i].sym) && *x_str) {
  124.              /* avoid "an unexplored", "an stone", "an air", "a water",
  125.                 "a floor of a room", "a dark part of a room";
  126.                 article==2 => "the", 1 => "an", 0 => (none) */
  127.              int article = strstri(x_str, " of a room") ? 2
  128.                            : !(alt_i <= 2
  129.                                || strcmp(x_str, "air") == 0
  130.                                || strcmp(x_str, "water") == 0);
  131.  
  132.              if (!found) {
  133.                  if (is_cmap_trap(i)) {
  134.                      Sprintf(out_str, "%sa trap", prefix);
  135.                      hit_trap = TRUE;
  136.                  } else {
  137.                      Sprintf(out_str, "%s%s", prefix,
  138.                              article == 2 ? the(x_str)
  139.                              : article == 1 ? an(x_str) : x_str);
  140.                  }
  141.                  *firstmatch = x_str;
  142.                  found++;
  143.              } else if (!u.uswallow && !(hit_trap && is_cmap_trap(i))
  144.                         && !(found >= 3 && is_cmap_drawbridge(i))
  145.                         /* don't mention vibrating square outside of Gehennom
  146.                            unless this happens to be one (hallucination?) */
  147.                         && (i != S_vibrating_square || Inhell
  148.                             || (looked && glyph_is_trap(glyph)
  149.                                 && glyph_to_trap(glyph) == VIBRATING_SQUARE))) {
  150.                  found += append_str(out_str, (article == 2) ? the(x_str)
  151.                                               : (article == 1) ? an(x_str)
  152.                                                 : x_str);
  153.                  if (is_cmap_trap(i))
  154.                      hit_trap = TRUE;
  155.              }
  156.  
  157.              if (i == S_altar || is_cmap_trap(i))
  158.                  need_to_look = TRUE;
  159.          }
  160.      }
  161.  
  162.      /* Now check for warning symbols */
  163.      for (i = 1; i < WARNCOUNT; i++) {
  164.          x_str = def_warnsyms[i].explanation;
  165.          if (sym == (looked ? warnsyms[i] : def_warnsyms[i].sym)) {
  166.              if (!found) {
  167.                  Sprintf(out_str, "%s%s", prefix, def_warnsyms[i].explanation);
  168.                  *firstmatch = def_warnsyms[i].explanation;
  169.                  found++;
  170.              } else {
  171.                  found += append_str(out_str, def_warnsyms[i].explanation);
  172.              }
  173.              /* Kludge: warning trumps boulders on the display.
  174.                 Reveal the boulder too or player can get confused */
  175.              if (looked && sobj_at(BOULDER, cc.x, cc.y))
  176.                  Strcat(out_str, " co-located with a boulder");
  177.              break; /* out of for loop*/
  178.          }
  179.      }
  180.  
  181.      /* if we ignored venom and list turned out to be short, put it back */
  182.      if (skipped_venom && found < 2) {
  183.          x_str = def_oc_syms[VENOM_CLASS].explain;
  184.          if (!found) {
  185.              Sprintf(out_str, "%s%s", prefix, an(x_str));
  186.              *firstmatch = x_str;
  187.              found++;
  188.          } else {
  189.              found += append_str(out_str, an(x_str));
  190.          }
  191.      }
  192.  
  193.      /* handle optional boulder symbol as a special case */
  194.      if (iflags.bouldersym && sym == iflags.bouldersym) {
  195.          if (!found) {
  196.              *firstmatch = "boulder";
  197.              Sprintf(out_str, "%s%s", prefix, an(*firstmatch));
  198.              found++;
  199.          } else {
  200.              found += append_str(out_str, "boulder");
  201.          }
  202.      }
  203.  
  204.      /*
  205.       * If we are looking at the screen, follow multiple possibilities or
  206.       * an ambiguous explanation by something more detailed.
  207.       */
  208.   didlook:
  209.      if (looked) {
  210.          if (found > 1 || need_to_look) {
  211.              char monbuf[BUFSZ];
  212.              char temp_buf[BUFSZ];
  213.  
  214.              (void) lookat(cc.x, cc.y, look_buf, monbuf);
  215.              *firstmatch = look_buf;
  216.              if (*(*firstmatch)) {
  217.                  Sprintf(temp_buf, " (%s)", *firstmatch);
  218.                  (void) strncat(out_str, temp_buf,
  219.                                 BUFSZ - strlen(out_str) - 1);
  220.                  found = 1; /* we have something to look up */
  221.              }
  222.              if (monbuf[0]) {
  223.                  Sprintf(temp_buf, " [seen: %s]", monbuf);
  224.                  (void) strncat(out_str, temp_buf,
  225.                                 BUFSZ - strlen(out_str) - 1);
  226.              }
  227.          }
  228.      }
  229.  
  230.      return found;
  231.  }
  232.  

do_look

  1.  /* getpos() return values */
  2.  #define LOOK_TRADITIONAL 0 /* '.' -- ask about "more info?" */
  3.  #define LOOK_QUICK 1       /* ',' -- skip "more info?" */
  4.  #define LOOK_ONCE 2        /* ';' -- skip and stop looping */
  5.  #define LOOK_VERBOSE 3     /* ':' -- show more info w/o asking */
  6.  
  7.  /* also used by getpos hack in do_name.c */
  8.  const char what_is_an_unknown_object[] = "an unknown object";
  9.  
  10.  int
  11.  do_look(mode, click_cc)
  12.  int mode;
  13.  coord *click_cc;
  14.  {
  15.      boolean quick = (mode == 1); /* use cursor; don't search for "more info" */
  16.      boolean clicklook = (mode == 2); /* right mouse-click method */
  17.      char out_str[BUFSZ];
  18.      const char *firstmatch = 0;
  19.      struct permonst *pm = 0;
  20.      int i = '\0', ans = 0;
  21.      int sym;              /* typed symbol or converted glyph */
  22.      int found;            /* count of matching syms found */
  23.      coord cc;             /* screen pos of unknown glyph */
  24.      boolean save_verbose; /* saved value of flags.verbose */
  25.      boolean from_screen;  /* question from the screen */
  26.  
  27.      if (!clicklook) {
  28.          if (quick) {
  29.              from_screen = TRUE; /* yes, we want to use the cursor */
  30.              i = 'y';
  31.          }
  32.  
  33.          if (i != 'y') {
  34.              menu_item *pick_list = (menu_item *) 0;
  35.              winid win;
  36.              anything any;
  37.  
  38.              any = zeroany;
  39.              win = create_nhwindow(NHW_MENU);
  40.              start_menu(win);
  41.              any.a_char = '/';
  42.              /* 'y' and 'n' to keep backwards compatibility with previous
  43.                 versions: "Specify unknown object by cursor?" */
  44.              add_menu(win, NO_GLYPH, &any,
  45.                       flags.lootabc ? 0 : any.a_char, 'y', ATR_NONE,
  46.                       "something on the map", MENU_UNSELECTED);
  47.              any.a_char = 'i';
  48.              add_menu(win, NO_GLYPH, &any,
  49.                       flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
  50.                       "something you're carrying", MENU_UNSELECTED);
  51.              any.a_char = '?';
  52.              add_menu(win, NO_GLYPH, &any,
  53.                       flags.lootabc ? 0 : any.a_char, 'n', ATR_NONE,
  54.                       "something else (by symbol or name)", MENU_UNSELECTED);
  55.              if (!u.uswallow && !Hallucination) {
  56.                  any = zeroany;
  57.                  add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE,
  58.                           "", MENU_UNSELECTED);
  59.                  /* these options work sensibly for the swallowed case,
  60.                     but there's no reason for the player to use them then;
  61.                     objects work fine when hallucinating, but screen
  62.                     symbol/monster class letter doesn't match up with
  63.                     bogus monster type, so suppress when hallucinating */
  64.                  any.a_char = 'm';
  65.                  add_menu(win, NO_GLYPH, &any,
  66.                           flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
  67.                           "nearby monsters", MENU_UNSELECTED);
  68.                  any.a_char = 'M';
  69.                  add_menu(win, NO_GLYPH, &any,
  70.                           flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
  71.                           "all monsters shown on map", MENU_UNSELECTED);
  72.                  any.a_char = 'o';
  73.                  add_menu(win, NO_GLYPH, &any,
  74.                           flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
  75.                           "nearby objects", MENU_UNSELECTED);
  76.                  any.a_char = 'O';
  77.                  add_menu(win, NO_GLYPH, &any,
  78.                           flags.lootabc ? 0 : any.a_char, 0, ATR_NONE,
  79.                           "all objects shown on map", MENU_UNSELECTED);
  80.              }
  81.              end_menu(win, "What do you want to look at:");
  82.              if (select_menu(win, PICK_ONE, &pick_list) > 0) {
  83.                  i = pick_list->item.a_char;
  84.                  free((genericptr_t) pick_list);
  85.              }
  86.              destroy_nhwindow(win);
  87.          }
  88.  
  89.          switch (i) {
  90.          default:
  91.          case 'q':
  92.              return 0;
  93.          case 'y':
  94.          case '/':
  95.              from_screen = TRUE;
  96.              sym = 0;
  97.              cc.x = u.ux;
  98.              cc.y = u.uy;
  99.              break;
  100.          case 'i':
  101.            {
  102.              char invlet;
  103.              struct obj *invobj;
  104.  
  105.              invlet = display_inventory((const char *) 0, TRUE);
  106.              if (!invlet || invlet == '\033')
  107.                  return 0;
  108.              *out_str = '\0';
  109.              for (invobj = invent; invobj; invobj = invobj->nobj)
  110.                  if (invobj->invlet == invlet) {
  111.                      strcpy(out_str, singular(invobj, xname));
  112.                      break;
  113.                  }
  114.              if (*out_str)
  115.                  checkfile(out_str, pm, TRUE, TRUE);
  116.              return 0;
  117.            }
  118.          case '?':
  119.              from_screen = FALSE;
  120.              getlin("Specify what? (type the word)", out_str);
  121.              if (out_str[0] == '\0' || out_str[0] == '\033')
  122.                  return 0;
  123.  
  124.              if (out_str[1]) { /* user typed in a complete string */
  125.                  checkfile(out_str, pm, TRUE, TRUE);
  126.                  return 0;
  127.              }
  128.              sym = out_str[0];
  129.              break;
  130.          case 'm':
  131.              look_all(TRUE, TRUE); /* list nearby monsters */
  132.              return 0;
  133.          case 'M':
  134.              look_all(FALSE, TRUE); /* list all monsters */
  135.              return 0;
  136.          case 'o':
  137.              look_all(TRUE, FALSE); /* list nearby objects */
  138.              return 0;
  139.          case 'O':
  140.              look_all(FALSE, FALSE); /* list all objects */
  141.              return 0;
  142.          }
  143.      } else { /* clicklook */
  144.          cc.x = click_cc->x;
  145.          cc.y = click_cc->y;
  146.          sym = 0;
  147.          from_screen = FALSE;
  148.      }
  149.  
  150.      /* Save the verbose flag, we change it later. */
  151.      save_verbose = flags.verbose;
  152.      flags.verbose = flags.verbose && !quick;
  153.      /*
  154.       * The user typed one letter, or we're identifying from the screen.
  155.       */
  156.      do {
  157.          /* Reset some variables. */
  158.          pm = (struct permonst *) 0;
  159.          found = 0;
  160.          out_str[0] = '\0';
  161.  
  162.          if (from_screen || clicklook) {
  163.              if (from_screen) {
  164.                  if (flags.verbose)
  165.                      pline("Please move the cursor to %s.",
  166.                            what_is_an_unknown_object);
  167.                  else
  168.                      pline("Pick an object.");
  169.  
  170.                  ans = getpos(&cc, quick, what_is_an_unknown_object);
  171.                  if (ans < 0 || cc.x < 0) {
  172.                      flags.verbose = save_verbose;
  173.                      return 0; /* done */
  174.                  }
  175.                  flags.verbose = FALSE; /* only print long question once */
  176.              }
  177.          }
  178.  
  179.          found = do_screen_description(cc, (from_screen || clicklook), sym,
  180.                                        out_str, &firstmatch);
  181.  
  182.          /* Finally, print out our explanation. */
  183.          if (found) {
  184.              /* Used putmixed() because there may be an encoded glyph present
  185.               */
  186.              putmixed(WIN_MESSAGE, 0, out_str);
  187.  
  188.              /* check the data file for information about this thing */
  189.              if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE
  190.                  && (ans == LOOK_VERBOSE || (flags.help && !quick))
  191.                  && !clicklook) {
  192.                  char temp_buf[BUFSZ];
  193.  
  194.                  Strcpy(temp_buf, firstmatch);
  195.                  checkfile(temp_buf, pm, FALSE,
  196.                            (boolean) (ans == LOOK_VERBOSE));
  197.              }
  198.          } else {
  199.              pline("I've never heard of such things.");
  200.          }
  201.  
  202.      } while (from_screen && !quick && ans != LOOK_ONCE && !clicklook);
  203.  
  204.      flags.verbose = save_verbose;
  205.      return 0;
  206.  }
  207.  

look_all

  1.  STATIC_OVL void
  2.  look_all(nearby, do_mons)
  3.  boolean nearby; /* True => within BOLTLIM, False => entire map */
  4.  boolean do_mons; /* True => monsters, False => objects */
  5.  {
  6.      winid win;
  7.      int x, y, lo_x, lo_y, hi_x, hi_y, glyph, count = 0;
  8.      char buf[BUFSZ], outbuf[BUFSZ], coordbuf[12], fmt[12]; /* "%02d,%02d" */
  9.  
  10.      /* row,column orientation rather than cartesian x,y */
  11.      Sprintf(fmt, "%%%sd,%%%sd",
  12.              (ROWNO <= 100) ? "02" : (ROWNO <= 1000) ? "03" : "",
  13.              (COLNO <= 100) ? "02" : (COLNO <= 1000) ? "03" : "");
  14.  
  15.      win = create_nhwindow(NHW_TEXT);
  16.      lo_y = nearby ? max(u.uy - BOLT_LIM, 0) : 0;
  17.      lo_x = nearby ? max(u.ux - BOLT_LIM, 1) : 1;
  18.      hi_y = nearby ? min(u.uy + BOLT_LIM, ROWNO - 1) : ROWNO - 1;
  19.      hi_x = nearby ? min(u.ux + BOLT_LIM, COLNO - 1) : COLNO - 1;
  20.      for (y = lo_y; y <= hi_y; y++) {
  21.          for (x = lo_x; x <= hi_x; x++) {
  22.              buf[0] = '\0';
  23.              glyph = glyph_at(x, y);
  24.              if (do_mons) {
  25.                  if (glyph_is_monster(glyph)) {
  26.                      struct monst *mtmp;
  27.  
  28.                      bhitpos.x = x; /* [is this actually necessary?] */
  29.                      bhitpos.y = y;
  30.                      if (x == u.ux && y == u.uy && canspotself()) {
  31.                          (void) self_lookat(buf);
  32.                          ++count;
  33.                      } else if ((mtmp = m_at(x, y)) != 0) {
  34.                          look_at_monster(buf, (char *) 0, mtmp, x, y);
  35.                          ++count;
  36.                      }
  37.                  } else if (glyph_is_invisible(glyph)) {
  38.                      /* remembered, unseen, creature */
  39.                      Strcpy(buf, invisexplain);
  40.                      ++count;
  41.                  } else if (glyph_is_warning(glyph)) {
  42.                      int warnindx = glyph_to_warning(glyph);
  43.  
  44.                      Strcpy(buf, def_warnsyms[warnindx].explanation);
  45.                      ++count;
  46.                  }
  47.              } else { /* !do_mons */
  48.                  if (glyph_is_object(glyph)) {
  49.                      look_at_object(buf, x, y, glyph);
  50.                      ++count;
  51.                  }
  52.              }
  53.              if (*buf) {
  54.                  if (count == 1) {
  55.                      char which[12];
  56.  
  57.                      Strcpy(which, do_mons ? "monsters" : "objects");
  58.                      if (nearby) {
  59.                          Sprintf(coordbuf, fmt, u.uy, u.ux);
  60.                          Sprintf(outbuf, "%s currently shown near %s:",
  61.                                  upstart(which), coordbuf);
  62.                      } else
  63.                          Sprintf(outbuf, "All %s currently shown on the map:",
  64.                                  which);
  65.                      putstr(win, 0, outbuf);
  66.                      putstr(win, 0, "");
  67.                  }
  68.                  Sprintf(coordbuf, fmt, y, x);
  69.                  /* prefix: "C  row,column  " */
  70.                  Sprintf(outbuf, "%s  %s  ", encglyph(glyph), coordbuf);
  71.                  /* guard against potential overflow */
  72.                  buf[sizeof buf - 1 - strlen(outbuf)] = '\0';
  73.                  Strcat(outbuf, buf);
  74.                  putmixed(win, 0, outbuf);
  75.              }
  76.          }
  77.      }
  78.      if (count)
  79.          display_nhwindow(win, TRUE);
  80.      else
  81.          pline("No %s are currently shown %s.",
  82.                do_mons ? "monsters" : "objects",
  83.                nearby ? "nearby" : "on the map");
  84.      destroy_nhwindow(win);
  85.  }
  86.  

dowhatis

  1.  /* the '/' command */
  2.  int
  3.  dowhatis()
  4.  {
  5.      return do_look(0, (coord *) 0);
  6.  }
  7.  

doquickwhatis

  1.  /* the ';' command */
  2.  int
  3.  doquickwhatis()
  4.  {
  5.      return do_look(1, (coord *) 0);
  6.  }
  7.  

doidtrap

  1.  /* the '^' command */
  2.  int
  3.  doidtrap()
  4.  {
  5.      register struct trap *trap;
  6.      int x, y, tt;
  7.  
  8.      if (!getdir("^"))
  9.          return 0;
  10.      x = u.ux + u.dx;
  11.      y = u.uy + u.dy;
  12.      for (trap = ftrap; trap; trap = trap->ntrap)
  13.          if (trap->tx == x && trap->ty == y) {
  14.              if (!trap->tseen)
  15.                  break;
  16.              tt = trap->ttyp;
  17.              if (u.dz) {
  18.                  if (u.dz < 0 ? (tt == TRAPDOOR || tt == HOLE)
  19.                               : tt == ROCKTRAP)
  20.                      break;
  21.              }
  22.              tt = what_trap(tt);
  23.              pline("That is %s%s%s.",
  24.                    an(defsyms[trap_to_defsym(tt)].explanation),
  25.                    !trap->madeby_u
  26.                       ? ""
  27.                       : (tt == WEB)
  28.                          ? " woven"
  29.                          /* trap doors & spiked pits can't be made by
  30.                             player, and should be considered at least
  31.                             as much "set" as "dug" anyway */
  32.                          : (tt == HOLE || tt == PIT)
  33.                             ? " dug"
  34.                             : " set",
  35.                    !trap->madeby_u ? "" : " by you");
  36.              return 0;
  37.          }
  38.      pline("I can't see a trap there.");
  39.      return 0;
  40.  }
  41.  

dowhatdoes_core

  1.  char *
  2.  dowhatdoes_core(q, cbuf)
  3.  char q;
  4.  char *cbuf;
  5.  {
  6.      dlb *fp;
  7.      char bufr[BUFSZ];
  8.      register char *buf = &bufr[6], *ep, ctrl, meta;
  9.  
  10.      fp = dlb_fopen(CMDHELPFILE, "r");
  11.      if (!fp) {
  12.          pline("Cannot open data file!");
  13.          return 0;
  14.      }
  15.  
  16.      ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0);
  17.      meta = ((0x80 & q) ? (0x7f & q) : 0);
  18.      while (dlb_fgets(buf, BUFSZ - 6, fp)) {
  19.          if ((ctrl && *buf == '^' && *(buf + 1) == ctrl)
  20.              || (meta && *buf == 'M' && *(buf + 1) == '-'
  21.                  && *(buf + 2) == meta) || *buf == q) {
  22.              ep = index(buf, '\n');
  23.              if (ep)
  24.                  *ep = 0;
  25.              if (ctrl && buf[2] == '\t') {
  26.                  buf = bufr + 1;
  27.                  (void) strncpy(buf, "^?      ", 8);
  28.                  buf[1] = ctrl;
  29.              } else if (meta && buf[3] == '\t') {
  30.                  buf = bufr + 2;
  31.                  (void) strncpy(buf, "M-?     ", 8);
  32.                  buf[2] = meta;
  33.              } else if (buf[1] == '\t') {
  34.                  buf = bufr;
  35.                  buf[0] = q;
  36.                  (void) strncpy(buf + 1, "       ", 7);
  37.              }
  38.              (void) dlb_fclose(fp);
  39.              Strcpy(cbuf, buf);
  40.              return cbuf;
  41.          }
  42.      }
  43.      (void) dlb_fclose(fp);
  44.      return (char *) 0;
  45.  }
  46.  

dowhatdoes

  1.  int
  2.  dowhatdoes()
  3.  {
  4.      char bufr[BUFSZ];
  5.      char q, *reslt;
  6.  
  7.  #if defined(UNIX) || defined(VMS)
  8.      introff();
  9.  #endif
  10.      q = yn_function("What command?", (char *) 0, '\0');
  11.  #if defined(UNIX) || defined(VMS)
  12.      intron();
  13.  #endif
  14.      reslt = dowhatdoes_core(q, bufr);
  15.      if (reslt)
  16.          pline1(reslt);
  17.      else
  18.          pline("I've never heard of such commands.");
  19.      return 0;
  20.  }
  21.  

docontact

  1.  void
  2.  docontact()
  3.  {
  4.      winid cwin = create_nhwindow(NHW_TEXT);
  5.      char buf[BUFSZ];
  6.  
  7.      if (sysopt.support) {
  8.          /*XXX overflow possibilities*/
  9.          Sprintf(buf, "To contact local support, %s", sysopt.support);
  10.          putstr(cwin, 0, buf);
  11.          putstr(cwin, 0, "");
  12.      } else if (sysopt.fmtd_wizard_list) { /* formatted SYSCF WIZARDS */
  13.          Sprintf(buf, "To contact local support, contact %s.",
  14.                  sysopt.fmtd_wizard_list);
  15.          putstr(cwin, 0, buf);
  16.          putstr(cwin, 0, "");
  17.      }
  18.      putstr(cwin, 0, "To contact the NetHack development team directly,");
  19.      /*XXX overflow possibilities*/
  20.      Sprintf(buf, "see the 'Contact' form on our website or email <%s>.",
  21.              DEVTEAM_EMAIL);
  22.      putstr(cwin, 0, buf);
  23.      putstr(cwin, 0, "");
  24.      putstr(cwin, 0, "For more information on NetHack, or to report a bug,");
  25.      Sprintf(buf, "visit our website \"%s\".", DEVTEAM_URL);
  26.      putstr(cwin, 0, buf);
  27.      display_nhwindow(cwin, FALSE);
  28.      destroy_nhwindow(cwin);
  29.  }
  30.  

help_menu

  1.  /* data for help_menu() */
  2.  static const char *help_menu_items[] = {
  3.      /*  0*/ "About NetHack (version information).",
  4.      /*  1*/ "Long description of the game and commands.",
  5.      /*  2*/ "List of game commands.",
  6.      /*  3*/ "Concise history of NetHack.",
  7.      /*  4*/ "Info on a character in the game display.",
  8.      /*  5*/ "Info on what a given key does.",
  9.      /*  6*/ "List of game options.",
  10.      /*  7*/ "Longer explanation of game options.",
  11.      /*  8*/ "List of extended commands.",
  12.      /*  9*/ "The NetHack license.",
  13.      /* 10*/ "Support information.",
  14.  #ifdef PORT_HELP
  15.      "%s-specific help and commands.",
  16.  #define PORT_HELP_ID 100
  17.  #define WIZHLP_SLOT 12
  18.  #else
  19.  #define WIZHLP_SLOT 11
  20.  #endif
  21.      "List of wizard-mode commands.", "", (char *) 0
  22.  };
  23.  
  24.  STATIC_OVL boolean
  25.  help_menu(sel)
  26.  int *sel;
  27.  {
  28.      winid tmpwin = create_nhwindow(NHW_MENU);
  29.  #ifdef PORT_HELP
  30.      char helpbuf[QBUFSZ];
  31.  #endif
  32.      int i, n;
  33.      menu_item *selected;
  34.      anything any;
  35.  
  36.      any = zeroany; /* zero all bits */
  37.      start_menu(tmpwin);
  38.      if (!wizard)
  39.          help_menu_items[WIZHLP_SLOT] = "",
  40.          help_menu_items[WIZHLP_SLOT + 1] = (char *) 0;
  41.      for (i = 0; help_menu_items[i]; i++)
  42.  #ifdef PORT_HELP
  43.          /* port-specific line has a %s in it for the PORT_ID */
  44.          if (help_menu_items[i][0] == '%') {
  45.              Sprintf(helpbuf, help_menu_items[i], PORT_ID);
  46.              any.a_int = PORT_HELP_ID + 1;
  47.              add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, helpbuf,
  48.                       MENU_UNSELECTED);
  49.          } else
  50.  #endif
  51.          {
  52.              any.a_int = (*help_menu_items[i]) ? i + 1 : 0;
  53.              add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  54.                       help_menu_items[i], MENU_UNSELECTED);
  55.          }
  56.      end_menu(tmpwin, "Select one item:");
  57.      n = select_menu(tmpwin, PICK_ONE, &selected);
  58.      destroy_nhwindow(tmpwin);
  59.      if (n > 0) {
  60.          *sel = selected[0].item.a_int - 1;
  61.          free((genericptr_t) selected);
  62.          return TRUE;
  63.      }
  64.      return FALSE;
  65.  }
  66.  

dohelp

  1.  /* the '?' command */
  2.  int
  3.  dohelp()
  4.  {
  5.      int sel = 0;
  6.  
  7.      if (help_menu(&sel)) {
  8.          switch (sel) {
  9.          case 0:
  10.              (void) doextversion();
  11.              break;
  12.          case 1:
  13.              display_file(HELP, TRUE);
  14.              break;
  15.          case 2:
  16.              display_file(SHELP, TRUE);
  17.              break;
  18.          case 3:
  19.              (void) dohistory();
  20.              break;
  21.          case 4:
  22.              (void) dowhatis();
  23.              break;
  24.          case 5:
  25.              (void) dowhatdoes();
  26.              break;
  27.          case 6:
  28.              option_help();
  29.              break;
  30.          case 7:
  31.              display_file(OPTIONFILE, TRUE);
  32.              break;
  33.          case 8:
  34.              (void) doextlist();
  35.              break;
  36.          case 9:
  37.              display_file(LICENSE, TRUE);
  38.              break;
  39.          case 10:
  40.              (void) docontact();
  41.              break;
  42.  #ifdef PORT_HELP
  43.          case PORT_HELP_ID:
  44.              port_help();
  45.              break;
  46.  #endif
  47.          default:
  48.              /* handle slot 11 or 12 */
  49.              display_file(DEBUGHELP, TRUE);
  50.              break;
  51.          }
  52.      }
  53.      return 0;
  54.  }
  55.  

dohistory

  1.  /* the 'V' command; also a choice for '?' */
  2.  int
  3.  dohistory()
  4.  {
  5.      display_file(HISTORY, TRUE);
  6.      return 0;
  7.  }
  8.  
  9.  /*pager.c*/