cliopts testing with getter functions
This commit is contained in:
parent
9220a523cb
commit
9c31ef534e
4 changed files with 22 additions and 17 deletions
|
|
@ -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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** void *data must be a structure starting with `int flag`
|
** void *data must be a structure starting with `int flag`
|
||||||
** to do polymorphism with t_data_template !
|
** to do polymorphism with t_data_template !
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include "cliopts.h"
|
# include "cliopts.h"
|
||||||
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue