(sct_typematch): New. Use it instead of typematch() where
appropriate. (typematch): Prefer exact match to partial match. Use plain char instead of s_char.
This commit is contained in:
parent
844b654d44
commit
f5e49a830c
5 changed files with 51 additions and 52 deletions
|
@ -176,7 +176,8 @@ extern void snxtsct_dist(register struct nstr_sect *, coord, coord, int);
|
|||
/* stmtch.c */
|
||||
/* in match.h */
|
||||
/* type.c */
|
||||
extern int typematch(s_char *, int);
|
||||
extern int sct_typematch(char *);
|
||||
extern int typematch(char *, int);
|
||||
/* vlist.c */
|
||||
extern int vl_find(register int, u_char *, u_short *, int);
|
||||
extern int vl_set(register int, u_int, u_char *, u_short *, u_char *, int);
|
||||
|
|
|
@ -118,7 +118,7 @@ do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash,
|
|||
if (!check_sect_ok(§))
|
||||
continue;
|
||||
|
||||
des = typematch(p, EF_SECTOR);
|
||||
des = sct_typematch(p);
|
||||
if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
|
||||
!player->god)) {
|
||||
pr("See \"info Sector-types\"\n");
|
||||
|
|
|
@ -641,7 +641,7 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
|
|||
sect->sct_dist_y = newy;
|
||||
break;
|
||||
case 's':
|
||||
des = typematch(p, EF_SECTOR);
|
||||
des = sct_typematch(p);
|
||||
if (des < 0)
|
||||
return RET_SYN;
|
||||
pr("Designation for sector %s changed from %c to %c\n",
|
||||
|
@ -650,7 +650,7 @@ doland(s_char op, int arg, s_char *p, struct sctstr *sect)
|
|||
sect->sct_type = des;
|
||||
break;
|
||||
case 'S':
|
||||
des = typematch(p, EF_SECTOR);
|
||||
des = sct_typematch(p);
|
||||
if (des < 0)
|
||||
return RET_SYN;
|
||||
pr("New Designation for sector %s changed from %c to %c\n",
|
||||
|
|
|
@ -61,7 +61,7 @@ shar(void)
|
|||
return RET_SYN;
|
||||
|
||||
if (player->argp[3] && *player->argp[3]) {
|
||||
if (typematch(player->argp[3], EF_SECTOR) < 0)
|
||||
if (sct_typematch(player->argp[3]) < 0)
|
||||
return RET_SYN;
|
||||
else
|
||||
des = *player->argp[3];
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
* Steve McClure, 2000
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "misc.h"
|
||||
#include "ship.h"
|
||||
|
@ -41,59 +42,56 @@
|
|||
#include "nuke.h"
|
||||
#include "file.h"
|
||||
#include "common.h"
|
||||
#include "match.h"
|
||||
|
||||
/*
|
||||
* Return index of sector called NAME in dchr[], or M_NOTFOUND.
|
||||
*/
|
||||
int
|
||||
typematch(s_char *buf, int type)
|
||||
sct_typematch(char *name)
|
||||
{
|
||||
register int n;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
len = strlen(buf);
|
||||
if (name[0] && !name[1])
|
||||
for (i = 0; dchr[i].d_name; ++i)
|
||||
if (dchr[i].d_mnem == *name)
|
||||
return i;
|
||||
return M_NOTFOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for NAME in the characteristics table for TYPE, return index.
|
||||
* Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
|
||||
* several.
|
||||
* If TYPE is EF_SHIP, search mchr[].
|
||||
* If TYPE is EF_PLANE, search plchr[].
|
||||
* If TYPE is EF_LAND, search lchr[].
|
||||
* If TYPE is EF_NUKE, search nchr[].
|
||||
*/
|
||||
int
|
||||
typematch(char *name, int type)
|
||||
{
|
||||
switch (type) {
|
||||
case EF_SECTOR:{
|
||||
register struct dchrstr *dcp;
|
||||
|
||||
if (!buf[0] || buf[1])
|
||||
return -1;
|
||||
for (dcp = dchr, n = 0; dcp->d_name; n++, dcp++)
|
||||
if (dcp->d_mnem == *buf)
|
||||
return n;
|
||||
}
|
||||
break;
|
||||
case EF_SHIP:{
|
||||
register struct mchrstr *mcp;
|
||||
|
||||
for (mcp = mchr, n = 0; *mcp->m_name; n++, mcp++)
|
||||
if (strncmp(mcp->m_name, buf, len) == 0)
|
||||
return n;
|
||||
}
|
||||
break;
|
||||
case EF_LAND:{
|
||||
register struct lchrstr *lcp;
|
||||
|
||||
for (lcp = lchr, n = 0; *lcp->l_name; n++, lcp++)
|
||||
if (strncmp(lcp->l_name, buf, len) == 0)
|
||||
return n;
|
||||
}
|
||||
break;
|
||||
case EF_PLANE:{
|
||||
register struct plchrstr *pcp;
|
||||
|
||||
for (pcp = plchr, n = 0; *pcp->pl_name; n++, pcp++)
|
||||
if (strncmp(pcp->pl_name, buf, len) == 0)
|
||||
return n;
|
||||
}
|
||||
break;
|
||||
case EF_NUKE:{
|
||||
register struct nchrstr *ncp;
|
||||
|
||||
for (ncp = nchr, n = 0; *ncp->n_name; n++, ncp++)
|
||||
if (strncmp(ncp->n_name, buf, len) == 0)
|
||||
return n;
|
||||
}
|
||||
break;
|
||||
case EF_SECTOR:
|
||||
return sct_typematch(name);
|
||||
case EF_SHIP:
|
||||
return stmtch(name, mchr,
|
||||
offsetof(struct mchrstr, m_name),
|
||||
sizeof(mchr[0]));
|
||||
case EF_LAND:
|
||||
return stmtch(name, lchr,
|
||||
offsetof(struct lchrstr, l_name),
|
||||
sizeof(lchr[0]));
|
||||
case EF_PLANE:
|
||||
return stmtch(name, plchr,
|
||||
offsetof(struct plchrstr, pl_name),
|
||||
sizeof(plchr[0]));
|
||||
case EF_NUKE:
|
||||
return stmtch(name, nchr,
|
||||
offsetof(struct nchrstr, n_name),
|
||||
sizeof(nchr[0]));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
return M_NOTFOUND;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue