MCPcopy Index your code
hub / github.com/NetHack/NetHack / checkfile

Function checkfile

src/pager.c:829–1129  ·  view source on GitHub ↗

* Look in the "data" file for more info. Called if the user typed in the * whole name (user_typed_name == TRUE), or we've found a possible match * with a character/glyph and flags.help is TRUE. * * NOTE: when (user_typed_name == FALSE), inp is considered read-only and * must not be changed directly, e.g. via lcase(). We want to force * lcase() for data.base lookup so that we can

Source from the content-addressed store, hash-verified

827 * Returns True if an entry is found, False otherwise.
828 */
829staticfn boolean
830checkfile(
831 char *inp, /* string to look up */
832 struct permonst *pm, /* monster type to look up (overrides 'inp') */
833 unsigned chkflags,
834 char *supplemental_name)
835{
836 dlb *fp;
837 char buf[BUFSZ], newstr[BUFSZ], givenname[BUFSZ];
838 char *ep, *dbase_str;
839 boolean user_typed_name = (chkflags & chkfilUsrTyped) != 0,
840 without_asking = (chkflags & chkfilDontAsk) != 0,
841 ia_checking = (chkflags & chkfilIaCheck) != 0;
842 unsigned long txt_offset = 0L;
843 winid datawin = WIN_ERR;
844 boolean res = FALSE;
845
846 fp = dlb_fopen(DATAFILE, "r");
847 if (!fp) {
848 pline("Cannot open 'data' file!");
849 return res;
850 }
851 /* If someone passed us garbage, prevent fault. */
852 if (!inp || strlen(inp) > (BUFSZ - 1)) {
853 impossible("bad do_look buffer passed (%s)!",
854 !inp ? "null" : "too long");
855 goto checkfile_done;
856 }
857
858 /* To prevent the need for entries in data.base like *ngel to account
859 * for Angel and angel, make the lookup string the same for both
860 * user_typed_name and picked name.
861 */
862 if (pm != (struct permonst *) 0 && !user_typed_name)
863 dbase_str = strcpy(newstr, pm->pmnames[NEUTRAL]);
864 else
865 dbase_str = strcpy(newstr, inp);
866 (void) lcase(dbase_str);
867
868 /*
869 * TODO:
870 * The switch from xname() to doname_vague_quan() in look_at_obj()
871 * had the unintended side-effect of making names picked from
872 * pointing at map objects become harder to simplify for lookup.
873 * We should split the prefix and suffix handling used by wish
874 * parsing and also wizmode monster generation out into separate
875 * routines and use those routines here. This currently lacks
876 * erosion handling and probably lots of other bits and pieces
877 * that wishing already understands and most of this duplicates
878 * stuff already done for wish handling or monster generation.
879 */
880 if (!strncmp(dbase_str, "interior of ", 12))
881 dbase_str += 12;
882 if (!strncmp(dbase_str, "a ", 2))
883 dbase_str += 2;
884 else if (!strncmp(dbase_str, "an ", 3))
885 dbase_str += 3;
886 else if (!strncmp(dbase_str, "the ", 4))

Callers 2

ia_checkfileFunction · 0.85
do_lookFunction · 0.85

Calls 15

dlb_fopenFunction · 0.85
lcaseFunction · 0.85
digitFunction · 0.85
strstriFunction · 0.85
copyncharsFunction · 0.85
fruit_from_nameFunction · 0.85
makesingularFunction · 0.85
dlb_fseekFunction · 0.85
dlb_fgetsFunction · 0.85
strip_newlineFunction · 0.85
pmatchFunction · 0.85
eosFunction · 0.85

Tested by

no test coverage detected