mise a jour des parentheses/accolades
This commit is contained in:
parent
288acbb378
commit
c77af3da9f
4 changed files with 87 additions and 27 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/04 14:50:04 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/04 18:16:37 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -113,9 +113,17 @@ typedef struct s_prompt_type
|
|||
char *new_prompt;
|
||||
} t_prompt_type;
|
||||
|
||||
typedef struct s_brackets
|
||||
{
|
||||
int pos;
|
||||
char tabl[100];
|
||||
} t_brackets;
|
||||
|
||||
extern t_key g_keys[];
|
||||
extern t_prompt_type g_prompt_tab[];
|
||||
extern t_brackets g_brackets;
|
||||
|
||||
void ft_reset_tab(char *tabl);
|
||||
void ft_putnc(char c, int n);
|
||||
int ft_nbr_len(int nbr);
|
||||
void ft_puttermcaps(char *str);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/04 14:51:44 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/04 18:26:59 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,8 @@ t_prompt_type g_prompt_tab[] =
|
|||
{0 , 0 , 0 },
|
||||
};
|
||||
|
||||
t_brackets g_brackets = {0 , {0}};
|
||||
|
||||
void ft_read_more(short c)
|
||||
{
|
||||
char *str_tmp;
|
||||
|
|
@ -33,35 +35,35 @@ void ft_read_more(short c)
|
|||
str_tmp2 = data_singleton()->line.input;
|
||||
str_tmp = ft_strjoin(str_tmp2, "\n");
|
||||
free(str_tmp2);
|
||||
data_singleton()->line.input = NULL;
|
||||
data_singleton()->line.pos = 0;
|
||||
STR = NULL;
|
||||
POS = 0;
|
||||
while (g_prompt_tab[i].key && !(g_prompt_tab[i].key & c))
|
||||
++i;
|
||||
data_singleton()->line.prompt_size = g_prompt_tab[i].value;
|
||||
ft_printf("\n%s", g_prompt_tab[i].new_prompt);
|
||||
str_tmp2 = ft_read_stdin();
|
||||
str_tmp2 = ft_strjoin(str_tmp, data_singleton()->line.input);
|
||||
str_tmp2 = ft_strjoin(str_tmp, STR);
|
||||
free(str_tmp);
|
||||
free(data_singleton()->line.input);
|
||||
data_singleton()->line.input = str_tmp2;
|
||||
free(STR);
|
||||
STR = str_tmp2;
|
||||
ft_check_line();
|
||||
}
|
||||
|
||||
void ft_check_this_char(char c, short *status)
|
||||
static void ft_check_this_char_quotes(char c, short *status)
|
||||
{
|
||||
int i;
|
||||
char *stats;
|
||||
|
||||
i = 0;
|
||||
stats = "\'`\"{(\\";
|
||||
stats = "\'`\"\\";
|
||||
while (stats[i] && stats[i] != c)
|
||||
++i;
|
||||
if (!stats[i])
|
||||
return ;
|
||||
if (((1 << i) & ~(*status)))
|
||||
if ((1 << i) & ~(*status))
|
||||
{
|
||||
if (((1 << i) > *status &&
|
||||
(*status == 0 && !(IS_QUOTES & *status) && (!(IS_DQUOTES & *status))))
|
||||
if (((1 << i) > *status && (*status == 0 && !(IS_QUOTES & *status)
|
||||
&& (!(IS_DQUOTES & *status))))
|
||||
|| (((1 << i) == IS_BQUOTES) && !(IS_QUOTES & *status)))
|
||||
(*status) = (*status) | (1 << i);
|
||||
}
|
||||
|
|
@ -69,6 +71,33 @@ void ft_check_this_char(char c, short *status)
|
|||
(*status) = (*status) ^ (1 << i);
|
||||
}
|
||||
|
||||
static int ft_brackets(char c)
|
||||
{
|
||||
if (c == '(')
|
||||
{
|
||||
g_brackets.tabl[g_brackets.pos] = '(';
|
||||
++g_brackets.pos;
|
||||
}
|
||||
else if (c == '{')
|
||||
{
|
||||
g_brackets.tabl[g_brackets.pos] = '{';
|
||||
++g_brackets.pos;
|
||||
}
|
||||
else if (c == '}')
|
||||
{
|
||||
if (!g_brackets.pos || g_brackets.tabl[g_brackets.pos - 1] != '{')
|
||||
return (1);
|
||||
g_brackets.tabl[--g_brackets.pos] = '\0';
|
||||
}
|
||||
else if (c == ')')
|
||||
{
|
||||
if (!g_brackets.pos || g_brackets.tabl[g_brackets.pos - 1] != '(')
|
||||
return (1);
|
||||
g_brackets.tabl[--g_brackets.pos] = '\0';
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_check_line(void)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -77,7 +106,9 @@ void ft_check_line(void)
|
|||
|
||||
i = 0;
|
||||
status = 0;
|
||||
str = data_singleton()->line.input;
|
||||
str = STR;
|
||||
ft_reset_tab((char *)g_brackets.tabl);
|
||||
g_brackets.pos = 0;
|
||||
if (!str)
|
||||
return ;
|
||||
while (str[i])
|
||||
|
|
@ -85,9 +116,17 @@ void ft_check_line(void)
|
|||
if (IS_BSLASH & status)
|
||||
status = status ^ IS_BSLASH;
|
||||
else
|
||||
ft_check_this_char(str[i], &status);
|
||||
{
|
||||
ft_check_this_char_quotes(str[i], &status);
|
||||
if (!status && ft_brackets(str[i]))
|
||||
return ;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (g_brackets.pos && g_brackets.tabl[0] == '(')
|
||||
status = status | IS_BRACKET;
|
||||
else if (g_brackets.pos && g_brackets.tabl[0] == '{')
|
||||
status = status | IS_ACCOLADE;
|
||||
if (status)
|
||||
ft_read_more(status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/04 15:36:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/04 16:35:33 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -47,11 +47,12 @@ void ft_up(void)
|
|||
i = 0;
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
if (!str)
|
||||
if (!str || !*pos)
|
||||
return ;
|
||||
if (str[*pos - 1] == '\n')
|
||||
{
|
||||
ft_puttermcaps("cd");
|
||||
if (*pos >= 2)
|
||||
(*pos) -= 2;
|
||||
ft_get_beggin(str, pos);
|
||||
ft_current_str(str, *pos);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/04 16:19:49 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/04 18:16:34 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -64,3 +64,15 @@ char *ft_strdupi(char const *s)
|
|||
}
|
||||
return (str);
|
||||
}
|
||||
|
||||
void ft_reset_tab(char *tabl)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tabl[i])
|
||||
{
|
||||
tabl[i] = '\0';
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue