"close brackets"
This commit is contained in:
Antoine Riard 2017-03-22 18:26:05 +01:00
commit 0f299d4b7e
3 changed files with 57 additions and 4 deletions

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/03/17 17:23:34 by gwojda ### ########.fr */ /* Updated: 2017/03/22 18:19:43 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -185,5 +185,6 @@ char *path_solver(t_comp *c, char *cmd, char *cwd);
int c_exclusion_folder(t_comp *c); int c_exclusion_folder(t_comp *c);
int ft_sstrlen(char **s); int ft_sstrlen(char **s);
char *ft_sstrtostr(char **s, char *sep); char *ft_sstrtostr(char **s, char *sep);
char *ft_add_escape(char *str, char to_escape);
#endif #endif

View file

@ -6,12 +6,61 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */
/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */ /* Updated: 2017/03/22 18:23:04 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "completion.h" #include "completion.h"
/*
** Count the number of time char c is in str.
*/
static size_t ft_strxchr(char *str, char c)
{
size_t rt;
rt = 0;
while(*str)
{
if (*str == c)
rt++;
str++;
}
return (rt);
}
/*
** Add escape char \ for char to_escape.
*/
char *ft_add_escape(char *str, char to_escape)
{
char *rt;
int i;
int j;
if (!str)
return (NULL);
if (!ft_strxchr(str, ' '))
return (ft_strdup(str));
rt = ft_strnew(ft_strlen(str) + ft_strxchr(str, to_escape));
i = 0;
j = 0;
while (str[i])
{
if (str[i] == to_escape)
{
i++;
rt[j++] = '\\';
rt[j++] = ' ';
}
else
rt[j++] = str[i++];
}
return (rt);
}
/* /*
** Support: Return the size of a char**. ** Support: Return the size of a char**.
*/ */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */
/* Updated: 2017/03/21 14:37:14 by gwojda ### ########.fr */ /* Updated: 2017/03/22 18:20:29 by alao ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,19 +53,22 @@ int c_updater(t_comp *c, char *select)
{ {
char *tmp; char *tmp;
char *rt; char *rt;
char *alter;
tmp = NULL; tmp = NULL;
rt = NULL; rt = NULL;
alter = ft_add_escape(select, ' ');
if (c->match) if (c->match)
tmp = ft_strsub(c->rcmd, 0, ft_strlen(c->rcmd) - ft_strlen(c->match)); tmp = ft_strsub(c->rcmd, 0, ft_strlen(c->rcmd) - ft_strlen(c->match));
else else
tmp = ft_strdup(c->rcmd); tmp = ft_strdup(c->rcmd);
rt = ft_strjoin(tmp, select); rt = ft_strjoin(tmp, alter);
tmp ? ft_memdel((void *)&tmp) : (0); tmp ? ft_memdel((void *)&tmp) : (0);
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
c->rcmd = ft_strdup(rt); c->rcmd = ft_strdup(rt);
c_updater_rcmd(c); c_updater_rcmd(c);
rt ? ft_memdel((void *)&rt) : (0); rt ? ft_memdel((void *)&rt) : (0);
alter ? ft_memdel((void *)&alter) : (0);
c_clear(data_singleton()); c_clear(data_singleton());
return (1); return (1);
} }