more plural/singular (trunk only)

Extend makeplural/makesingular case-insensitivity to vtense() and to
wizard mode wishing for dungeon features.  And the previous set of fixes
missed one:  makesingular("zombies") was producing "zomby".  Plus a bit of
groundwork for a likely second overhaul of makeplural/makesingular.
This commit is contained in:
nethack.rankin
2007-05-03 01:17:46 +00:00
parent 894e7f0267
commit 15e79e99b9
3 changed files with 73 additions and 73 deletions

View File

@@ -20,7 +20,8 @@ NetHack, except that rounddiv may call panic().
char * eos (char *)
char * strkitten (char *,char)
void copynchars (char *,const char *,int)
void Strcasecpy (char *,const char *)
char chrcasecpy (int,int)
char * strcasecpy (char *,const char *)
char * s_suffix (const char *)
char * xcrypt (const char *, char *)
boolean onlyspace (const char *)
@@ -157,19 +158,33 @@ copynchars(dst, src, n) /* truncating string copy */
*dst = '\0';
}
/* this assumes ASCII; someday we'll have to switch over to <ctype.h> */
#define nh_islower(c) ((c) >= 'a' && (c) <= 'z')
#define nh_isupper(c) ((c) >= 'A' && (c) <= 'Z')
#define nh_tolower(c) lowc(c)
#define nh_toupper(c) highc(c)
/* mostly used by strcasecpy */
char
chrcasecpy(oc, nc) /* convert char nc into oc's case */
int oc, nc;
{
#if 0 /* this will be necessary if we switch to <ctype.h> */
oc = (int)(unsigned char)oc;
nc = (int)(unsigned char)nc;
#endif
if ('a' <= oc && oc <= 'z') {
/* old char is lower case; if new char is upper case, downcase it */
if ('A' <= nc && nc <= 'Z') nc += 'a' - 'A'; /* lowc(nc) */
} else if ('A' <= oc && oc <= 'Z') {
/* old char is upper case; if new char is lower case, upcase it */
if ('a' <= nc && nc <= 'z') nc += 'A' - 'a'; /* highc(nc) */
}
return (char)nc;
}
/* for case-insensitive editions of makeplural() and makesingular();
src might be shorter, same length, or longer than dst */
void
Strcasecpy(dst, src) /* overwrite string, preserving old chars' case */
char *
strcasecpy(dst, src) /* overwrite string, preserving old chars' case */
char *dst;
const char *src;
{
char *result = dst;
int ic, oc, dst_exhausted = 0;
/* while dst has characters, replace each one with corresponding
@@ -177,27 +192,15 @@ Strcasecpy(dst, src) /* overwrite string, preserving old chars' case */
once dst runs out, propagate the case of its last character to any
remaining src; if dst starts empty, it must be a pointer to the
tail of some other string because we examine the char at dst[-1] */
while ((ic = (int)(unsigned char)*src++) != '\0') {
while ((ic = (int)*src++) != '\0') {
if (!dst_exhausted && !*dst) dst_exhausted = 1;
/* fetch old character */
oc = (int)(unsigned char)*(dst - dst_exhausted);
/* possibly convert new character */
if (nh_islower(oc)) { /* the usual case... */
if (nh_isupper(ic)) ic = nh_tolower(ic);
} else if (nh_isupper(oc)) {
if (nh_islower(ic)) ic = nh_toupper(ic);
}
/* store new character */
*dst++ = (char)ic;
oc = (int)*(dst - dst_exhausted);
*dst++ = chrcasecpy(oc, ic);
}
*dst = '\0';
return result;
}
#undef nh_islower
#undef nh_isupper
#undef nh_tolower
#undef nh_toupper
char *
s_suffix(s) /* return a name converted to possessive */
const char *s;