Factor parse_map_arg() out of do_map()
This commit is contained in:
parent
78fd95f67c
commit
619b3def31
1 changed files with 29 additions and 17 deletions
|
@ -70,6 +70,7 @@
|
||||||
/* whether to revert bmap, internal to do_map() */
|
/* whether to revert bmap, internal to do_map() */
|
||||||
#define MAP_BMAP_REVERT bit(7)
|
#define MAP_BMAP_REVERT bit(7)
|
||||||
|
|
||||||
|
static int parse_map_arg(int, char *, struct nstr_sect *, char *);
|
||||||
static int parse_map_flags(int, char *);
|
static int parse_map_flags(int, char *);
|
||||||
static int revert_bmap(struct nstr_sect *);
|
static int revert_bmap(struct nstr_sect *);
|
||||||
static int draw_map(char, int, struct nstr_sect *);
|
static int draw_map(char, int, struct nstr_sect *);
|
||||||
|
@ -78,27 +79,17 @@ static char map_char(int, natid, int);
|
||||||
static int unit_map(int, int, struct nstr_sect *, char *);
|
static int unit_map(int, int, struct nstr_sect *, char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
do_map(int bmap, int unit_type, char *arg, char *map_flags_arg)
|
do_map(int bmap, int unit_type, char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
char origin = '\0';
|
char origin;
|
||||||
int map_flags;
|
int res, map_flags;
|
||||||
|
|
||||||
switch (sarg_type(arg)) {
|
res = parse_map_arg(unit_type, arg1, &ns, &origin);
|
||||||
case NS_DIST:
|
if (res != RET_OK)
|
||||||
case NS_AREA:
|
return res;
|
||||||
case NS_ALL:
|
|
||||||
if (!snxtsct(&ns, arg))
|
|
||||||
return RET_SYN;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (unit_map(unit_type, atoi(arg), &ns, &origin) < 0) {
|
|
||||||
pr("No such %s\n", ef_nameof(unit_type));
|
|
||||||
return RET_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
map_flags = parse_map_flags(bmap, map_flags_arg);
|
map_flags = parse_map_flags(bmap, arg2);
|
||||||
if (map_flags < 0)
|
if (map_flags < 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
|
||||||
|
@ -107,6 +98,27 @@ do_map(int bmap, int unit_type, char *arg, char *map_flags_arg)
|
||||||
return draw_map(origin, map_flags, &ns);
|
return draw_map(origin, map_flags, &ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
parse_map_arg(int unit_type, char *arg,
|
||||||
|
struct nstr_sect *nsp, char *originp)
|
||||||
|
{
|
||||||
|
switch (sarg_type(arg)) {
|
||||||
|
case NS_DIST:
|
||||||
|
case NS_AREA:
|
||||||
|
case NS_ALL:
|
||||||
|
if (!snxtsct(nsp, arg))
|
||||||
|
return RET_SYN;
|
||||||
|
*originp = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (unit_map(unit_type, atoi(arg), nsp, originp) < 0) {
|
||||||
|
pr("No such %s\n", ef_nameof(unit_type));
|
||||||
|
return RET_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
warn_deprecated_arg(char *what, char *arg, char *use)
|
warn_deprecated_arg(char *what, char *arg, char *use)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue