(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 */
|
/* stmtch.c */
|
||||||
/* in match.h */
|
/* in match.h */
|
||||||
/* type.c */
|
/* type.c */
|
||||||
extern int typematch(s_char *, int);
|
extern int sct_typematch(char *);
|
||||||
|
extern int typematch(char *, int);
|
||||||
/* vlist.c */
|
/* vlist.c */
|
||||||
extern int vl_find(register int, u_char *, u_short *, int);
|
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);
|
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(§))
|
if (!check_sect_ok(§))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
des = typematch(p, EF_SECTOR);
|
des = sct_typematch(p);
|
||||||
if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
|
if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) &&
|
||||||
!player->god)) {
|
!player->god)) {
|
||||||
pr("See \"info Sector-types\"\n");
|
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;
|
sect->sct_dist_y = newy;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
des = typematch(p, EF_SECTOR);
|
des = sct_typematch(p);
|
||||||
if (des < 0)
|
if (des < 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
pr("Designation for sector %s changed from %c to %c\n",
|
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;
|
sect->sct_type = des;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
des = typematch(p, EF_SECTOR);
|
des = sct_typematch(p);
|
||||||
if (des < 0)
|
if (des < 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
pr("New Designation for sector %s changed from %c to %c\n",
|
pr("New Designation for sector %s changed from %c to %c\n",
|
||||||
|
|
|
@ -61,7 +61,7 @@ shar(void)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
|
||||||
if (player->argp[3] && *player->argp[3]) {
|
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;
|
return RET_SYN;
|
||||||
else
|
else
|
||||||
des = *player->argp[3];
|
des = *player->argp[3];
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
* Steve McClure, 2000
|
* Steve McClure, 2000
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
@ -41,59 +42,56 @@
|
||||||
#include "nuke.h"
|
#include "nuke.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "match.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return index of sector called NAME in dchr[], or M_NOTFOUND.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
typematch(s_char *buf, int type)
|
sct_typematch(char *name)
|
||||||
{
|
{
|
||||||
register int n;
|
int i;
|
||||||
int len;
|
|
||||||
|
|
||||||
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) {
|
switch (type) {
|
||||||
case EF_SECTOR:{
|
case EF_SECTOR:
|
||||||
register struct dchrstr *dcp;
|
return sct_typematch(name);
|
||||||
|
case EF_SHIP:
|
||||||
if (!buf[0] || buf[1])
|
return stmtch(name, mchr,
|
||||||
return -1;
|
offsetof(struct mchrstr, m_name),
|
||||||
for (dcp = dchr, n = 0; dcp->d_name; n++, dcp++)
|
sizeof(mchr[0]));
|
||||||
if (dcp->d_mnem == *buf)
|
case EF_LAND:
|
||||||
return n;
|
return stmtch(name, lchr,
|
||||||
}
|
offsetof(struct lchrstr, l_name),
|
||||||
break;
|
sizeof(lchr[0]));
|
||||||
case EF_SHIP:{
|
case EF_PLANE:
|
||||||
register struct mchrstr *mcp;
|
return stmtch(name, plchr,
|
||||||
|
offsetof(struct plchrstr, pl_name),
|
||||||
for (mcp = mchr, n = 0; *mcp->m_name; n++, mcp++)
|
sizeof(plchr[0]));
|
||||||
if (strncmp(mcp->m_name, buf, len) == 0)
|
case EF_NUKE:
|
||||||
return n;
|
return stmtch(name, nchr,
|
||||||
}
|
offsetof(struct nchrstr, n_name),
|
||||||
break;
|
sizeof(nchr[0]));
|
||||||
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;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return -1;
|
return M_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue