heredoc whitespace
This commit is contained in:
commit
8b6fd7bb1d
21 changed files with 116 additions and 57 deletions
|
|
@ -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/27 17:42:17 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 08:13:56 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -179,6 +179,10 @@ void c_printer(t_comp *c);
|
||||||
** c_exclusion_foldr : Check for match folder.
|
** c_exclusion_foldr : Check for match folder.
|
||||||
** ft_sstrlen : Return size of char **.
|
** ft_sstrlen : Return size of char **.
|
||||||
** ft_sstrtostr : Create char * from char ** with char *sep between.
|
** ft_sstrtostr : Create char * from char ** with char *sep between.
|
||||||
|
** ft_add_escape : Add escape char to str.
|
||||||
|
** c_lst_id : Repair ID list.
|
||||||
|
** c_is_delim : Check char for specific one.
|
||||||
|
** c_strdupi : Dupe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c_clear(t_data *s);
|
int c_clear(t_data *s);
|
||||||
|
|
@ -189,6 +193,7 @@ 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);
|
char *ft_add_escape(char *str, char to_escape);
|
||||||
void c_lst_id(t_comp *c);
|
void c_lst_id(t_comp *c);
|
||||||
|
int c_is_delim(char c);
|
||||||
char *c_strdupi(char *s, int (*f)(char));
|
char *c_strdupi(char *s, int (*f)(char));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 15:46:34 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 20:22:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -135,7 +135,6 @@ struct s_exec
|
||||||
int fdin;
|
int fdin;
|
||||||
t_list *op_stack;
|
t_list *op_stack;
|
||||||
char **case_pattern;
|
char **case_pattern;
|
||||||
int control_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int exec_init(t_exec *exec);
|
int exec_init(t_exec *exec);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: jhalford <jack@crans.org> +#+ +:+ +#+ #
|
# By: jhalford <jack@crans.org> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2017/02/07 16:09:36 by jhalford #+# #+# #
|
# Created: 2017/02/07 16:09:36 by jhalford #+# #+# #
|
||||||
# Updated: 2017/03/23 16:49:31 by gwojda ### ########.fr #
|
# Updated: 2017/03/27 21:59:31 by gwojda ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ RM = /bin/rm -rf
|
||||||
|
|
||||||
W_FLAGS = -Wall -Wextra -Werror -g
|
W_FLAGS = -Wall -Wextra -Werror -g
|
||||||
D_FLAGS = -g
|
D_FLAGS = -g
|
||||||
V_FLAGS = -fvisibility=hidden
|
V_FLAGS = #-fvisibility=hidden
|
||||||
FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS)
|
FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS)
|
||||||
|
|
||||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/25 18:20:42 by ariard #+# #+# */
|
/* Created: 2017/03/25 18:20:42 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/27 18:08:13 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 20:15:45 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,8 +20,8 @@
|
||||||
#define CDERR_0 "cd: too many arguments"
|
#define CDERR_0 "cd: too many arguments"
|
||||||
#define CDERR_1 "cd %s not set"
|
#define CDERR_1 "cd %s not set"
|
||||||
#define CDERR_2 "cd : %s: No such file or directory"
|
#define CDERR_2 "cd : %s: No such file or directory"
|
||||||
#define CDERR_3 "cd : %s: Permission denied"
|
#define CDERR_3 "cd : %s: Not a directory"
|
||||||
#define CDERR_4 "cd : %s: Not a directory"
|
#define CDERR_4 "cd : %s: Permission denied"
|
||||||
#define CDERR_5 "cd : unable to proceed: %s"
|
#define CDERR_5 "cd : unable to proceed: %s"
|
||||||
|
|
||||||
static t_cliopts g_cdopts[] =
|
static t_cliopts g_cdopts[] =
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,27 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/27 18:51:59 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 08:15:31 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static int c_is_delim(char c)
|
/*
|
||||||
|
** Check char
|
||||||
|
*/
|
||||||
|
|
||||||
|
int c_is_delim(char c)
|
||||||
{
|
{
|
||||||
if (c == ' ' || c == '<' || c == '>' || c == '\n' || c == ';')
|
if (c == ' ' || c == '<' || c == '>' || c == '\n' || c == ';')
|
||||||
return (1);
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** strdupi
|
||||||
|
*/
|
||||||
|
|
||||||
char *c_strdupi(char *s, int (*f)(char))
|
char *c_strdupi(char *s, int (*f)(char))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,28 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 16:09:08 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
|
static char *c_current_words(void)
|
||||||
|
{
|
||||||
|
size_t pos;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
pos = data_singleton()->line.pos;
|
||||||
|
str = data_singleton()->line.input;
|
||||||
|
if (pos && c_is_delim(str[pos]))
|
||||||
|
--pos;
|
||||||
|
while (pos && !c_is_delim(str[pos]))
|
||||||
|
--pos;
|
||||||
|
if (c_is_delim(str[pos]))
|
||||||
|
++pos;
|
||||||
|
return (c_strdupi(str + pos, &c_is_delim));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Recreate a c->match value by adding the new key pressed to it.
|
** Recreate a c->match value by adding the new key pressed to it.
|
||||||
*/
|
*/
|
||||||
|
|
@ -20,17 +36,22 @@ static int c_refresh_match(t_comp *c, long int keypress)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char kpconv[2];
|
char kpconv[2];
|
||||||
|
char *dump;
|
||||||
|
|
||||||
kpconv[0] = (char)keypress;
|
kpconv[0] = (char)keypress;
|
||||||
kpconv[1] = '\0';
|
kpconv[1] = '\0';
|
||||||
tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv);
|
tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv);
|
||||||
c->match ? ft_memdel((void *)&c->match) : (0);
|
c->match ? ft_memdel((void *)&c->match) : (0);
|
||||||
|
dump = c_current_words();
|
||||||
|
if (!(ft_strchr(dump, '$')))
|
||||||
|
c->match = ft_strdup(tmp);
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
tmp = ft_strjoin(c->rcmd, kpconv);
|
tmp = ft_strjoin(c->rcmd, kpconv);
|
||||||
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
|
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
|
||||||
c->rcmd = ft_strdup(tmp);
|
c->rcmd = ft_strdup(tmp);
|
||||||
c->ircmd++;
|
c->ircmd++;
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
dump ? ft_memdel((void *)&dump) : (0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
|
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/24 14:52:00 by ariard ### ########.fr */
|
/* Updated: 2017/03/28 20:29:55 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,6 +27,7 @@ int plaunch_for(t_process *p)
|
||||||
return (SH_ERR(FORERR_0, var));
|
return (SH_ERR(FORERR_0, var));
|
||||||
i = 0;
|
i = 0;
|
||||||
av = token_to_argv(temp, 1);
|
av = token_to_argv(temp, 1);
|
||||||
|
data_singleton()->exec.job.attrs &= ~JOB_BG;
|
||||||
while (av[++i])
|
while (av[++i])
|
||||||
{
|
{
|
||||||
builtin_setenv("setenv", (char*[]){"local", var, av[i], 0},
|
builtin_setenv("setenv", (char*[]){"local", var, av[i], 0},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
|
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/22 19:22:56 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 20:30:19 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@ int plaunch_until(t_process *p)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
data_singleton()->exec.job.attrs &= ~JOB_BG;
|
||||||
ft_exec(&p->data.d_until.condition);
|
ft_exec(&p->data.d_until.condition);
|
||||||
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/24 22:43:37 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 20:29:54 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@ int plaunch_while(t_process *p)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
data_singleton()->exec.job.attrs &= ~JOB_BG;
|
||||||
ft_exec(&p->data.d_while.condition);
|
ft_exec(&p->data.d_while.condition);
|
||||||
while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")))
|
while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 16:46:26 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 20:29:23 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,12 +16,12 @@ int process_fork(t_process *p)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (!p)
|
|
||||||
return (0);
|
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
exit(SH_ERR("fork(): %s", strerror(errno)));
|
exit(SH_ERR("fork(): %s", strerror(errno)));
|
||||||
else if (pid != 0)
|
else if (pid != 0)
|
||||||
return (pid);
|
return (pid);
|
||||||
|
if (!p)
|
||||||
|
return (0);
|
||||||
exec_destroy(&data_singleton()->exec);
|
exec_destroy(&data_singleton()->exec);
|
||||||
jobc_destroy(&data_singleton()->jobc);
|
jobc_destroy(&data_singleton()->jobc);
|
||||||
if ((pid = 1) && process_redirect(p) == 0)
|
if ((pid = 1) && process_redirect(p) == 0)
|
||||||
|
|
@ -39,8 +39,7 @@ int process_fork(t_process *p)
|
||||||
int process_launch(t_process *p)
|
int process_launch(t_process *p)
|
||||||
{
|
{
|
||||||
p->state = PROCESS_RUNNING;
|
p->state = PROCESS_RUNNING;
|
||||||
if (!IS_PIPESINGLE(*p)
|
if (!IS_PIPESINGLE(*p) || p->type == PROCESS_FILE
|
||||||
|| p->type == PROCESS_FILE
|
|
||||||
|| p->type == PROCESS_SUBSHELL)
|
|| p->type == PROCESS_SUBSHELL)
|
||||||
{
|
{
|
||||||
p->pid = process_fork(p);
|
p->pid = process_fork(p);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,18 @@
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static char *h_free_one(t_list **head, t_list *list, t_list *ref)
|
||||||
|
{
|
||||||
|
if (!((*head)->next))
|
||||||
|
ft_lstdelone(head, &ft_hash_free);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ref->next = list->next;
|
||||||
|
ft_lstdelone(&list, &ft_hash_free);
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
char *ft_is_hash(char *cmd)
|
char *ft_is_hash(char *cmd)
|
||||||
{
|
{
|
||||||
t_list *list;
|
t_list *list;
|
||||||
|
|
@ -25,12 +37,9 @@ char *ft_is_hash(char *cmd)
|
||||||
{
|
{
|
||||||
if (!ft_strcmp(((t_hash *)list->content)->key, cmd))
|
if (!ft_strcmp(((t_hash *)list->content)->key, cmd))
|
||||||
{
|
{
|
||||||
if (access(((t_hash *)list->content)->path, X_OK))
|
if (access(((t_hash *)list->content)->path,
|
||||||
{
|
X_OK | F_OK) < 0)
|
||||||
ref->next = list->next;
|
return (h_free_one(&g_hash[id], list, ref));
|
||||||
ft_lstdelone(&list, &ft_hash_free);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (ft_strdup(((t_hash *)list->content)->path));
|
return (ft_strdup(((t_hash *)list->content)->path));
|
||||||
}
|
}
|
||||||
ref = list;
|
ref = list;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 12:22:12 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -61,6 +61,8 @@ static int ft_modify_str(char *str_srch, size_t srch_pos, char **str,
|
||||||
*str = ft_strdup(*str);
|
*str = ft_strdup(*str);
|
||||||
ft_current_str(*str, *pos);
|
ft_current_str(*str, *pos);
|
||||||
ft_get_next_str(*str, pos);
|
ft_get_next_str(*str, pos);
|
||||||
|
if ((*str)[*pos])
|
||||||
|
++(*pos);
|
||||||
}
|
}
|
||||||
free(str_srch);
|
free(str_srch);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/27 19:49:31 by ariard ### ########.fr */
|
/* Updated: 2017/03/27 21:44:14 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -80,10 +80,7 @@ int get_reserved_words(t_list *temp)
|
||||||
if (recognization_rvwords(pv_tk, ante_token))
|
if (recognization_rvwords(pv_tk, ante_token))
|
||||||
match_words(token);
|
match_words(token);
|
||||||
if (token && token->type == TK_BANG && is_bang(pv_tk))
|
if (token && token->type == TK_BANG && is_bang(pv_tk))
|
||||||
{
|
|
||||||
DG("token type is %s", read_state(token->type));
|
|
||||||
token->type = TK_WORD;
|
token->type = TK_WORD;
|
||||||
}
|
|
||||||
if (ante_token && (ante_token->type == TK_CASE
|
if (ante_token && (ante_token->type == TK_CASE
|
||||||
|| ante_token->type == TK_FOR)
|
|| ante_token->type == TK_FOR)
|
||||||
&& ft_strncmp(token->data, "in", 2) == 0)
|
&& ft_strncmp(token->data, "in", 2) == 0)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,18 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
/* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 18:52:15 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 19:55:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static int is_spec_dquote_esc(char c)
|
||||||
|
{
|
||||||
|
return (c == '"' || c == '$' || c == '`'
|
||||||
|
|| c == '\\' || c == '!');
|
||||||
|
}
|
||||||
|
|
||||||
int lexer_dquote(t_list **alst, t_lexer *lexer)
|
int lexer_dquote(t_list **alst, t_lexer *lexer)
|
||||||
{
|
{
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
@ -19,18 +25,16 @@ int lexer_dquote(t_list **alst, t_lexer *lexer)
|
||||||
token = (*alst)->content;
|
token = (*alst)->content;
|
||||||
token->type = token->type ? token->type : TK_WORD;
|
token->type = token->type ? token->type : TK_WORD;
|
||||||
if (lexer->str[lexer->pos] == '"')
|
if (lexer->str[lexer->pos] == '"')
|
||||||
|
get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD) ?
|
||||||
|
pop(&lexer->stack) : push(&lexer->stack, DQUOTE) && 0;
|
||||||
|
else if (lexer->str[lexer->pos] == '\\')
|
||||||
{
|
{
|
||||||
if (get_lexer_stack(*lexer) == DQUOTE && (lexer->state = WORD))
|
if (lexer->str[++lexer->pos] == 0)
|
||||||
pop(&lexer->stack);
|
|
||||||
else
|
|
||||||
push(&lexer->stack, DQUOTE);
|
|
||||||
}
|
|
||||||
else if (lexer->str[lexer->pos] == '\\' && lexer->str[lexer->pos + 1] == 0)
|
|
||||||
{
|
|
||||||
lexer->pos++;
|
|
||||||
if (lexer->str[lexer->pos] == 0)
|
|
||||||
return (push(&lexer->stack, BACKSLASH) ? 0 : 0);
|
return (push(&lexer->stack, BACKSLASH) ? 0 : 0);
|
||||||
token_append(token, lexer, 1, 0);
|
else if (is_spec_dquote_esc(lexer->str[lexer->pos]))
|
||||||
|
token_append(token, lexer, 1, 1);
|
||||||
|
else if (--lexer->pos || 1)
|
||||||
|
token_append(token, lexer, 1, 1);
|
||||||
}
|
}
|
||||||
else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE))
|
else if (lexer->str[lexer->pos] == '`' && (lexer->state = BQUOTE))
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
|
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/21 10:03:23 by gwojda ### ########.fr */
|
/* Updated: 2017/03/27 22:06:09 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/21 10:14:46 by gwojda ### ########.fr */
|
/* Updated: 2017/03/27 22:07:39 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp)
|
||||||
++(*i);
|
++(*i);
|
||||||
ft_putnc('\b', *i - tmp);
|
ft_putnc('\b', *i - tmp);
|
||||||
(*i) = tmp;
|
(*i) = tmp;
|
||||||
if (ft_strlen(*str) == 0)
|
if (!**str)
|
||||||
ft_strdel(str);
|
ft_strdel(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,5 +105,7 @@ int ft_del(char **str, size_t *pos)
|
||||||
++(*pos);
|
++(*pos);
|
||||||
ft_putnc('\b', *pos - tmp);
|
ft_putnc('\b', *pos - tmp);
|
||||||
*pos = tmp;
|
*pos = tmp;
|
||||||
|
if (!**str)
|
||||||
|
ft_strdel(str);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/27 18:10:21 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 14:57:13 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ int readline(int has_prompt, char **input)
|
||||||
data_singleton()->line.prompt_size = 1;
|
data_singleton()->line.prompt_size = 1;
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
{
|
{
|
||||||
|
ft_strdel(input);
|
||||||
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
|
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
|
||||||
return (!ret);
|
return (!ret);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/28 23:19:27 by ariard ### ########.fr */
|
/* Updated: 2017/03/28 23:26:06 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,6 +32,22 @@ static int do_readline_routine(char **stream)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int exec_instruction(t_btree **ast, char **stream)
|
||||||
|
{
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
data = data_singleton();
|
||||||
|
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
|
||||||
|
ft_add_str_in_history(data->lexer.str);
|
||||||
|
else
|
||||||
|
ft_strdel(stream);
|
||||||
|
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
||||||
|
exit(1);
|
||||||
|
else if (data->parser.state != SUCCESS)
|
||||||
|
set_exitstatus(1, 1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
static int handle_instruction(t_list **token, t_btree **ast)
|
static int handle_instruction(t_list **token, t_btree **ast)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -46,20 +62,13 @@ static int handle_instruction(t_list **token, t_btree **ast)
|
||||||
return (ret);
|
return (ret);
|
||||||
if (do_lexer_routine(token, stream) > 0)
|
if (do_lexer_routine(token, stream) > 0)
|
||||||
continue ;
|
continue ;
|
||||||
token_print(*token);
|
|
||||||
if ((ret = do_parser_routine(token, ast)) == 1
|
if ((ret = do_parser_routine(token, ast)) == 1
|
||||||
&& SH_NO_INTERACTIVE(data->opts))
|
&& SH_NO_INTERACTIVE(data->opts))
|
||||||
return (ret);
|
return (ret);
|
||||||
else if (ret > 0)
|
else if (ret > 0)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
|
return (exec_instruction(ast, &stream));
|
||||||
ft_add_str_in_history(data->lexer.str);
|
|
||||||
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
|
||||||
exit(1);
|
|
||||||
else if (data->parser.state != SUCCESS)
|
|
||||||
set_exitstatus(1, 1);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av, char **env)
|
int main(int ac, char **av, char **env)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/19 14:24:14 by wescande #+# #+# */
|
/* Created: 2017/03/19 14:24:14 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/27 21:02:08 by ariard ### ########.fr */
|
/* Updated: 2017/03/27 21:43:44 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue