From 9c31ef534efdf044ecf47a6a88f5eb8ae4261881 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 15 Mar 2017 21:23:31 +0100 Subject: [PATCH] cliopts testing with getter functions --- libft/includes/cliopts.h | 2 +- libft/includes/error.h | 10 ++++++---- libft/src/cliopts/cliopts_get.c | 21 +++++++++++---------- libft/src/error/error.c | 6 ++++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libft/includes/cliopts.h b/libft/includes/cliopts.h index 6182e387..2de89bd8 100644 --- a/libft/includes/cliopts.h +++ b/libft/includes/cliopts.h @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/libft/includes/error.h b/libft/includes/error.h index 7c00d0b2..e449af37 100644 --- a/libft/includes/error.h +++ b/libft/includes/error.h @@ -6,7 +6,7 @@ /* 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 { E_NOERR, - E_OPTINVS, - E_OPTINVC, - E_OPTARG, + E_CO_INV, + E_CO_INVL, + E_CO_MULT, + E_CO_MISS, + E_CO_MISSL, E_MAX, }; diff --git a/libft/src/cliopts/cliopts_get.c b/libft/src/cliopts/cliopts_get.c index 0882ed23..9aaea51f 100644 --- a/libft/src/cliopts/cliopts_get.c +++ b/libft/src/cliopts/cliopts_get.c @@ -6,14 +6,14 @@ /* 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` -** to do polymorphism with t_data_template ! -*/ + ** void *data must be a structure starting with `int flag` + ** to do polymorphism with t_data_template ! + */ # include "cliopts.h" @@ -50,14 +50,15 @@ static int cliopts_parse_short(char ***av, t_cliopts opt_map[], void *data) while (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 (!(arg[i - 1] == '-' && arg[i + 1] == 0)) - return (ERR_SET(E_OPTARG, *arg)); + return (ERR_SET(E_CO_MULT, *arg)); ++(*av); 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_off; @@ -75,14 +76,14 @@ static int cliopts_parse_long(char ***av, t_cliopts opt_map[], void *data) arg = **av + 2; 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_off; if (map->get) { ++(*av); if ((map->get)(av, data)) - return (1); + return (ERR_SET(E_CO_MISSL, arg)); } ++(*av); return (0); @@ -93,7 +94,7 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data) if (!av) return (1); av++; - while (*av) + while (av && *av) { if (ft_strcmp(*av, "--") == 0) return (0); diff --git a/libft/src/error/error.c b/libft/src/error/error.c index 267274ca..2c82901b 100644 --- a/libft/src/error/error.c +++ b/libft/src/error/error.c @@ -6,7 +6,7 @@ /* 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] = { "no error", - "invalid option --%s", "invalid option -%c", + "invalid option --%s", "option '%c' awaits argument(s): please don't combine", + "option '%c': missing argument", + "option '%s': missing argument", }; int g_errnum = 0;