Home | History | Annotate | Line # | Download | only in hack
hack.objnam.c revision 1.7
      1  1.7  dholland /*	$NetBSD: hack.objnam.c,v 1.7 2008/01/28 06:55:42 dholland Exp $	*/
      2  1.4  christos 
      3  1.2   mycroft /*
      4  1.6       jsm  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
      5  1.6       jsm  * Amsterdam
      6  1.6       jsm  * All rights reserved.
      7  1.6       jsm  *
      8  1.6       jsm  * Redistribution and use in source and binary forms, with or without
      9  1.6       jsm  * modification, are permitted provided that the following conditions are
     10  1.6       jsm  * met:
     11  1.6       jsm  *
     12  1.6       jsm  * - Redistributions of source code must retain the above copyright notice,
     13  1.6       jsm  * this list of conditions and the following disclaimer.
     14  1.6       jsm  *
     15  1.6       jsm  * - Redistributions in binary form must reproduce the above copyright
     16  1.6       jsm  * notice, this list of conditions and the following disclaimer in the
     17  1.6       jsm  * documentation and/or other materials provided with the distribution.
     18  1.6       jsm  *
     19  1.6       jsm  * - Neither the name of the Stichting Centrum voor Wiskunde en
     20  1.6       jsm  * Informatica, nor the names of its contributors may be used to endorse or
     21  1.6       jsm  * promote products derived from this software without specific prior
     22  1.6       jsm  * written permission.
     23  1.6       jsm  *
     24  1.6       jsm  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     25  1.6       jsm  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.6       jsm  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     27  1.6       jsm  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     28  1.6       jsm  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29  1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30  1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     31  1.6       jsm  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     32  1.6       jsm  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     33  1.6       jsm  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     34  1.6       jsm  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35  1.6       jsm  */
     36  1.6       jsm 
     37  1.6       jsm /*
     38  1.6       jsm  * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
     39  1.6       jsm  * All rights reserved.
     40  1.6       jsm  *
     41  1.6       jsm  * Redistribution and use in source and binary forms, with or without
     42  1.6       jsm  * modification, are permitted provided that the following conditions
     43  1.6       jsm  * are met:
     44  1.6       jsm  * 1. Redistributions of source code must retain the above copyright
     45  1.6       jsm  *    notice, this list of conditions and the following disclaimer.
     46  1.6       jsm  * 2. Redistributions in binary form must reproduce the above copyright
     47  1.6       jsm  *    notice, this list of conditions and the following disclaimer in the
     48  1.6       jsm  *    documentation and/or other materials provided with the distribution.
     49  1.6       jsm  * 3. The name of the author may not be used to endorse or promote products
     50  1.6       jsm  *    derived from this software without specific prior written permission.
     51  1.6       jsm  *
     52  1.6       jsm  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     53  1.6       jsm  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     54  1.6       jsm  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
     55  1.6       jsm  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     56  1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     57  1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     58  1.6       jsm  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     59  1.6       jsm  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     60  1.6       jsm  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     61  1.6       jsm  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62  1.2   mycroft  */
     63  1.2   mycroft 
     64  1.4  christos #include <sys/cdefs.h>
     65  1.2   mycroft #ifndef lint
     66  1.7  dholland __RCSID("$NetBSD: hack.objnam.c,v 1.7 2008/01/28 06:55:42 dholland Exp $");
     67  1.4  christos #endif				/* not lint */
     68  1.1       cgd 
     69  1.4  christos #include <stdlib.h>
     70  1.4  christos #include "hack.h"
     71  1.4  christos #include "extern.h"
     72  1.1       cgd #define Sprintf (void) sprintf
     73  1.1       cgd #define Strcat  (void) strcat
     74  1.1       cgd #define	Strcpy	(void) strcpy
     75  1.1       cgd #define	PREFIX	15
     76  1.1       cgd 
     77  1.4  christos char           *
     78  1.4  christos strprepend(s, pref)
     79  1.4  christos 	char           *s, *pref;
     80  1.4  christos {
     81  1.4  christos 	int             i = strlen(pref);
     82  1.4  christos 	if (i > PREFIX) {
     83  1.1       cgd 		pline("WARNING: prefix too short.");
     84  1.4  christos 		return (s);
     85  1.1       cgd 	}
     86  1.1       cgd 	s -= i;
     87  1.1       cgd 	(void) strncpy(s, pref, i);	/* do not copy trailing 0 */
     88  1.4  christos 	return (s);
     89  1.1       cgd }
     90  1.1       cgd 
     91  1.4  christos char           *
     92  1.4  christos sitoa(a)
     93  1.4  christos 	int             a;
     94  1.4  christos {
     95  1.4  christos 	static char     buf[13];
     96  1.1       cgd 	Sprintf(buf, (a < 0) ? "%d" : "+%d", a);
     97  1.4  christos 	return (buf);
     98  1.1       cgd }
     99  1.1       cgd 
    100  1.4  christos char           *
    101  1.1       cgd typename(otyp)
    102  1.4  christos 	int             otyp;
    103  1.1       cgd {
    104  1.4  christos 	static char     buf[BUFSZ];
    105  1.4  christos 	struct objclass *ocl = &objects[otyp];
    106  1.5       jsm 	const char     *an = ocl->oc_name;
    107  1.5       jsm 	const char     *dn = ocl->oc_descr;
    108  1.4  christos 	char           *un = ocl->oc_uname;
    109  1.4  christos 	int             nn = ocl->oc_name_known;
    110  1.4  christos 	switch (ocl->oc_olet) {
    111  1.1       cgd 	case POTION_SYM:
    112  1.1       cgd 		Strcpy(buf, "potion");
    113  1.1       cgd 		break;
    114  1.1       cgd 	case SCROLL_SYM:
    115  1.1       cgd 		Strcpy(buf, "scroll");
    116  1.1       cgd 		break;
    117  1.1       cgd 	case WAND_SYM:
    118  1.1       cgd 		Strcpy(buf, "wand");
    119  1.1       cgd 		break;
    120  1.1       cgd 	case RING_SYM:
    121  1.1       cgd 		Strcpy(buf, "ring");
    122  1.1       cgd 		break;
    123  1.1       cgd 	default:
    124  1.4  christos 		if (nn) {
    125  1.1       cgd 			Strcpy(buf, an);
    126  1.4  christos 			if (otyp >= TURQUOISE && otyp <= JADE)
    127  1.1       cgd 				Strcat(buf, " stone");
    128  1.4  christos 			if (un)
    129  1.1       cgd 				Sprintf(eos(buf), " called %s", un);
    130  1.4  christos 			if (dn)
    131  1.1       cgd 				Sprintf(eos(buf), " (%s)", dn);
    132  1.1       cgd 		} else {
    133  1.1       cgd 			Strcpy(buf, dn ? dn : an);
    134  1.4  christos 			if (ocl->oc_olet == GEM_SYM)
    135  1.1       cgd 				Strcat(buf, " gem");
    136  1.4  christos 			if (un)
    137  1.1       cgd 				Sprintf(eos(buf), " called %s", un);
    138  1.1       cgd 		}
    139  1.4  christos 		return (buf);
    140  1.1       cgd 	}
    141  1.1       cgd 	/* here for ring/scroll/potion/wand */
    142  1.4  christos 	if (nn)
    143  1.1       cgd 		Sprintf(eos(buf), " of %s", an);
    144  1.4  christos 	if (un)
    145  1.1       cgd 		Sprintf(eos(buf), " called %s", un);
    146  1.4  christos 	if (dn)
    147  1.1       cgd 		Sprintf(eos(buf), " (%s)", dn);
    148  1.4  christos 	return (buf);
    149  1.1       cgd }
    150  1.1       cgd 
    151  1.4  christos char           *
    152  1.1       cgd xname(obj)
    153  1.4  christos 	struct obj     *obj;
    154  1.1       cgd {
    155  1.4  christos 	static char     bufr[BUFSZ];
    156  1.4  christos 	char           *buf = &(bufr[PREFIX]);	/* leave room for "17 -3 " */
    157  1.4  christos 	int             nn = objects[obj->otyp].oc_name_known;
    158  1.5       jsm 	const char     *an = objects[obj->otyp].oc_name;
    159  1.5       jsm 	const char     *dn = objects[obj->otyp].oc_descr;
    160  1.4  christos 	char           *un = objects[obj->otyp].oc_uname;
    161  1.4  christos 	int             pl = (obj->quan != 1);
    162  1.4  christos 	if (!obj->dknown && !Blind)
    163  1.4  christos 		obj->dknown = 1;/* %% doesnt belong here */
    164  1.4  christos 	switch (obj->olet) {
    165  1.1       cgd 	case AMULET_SYM:
    166  1.1       cgd 		Strcpy(buf, (obj->spe < 0 && obj->known)
    167  1.4  christos 		       ? "cheap plastic imitation of the " : "");
    168  1.4  christos 		Strcat(buf, "Amulet of Yendor");
    169  1.1       cgd 		break;
    170  1.1       cgd 	case TOOL_SYM:
    171  1.4  christos 		if (!nn) {
    172  1.1       cgd 			Strcpy(buf, dn);
    173  1.1       cgd 			break;
    174  1.1       cgd 		}
    175  1.4  christos 		Strcpy(buf, an);
    176  1.1       cgd 		break;
    177  1.1       cgd 	case FOOD_SYM:
    178  1.4  christos 		if (obj->otyp == DEAD_HOMUNCULUS && pl) {
    179  1.1       cgd 			pl = 0;
    180  1.1       cgd 			Strcpy(buf, "dead homunculi");
    181  1.1       cgd 			break;
    182  1.1       cgd 		}
    183  1.1       cgd 		/* fungis ? */
    184  1.1       cgd 		/* fall into next case */
    185  1.1       cgd 	case WEAPON_SYM:
    186  1.4  christos 		if (obj->otyp == WORM_TOOTH && pl) {
    187  1.1       cgd 			pl = 0;
    188  1.1       cgd 			Strcpy(buf, "worm teeth");
    189  1.1       cgd 			break;
    190  1.1       cgd 		}
    191  1.4  christos 		if (obj->otyp == CRYSKNIFE && pl) {
    192  1.1       cgd 			pl = 0;
    193  1.1       cgd 			Strcpy(buf, "crysknives");
    194  1.1       cgd 			break;
    195  1.1       cgd 		}
    196  1.1       cgd 		/* fall into next case */
    197  1.1       cgd 	case ARMOR_SYM:
    198  1.1       cgd 	case CHAIN_SYM:
    199  1.1       cgd 	case ROCK_SYM:
    200  1.4  christos 		Strcpy(buf, an);
    201  1.1       cgd 		break;
    202  1.1       cgd 	case BALL_SYM:
    203  1.1       cgd 		Sprintf(buf, "%sheavy iron ball",
    204  1.1       cgd 		  (obj->owt > objects[obj->otyp].oc_weight) ? "very " : "");
    205  1.1       cgd 		break;
    206  1.1       cgd 	case POTION_SYM:
    207  1.4  christos 		if (nn || un || !obj->dknown) {
    208  1.1       cgd 			Strcpy(buf, "potion");
    209  1.4  christos 			if (pl) {
    210  1.1       cgd 				pl = 0;
    211  1.1       cgd 				Strcat(buf, "s");
    212  1.1       cgd 			}
    213  1.4  christos 			if (!obj->dknown)
    214  1.4  christos 				break;
    215  1.4  christos 			if (un) {
    216  1.1       cgd 				Strcat(buf, " called ");
    217  1.1       cgd 				Strcat(buf, un);
    218  1.1       cgd 			} else {
    219  1.1       cgd 				Strcat(buf, " of ");
    220  1.1       cgd 				Strcat(buf, an);
    221  1.1       cgd 			}
    222  1.1       cgd 		} else {
    223  1.1       cgd 			Strcpy(buf, dn);
    224  1.1       cgd 			Strcat(buf, " potion");
    225  1.1       cgd 		}
    226  1.1       cgd 		break;
    227  1.1       cgd 	case SCROLL_SYM:
    228  1.1       cgd 		Strcpy(buf, "scroll");
    229  1.4  christos 		if (pl) {
    230  1.1       cgd 			pl = 0;
    231  1.1       cgd 			Strcat(buf, "s");
    232  1.1       cgd 		}
    233  1.4  christos 		if (!obj->dknown)
    234  1.4  christos 			break;
    235  1.4  christos 		if (nn) {
    236  1.1       cgd 			Strcat(buf, " of ");
    237  1.1       cgd 			Strcat(buf, an);
    238  1.4  christos 		} else if (un) {
    239  1.1       cgd 			Strcat(buf, " called ");
    240  1.1       cgd 			Strcat(buf, un);
    241  1.1       cgd 		} else {
    242  1.1       cgd 			Strcat(buf, " labeled ");
    243  1.1       cgd 			Strcat(buf, dn);
    244  1.1       cgd 		}
    245  1.1       cgd 		break;
    246  1.1       cgd 	case WAND_SYM:
    247  1.4  christos 		if (!obj->dknown)
    248  1.1       cgd 			Sprintf(buf, "wand");
    249  1.4  christos 		else if (nn)
    250  1.1       cgd 			Sprintf(buf, "wand of %s", an);
    251  1.4  christos 		else if (un)
    252  1.1       cgd 			Sprintf(buf, "wand called %s", un);
    253  1.1       cgd 		else
    254  1.1       cgd 			Sprintf(buf, "%s wand", dn);
    255  1.1       cgd 		break;
    256  1.1       cgd 	case RING_SYM:
    257  1.4  christos 		if (!obj->dknown)
    258  1.1       cgd 			Sprintf(buf, "ring");
    259  1.4  christos 		else if (nn)
    260  1.1       cgd 			Sprintf(buf, "ring of %s", an);
    261  1.4  christos 		else if (un)
    262  1.1       cgd 			Sprintf(buf, "ring called %s", un);
    263  1.1       cgd 		else
    264  1.1       cgd 			Sprintf(buf, "%s ring", dn);
    265  1.1       cgd 		break;
    266  1.1       cgd 	case GEM_SYM:
    267  1.4  christos 		if (!obj->dknown) {
    268  1.1       cgd 			Strcpy(buf, "gem");
    269  1.1       cgd 			break;
    270  1.1       cgd 		}
    271  1.4  christos 		if (!nn) {
    272  1.1       cgd 			Sprintf(buf, "%s gem", dn);
    273  1.1       cgd 			break;
    274  1.1       cgd 		}
    275  1.1       cgd 		Strcpy(buf, an);
    276  1.4  christos 		if (obj->otyp >= TURQUOISE && obj->otyp <= JADE)
    277  1.1       cgd 			Strcat(buf, " stone");
    278  1.1       cgd 		break;
    279  1.1       cgd 	default:
    280  1.4  christos 		Sprintf(buf, "glorkum %c (0%o) %u %d",
    281  1.4  christos 			obj->olet, obj->olet, obj->otyp, obj->spe);
    282  1.1       cgd 	}
    283  1.4  christos 	if (pl) {
    284  1.4  christos 		char           *p;
    285  1.1       cgd 
    286  1.4  christos 		for (p = buf; *p; p++) {
    287  1.4  christos 			if (!strncmp(" of ", p, 4)) {
    288  1.1       cgd 				/* pieces of, cloves of, lumps of */
    289  1.4  christos 				int             c1, c2 = 's';
    290  1.1       cgd 
    291  1.1       cgd 				do {
    292  1.4  christos 					c1 = c2;
    293  1.4  christos 					c2 = *p;
    294  1.4  christos 					*p++ = c1;
    295  1.4  christos 				} while (c1);
    296  1.1       cgd 				goto nopl;
    297  1.1       cgd 			}
    298  1.1       cgd 		}
    299  1.4  christos 		p = eos(buf) - 1;
    300  1.4  christos 		if (*p == 's' || *p == 'z' || *p == 'x' ||
    301  1.1       cgd 		    (*p == 'h' && p[-1] == 's'))
    302  1.1       cgd 			Strcat(buf, "es");	/* boxes */
    303  1.4  christos 		else if (*p == 'y' && !strchr(vowels, p[-1]))
    304  1.1       cgd 			Strcpy(p, "ies");	/* rubies, zruties */
    305  1.1       cgd 		else
    306  1.1       cgd 			Strcat(buf, "s");
    307  1.1       cgd 	}
    308  1.1       cgd nopl:
    309  1.4  christos 	if (obj->onamelth) {
    310  1.1       cgd 		Strcat(buf, " named ");
    311  1.1       cgd 		Strcat(buf, ONAME(obj));
    312  1.1       cgd 	}
    313  1.4  christos 	return (buf);
    314  1.1       cgd }
    315  1.1       cgd 
    316  1.4  christos char           *
    317  1.1       cgd doname(obj)
    318  1.4  christos 	struct obj     *obj;
    319  1.1       cgd {
    320  1.4  christos 	char            prefix[PREFIX];
    321  1.4  christos 	char           *bp = xname(obj);
    322  1.4  christos 	if (obj->quan != 1)
    323  1.1       cgd 		Sprintf(prefix, "%u ", obj->quan);
    324  1.1       cgd 	else
    325  1.1       cgd 		Strcpy(prefix, "a ");
    326  1.4  christos 	switch (obj->olet) {
    327  1.1       cgd 	case AMULET_SYM:
    328  1.4  christos 		if (strncmp(bp, "cheap ", 6))
    329  1.1       cgd 			Strcpy(prefix, "the ");
    330  1.1       cgd 		break;
    331  1.1       cgd 	case ARMOR_SYM:
    332  1.4  christos 		if (obj->owornmask & W_ARMOR)
    333  1.1       cgd 			Strcat(bp, " (being worn)");
    334  1.1       cgd 		/* fall into next case */
    335  1.1       cgd 	case WEAPON_SYM:
    336  1.4  christos 		if (obj->known) {
    337  1.1       cgd 			Strcat(prefix, sitoa(obj->spe));
    338  1.1       cgd 			Strcat(prefix, " ");
    339  1.1       cgd 		}
    340  1.1       cgd 		break;
    341  1.1       cgd 	case WAND_SYM:
    342  1.4  christos 		if (obj->known)
    343  1.1       cgd 			Sprintf(eos(bp), " (%d)", obj->spe);
    344  1.1       cgd 		break;
    345  1.1       cgd 	case RING_SYM:
    346  1.4  christos 		if (obj->owornmask & W_RINGR)
    347  1.4  christos 			Strcat(bp, " (on right hand)");
    348  1.4  christos 		if (obj->owornmask & W_RINGL)
    349  1.4  christos 			Strcat(bp, " (on left hand)");
    350  1.4  christos 		if (obj->known && (objects[obj->otyp].bits & SPEC)) {
    351  1.1       cgd 			Strcat(prefix, sitoa(obj->spe));
    352  1.1       cgd 			Strcat(prefix, " ");
    353  1.1       cgd 		}
    354  1.1       cgd 		break;
    355  1.1       cgd 	}
    356  1.4  christos 	if (obj->owornmask & W_WEP)
    357  1.1       cgd 		Strcat(bp, " (weapon in hand)");
    358  1.4  christos 	if (obj->unpaid)
    359  1.1       cgd 		Strcat(bp, " (unpaid)");
    360  1.4  christos 	if (!strcmp(prefix, "a ") && strchr(vowels, *bp))
    361  1.1       cgd 		Strcpy(prefix, "an ");
    362  1.1       cgd 	bp = strprepend(bp, prefix);
    363  1.4  christos 	return (bp);
    364  1.1       cgd }
    365  1.1       cgd 
    366  1.1       cgd /* used only in hack.fight.c (thitu) */
    367  1.4  christos void
    368  1.5       jsm setan(const char *str, char *buf)
    369  1.1       cgd {
    370  1.4  christos 	if (strchr(vowels, *str))
    371  1.1       cgd 		Sprintf(buf, "an %s", str);
    372  1.1       cgd 	else
    373  1.1       cgd 		Sprintf(buf, "a %s", str);
    374  1.1       cgd }
    375  1.1       cgd 
    376  1.4  christos char           *
    377  1.4  christos aobjnam(otmp, verb)
    378  1.4  christos 	struct obj     *otmp;
    379  1.5       jsm 	const char           *verb;
    380  1.4  christos {
    381  1.4  christos 	char           *bp = xname(otmp);
    382  1.4  christos 	char            prefix[PREFIX];
    383  1.4  christos 	if (otmp->quan != 1) {
    384  1.1       cgd 		Sprintf(prefix, "%u ", otmp->quan);
    385  1.1       cgd 		bp = strprepend(bp, prefix);
    386  1.1       cgd 	}
    387  1.4  christos 	if (verb) {
    388  1.1       cgd 		/* verb is given in plural (i.e., without trailing s) */
    389  1.1       cgd 		Strcat(bp, " ");
    390  1.4  christos 		if (otmp->quan != 1)
    391  1.1       cgd 			Strcat(bp, verb);
    392  1.4  christos 		else if (!strcmp(verb, "are"))
    393  1.1       cgd 			Strcat(bp, "is");
    394  1.1       cgd 		else {
    395  1.1       cgd 			Strcat(bp, verb);
    396  1.1       cgd 			Strcat(bp, "s");
    397  1.1       cgd 		}
    398  1.1       cgd 	}
    399  1.4  christos 	return (bp);
    400  1.1       cgd }
    401  1.1       cgd 
    402  1.4  christos char           *
    403  1.1       cgd Doname(obj)
    404  1.4  christos 	struct obj     *obj;
    405  1.1       cgd {
    406  1.4  christos 	char           *s = doname(obj);
    407  1.1       cgd 
    408  1.4  christos 	if ('a' <= *s && *s <= 'z')
    409  1.4  christos 		*s -= ('a' - 'A');
    410  1.4  christos 	return (s);
    411  1.1       cgd }
    412  1.1       cgd 
    413  1.5       jsm const char *const wrp[] = {"wand", "ring", "potion", "scroll", "gem"};
    414  1.5       jsm const char wrpsym[] = {WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM};
    415  1.1       cgd 
    416  1.4  christos struct obj     *
    417  1.4  christos readobjnam(bp)
    418  1.4  christos 	char           *bp;
    419  1.4  christos {
    420  1.4  christos 	char           *p;
    421  1.7  dholland 	unsigned        ii;
    422  1.7  dholland 	int		i;
    423  1.4  christos 	int             cnt, spe, spesgn, typ, heavy;
    424  1.4  christos 	char            let;
    425  1.4  christos 	char           *un, *dn, *an;
    426  1.4  christos 	/* int the = 0; char *oname = 0; */
    427  1.1       cgd 	cnt = spe = spesgn = typ = heavy = 0;
    428  1.1       cgd 	let = 0;
    429  1.1       cgd 	an = dn = un = 0;
    430  1.4  christos 	for (p = bp; *p; p++)
    431  1.4  christos 		if ('A' <= *p && *p <= 'Z')
    432  1.4  christos 			*p += 'a' - 'A';
    433  1.4  christos 	if (!strncmp(bp, "the ", 4)) {
    434  1.4  christos 		/* the = 1; */
    435  1.1       cgd 		bp += 4;
    436  1.4  christos 	} else if (!strncmp(bp, "an ", 3)) {
    437  1.1       cgd 		cnt = 1;
    438  1.1       cgd 		bp += 3;
    439  1.4  christos 	} else if (!strncmp(bp, "a ", 2)) {
    440  1.1       cgd 		cnt = 1;
    441  1.1       cgd 		bp += 2;
    442  1.1       cgd 	}
    443  1.4  christos 	if (!cnt && digit(*bp)) {
    444  1.1       cgd 		cnt = atoi(bp);
    445  1.4  christos 		while (digit(*bp))
    446  1.4  christos 			bp++;
    447  1.4  christos 		while (*bp == ' ')
    448  1.4  christos 			bp++;
    449  1.1       cgd 	}
    450  1.4  christos 	if (!cnt)
    451  1.4  christos 		cnt = 1;	/* %% what with "gems" etc. ? */
    452  1.1       cgd 
    453  1.4  christos 	if (*bp == '+' || *bp == '-') {
    454  1.1       cgd 		spesgn = (*bp++ == '+') ? 1 : -1;
    455  1.1       cgd 		spe = atoi(bp);
    456  1.4  christos 		while (digit(*bp))
    457  1.4  christos 			bp++;
    458  1.4  christos 		while (*bp == ' ')
    459  1.4  christos 			bp++;
    460  1.1       cgd 	} else {
    461  1.4  christos 		p = strrchr(bp, '(');
    462  1.4  christos 		if (p) {
    463  1.4  christos 			if (p > bp && p[-1] == ' ')
    464  1.4  christos 				p[-1] = 0;
    465  1.4  christos 			else
    466  1.4  christos 				*p = 0;
    467  1.1       cgd 			p++;
    468  1.1       cgd 			spe = atoi(p);
    469  1.4  christos 			while (digit(*p))
    470  1.4  christos 				p++;
    471  1.4  christos 			if (strcmp(p, ")"))
    472  1.4  christos 				spe = 0;
    473  1.4  christos 			else
    474  1.4  christos 				spesgn = 1;
    475  1.4  christos 		}
    476  1.4  christos 	}
    477  1.4  christos 	/*
    478  1.4  christos 	 * now we have the actual name, as delivered by xname, say green
    479  1.4  christos 	 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
    480  1.4  christos 	 * fortune cookies very heavy iron ball named hoei wand of wishing
    481  1.4  christos 	 * elven cloak
    482  1.4  christos 	 */
    483  1.4  christos 	for (p = bp; *p; p++)
    484  1.4  christos 		if (!strncmp(p, " named ", 7)) {
    485  1.4  christos 			*p = 0;
    486  1.4  christos 			/* oname = p+7; */
    487  1.4  christos 		}
    488  1.4  christos 	for (p = bp; *p; p++)
    489  1.4  christos 		if (!strncmp(p, " called ", 8)) {
    490  1.4  christos 			*p = 0;
    491  1.4  christos 			un = p + 8;
    492  1.4  christos 		}
    493  1.4  christos 	for (p = bp; *p; p++)
    494  1.4  christos 		if (!strncmp(p, " labeled ", 9)) {
    495  1.4  christos 			*p = 0;
    496  1.4  christos 			dn = p + 9;
    497  1.4  christos 		}
    498  1.1       cgd 	/* first change to singular if necessary */
    499  1.4  christos 	if (cnt != 1) {
    500  1.1       cgd 		/* find "cloves of garlic", "worthless pieces of blue glass" */
    501  1.4  christos 		for (p = bp; *p; p++)
    502  1.4  christos 			if (!strncmp(p, "s of ", 5)) {
    503  1.4  christos 				while ((*p = p[1]) != '\0')
    504  1.4  christos 					p++;
    505  1.4  christos 				goto sing;
    506  1.4  christos 			}
    507  1.1       cgd 		/* remove -s or -es (boxes) or -ies (rubies, zruties) */
    508  1.1       cgd 		p = eos(bp);
    509  1.4  christos 		if (p[-1] == 's') {
    510  1.4  christos 			if (p[-2] == 'e') {
    511  1.4  christos 				if (p[-3] == 'i') {
    512  1.4  christos 					if (!strcmp(p - 7, "cookies"))
    513  1.1       cgd 						goto mins;
    514  1.4  christos 					Strcpy(p - 3, "y");
    515  1.1       cgd 					goto sing;
    516  1.1       cgd 				}
    517  1.1       cgd 				/* note: cloves / knives from clove / knife */
    518  1.4  christos 				if (!strcmp(p - 6, "knives")) {
    519  1.4  christos 					Strcpy(p - 3, "fe");
    520  1.1       cgd 					goto sing;
    521  1.1       cgd 				}
    522  1.1       cgd 				/* note: nurses, axes but boxes */
    523  1.4  christos 				if (!strcmp(p - 5, "boxes")) {
    524  1.1       cgd 					p[-2] = 0;
    525  1.1       cgd 					goto sing;
    526  1.1       cgd 				}
    527  1.1       cgd 			}
    528  1.4  christos 	mins:
    529  1.1       cgd 			p[-1] = 0;
    530  1.1       cgd 		} else {
    531  1.4  christos 			if (!strcmp(p - 9, "homunculi")) {
    532  1.4  christos 				Strcpy(p - 1, "us");	/* !! makes string
    533  1.4  christos 							 * longer */
    534  1.1       cgd 				goto sing;
    535  1.1       cgd 			}
    536  1.4  christos 			if (!strcmp(p - 5, "teeth")) {
    537  1.4  christos 				Strcpy(p - 5, "tooth");
    538  1.1       cgd 				goto sing;
    539  1.1       cgd 			}
    540  1.1       cgd 			/* here we cannot find the plural suffix */
    541  1.1       cgd 		}
    542  1.1       cgd 	}
    543  1.1       cgd sing:
    544  1.4  christos 	if (!strcmp(bp, "amulet of yendor")) {
    545  1.1       cgd 		typ = AMULET_OF_YENDOR;
    546  1.1       cgd 		goto typfnd;
    547  1.1       cgd 	}
    548  1.1       cgd 	p = eos(bp);
    549  1.4  christos 	if (!strcmp(p - 5, " mail")) {	/* Note: ring mail is not a ring ! */
    550  1.1       cgd 		let = ARMOR_SYM;
    551  1.1       cgd 		an = bp;
    552  1.1       cgd 		goto srch;
    553  1.1       cgd 	}
    554  1.7  dholland 	for (ii = 0; ii < sizeof(wrpsym); ii++) {
    555  1.7  dholland 		int             j = strlen(wrp[ii]);
    556  1.7  dholland 		if (!strncmp(bp, wrp[ii], j)) {
    557  1.7  dholland 			let = wrpsym[ii];
    558  1.1       cgd 			bp += j;
    559  1.4  christos 			if (!strncmp(bp, " of ", 4))
    560  1.4  christos 				an = bp + 4;
    561  1.1       cgd 			/* else if(*bp) ?? */
    562  1.1       cgd 			goto srch;
    563  1.1       cgd 		}
    564  1.7  dholland 		if (!strcmp(p - j, wrp[ii])) {
    565  1.7  dholland 			let = wrpsym[ii];
    566  1.1       cgd 			p -= j;
    567  1.1       cgd 			*p = 0;
    568  1.4  christos 			if (p[-1] == ' ')
    569  1.4  christos 				p[-1] = 0;
    570  1.1       cgd 			dn = bp;
    571  1.1       cgd 			goto srch;
    572  1.1       cgd 		}
    573  1.1       cgd 	}
    574  1.4  christos 	if (!strcmp(p - 6, " stone")) {
    575  1.1       cgd 		p[-6] = 0;
    576  1.1       cgd 		let = GEM_SYM;
    577  1.1       cgd 		an = bp;
    578  1.1       cgd 		goto srch;
    579  1.1       cgd 	}
    580  1.4  christos 	if (!strcmp(bp, "very heavy iron ball")) {
    581  1.1       cgd 		heavy = 1;
    582  1.1       cgd 		typ = HEAVY_IRON_BALL;
    583  1.1       cgd 		goto typfnd;
    584  1.1       cgd 	}
    585  1.1       cgd 	an = bp;
    586  1.1       cgd srch:
    587  1.4  christos 	if (!an && !dn && !un)
    588  1.1       cgd 		goto any;
    589  1.1       cgd 	i = 1;
    590  1.4  christos 	if (let)
    591  1.4  christos 		i = bases[letindex(let)];
    592  1.4  christos 	while (i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)) {
    593  1.5       jsm 		const char           *zn = objects[i].oc_name;
    594  1.1       cgd 
    595  1.4  christos 		if (!zn)
    596  1.4  christos 			goto nxti;
    597  1.4  christos 		if (an && strcmp(an, zn))
    598  1.1       cgd 			goto nxti;
    599  1.4  christos 		if (dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
    600  1.1       cgd 			goto nxti;
    601  1.4  christos 		if (un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
    602  1.1       cgd 			goto nxti;
    603  1.1       cgd 		typ = i;
    604  1.1       cgd 		goto typfnd;
    605  1.4  christos nxti:
    606  1.1       cgd 		i++;
    607  1.1       cgd 	}
    608  1.1       cgd any:
    609  1.4  christos 	if (!let)
    610  1.4  christos 		let = wrpsym[rn2(sizeof(wrpsym))];
    611  1.1       cgd 	typ = probtype(let);
    612  1.1       cgd typfnd:
    613  1.4  christos 	{
    614  1.4  christos 		struct obj     *otmp;
    615  1.4  christos 		let = objects[typ].oc_olet;
    616  1.4  christos 		otmp = mksobj(typ);
    617  1.4  christos 		if (heavy)
    618  1.4  christos 			otmp->owt += 15;
    619  1.4  christos 		if (cnt > 0 && strchr("%?!*)", let) &&
    620  1.1       cgd 		(cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
    621  1.4  christos 			otmp->quan = cnt;
    622  1.1       cgd 
    623  1.4  christos 		if (spe > 3 && spe > otmp->spe)
    624  1.4  christos 			spe = 0;
    625  1.4  christos 		else if (let == WAND_SYM)
    626  1.4  christos 			spe = otmp->spe;
    627  1.4  christos 		if (spe == 3 && u.uluck < 0)
    628  1.4  christos 			spesgn = -1;
    629  1.4  christos 		if (let != WAND_SYM && spesgn == -1)
    630  1.4  christos 			spe = -spe;
    631  1.4  christos 		if (let == BALL_SYM)
    632  1.4  christos 			spe = 0;
    633  1.4  christos 		else if (let == AMULET_SYM)
    634  1.4  christos 			spe = -1;
    635  1.4  christos 		else if (typ == WAN_WISHING && rn2(10))
    636  1.4  christos 			spe = (rn2(10) ? -1 : 0);
    637  1.4  christos 		otmp->spe = spe;
    638  1.1       cgd 
    639  1.4  christos 		if (spesgn == -1)
    640  1.4  christos 			otmp->cursed = 1;
    641  1.1       cgd 
    642  1.4  christos 		return (otmp);
    643  1.4  christos 	}
    644  1.1       cgd }
    645