2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * type.c: typename to array offset translation
29 * Known contributors to this file:
32 * Markus Armbruster, 2004-2011
44 #include "prototypes.h"
49 * Return index of sector called @name in dchr[], or M_NOTFOUND.
52 sct_typematch(char *name)
56 if (name[0] && !name[1])
57 for (i = 0; dchr[i].d_name; ++i)
58 if (dchr[i].d_mnem == *name)
64 * Search table @type for an element matching @name, return its index.
65 * Accepts EF_BAD, but of course never finds anything then.
66 * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
70 ef_elt_byname(int type, char *name)
78 return sct_typematch(name);
80 return stmtch(name, mchr,
81 offsetof(struct mchrstr, m_name),
84 return stmtch(name, lchr,
85 offsetof(struct lchrstr, l_name),
88 return stmtch(name, plchr,
89 offsetof(struct plchrstr, pl_name),
92 return stmtch(name, nchr,
93 offsetof(struct nchrstr, n_name),
96 return stmtch(name, ichr,
97 offsetof(struct ichrstr, i_name),
100 return stmtch(name, pchr,
101 offsetof(struct pchrstr, p_sname),
104 return stmtch(name, empfile,
105 offsetof(struct empfile, name),
108 if (ef_cadef(type) == symbol_ca)
109 return stmtch(name, ef_ptr(type, 0),
110 offsetof(struct symbol, name),
111 sizeof(struct symbol));