/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
#include <config.h>
-#include "misc.h"
-#include "player.h"
-#include "nat.h"
#include "file.h"
+#include "match.h"
+#include "nat.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;
+ if (natp->nat_stat == STAT_UNUSED)
+ continue;
ncp = natp->nat_cnam;
for (cp = cntry; *cp == *ncp; cp++, ncp++) {
if (*cp == 0)
- return cn;
+ return cn; /* exact match */
}
- if (cp > cntry && *cp == 0) {
- best = cn;
- bcount++;
+ if (*cp == 0) {
+ /* 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;
}