2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, 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
45 #include "prototypes.h"
50 * Return index of sector called @name in dchr[], or M_NOTFOUND.
53 sct_typematch(char *name)
57 if (name[0] && !name[1])
58 for (i = 0; dchr[i].d_name; ++i)
59 if (dchr[i].d_mnem == *name)
65 * Search table @type for an element matching @name, return its index.
66 * Accepts EF_BAD, but of course never finds anything then.
67 * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
71 ef_elt_byname(int type, char *name)
79 return sct_typematch(name);
81 return stmtch(name, mchr,
82 offsetof(struct mchrstr, m_name),
85 return stmtch(name, lchr,
86 offsetof(struct lchrstr, l_name),
89 return stmtch(name, plchr,
90 offsetof(struct plchrstr, pl_name),
93 return stmtch(name, nchr,
94 offsetof(struct nchrstr, n_name),
97 return stmtch(name, ichr,
98 offsetof(struct ichrstr, i_name),
101 return stmtch(name, pchr,
102 offsetof(struct pchrstr, p_sname),
105 return stmtch(name, empfile,
106 offsetof(struct empfile, name),
109 if (ef_cadef(type) == symbol_ca)
110 return stmtch(name, ef_ptr(type, 0),
111 offsetof(struct symbol, name),
112 sizeof(struct symbol));