2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, 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 * sarg.c: Parse selection arguments
29 * Known contributors to this file:
31 * Markus Armbruster, 2004-2009
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
52 * ~ or letter --> NS_GROUP
55 * or 0 for none of the above.
67 if (c == '#' || strchr(str, ','))
71 if (c == '~' || isalpha(c))
77 sarg_xy(char *str, coord *xp, coord *yp)
82 x = strtox(str, &str);
83 if (x < 0 || *str++ != ',')
85 y = strtoy(str, &str);
86 if (y < 0 || (*str != 0 && !isspace(*str)))
90 np = getnatp(player->cnum);
97 * translate #1 or lx:ly,hx:hy into a result range struct
98 * returns absolute coords
101 sarg_area(char *str, struct range *rp)
105 struct realmstr realm;
110 * realm #X where (X > 0 && X < MAXNOR)
111 * Assumes realms are in abs coordinates
114 rlm = strtol(str, &end, 10);
115 if (end == str || (*end != 0 && !isspace(*end))
116 || rlm < 0 || MAXNOR <= rlm)
120 getrealm(rlm, player->cnum, &realm);
127 * full map specification
129 * ly, hy are optional.
131 rp->lx = rp->hx = strtox(str, &str);
135 rp->hx = strtox(str + 1, &str);
141 rp->ly = rp->hy = strtoy(str, &str);
145 rp->hy = strtoy(str + 1, &str);
149 if (*str != 0 && !isspace(*str))
151 np = getnatp(player->cnum);
152 rp->lx = xabs(np, rp->lx);
153 rp->hx = xabs(np, rp->hx);
154 rp->ly = yabs(np, rp->ly);
155 rp->hy = yabs(np, rp->hy);
162 * translate @x,y:int into
166 sarg_range(char *str, coord *xp, coord *yp, int *dist)
175 x = strtox(str, &str);
176 if (x < 0 || *str++ != ',')
178 y = strtoy(str, &str);
179 if (y < 0 || *str++ != ':')
181 d = strtol(str, &end, 10);
182 if (end == str || (*end != 0 && !isspace(*end)) || d < 0)
185 np = getnatp(player->cnum);
192 * list of idents; id/id/id/id/id
195 sarg_list(char *str, int *list, int max)
203 n = strtol(str, &end, 10);
204 if (end == str || n < 0) {
205 pr("Illegal character '%c'\n", *str);
208 for (j = 0; j < i; j++) {
214 pr("List too long (limit is %d)\n", max);
220 } while (*str++ == '/');
222 if (str[-1] != 0 && !isspace(str[-1])) {
223 pr("Expecting '/', got '%c'\n", str[-1]);