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-2010
42 #include "prototypes.h"
48 * #1, lx:ly,hx:hy --> NS_AREA
49 * @x,y:dist --> NS_DIST
50 * %d or %d/%d/%d --> NS_LIST
51 * ~ or letter --> NS_GROUP
54 * or 0 for none of the above.
66 if (c == '#' || strchr(str, ','))
70 if (c == '~' || isalpha(c))
76 sarg_xy(char *str, coord *xp, coord *yp)
81 x = strtox(str, &str);
82 if (x < 0 || *str++ != ',')
84 y = strtoy(str, &str);
85 if (y < 0 || (*str != 0 && !isspace(*str)))
89 np = getnatp(player->cnum);
96 * translate #1 or lx:ly,hx:hy into a result range struct
97 * returns absolute coords
100 sarg_area(char *str, struct range *rp)
104 struct realmstr realm;
109 * realm #X where (X > 0 && X < MAXNOR)
110 * Assumes realms are in abs coordinates
113 rlm = strtol(str, &end, 10);
114 if (end == str || (*end != 0 && !isspace(*end))
115 || rlm < 0 || MAXNOR <= rlm)
119 getrealm(rlm, player->cnum, &realm);
126 * full map specification
128 * ly, hy are optional.
130 rp->lx = rp->hx = strtox(str, &str);
134 rp->hx = strtox(str + 1, &str);
140 rp->ly = rp->hy = strtoy(str, &str);
144 rp->hy = strtoy(str + 1, &str);
148 if (*str != 0 && !isspace(*str))
150 np = getnatp(player->cnum);
151 rp->lx = xabs(np, rp->lx);
152 rp->hx = xabs(np, rp->hx);
153 rp->ly = yabs(np, rp->ly);
154 rp->hy = yabs(np, rp->hy);
161 * translate @x,y:int into
165 sarg_range(char *str, coord *xp, coord *yp, int *dist)
174 x = strtox(str, &str);
175 if (x < 0 || *str++ != ',')
177 y = strtoy(str, &str);
178 if (y < 0 || *str++ != ':')
180 d = strtol(str, &end, 10);
181 if (end == str || (*end != 0 && !isspace(*end)) || d < 0)
184 np = getnatp(player->cnum);
191 * list of idents; id/id/id/id/id
194 sarg_list(char *str, int *list, int max)
202 n = strtol(str, &end, 10);
203 if (end == str || n < 0) {
204 pr("Illegal character '%c'\n", *str);
207 for (j = 0; j < i; j++) {
213 pr("List too long (limit is %d)\n", max);
219 } while (*str++ == '/');
221 if (str[-1] != 0 && !isspace(str[-1])) {
222 pr("Expecting '/', got '%c'\n", str[-1]);