Home | History | Annotate | Line # | Download | only in hack
hack.objnam.c revision 1.9
      1  1.9  dholland /*	$NetBSD: hack.objnam.c,v 1.9 2009/06/07 20:13:18 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.9  dholland __RCSID("$NetBSD: hack.objnam.c,v 1.9 2009/06/07 20:13:18 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.9  dholland #define Snprintf (void) snprintf
     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.8  dholland strprepend(char *s, char *pref)
     79  1.4  christos {
     80  1.4  christos 	int             i = strlen(pref);
     81  1.4  christos 	if (i > PREFIX) {
     82  1.1       cgd 		pline("WARNING: prefix too short.");
     83  1.4  christos 		return (s);
     84  1.1       cgd 	}
     85  1.1       cgd 	s -= i;
     86  1.1       cgd 	(void) strncpy(s, pref, i);	/* do not copy trailing 0 */
     87  1.4  christos 	return (s);
     88  1.1       cgd }
     89  1.1       cgd 
     90  1.4  christos char           *
     91  1.8  dholland sitoa(int a)
     92  1.4  christos {
     93  1.4  christos 	static char     buf[13];
     94  1.9  dholland 	Snprintf(buf, sizeof(buf), (a < 0) ? "%d" : "+%d", a);
     95  1.4  christos 	return (buf);
     96  1.1       cgd }
     97  1.1       cgd 
     98  1.4  christos char           *
     99  1.8  dholland typename(int otyp)
    100  1.1       cgd {
    101  1.4  christos 	static char     buf[BUFSZ];
    102  1.9  dholland 	size_t bufpos;
    103  1.4  christos 	struct objclass *ocl = &objects[otyp];
    104  1.5       jsm 	const char     *an = ocl->oc_name;
    105  1.5       jsm 	const char     *dn = ocl->oc_descr;
    106  1.4  christos 	char           *un = ocl->oc_uname;
    107  1.4  christos 	int             nn = ocl->oc_name_known;
    108  1.4  christos 	switch (ocl->oc_olet) {
    109  1.1       cgd 	case POTION_SYM:
    110  1.1       cgd 		Strcpy(buf, "potion");
    111  1.1       cgd 		break;
    112  1.1       cgd 	case SCROLL_SYM:
    113  1.1       cgd 		Strcpy(buf, "scroll");
    114  1.1       cgd 		break;
    115  1.1       cgd 	case WAND_SYM:
    116  1.1       cgd 		Strcpy(buf, "wand");
    117  1.1       cgd 		break;
    118  1.1       cgd 	case RING_SYM:
    119  1.1       cgd 		Strcpy(buf, "ring");
    120  1.1       cgd 		break;
    121  1.1       cgd 	default:
    122  1.4  christos 		if (nn) {
    123  1.1       cgd 			Strcpy(buf, an);
    124  1.4  christos 			if (otyp >= TURQUOISE && otyp <= JADE)
    125  1.1       cgd 				Strcat(buf, " stone");
    126  1.9  dholland 			if (un) {
    127  1.9  dholland 				bufpos = strlen(buf);
    128  1.9  dholland 				Snprintf(buf+bufpos, sizeof(buf)-bufpos,
    129  1.9  dholland 					" called %s", un);
    130  1.9  dholland 			}
    131  1.9  dholland 			if (dn) {
    132  1.9  dholland 				bufpos = strlen(buf);
    133  1.9  dholland 				Snprintf(buf+bufpos, sizeof(buf)-bufpos,
    134  1.9  dholland 					" (%s)", dn);
    135  1.9  dholland 			}
    136  1.1       cgd 		} else {
    137  1.9  dholland 			strlcpy(buf, dn ? dn : an, sizeof(buf));
    138  1.9  dholland 			if (ocl->oc_olet == GEM_SYM) {
    139  1.9  dholland 				strlcat(buf, " gem", sizeof(buf));
    140  1.9  dholland 			}
    141  1.9  dholland 			if (un) {
    142  1.9  dholland 				bufpos = strlen(buf);
    143  1.9  dholland 				Snprintf(buf+bufpos, sizeof(buf)-bufpos,
    144  1.9  dholland 					" called %s", un);
    145  1.9  dholland 			}
    146  1.1       cgd 		}
    147  1.4  christos 		return (buf);
    148  1.1       cgd 	}
    149  1.1       cgd 	/* here for ring/scroll/potion/wand */
    150  1.9  dholland 	if (nn) {
    151  1.9  dholland 		bufpos = strlen(buf);
    152  1.9  dholland 		Snprintf(buf+bufpos, sizeof(buf)-bufpos, " of %s", an);
    153  1.9  dholland 	}
    154  1.9  dholland 	if (un) {
    155  1.9  dholland 		bufpos = strlen(buf);
    156  1.9  dholland 		Snprintf(buf+bufpos, sizeof(buf)-bufpos, " called %s", un);
    157  1.9  dholland 	}
    158  1.9  dholland 	if (dn) {
    159  1.9  dholland 		bufpos = strlen(buf);
    160  1.9  dholland 		Snprintf(buf+bufpos, sizeof(buf)-bufpos, " (%s)", dn);
    161  1.9  dholland 	}
    162  1.4  christos 	return (buf);
    163  1.1       cgd }
    164  1.1       cgd 
    165  1.4  christos char           *
    166  1.8  dholland xname(struct obj *obj)
    167  1.1       cgd {
    168  1.4  christos 	static char     bufr[BUFSZ];
    169  1.9  dholland 	/* caution: doname() and aobjnam() below "know" these sizes */
    170  1.4  christos 	char           *buf = &(bufr[PREFIX]);	/* leave room for "17 -3 " */
    171  1.9  dholland 	size_t          bufmax = sizeof(bufr) - PREFIX;
    172  1.4  christos 	int             nn = objects[obj->otyp].oc_name_known;
    173  1.5       jsm 	const char     *an = objects[obj->otyp].oc_name;
    174  1.5       jsm 	const char     *dn = objects[obj->otyp].oc_descr;
    175  1.4  christos 	char           *un = objects[obj->otyp].oc_uname;
    176  1.4  christos 	int             pl = (obj->quan != 1);
    177  1.9  dholland 
    178  1.4  christos 	if (!obj->dknown && !Blind)
    179  1.4  christos 		obj->dknown = 1;/* %% doesnt belong here */
    180  1.4  christos 	switch (obj->olet) {
    181  1.1       cgd 	case AMULET_SYM:
    182  1.1       cgd 		Strcpy(buf, (obj->spe < 0 && obj->known)
    183  1.4  christos 		       ? "cheap plastic imitation of the " : "");
    184  1.4  christos 		Strcat(buf, "Amulet of Yendor");
    185  1.1       cgd 		break;
    186  1.1       cgd 	case TOOL_SYM:
    187  1.4  christos 		if (!nn) {
    188  1.9  dholland 			strlcpy(buf, dn, bufmax);
    189  1.1       cgd 			break;
    190  1.1       cgd 		}
    191  1.9  dholland 		strlcpy(buf, an, bufmax);
    192  1.1       cgd 		break;
    193  1.1       cgd 	case FOOD_SYM:
    194  1.4  christos 		if (obj->otyp == DEAD_HOMUNCULUS && pl) {
    195  1.1       cgd 			pl = 0;
    196  1.1       cgd 			Strcpy(buf, "dead homunculi");
    197  1.1       cgd 			break;
    198  1.1       cgd 		}
    199  1.1       cgd 		/* fungis ? */
    200  1.1       cgd 		/* fall into next case */
    201  1.1       cgd 	case WEAPON_SYM:
    202  1.4  christos 		if (obj->otyp == WORM_TOOTH && pl) {
    203  1.1       cgd 			pl = 0;
    204  1.1       cgd 			Strcpy(buf, "worm teeth");
    205  1.1       cgd 			break;
    206  1.1       cgd 		}
    207  1.4  christos 		if (obj->otyp == CRYSKNIFE && pl) {
    208  1.1       cgd 			pl = 0;
    209  1.1       cgd 			Strcpy(buf, "crysknives");
    210  1.1       cgd 			break;
    211  1.1       cgd 		}
    212  1.1       cgd 		/* fall into next case */
    213  1.1       cgd 	case ARMOR_SYM:
    214  1.1       cgd 	case CHAIN_SYM:
    215  1.1       cgd 	case ROCK_SYM:
    216  1.9  dholland 		strlcpy(buf, an, bufmax);
    217  1.1       cgd 		break;
    218  1.1       cgd 	case BALL_SYM:
    219  1.9  dholland 		Snprintf(buf, bufmax, "%sheavy iron ball",
    220  1.1       cgd 		  (obj->owt > objects[obj->otyp].oc_weight) ? "very " : "");
    221  1.1       cgd 		break;
    222  1.1       cgd 	case POTION_SYM:
    223  1.4  christos 		if (nn || un || !obj->dknown) {
    224  1.1       cgd 			Strcpy(buf, "potion");
    225  1.4  christos 			if (pl) {
    226  1.1       cgd 				pl = 0;
    227  1.1       cgd 				Strcat(buf, "s");
    228  1.1       cgd 			}
    229  1.4  christos 			if (!obj->dknown)
    230  1.4  christos 				break;
    231  1.4  christos 			if (un) {
    232  1.1       cgd 				Strcat(buf, " called ");
    233  1.9  dholland 				strlcat(buf, un, bufmax);
    234  1.1       cgd 			} else {
    235  1.1       cgd 				Strcat(buf, " of ");
    236  1.9  dholland 				strlcat(buf, an, bufmax);
    237  1.1       cgd 			}
    238  1.1       cgd 		} else {
    239  1.9  dholland 			strlcpy(buf, dn, bufmax);
    240  1.9  dholland 			strlcat(buf, " potion", bufmax);
    241  1.1       cgd 		}
    242  1.1       cgd 		break;
    243  1.1       cgd 	case SCROLL_SYM:
    244  1.1       cgd 		Strcpy(buf, "scroll");
    245  1.4  christos 		if (pl) {
    246  1.1       cgd 			pl = 0;
    247  1.1       cgd 			Strcat(buf, "s");
    248  1.1       cgd 		}
    249  1.4  christos 		if (!obj->dknown)
    250  1.4  christos 			break;
    251  1.4  christos 		if (nn) {
    252  1.1       cgd 			Strcat(buf, " of ");
    253  1.9  dholland 			strlcat(buf, an, bufmax);
    254  1.4  christos 		} else if (un) {
    255  1.1       cgd 			Strcat(buf, " called ");
    256  1.9  dholland 			strlcat(buf, un, bufmax);
    257  1.1       cgd 		} else {
    258  1.1       cgd 			Strcat(buf, " labeled ");
    259  1.9  dholland 			strlcat(buf, dn, bufmax);
    260  1.1       cgd 		}
    261  1.1       cgd 		break;
    262  1.1       cgd 	case WAND_SYM:
    263  1.4  christos 		if (!obj->dknown)
    264  1.9  dholland 			Snprintf(buf, bufmax, "wand");
    265  1.4  christos 		else if (nn)
    266  1.9  dholland 			Snprintf(buf, bufmax, "wand of %s", an);
    267  1.4  christos 		else if (un)
    268  1.9  dholland 			Snprintf(buf, bufmax, "wand called %s", un);
    269  1.1       cgd 		else
    270  1.9  dholland 			Snprintf(buf, bufmax, "%s wand", dn);
    271  1.1       cgd 		break;
    272  1.1       cgd 	case RING_SYM:
    273  1.4  christos 		if (!obj->dknown)
    274  1.9  dholland 			Snprintf(buf, bufmax, "ring");
    275  1.4  christos 		else if (nn)
    276  1.9  dholland 			Snprintf(buf, bufmax, "ring of %s", an);
    277  1.4  christos 		else if (un)
    278  1.9  dholland 			Snprintf(buf, bufmax, "ring called %s", un);
    279  1.1       cgd 		else
    280  1.9  dholland 			Snprintf(buf, bufmax, "%s ring", dn);
    281  1.1       cgd 		break;
    282  1.1       cgd 	case GEM_SYM:
    283  1.4  christos 		if (!obj->dknown) {
    284  1.1       cgd 			Strcpy(buf, "gem");
    285  1.1       cgd 			break;
    286  1.1       cgd 		}
    287  1.4  christos 		if (!nn) {
    288  1.9  dholland 			Snprintf(buf, bufmax, "%s gem", dn);
    289  1.1       cgd 			break;
    290  1.1       cgd 		}
    291  1.9  dholland 		strlcpy(buf, an, bufmax);
    292  1.4  christos 		if (obj->otyp >= TURQUOISE && obj->otyp <= JADE)
    293  1.9  dholland 			strlcat(buf, " stone", bufmax);
    294  1.1       cgd 		break;
    295  1.1       cgd 	default:
    296  1.9  dholland 		Snprintf(buf, bufmax, "glorkum %c (0%o) %u %d",
    297  1.4  christos 			obj->olet, obj->olet, obj->otyp, obj->spe);
    298  1.1       cgd 	}
    299  1.4  christos 	if (pl) {
    300  1.4  christos 		char           *p;
    301  1.1       cgd 
    302  1.4  christos 		for (p = buf; *p; p++) {
    303  1.4  christos 			if (!strncmp(" of ", p, 4)) {
    304  1.1       cgd 				/* pieces of, cloves of, lumps of */
    305  1.4  christos 				int             c1, c2 = 's';
    306  1.1       cgd 
    307  1.1       cgd 				do {
    308  1.4  christos 					c1 = c2;
    309  1.4  christos 					c2 = *p;
    310  1.4  christos 					*p++ = c1;
    311  1.4  christos 				} while (c1);
    312  1.1       cgd 				goto nopl;
    313  1.1       cgd 			}
    314  1.1       cgd 		}
    315  1.4  christos 		p = eos(buf) - 1;
    316  1.4  christos 		if (*p == 's' || *p == 'z' || *p == 'x' ||
    317  1.9  dholland 		    (*p == 'h' && p[-1] == 's')) {
    318  1.9  dholland 			/* boxes */
    319  1.9  dholland 			strlcat(buf, "es", bufmax);
    320  1.9  dholland 		} else if (*p == 'y' && !strchr(vowels, p[-1])) {
    321  1.9  dholland 			/* rubies, zruties */
    322  1.9  dholland 			*p = '\0';
    323  1.9  dholland 			strlcat(buf, "ies", bufmax);
    324  1.9  dholland 		} else {
    325  1.9  dholland 			strlcat(buf, "s", bufmax);
    326  1.9  dholland 		}
    327  1.1       cgd 	}
    328  1.1       cgd nopl:
    329  1.4  christos 	if (obj->onamelth) {
    330  1.9  dholland 		strlcat(buf, " named ", bufmax);
    331  1.9  dholland 		strlcat(buf, ONAME(obj), bufmax);
    332  1.1       cgd 	}
    333  1.4  christos 	return (buf);
    334  1.1       cgd }
    335  1.1       cgd 
    336  1.4  christos char           *
    337  1.8  dholland doname(struct obj *obj)
    338  1.1       cgd {
    339  1.4  christos 	char            prefix[PREFIX];
    340  1.4  christos 	char           *bp = xname(obj);
    341  1.9  dholland 	size_t          bppos, bpmax;
    342  1.9  dholland 
    343  1.9  dholland 	/* XXX do this better somehow w/o knowing internals of xname() */
    344  1.9  dholland 	bpmax = BUFSZ - PREFIX;
    345  1.9  dholland 
    346  1.4  christos 	if (obj->quan != 1)
    347  1.9  dholland 		Snprintf(prefix, sizeof(prefix), "%u ", obj->quan);
    348  1.1       cgd 	else
    349  1.1       cgd 		Strcpy(prefix, "a ");
    350  1.4  christos 	switch (obj->olet) {
    351  1.1       cgd 	case AMULET_SYM:
    352  1.4  christos 		if (strncmp(bp, "cheap ", 6))
    353  1.1       cgd 			Strcpy(prefix, "the ");
    354  1.1       cgd 		break;
    355  1.1       cgd 	case ARMOR_SYM:
    356  1.4  christos 		if (obj->owornmask & W_ARMOR)
    357  1.9  dholland 			strlcat(bp, " (being worn)", bpmax);
    358  1.1       cgd 		/* fall into next case */
    359  1.1       cgd 	case WEAPON_SYM:
    360  1.4  christos 		if (obj->known) {
    361  1.9  dholland 			strlcat(prefix, sitoa(obj->spe), sizeof(prefix));
    362  1.9  dholland 			strlcat(prefix, " ", sizeof(prefix));
    363  1.1       cgd 		}
    364  1.1       cgd 		break;
    365  1.1       cgd 	case WAND_SYM:
    366  1.9  dholland 		if (obj->known) {
    367  1.9  dholland 			bppos = strlen(bp);
    368  1.9  dholland 			Snprintf(bp+bppos, bpmax-bppos, " (%d)", obj->spe);
    369  1.9  dholland 		}
    370  1.1       cgd 		break;
    371  1.1       cgd 	case RING_SYM:
    372  1.4  christos 		if (obj->owornmask & W_RINGR)
    373  1.9  dholland 			strlcat(bp, " (on right hand)", bpmax);
    374  1.4  christos 		if (obj->owornmask & W_RINGL)
    375  1.9  dholland 			strlcat(bp, " (on left hand)", bpmax);
    376  1.4  christos 		if (obj->known && (objects[obj->otyp].bits & SPEC)) {
    377  1.9  dholland 			strlcat(prefix, sitoa(obj->spe), sizeof(prefix));
    378  1.9  dholland 			strlcat(prefix, " ", sizeof(prefix));
    379  1.1       cgd 		}
    380  1.1       cgd 		break;
    381  1.1       cgd 	}
    382  1.4  christos 	if (obj->owornmask & W_WEP)
    383  1.9  dholland 		strlcat(bp, " (weapon in hand)", bpmax);
    384  1.4  christos 	if (obj->unpaid)
    385  1.9  dholland 		strlcat(bp, " (unpaid)", bpmax);
    386  1.4  christos 	if (!strcmp(prefix, "a ") && strchr(vowels, *bp))
    387  1.1       cgd 		Strcpy(prefix, "an ");
    388  1.1       cgd 	bp = strprepend(bp, prefix);
    389  1.4  christos 	return (bp);
    390  1.1       cgd }
    391  1.1       cgd 
    392  1.1       cgd /* used only in hack.fight.c (thitu) */
    393  1.4  christos void
    394  1.9  dholland setan(const char *str, char *buf, size_t bufmax)
    395  1.1       cgd {
    396  1.4  christos 	if (strchr(vowels, *str))
    397  1.9  dholland 		Snprintf(buf, bufmax, "an %s", str);
    398  1.1       cgd 	else
    399  1.9  dholland 		Snprintf(buf, bufmax, "a %s", str);
    400  1.1       cgd }
    401  1.1       cgd 
    402  1.4  christos char           *
    403  1.8  dholland aobjnam(struct obj *otmp, const char *verb)
    404  1.4  christos {
    405  1.4  christos 	char           *bp = xname(otmp);
    406  1.4  christos 	char            prefix[PREFIX];
    407  1.9  dholland 	size_t          bpmax;
    408  1.9  dholland 
    409  1.9  dholland 	/* XXX do this better somehow w/o knowing internals of xname() */
    410  1.9  dholland 	bpmax = BUFSZ - PREFIX;
    411  1.9  dholland 
    412  1.4  christos 	if (otmp->quan != 1) {
    413  1.9  dholland 		Snprintf(prefix, sizeof(prefix), "%u ", otmp->quan);
    414  1.1       cgd 		bp = strprepend(bp, prefix);
    415  1.1       cgd 	}
    416  1.4  christos 	if (verb) {
    417  1.1       cgd 		/* verb is given in plural (i.e., without trailing s) */
    418  1.9  dholland 		strlcat(bp, " ", bpmax);
    419  1.4  christos 		if (otmp->quan != 1)
    420  1.9  dholland 			strlcat(bp, verb, bpmax);
    421  1.4  christos 		else if (!strcmp(verb, "are"))
    422  1.9  dholland 			strlcat(bp, "is", bpmax);
    423  1.1       cgd 		else {
    424  1.9  dholland 			strlcat(bp, verb, bpmax);
    425  1.9  dholland 			strlcat(bp, "s", bpmax);
    426  1.1       cgd 		}
    427  1.1       cgd 	}
    428  1.4  christos 	return (bp);
    429  1.1       cgd }
    430  1.1       cgd 
    431  1.4  christos char           *
    432  1.8  dholland Doname(struct obj *obj)
    433  1.1       cgd {
    434  1.4  christos 	char           *s = doname(obj);
    435  1.1       cgd 
    436  1.4  christos 	if ('a' <= *s && *s <= 'z')
    437  1.4  christos 		*s -= ('a' - 'A');
    438  1.4  christos 	return (s);
    439  1.1       cgd }
    440  1.1       cgd 
    441  1.5       jsm const char *const wrp[] = {"wand", "ring", "potion", "scroll", "gem"};
    442  1.5       jsm const char wrpsym[] = {WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM};
    443  1.1       cgd 
    444  1.4  christos struct obj     *
    445  1.8  dholland readobjnam(char *bp)
    446  1.4  christos {
    447  1.4  christos 	char           *p;
    448  1.7  dholland 	unsigned        ii;
    449  1.7  dholland 	int		i;
    450  1.4  christos 	int             cnt, spe, spesgn, typ, heavy;
    451  1.4  christos 	char            let;
    452  1.4  christos 	char           *un, *dn, *an;
    453  1.4  christos 	/* int the = 0; char *oname = 0; */
    454  1.1       cgd 	cnt = spe = spesgn = typ = heavy = 0;
    455  1.1       cgd 	let = 0;
    456  1.1       cgd 	an = dn = un = 0;
    457  1.4  christos 	for (p = bp; *p; p++)
    458  1.4  christos 		if ('A' <= *p && *p <= 'Z')
    459  1.4  christos 			*p += 'a' - 'A';
    460  1.4  christos 	if (!strncmp(bp, "the ", 4)) {
    461  1.4  christos 		/* the = 1; */
    462  1.1       cgd 		bp += 4;
    463  1.4  christos 	} else if (!strncmp(bp, "an ", 3)) {
    464  1.1       cgd 		cnt = 1;
    465  1.1       cgd 		bp += 3;
    466  1.4  christos 	} else if (!strncmp(bp, "a ", 2)) {
    467  1.1       cgd 		cnt = 1;
    468  1.1       cgd 		bp += 2;
    469  1.1       cgd 	}
    470  1.4  christos 	if (!cnt && digit(*bp)) {
    471  1.1       cgd 		cnt = atoi(bp);
    472  1.4  christos 		while (digit(*bp))
    473  1.4  christos 			bp++;
    474  1.4  christos 		while (*bp == ' ')
    475  1.4  christos 			bp++;
    476  1.1       cgd 	}
    477  1.4  christos 	if (!cnt)
    478  1.4  christos 		cnt = 1;	/* %% what with "gems" etc. ? */
    479  1.1       cgd 
    480  1.4  christos 	if (*bp == '+' || *bp == '-') {
    481  1.1       cgd 		spesgn = (*bp++ == '+') ? 1 : -1;
    482  1.1       cgd 		spe = atoi(bp);
    483  1.4  christos 		while (digit(*bp))
    484  1.4  christos 			bp++;
    485  1.4  christos 		while (*bp == ' ')
    486  1.4  christos 			bp++;
    487  1.1       cgd 	} else {
    488  1.4  christos 		p = strrchr(bp, '(');
    489  1.4  christos 		if (p) {
    490  1.4  christos 			if (p > bp && p[-1] == ' ')
    491  1.4  christos 				p[-1] = 0;
    492  1.4  christos 			else
    493  1.4  christos 				*p = 0;
    494  1.1       cgd 			p++;
    495  1.1       cgd 			spe = atoi(p);
    496  1.4  christos 			while (digit(*p))
    497  1.4  christos 				p++;
    498  1.4  christos 			if (strcmp(p, ")"))
    499  1.4  christos 				spe = 0;
    500  1.4  christos 			else
    501  1.4  christos 				spesgn = 1;
    502  1.4  christos 		}
    503  1.4  christos 	}
    504  1.4  christos 	/*
    505  1.4  christos 	 * now we have the actual name, as delivered by xname, say green
    506  1.4  christos 	 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
    507  1.4  christos 	 * fortune cookies very heavy iron ball named hoei wand of wishing
    508  1.4  christos 	 * elven cloak
    509  1.4  christos 	 */
    510  1.4  christos 	for (p = bp; *p; p++)
    511  1.4  christos 		if (!strncmp(p, " named ", 7)) {
    512  1.4  christos 			*p = 0;
    513  1.4  christos 			/* oname = p+7; */
    514  1.4  christos 		}
    515  1.4  christos 	for (p = bp; *p; p++)
    516  1.4  christos 		if (!strncmp(p, " called ", 8)) {
    517  1.4  christos 			*p = 0;
    518  1.4  christos 			un = p + 8;
    519  1.4  christos 		}
    520  1.4  christos 	for (p = bp; *p; p++)
    521  1.4  christos 		if (!strncmp(p, " labeled ", 9)) {
    522  1.4  christos 			*p = 0;
    523  1.4  christos 			dn = p + 9;
    524  1.4  christos 		}
    525  1.1       cgd 	/* first change to singular if necessary */
    526  1.4  christos 	if (cnt != 1) {
    527  1.1       cgd 		/* find "cloves of garlic", "worthless pieces of blue glass" */
    528  1.4  christos 		for (p = bp; *p; p++)
    529  1.4  christos 			if (!strncmp(p, "s of ", 5)) {
    530  1.4  christos 				while ((*p = p[1]) != '\0')
    531  1.4  christos 					p++;
    532  1.4  christos 				goto sing;
    533  1.4  christos 			}
    534  1.1       cgd 		/* remove -s or -es (boxes) or -ies (rubies, zruties) */
    535  1.1       cgd 		p = eos(bp);
    536  1.4  christos 		if (p[-1] == 's') {
    537  1.4  christos 			if (p[-2] == 'e') {
    538  1.4  christos 				if (p[-3] == 'i') {
    539  1.4  christos 					if (!strcmp(p - 7, "cookies"))
    540  1.1       cgd 						goto mins;
    541  1.4  christos 					Strcpy(p - 3, "y");
    542  1.1       cgd 					goto sing;
    543  1.1       cgd 				}
    544  1.1       cgd 				/* note: cloves / knives from clove / knife */
    545  1.4  christos 				if (!strcmp(p - 6, "knives")) {
    546  1.4  christos 					Strcpy(p - 3, "fe");
    547  1.1       cgd 					goto sing;
    548  1.1       cgd 				}
    549  1.1       cgd 				/* note: nurses, axes but boxes */
    550  1.4  christos 				if (!strcmp(p - 5, "boxes")) {
    551  1.1       cgd 					p[-2] = 0;
    552  1.1       cgd 					goto sing;
    553  1.1       cgd 				}
    554  1.1       cgd 			}
    555  1.4  christos 	mins:
    556  1.1       cgd 			p[-1] = 0;
    557  1.1       cgd 		} else {
    558  1.4  christos 			if (!strcmp(p - 9, "homunculi")) {
    559  1.4  christos 				Strcpy(p - 1, "us");	/* !! makes string
    560  1.4  christos 							 * longer */
    561  1.1       cgd 				goto sing;
    562  1.1       cgd 			}
    563  1.4  christos 			if (!strcmp(p - 5, "teeth")) {
    564  1.4  christos 				Strcpy(p - 5, "tooth");
    565  1.1       cgd 				goto sing;
    566  1.1       cgd 			}
    567  1.1       cgd 			/* here we cannot find the plural suffix */
    568  1.1       cgd 		}
    569  1.1       cgd 	}
    570  1.1       cgd sing:
    571  1.4  christos 	if (!strcmp(bp, "amulet of yendor")) {
    572  1.1       cgd 		typ = AMULET_OF_YENDOR;
    573  1.1       cgd 		goto typfnd;
    574  1.1       cgd 	}
    575  1.1       cgd 	p = eos(bp);
    576  1.4  christos 	if (!strcmp(p - 5, " mail")) {	/* Note: ring mail is not a ring ! */
    577  1.1       cgd 		let = ARMOR_SYM;
    578  1.1       cgd 		an = bp;
    579  1.1       cgd 		goto srch;
    580  1.1       cgd 	}
    581  1.7  dholland 	for (ii = 0; ii < sizeof(wrpsym); ii++) {
    582  1.7  dholland 		int             j = strlen(wrp[ii]);
    583  1.7  dholland 		if (!strncmp(bp, wrp[ii], j)) {
    584  1.7  dholland 			let = wrpsym[ii];
    585  1.1       cgd 			bp += j;
    586  1.4  christos 			if (!strncmp(bp, " of ", 4))
    587  1.4  christos 				an = bp + 4;
    588  1.1       cgd 			/* else if(*bp) ?? */
    589  1.1       cgd 			goto srch;
    590  1.1       cgd 		}
    591  1.7  dholland 		if (!strcmp(p - j, wrp[ii])) {
    592  1.7  dholland 			let = wrpsym[ii];
    593  1.1       cgd 			p -= j;
    594  1.1       cgd 			*p = 0;
    595  1.4  christos 			if (p[-1] == ' ')
    596  1.4  christos 				p[-1] = 0;
    597  1.1       cgd 			dn = bp;
    598  1.1       cgd 			goto srch;
    599  1.1       cgd 		}
    600  1.1       cgd 	}
    601  1.4  christos 	if (!strcmp(p - 6, " stone")) {
    602  1.1       cgd 		p[-6] = 0;
    603  1.1       cgd 		let = GEM_SYM;
    604  1.1       cgd 		an = bp;
    605  1.1       cgd 		goto srch;
    606  1.1       cgd 	}
    607  1.4  christos 	if (!strcmp(bp, "very heavy iron ball")) {
    608  1.1       cgd 		heavy = 1;
    609  1.1       cgd 		typ = HEAVY_IRON_BALL;
    610  1.1       cgd 		goto typfnd;
    611  1.1       cgd 	}
    612  1.1       cgd 	an = bp;
    613  1.1       cgd srch:
    614  1.4  christos 	if (!an && !dn && !un)
    615  1.1       cgd 		goto any;
    616  1.1       cgd 	i = 1;
    617  1.4  christos 	if (let)
    618  1.4  christos 		i = bases[letindex(let)];
    619  1.4  christos 	while (i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)) {
    620  1.5       jsm 		const char           *zn = objects[i].oc_name;
    621  1.1       cgd 
    622  1.4  christos 		if (!zn)
    623  1.4  christos 			goto nxti;
    624  1.4  christos 		if (an && strcmp(an, zn))
    625  1.1       cgd 			goto nxti;
    626  1.4  christos 		if (dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
    627  1.1       cgd 			goto nxti;
    628  1.4  christos 		if (un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
    629  1.1       cgd 			goto nxti;
    630  1.1       cgd 		typ = i;
    631  1.1       cgd 		goto typfnd;
    632  1.4  christos nxti:
    633  1.1       cgd 		i++;
    634  1.1       cgd 	}
    635  1.1       cgd any:
    636  1.4  christos 	if (!let)
    637  1.4  christos 		let = wrpsym[rn2(sizeof(wrpsym))];
    638  1.1       cgd 	typ = probtype(let);
    639  1.1       cgd typfnd:
    640  1.4  christos 	{
    641  1.4  christos 		struct obj     *otmp;
    642  1.4  christos 		let = objects[typ].oc_olet;
    643  1.4  christos 		otmp = mksobj(typ);
    644  1.4  christos 		if (heavy)
    645  1.4  christos 			otmp->owt += 15;
    646  1.4  christos 		if (cnt > 0 && strchr("%?!*)", let) &&
    647  1.1       cgd 		(cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
    648  1.4  christos 			otmp->quan = cnt;
    649  1.1       cgd 
    650  1.4  christos 		if (spe > 3 && spe > otmp->spe)
    651  1.4  christos 			spe = 0;
    652  1.4  christos 		else if (let == WAND_SYM)
    653  1.4  christos 			spe = otmp->spe;
    654  1.4  christos 		if (spe == 3 && u.uluck < 0)
    655  1.4  christos 			spesgn = -1;
    656  1.4  christos 		if (let != WAND_SYM && spesgn == -1)
    657  1.4  christos 			spe = -spe;
    658  1.4  christos 		if (let == BALL_SYM)
    659  1.4  christos 			spe = 0;
    660  1.4  christos 		else if (let == AMULET_SYM)
    661  1.4  christos 			spe = -1;
    662  1.4  christos 		else if (typ == WAN_WISHING && rn2(10))
    663  1.4  christos 			spe = (rn2(10) ? -1 : 0);
    664  1.4  christos 		otmp->spe = spe;
    665  1.1       cgd 
    666  1.4  christos 		if (spesgn == -1)
    667  1.4  christos 			otmp->cursed = 1;
    668  1.1       cgd 
    669  1.4  christos 		return (otmp);
    670  1.4  christos 	}
    671  1.1       cgd }
    672