Add streq() and start finding places it fixes warnings.
Some type fixes from Michael Allison.
This commit is contained in:
@@ -999,6 +999,7 @@ extern int strncmpi(const char *, const char *, int);
|
||||
#ifndef STRSTRI
|
||||
extern char *strstri(const char *, const char *);
|
||||
#endif
|
||||
extern int streq(const char *, const char *, boolean);
|
||||
extern boolean fuzzymatch(const char *, const char *, const char *, boolean);
|
||||
extern void init_random(int(*fn)(int));
|
||||
extern void reseed_random(int(*fn)(int));
|
||||
|
||||
@@ -158,7 +158,7 @@ dupstr_n(const char *string, unsigned int *lenout)
|
||||
if(len >= LARGEST_INT)
|
||||
panic("string too long");
|
||||
*lenout = (unsigned int) len;
|
||||
return strcpy((char *) alloc((unsigned)len + 1), string);
|
||||
return strcpy((char *) alloc(len + 1), string);
|
||||
}
|
||||
|
||||
/*alloc.c*/
|
||||
|
||||
10
src/botl.c
10
src/botl.c
@@ -364,8 +364,7 @@ title_to_mon(const char *str, int *rank_indx, int *title_length)
|
||||
/* loop through each of the rank titles for role #i */
|
||||
for (j = 0; j < 9; j++) {
|
||||
if (roles[i].rank[j].m
|
||||
&& !strncmpi(str, roles[i].rank[j].m,
|
||||
strlen(roles[i].rank[j].m))) {
|
||||
&& streq(str, roles[i].rank[j].m, TRUE)) {
|
||||
if (rank_indx)
|
||||
*rank_indx = j;
|
||||
if (title_length)
|
||||
@@ -373,8 +372,7 @@ title_to_mon(const char *str, int *rank_indx, int *title_length)
|
||||
return roles[i].mnum;
|
||||
}
|
||||
if (roles[i].rank[j].f
|
||||
&& !strncmpi(str, roles[i].rank[j].f,
|
||||
strlen(roles[i].rank[j].f))) {
|
||||
&& streq(str, roles[i].rank[j].m, TRUE)) {
|
||||
if (rank_indx)
|
||||
*rank_indx = j;
|
||||
if (title_length)
|
||||
@@ -498,7 +496,7 @@ static char *conditionbitmask2str(unsigned long);
|
||||
static unsigned long match_str2conditionbitmask(const char *);
|
||||
static unsigned long str2conditionbitmask(char *);
|
||||
static boolean parse_condition(char (*)[QBUFSZ], int);
|
||||
static char *hlattr2attrname(int, char *, int);
|
||||
static char *hlattr2attrname(int, char *, size_t);
|
||||
static void status_hilite_linestr_add(int, struct hilite_s *, unsigned long,
|
||||
const char *);
|
||||
static void status_hilite_linestr_done(void);
|
||||
@@ -2926,7 +2924,7 @@ clear_status_hilites(void)
|
||||
}
|
||||
|
||||
static char *
|
||||
hlattr2attrname(int attrib, char *buf, int bufsz)
|
||||
hlattr2attrname(int attrib, char *buf, size_t bufsz)
|
||||
{
|
||||
if (attrib && buf) {
|
||||
char attbuf[BUFSZ];
|
||||
|
||||
@@ -2466,8 +2466,7 @@ donamelevel(void)
|
||||
/* add new annotation, unless it's all spaces (which will be an
|
||||
empty string after mungspaces() above) */
|
||||
if (*nbuf && strcmp(nbuf, " ")) {
|
||||
mptr->custom = dupstr(nbuf);
|
||||
mptr->custom_lth = strlen(mptr->custom);
|
||||
mptr->custom = dupstr_n(nbuf,&mptr->custom_lth);
|
||||
}
|
||||
return ECMD_OK;
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@ rounddiv(long x, int y)
|
||||
divsgn = -divsgn;
|
||||
x = -x;
|
||||
}
|
||||
r = x / y;
|
||||
r = (int) (x / y);
|
||||
m = x % y;
|
||||
if (2 * m >= y)
|
||||
r++;
|
||||
@@ -837,6 +837,30 @@ strstri(const char *str, const char *sub)
|
||||
}
|
||||
#endif /* STRSTRI */
|
||||
|
||||
/* string equality, possibly ignoring case; panics on huge strings */
|
||||
int
|
||||
streq(register const char *s1, register const char *s2,
|
||||
boolean caseblind)
|
||||
{
|
||||
register char t1, t2;
|
||||
int n = LARGEST_INT;
|
||||
|
||||
while (n--) {
|
||||
if (!*s2)
|
||||
return (*s1 == 0); /* s1 >= s2 */
|
||||
else if (!*s1)
|
||||
return 1; /* s1 < s2 */
|
||||
t1 = caseblind ? lowc(*s1) : *s1;
|
||||
t2 = caseblind ? lowc(*s2) : *s2;
|
||||
s1++,s2++;
|
||||
if (t1 != t2)
|
||||
return 0;
|
||||
}
|
||||
if (n==0)
|
||||
panic("string too long");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* compare two strings for equality, ignoring the presence of specified
|
||||
characters (typically whitespace) and possibly ignoring case */
|
||||
boolean
|
||||
|
||||
@@ -860,20 +860,20 @@ name_to_monplus(
|
||||
|
||||
for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
|
||||
for (mgend = MALE; mgend < NUM_MGENDERS; mgend++) {
|
||||
int m_i_len;
|
||||
size_t m_i_len;
|
||||
|
||||
if (!mons[i].pmnames[mgend])
|
||||
continue;
|
||||
|
||||
m_i_len = (int) strlen(mons[i].pmnames[mgend]);
|
||||
if (m_i_len > len && !strncmpi(mons[i].pmnames[mgend], str, m_i_len)) {
|
||||
if (m_i_len == (int) slen) {
|
||||
m_i_len = strlen(mons[i].pmnames[mgend]);
|
||||
if (m_i_len > (size_t) len && !strncmpi(mons[i].pmnames[mgend], str, (int) m_i_len)) {
|
||||
if (m_i_len == slen) {
|
||||
mntmp = i;
|
||||
len = m_i_len;
|
||||
len = (int) m_i_len;
|
||||
matchgend = mgend;
|
||||
exact_match = TRUE;
|
||||
break; /* exact match */
|
||||
} else if ((int) slen > m_i_len
|
||||
} else if (slen > m_i_len
|
||||
&& (str[m_i_len] == ' '
|
||||
|| !strcmpi(&str[m_i_len], "s")
|
||||
|| !strncmpi(&str[m_i_len], "s ", 2)
|
||||
@@ -884,7 +884,7 @@ name_to_monplus(
|
||||
|| !strcmpi(&str[m_i_len], "es")
|
||||
|| !strncmpi(&str[m_i_len], "es ", 3))) {
|
||||
mntmp = i;
|
||||
len = m_i_len;
|
||||
len = (int) m_i_len;
|
||||
matchgend = mgend;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3196,7 +3196,7 @@ wizterrainwish(struct _readobjnam_data *d)
|
||||
const char *tname;
|
||||
|
||||
tname = trapname(trap, TRUE);
|
||||
if (strncmpi(tname, bp, strlen(tname)))
|
||||
if(!streq(tname, bp, TRUE))
|
||||
continue;
|
||||
/* found it; avoid stupid mistakes */
|
||||
if (is_hole(trap) && !Can_fall_thru(&u.uz))
|
||||
|
||||
@@ -6660,7 +6660,8 @@ msgtype_parse_add(char *str)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SIZE(msgtype_names); i++)
|
||||
if (!strncmpi(msgtype_names[i].name, msgtype, strlen(msgtype))) {
|
||||
if (streq(msgtype_names[i].name, msgtype, TRUE)) {
|
||||
//if (!strncmpi(msgtype_names[i].name, msgtype, strlen(msgtype))) {
|
||||
typ = msgtype_names[i].msgtyp;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user