(cnumb): Return the same error values as stmtch(). Callers don't
(yet) care for the difference.
This commit is contained in:
parent
c949d84774
commit
ffa21cf379
2 changed files with 19 additions and 13 deletions
|
@ -466,7 +466,7 @@ extern void caploss(struct sctstr *, natid, s_char *);
|
|||
extern int chkmoney(long, long, s_char *);
|
||||
extern int check_cost(int, int, long, int *, s_char *);
|
||||
/* cnumb.c */
|
||||
extern int cnumb(s_char *);
|
||||
extern int cnumb(char *);
|
||||
/* coastal.c */
|
||||
extern void set_coastal(struct sctstr *sp, int des);
|
||||
/* control.c */
|
||||
|
|
|
@ -37,19 +37,24 @@
|
|||
#include "player.h"
|
||||
#include "nat.h"
|
||||
#include "file.h"
|
||||
#include "match.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
/*
|
||||
* Search for a country matching CNTRY, return its number.
|
||||
* Return M_NOTFOUND if no such country exists, M_NOTUNIQUE if there
|
||||
* are several.
|
||||
*/
|
||||
int
|
||||
cnumb(s_char *cntry)
|
||||
cnumb(char *cntry)
|
||||
{
|
||||
register s_char *ncp;
|
||||
register s_char *cp;
|
||||
register struct natstr *natp;
|
||||
int bcount;
|
||||
natid best;
|
||||
char *ncp;
|
||||
char *cp;
|
||||
struct natstr *natp;
|
||||
int res;
|
||||
natid cn;
|
||||
|
||||
bcount = 0;
|
||||
res = M_NOTFOUND;
|
||||
for (cn = 0; cn < MAXNOC; cn++) {
|
||||
if ((natp = getnatp(cn)) == 0)
|
||||
break;
|
||||
|
@ -58,13 +63,14 @@ cnumb(s_char *cntry)
|
|||
ncp = natp->nat_cnam;
|
||||
for (cp = cntry; *cp == *ncp; cp++, ncp++) {
|
||||
if (*cp == 0)
|
||||
return cn;
|
||||
return cn; /* exact match */
|
||||
}
|
||||
if (*cp == 0) {
|
||||
best = cn;
|
||||
bcount++;
|
||||
/* is a prefix */
|
||||
if (res >= 0)
|
||||
return M_NOTUNIQUE;
|
||||
res = cn;
|
||||
}
|
||||
}
|
||||
/* can only have 1 match or not successful */
|
||||
return bcount == 1 ? (int)best : -1;
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue