2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * sarg.c: Parse selection arguments
30 * Known contributors to this file:
43 #include "prototypes.h"
49 * #1, lx:ly,hx:hy --> NS_AREA
50 * @x,y:dist --> NS_DIST
51 * %d or %d/%d/%d --> NS_LIST
54 * or 0 for none of the above.
57 sarg_type(s_char *ptr)
66 if (c == '#' || index(ptr, ',') != 0)
70 if (c == '~' || isupper(c) || islower(c))
76 sarg_xy(s_char *ptr, coord *xp, coord *yp)
78 if (sarg_type(ptr) != NS_AREA)
83 if (!isdigit(*ptr) && *ptr != '-')
86 inputxy(xp, yp, player->cnum);
92 /* returns absolute coords */
94 sarg_getrange(s_char *buf, register struct range *rp)
105 * realm #X where (X > 0 && X < MAXNOR)
106 * Assumes realms are in abs coordinates
110 if (rlm < 0 || rlm >= MAXNOR)
112 np = getnatp(player->cnum);
113 rp->lx = np->nat_b[rlm].b_xl;
114 rp->hx = np->nat_b[rlm].b_xh;
115 rp->ly = np->nat_b[rlm].b_yl;
116 rp->hy = np->nat_b[rlm].b_yh;
119 * full map specification
121 * ly, hy are optional.
123 if (!isdigit(c) && c != '-')
125 rp->lx = rp->hx = atoip(&bp);
132 if (!isdigit(c) && c != '-')
134 rp->ly = rp->hy = atoip(&bp);
139 inputxy(&rp->lx, &rp->ly, player->cnum);
140 inputxy(&rp->hx, &rp->hy, player->cnum);
147 * translate #1 or lx:ly,hx:hy into
148 * a result range struct
151 sarg_area(s_char *buf, register struct range *rp)
153 if (!sarg_getrange(buf, rp))
156 if (rp->hx >= WORLD_X)
159 if (rp->hy >= WORLD_Y)
166 * translate @x,y:int into
170 sarg_range(s_char *buf, coord *xp, coord *yp, int *dist)
175 if (bp == 0 || *bp == 0)
185 inputxy(xp, yp, player->cnum);
191 * list of idents; id/id/id/id/id
194 sarg_list(s_char *str, register int *list, int max)
202 for (i = 0; i < max; i++) {
203 if (!isdigit(*arg)) {
204 pr("Illegal character '%c'\n", *arg);
208 for (j = 0; j < i; j++) {
213 /* duplicate; ignore */
220 pr("Expecting '/', got '%c'\n", *arg);