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:
44 #include "prototypes.h"
50 * #1, lx:ly,hx:hy --> NS_AREA
51 * @x,y:dist --> NS_DIST
52 * %d or %d/%d/%d --> NS_LIST
55 * or 0 for none of the above.
58 sarg_type(s_char *ptr)
67 if (c == '#' || strchr(ptr, ',') != 0)
71 if (c == '~' || isupper(c) || islower(c))
77 sarg_xy(s_char *ptr, coord *xp, coord *yp)
79 if (sarg_type(ptr) != NS_AREA)
84 if (!isdigit(*ptr) && *ptr != '-')
87 inputxy(xp, yp, player->cnum);
93 /* returns absolute coords */
95 sarg_getrange(s_char *buf, register struct range *rp)
106 * realm #X where (X > 0 && X < MAXNOR)
107 * Assumes realms are in abs coordinates
111 if (rlm < 0 || rlm >= MAXNOR)
113 np = getnatp(player->cnum);
114 rp->lx = np->nat_b[rlm].b_xl;
115 rp->hx = np->nat_b[rlm].b_xh;
116 rp->ly = np->nat_b[rlm].b_yl;
117 rp->hy = np->nat_b[rlm].b_yh;
120 * full map specification
122 * ly, hy are optional.
124 if (!isdigit(c) && c != '-')
126 rp->lx = rp->hx = atoip(&bp);
133 if (!isdigit(c) && c != '-')
135 rp->ly = rp->hy = atoip(&bp);
140 inputxy(&rp->lx, &rp->ly, player->cnum);
141 inputxy(&rp->hx, &rp->hy, player->cnum);
148 * translate #1 or lx:ly,hx:hy into
149 * a result range struct
152 sarg_area(s_char *buf, register struct range *rp)
154 if (!sarg_getrange(buf, rp))
157 if (rp->hx >= WORLD_X)
160 if (rp->hy >= WORLD_Y)
167 * translate @x,y:int into
171 sarg_range(s_char *buf, coord *xp, coord *yp, int *dist)
176 if (bp == 0 || *bp == 0)
186 inputxy(xp, yp, player->cnum);
192 * list of idents; id/id/id/id/id
195 sarg_list(s_char *str, register int *list, int max)
203 for (i = 0; i < max; i++) {
204 if (!isdigit(*arg)) {
205 pr("Illegal character '%c'\n", *arg);
209 for (j = 0; j < i; j++) {
214 /* duplicate; ignore */
221 pr("Expecting '/', got '%c'\n", *arg);