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