cliopts testing with getter functions

This commit is contained in:
Jack Halford 2017-03-15 21:23:31 +01:00
parent 4ab87feccb
commit 72ab154c49
4 changed files with 22 additions and 17 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:39:31 by jhalford ### ########.fr */ /* Updated: 2017/03/15 19:00:17 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
/* Updated: 2017/03/14 20:25:26 by jhalford ### ########.fr */ /* Updated: 2017/03/15 20:45:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,9 +27,11 @@
enum e_errors enum e_errors
{ {
E_NOERR, E_NOERR,
E_OPTINVS, E_CO_INV,
E_OPTINVC, E_CO_INVL,
E_OPTARG, E_CO_MULT,
E_CO_MISS,
E_CO_MISSL,
E_MAX, E_MAX,
}; };

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */ /* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:43:06 by jhalford ### ########.fr */ /* Updated: 2017/03/15 21:18:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,14 +50,15 @@ static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data)
while (arg[i]) while (arg[i])
{ {
if (!(map = get_map_short(opt_map, arg[i]))) if (!(map = get_map_short(opt_map, arg[i])))
return (ERR_SET(E_OPTINVC, arg[i])); return (ERR_SET(E_CO_INV, arg[i]));
if (map->get) if (map->get)
{ {
if (!(arg[i - 1] == '-' && arg[i + 1] == 0)) if (!(arg[i - 1] == '-' && arg[i + 1] == 0))
return (ERR_SET(E_OPTARG, *arg)); return (ERR_SET(E_CO_MULT, *arg));
++(*av); ++(*av);
if ((map->get)(av, data)) if ((map->get)(av, data))
return (1); return (ERR_SET(E_CO_MISS, *arg));
break;
} }
((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag |= map->flag_on;
((t_data_template*)data)->flag &= ~map->flag_off; ((t_data_template*)data)->flag &= ~map->flag_off;
@ -75,14 +76,14 @@ static int cliopts_parse_long(char ***av, t_cliopts opt_map[], void *data)
arg = **av + 2; arg = **av + 2;
if (!(map = get_map_long(opt_map, arg))) if (!(map = get_map_long(opt_map, arg)))
return (ERR_SET(E_OPTINVS, arg)); return (ERR_SET(E_CO_INVL, arg));
((t_data_template*)data)->flag |= map->flag_on; ((t_data_template*)data)->flag |= map->flag_on;
((t_data_template*)data)->flag &= ~map->flag_off; ((t_data_template*)data)->flag &= ~map->flag_off;
if (map->get) if (map->get)
{ {
++(*av); ++(*av);
if ((map->get)(av, data)) if ((map->get)(av, data))
return (1); return (ERR_SET(E_CO_MISSL, arg));
} }
++(*av); ++(*av);
return (0); return (0);
@ -93,7 +94,7 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data)
if (!av) if (!av)
return (1); return (1);
av++; av++;
while (*av) while (av && *av)
{ {
if (ft_strcmp(*av, "--") == 0) if (ft_strcmp(*av, "--") == 0)
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */ /* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
/* Updated: 2017/03/14 20:26:46 by jhalford ### ########.fr */ /* Updated: 2017/03/15 20:45:41 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,9 +15,11 @@
char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] = char g_error_msglist[E_MAX][ERRMSG_MAX_SIZE] =
{ {
"no error", "no error",
"invalid option --%s",
"invalid option -%c", "invalid option -%c",
"invalid option --%s",
"option '%c' awaits argument(s): please don't combine", "option '%c' awaits argument(s): please don't combine",
"option '%c': missing argument",
"option '%s': missing argument",
}; };
int g_errnum = 0; int g_errnum = 0;