This commit is contained in:
Antoine Riard 2017-03-15 20:08:04 +01:00
commit a68ad0af01
52 changed files with 376 additions and 244 deletions

View file

@ -6,14 +6,14 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/14 21:59:22 by ariard ### ########.fr #
# Updated: 2017/03/15 18:11:31 by jhalford ### ########.fr #
# #
# **************************************************************************** #
NAME = 42sh
CC = gcc
FLAGS = -Wall -Wextra -Werror -g
FLAGS = -Wall -Wextra -Werror -fvisibility=hidden
D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc)
@ -309,6 +309,7 @@ $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS)
$(LIBS) \
$(LIBFT_LIB) \
$(FLAGS) $(D_FLAGS)
@strip -x $@
@printf "\r\033[48;5;15;38;5;25m✅ MAKE $(NAME)\033[0m\033[K\n"
$(LIBFT_LIB):

5
42sh/auteur Normal file
View file

@ -0,0 +1,5 @@
alao
ariard
gwojda
jhalford
wescande

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/03/14 12:09:55 by gwojda ### ########.fr */
/* Updated: 2017/03/15 13:47:27 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
# define COMPLETION_H
# include "minishell.h"
#define RETARDED_BEHAVIOR 0
# define RETARDED_BEHAVIOR 0
/*
** Autocompletion list for the valid candidates from the parser.
@ -178,5 +178,6 @@ int c_seek_env(t_comp *c, char *current_word);
void c_seek_abs_path(t_comp *c, char *current_word);
void c_arrow(t_comp *c, long int keypress);
int c_chevron(t_comp *c);
int c_dispatcher(t_data *s);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/15 17:25:13 by ariard ### ########.fr */
/* Updated: 2017/03/15 20:03:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
/* Updated: 2017/03/08 23:24:38 by ariard ### ########.fr */
/* Updated: 2017/03/14 23:14:14 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -100,7 +100,7 @@ void expand_home(t_glob *gl, char *str);
void expand_var(t_glob *tglob);
void expand_home(t_glob *gl, char *str);
int match_pattern(t_glob *tglob, char *str, char *full_word);
int dir_research(t_glob *tglob, char *p, char *pat, int rec, int first);
int dir_research(t_glob *tglob, char *p, char *pat, int *mode);
char **gen_tab(const char *pat, const unsigned char *esc,
const unsigned char *esc2, int dup);
char **ft_strsplit_spe(const char *str,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:34:13 by jhalford ### ########.fr */
/* Updated: 2017/03/15 16:35:42 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,6 +54,7 @@ void data_exit(void);
int instruction_free(t_list **token, t_parser *parser,
t_btree **ast);
void content_free(void *data, size_t content_size);
char *ft_putast(void *node);
void ft_putast2(void *node);

82
42sh/scriptheader.sh Executable file
View file

@ -0,0 +1,82 @@
#!/bin/sh
function elem_in_array()
{
for cur in $2
do
if [ "$1" == "$cur" ]
then
echo "1"
return 1
fi
done
echo "0"
return 0
}
function array_in_array()
{
for cur in $1
do
match=$(elem_in_array "$cur" "$2")
if [ "$match" -ne 1 ]
then
echo "0"
return 0
fi
done
echo "1"
return 1
}
word=$(git status -s | sed 's/.* //')
red="\033[38;5;1m"
gre="\033[38;5;2m"
cya="\033[38;5;6m"
res="\033[0m"
for i in $word
do
if [ -e $i ]
then
if [ -f $i ]
then
diff=$(git diff -U0 --exit-code --color $i)
if [ "$?" -eq 1 ]
then
nb_lines=$(echo "$diff" | wc -l)
if [ "$nb_lines" -eq 7 ]
then
match=$(array_in_array "-9 +9 Updated: by ### ########.fr" "$diff")
if [ $match -eq 1 ]
then
echo "\n$cya CHANGES on $i :$res"
echo "$diff"
echo "$cya Are you sure?$res"
read -r -p " [y/N]" response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
i_tmp=$(echo $i | sed 's/\//_/g')
cp $i "$HOME/Documents/.$i_tmp.back"
git checkout $i
echo "$gre D - O - N - E $res"
echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n"
else
echo "$cya Nothing done for $i$res\n"
fi
else
echo "$gre$i is not concerned (diff on the good lines)$res"
fi
else
echo "$gre$i is not concerned (diff is too big)$res"
fi
else
echo "$gre$i is not concerned (diff is null)$res"
fi
else
echo "$red$i is not a regular file$res"
fi
else
echo "$red$i doesn't exist$res"
fi
done

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
/* Updated: 2017/03/09 14:58:10 by jhalford ### ########.fr */
/* Updated: 2017/03/15 10:52:44 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -83,7 +83,7 @@ int builtin_cd(const char *path,
if (!(target = builtin_cd_special(av + i, envp)))
return (1);
cwd = getcwd(NULL, 0);
builtin_setenv(path, (char*[3]){"OLDPWD", cwd, NULL}, envp);
builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp);
free(cwd);
if (chdir(target))
{
@ -93,7 +93,7 @@ int builtin_cd(const char *path,
else if (target != av[i])
ft_printf("%s\n", target);
cwd = getcwd(NULL, 0);
builtin_setenv(path, (char*[3]){"PWD", cwd, NULL}, envp);
builtin_setenv(path, (char*[4]){"setenv", "PWD", cwd, NULL}, envp);
free(cwd);
if (!ft_strcmp(*(av + i), "-"))
free(target);

View file

@ -6,44 +6,53 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2017/03/15 02:12:56 by ariard ### ########.fr */
/* Updated: 2017/03/15 16:29:51 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int builtin_setenv(const char *path, char *const av[], char *const envp[])
static int assign_var(char *const av[], char ***env)
{
char *str;
char ***env;
int i;
i = -1;
str = ft_str3join(av[1], "=", av[2]);
while ((*env) && (*env)[++i])
{
if (ft_strcmp((*env)[i], av[1]) == '='
&& ft_strlen(av[1]) == ft_strlenchr((*env)[i], '='))
{
ft_strdel(&(*env)[i]);
(*env)[i] = str;
return (0);
}
}
*env = ft_sstradd(*env, str);
ft_strdel(&str);
return (0);
}
int builtin_setenv(const char *path,
char *const av[], char *const envp[])
{
char ***env;
(void)envp;
(void)path;
i = 0;
env = ft_strcmp(av[0], "local") == 0 ?
&data_singleton()->local_var : &data_singleton()->env;
av++;
if (!av[0])
if (!av || !av[0])
return (1);
if (ft_strcmp(av[0], "local") == 0)
env = &data_singleton()->local_var;
else
env = &data_singleton()->env;
if (!av[1])
{
ft_sstrprint(*env, '\n');
ft_putchar('\n');
}
else
{
str = ft_str3join(av[0], "=", av[2]);
while ((*env) && (*env)[i])
{
if (ft_strcmp((*env)[i], av[0]) == '=')
{
ft_strdel(&(*env)[i]);
(*env)[i] = str;
return (0);
}
i++;
}
*env = ft_sstradd(*env, str);
ft_strdel(&str);
}
return (assign_var(av, env));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/15 18:31:21 by ariard ### ########.fr */
/* Updated: 2017/03/15 20:01:03 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,7 @@ t_stof g_builtin[] =
{"export", &builtin_export},
{"unset", &builtin_unset},
{"setenv", &builtin_setenv},
{"local", &builtin_setenv},
{"unsetenv", &builtin_unsetenv},
{"env", &builtin_env},
{"exit", &builtin_exit},
@ -41,7 +42,10 @@ t_execf *is_builtin(t_process *p)
while (g_builtin[++i].name)
{
if (ft_strcmp(g_builtin[i].name, p->data.cmd.av[0]) == 0)
{
DG();
return (g_builtin[i].f);
}
}
return (NULL);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */
/* Updated: 2017/03/09 17:34:43 by gwojda ### ########.fr */
/* Updated: 2017/03/15 06:57:53 by alao ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,5 +48,6 @@ void c_seek_abs_path(t_comp *c, char *current_word)
}
!c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0;
c_parser(c, c->cpath, c->match);
c_exclusion_folder(c);
if (c->lst == NULL || c->lst == c->lst->prev)
c_exclusion_folder(c);
}

View file

@ -6,100 +6,85 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/10 09:04:42 by alao #+# #+# */
/* Updated: 2017/03/10 12:44:05 by alao ### ########.fr */
/* Updated: 2017/03/15 14:26:11 by alao ### ########.fr */
/* */
/* ************************************************************************** */
#include "completion.h"
static void c_arrow_right(t_comp *c)
/*
**
*/
static int c_idsolver(t_comp *c, int ids, int ids_bk)
{
t_clst *ptr;
int i;
if (ids > c->lst->prev->id)
{
ids -= c->lst->prev->id;
if (ids_bk < ((c->lst->prev->id - (c->lst->prev->id % c->c_line)) + 1))
ids = ids + (c->lst->prev->id % c->c_line);
else
ids = ids - (c->c_line - (c->lst->prev->id % c->c_line));
}
else if (ids < c->lst->id)
{
if (ids_bk <= (c->lst->prev->id % c->c_line))
ids = (c->lst->prev->id - (c->lst->prev->id % c->c_line)) + ids_bk;
else
ids = c->lst->prev->id - (ids * -1) - (c->lst->prev->id % c->c_line);
if (ids < c->lst->id)
{
DG("Failsafe %d", ids);
ids = 1;
}
}
return (ids);
}
/*
**
*/
static void c_arrow_multi(t_comp *c, long int keypress)
{
t_clst *ptr;
int ids;
int ids_bk;
ids = 0;
ptr = c->lst;
i = 0;
while (!ptr->cursor)
ptr = ptr->next;
ptr->cursor = 0;
while (i < c->c_line)
{
ids = ptr->id;
ids_bk = ids;
(keypress == 4479771) ? (ids -= c->c_line) : (0);
(keypress == 4414235) ? (ids += c->c_line) : (0);
ids = c_idsolver(c, ids, ids_bk);
ptr = c->lst;
while (ptr->id != ids)
ptr = ptr->next;
if (ptr == c->lst)
i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
i++;
}
if (c->pos_x == (c->c_pline - 1))
{
i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
while (i < c->c_line)
{
ptr = ptr->next;
i++;
}
}
ptr->cursor = 1;
}
static void c_arrow_left(t_comp *c)
{
t_clst *ptr;
int i;
ptr = c->lst;
i = 0;
while (!ptr->cursor)
ptr = ptr->next;
ptr->cursor = 0;
while (i < c->c_line)
{
ptr = ptr->prev;
if (ptr == c->lst)
i += c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
i++;
}
/* if (c->pos_x == 1)
{
i = c->c_line - (c->c_sy - ((c->c_pline - 1) * c->c_line));
while (i < c->c_line)
{
ptr = ptr->prev;
i++;
}
}*/
ptr->cursor = 1;
}
static void c_arrow_down(t_comp *c)
{
t_clst *ptr;
ptr = c->lst;
while (!ptr->cursor)
ptr = ptr->next;
ptr->cursor = 0;
ptr->next->cursor = 1;
}
static void c_arrow_up(t_comp *c)
{
t_clst *ptr;
ptr = c->lst;
while (!ptr->cursor)
ptr = ptr->next;
ptr->cursor = 0;
ptr->prev->cursor = 1;
}
/*
**
*/
void c_arrow(t_comp *c, long int keypress)
{
if (keypress == 4283163)
c_arrow_up(c);
if (keypress == 4348699)
c_arrow_down(c);
if (keypress == 4479771)
c_arrow_left(c);
if (keypress == 4414235)
c_arrow_right(c);
t_clst *ptr;
ptr = c->lst;
if (keypress == 4479771 || keypress == 4414235)
c_arrow_multi(c, keypress);
else
{
while (!ptr->cursor)
ptr = ptr->next;
ptr->cursor = 0;
(keypress == 4283163) ? (ptr->prev->cursor = 1) : (0);
(keypress == 4348699) ? (ptr->next->cursor = 1) : (0);
}
}

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */
/* Updated: 2017/03/14 12:09:36 by gwojda ### ########.fr */
/* Updated: 2017/03/15 11:47:40 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,10 +70,6 @@ static char *c_slicer(t_comp *c)
i--;
tmp[i] == '/' ? i++ : (0);
rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i);
/* if (c_chevron(c))
c->match = ft_strdup("");
else
c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);*/
tmp ? ft_memdel((void *)&tmp) : (0);
return (rt);
}

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/14 12:29:12 by gwojda ### ########.fr */
/* Updated: 2017/03/14 17:22:10 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:52:07 by alao #+# #+# */
/* Updated: 2017/03/14 11:37:25 by gwojda ### ########.fr */
/* Updated: 2017/03/15 06:53:34 by alao ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@
void c_add_to_lst(t_comp *c, t_clst *node)
{
DG("\tADD %s", node->name);
if (c->lst == NULL)
{
c->lst = node;
@ -41,6 +42,9 @@ void c_add_to_lst(t_comp *c, t_clst *node)
** created and the function above is called to add it.
*/
//TODO: The above function doesn't reject . and .. folder for abs_path. Fix needed.
/*
static int c_storing(t_comp *c, char *value, unsigned char type)
{
t_clst *tmp;
@ -59,6 +63,33 @@ static int c_storing(t_comp *c, char *value, unsigned char type)
c_add_to_lst(c, tmp);
return (0);
}
*/
static int c_storing(t_comp *c, char *value, unsigned char type)
{
t_clst *tmp;
if (c->match && c->match[0] == '.')
{
if (ft_strequ(".", value) || ft_strequ("..", value))
return (0);
}
else
{
if (ft_strncmp(".", value, 1) == 0 || ft_strncmp("..", value, 2) == 0)
return (0);
}
if (c->match && ft_strnequ(c->match, value, ft_strlen(c->match)) != 1)
return (0);
if (!(tmp = (t_clst *)malloc(sizeof(t_clst))))
return (-1);
tmp->name = ft_strdup(value);
tmp->len = ft_strlen(tmp->name);
tmp->type = (int)type;
tmp->cursor = 0;
c_add_to_lst(c, tmp);
return (0);
}
/*
** Cycle through the path specified.

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 12:55:39 by alao #+# #+# */
/* Updated: 2017/03/10 16:09:46 by gwojda ### ########.fr */
/* Updated: 2017/03/15 14:30:37 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -126,7 +126,8 @@ void c_printer(t_comp *c)
//int offset;
loop = c->c_line;
if (!c->c_line)
return ;
max_line = c->c_line - (c->m_size - 1);
ptr = c_rolling(c);
if ((c->pos_y * (c->m_size - 1)) > c->c_line)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
/* Updated: 2017/03/14 17:21:37 by gwojda ### ########.fr */
/* Updated: 2017/03/15 11:50:15 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,17 +28,16 @@ static int c_storing(t_comp *c, char *value)
int c_seek_env(t_comp *c, char *current_word)
{
char *match;
char **env;
int i;
i = 0;
env = data_singleton()->env;
match = ft_strdupi_w(current_word + 1);
c->match = ft_strdupi_w(current_word + 1);
while (env[i])
{
if (!ft_strncmp(match, env[i], ft_strlen(match)) &&
env[i][ft_strlen(match)] != '=')
if (!ft_strncmp(c->match, env[i], ft_strlen(c->match)) &&
env[i][ft_strlen(c->match)] != '=')
c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i]));
++i;
}

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 08:50:26 by alao #+# #+# */
/* Updated: 2017/03/10 08:45:52 by alao ### ########.fr */
/* Updated: 2017/03/15 14:25:54 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,7 +54,7 @@ int c_sizing(t_comp *c)
c->lst && c->lst->name ? c_max_length(c) : 0;
c->c_pline = c->win_x / (c->c_sx + 2);
c->c_line = 0;
while ((c->c_line * c->c_pline) < c->c_sy)
while (c->c_pline && (c->c_line * c->c_pline) < c->c_sy)
c->c_line++;
if ((c->win_x < c->c_sx))
{

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
/* Updated: 2017/03/14 10:51:14 by gwojda ### ########.fr */
/* Updated: 2017/03/15 14:36:43 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -92,7 +92,7 @@ void c_term_mv_down(t_comp *c)
value = c->m_size - 1;
else
value = c->c_line - 1;
while (i != value)
while (value >= 0 && i != value)
{
ft_putstr(tgetstr("up", NULL));
i++;

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
/* Updated: 2017/03/14 11:22:04 by gwojda ### ########.fr */
/* Updated: 2017/03/15 14:37:34 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/15 18:46:46 by ariard ### ########.fr */
/* Updated: 2017/03/15 19:58:48 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,8 @@ int exec_leaf(t_btree **ast)
job = &data_singleton()->exec.job;
if (process_set(&p, *ast))
return (1);
if (p.type >= PROCESS_MAX)
return (1);
p.map = g_process_map[p.type];
if (!(process_launch(&p)))
{

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* exec_semi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
/* Updated: 2017/03/10 14:55:05 by ariard ### ########.fr */
/* Updated: 2017/03/15 15:55:43 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:59:28 by jhalford ### ########.fr */
/* Updated: 2017/03/15 17:48:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* plaunch_for.c :+: :+: :+: */
/* plaunch_for.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
/* Updated: 2017/03/15 01:57:25 by ariard ### ########.fr */
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
/* Updated: 2017/03/15 03:51:52 by wescande ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/13 14:01:23 by jhalford ### ########.fr */
/* Updated: 2017/03/15 18:06:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,6 +30,8 @@ int process_redirect(t_process *p)
int i;
redirs = p->redirs;
if (p->to_close != STDIN)
close(p->to_close);
while (redirs)
{
redir = redirs->content;
@ -54,8 +56,6 @@ int process_redirect(t_process *p)
redirs = redirs->next;
}
/* DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); */
if (p->to_close != STDIN)
close(p->to_close);
if (p->fdin != STDIN)
dup2_close(p->fdin, STDIN);
if (p->fdout != STDOUT)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/03/13 23:33:06 by jhalford ### ########.fr */
/* Updated: 2017/03/15 18:11:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,10 +25,7 @@ int process_setgroup(t_process *p, pid_t pid)
return (0);
DG("setpgid(%i, %i)", pid, j->pgid);
if (setpgid(pid, j->pgid) == -1)
{
ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno);
perror("");
}
if (pid == 0 && JOB_IS_FG(j->attrs))
{
DG("tcsetpgrp[%i]", j->pgid);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
/* Updated: 2017/03/11 17:32:20 by jhalford ### ########.fr */
/* Updated: 2017/03/15 17:49:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,10 +33,9 @@ int redirect_greatand(t_redir *redir)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_RDONLY | O_RDWR))
if (fd_is_valid(fdold, O_WRONLY | O_RDWR))
dup2_close(fdold, fdnew);
else
close(fdnew);
/* return (bad_fd(fdold)); */
return (bad_fd(fdold));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
/* Updated: 2017/03/10 14:00:40 by jhalford ### ########.fr */
/* Updated: 2017/03/15 17:49:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,10 +33,9 @@ int redirect_lessand(t_redir *redir)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_WRONLY | O_RDWR))
if (fd_is_valid(fdold, O_RDONLY | O_RDWR))
dup2_close(fdold, fdnew);
else
close(fdnew);
/* return (bad_fd(fdold)); */
return (bad_fd(fdold));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:11:39 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,7 +44,7 @@ char *command_getoutput(char *command)
{
close(fds[PIPE_READ]);
dup2_close(fds[PIPE_WRITE], STDOUT);
execle(data_singleton()->argv[0],data_singleton()->argv[0],
execle(data_singleton()->argv[0], data_singleton()->argv[0],
"-c", command, NULL,
data_singleton()->env);
exit(1);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
/* Updated: 2017/03/09 03:24:59 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:14:19 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,7 +32,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat,
else
path = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
if (recursive)
dir_research(gl, path, pat, recursive, 0);
dir_research(gl, path, pat, (int[]){recursive, 0});
gl->pat = pat;
if (match_pattern(gl, str[1], path))
{
@ -46,7 +46,7 @@ static void dir_list_content(t_glob *gl, char **str, char *pat,
}
int dir_research(t_glob *gl, char *p,
char *pat, int recursive, int first)
char *pat, int *mode)
{
DIR *dir;
struct dirent *in;
@ -54,7 +54,7 @@ int dir_research(t_glob *gl, char *p,
if (!*pat)
{
gl->found = 1;
if (!first)
if (!mode[1])
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 *
(p[0] == '.' && p[1] == '/'), "/"));
else
@ -66,7 +66,7 @@ int dir_research(t_glob *gl, char *p,
dir = opendir(p);
while ((in = readdir(dir)))
dir_list_content(gl,
(char *[2]){p, in->d_name}, pat, recursive);
(char *[2]){p, in->d_name}, pat, mode[0]);
closedir(dir);
}
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 15:38:14 by jhalford #+# #+# */
/* Updated: 2017/02/24 22:05:04 by ariard ### ########.fr */
/* Updated: 2017/03/15 18:12:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,10 +20,10 @@ void esc_print(char *str, unsigned char *esc)
while (*cur)
{
if (is_char_esc(esc, str, cur))
printf("\\%c", *cur);
ft_printf("\\%c", *cur);
else
printf("%c", *cur);
ft_printf("%c", *cur);
++cur;
}
printf("\n");
ft_printf("\n");
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:53:12 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,11 +49,9 @@ static void init_expand(t_bquote *me, char *content, int esc)
{
ft_ld_pushfront(me->wk, gen_tab(ft_strjoinf(ft_strjoin(me->s1, content),
me->s2, 1),
calc_expand_esc(me->esc, ft_strlen(me->s1),
(int[2]){ft_strlen(content), 1},
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
ft_strlen(me->s2)}),
calc_expand_esc(me->esc2, ft_strlen(me->s1),
calc_expand_esc(me->esc, ft_strlen(me->s1), (int[2]){ft_strlen(content), 1},
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid), ft_strlen(me->s2)}),
calc_expand_esc(me->esc2, ft_strlen(me->s1),
(int[2]){ft_strlen(content), 1},
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
ft_strlen(me->s2)}), 0));
@ -75,7 +73,7 @@ static char *get_output(char *command)
int len;
if (!(output = command_getoutput(command)))
return (NULL);//ft_strnew(0));
return (NULL);
len = ft_strlen(output);
while (output[--len] == '\n')
output[len] = '\0';
@ -88,7 +86,7 @@ static int search_bquote(t_bquote *me)
char *content;
sta = NULL;
while (*me->str)
while (*(++me->str))
{
sta = *me->str == '`' && !sta
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta;
@ -99,14 +97,14 @@ static int search_bquote(t_bquote *me)
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
me->s2 = ft_strdup(me->str + 1);
if ((content = get_output(me->mid)))
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
init_expand(me, content,
is_char_esc(me->esc, CH(*me->wk)[0], sta));
ft_strdel(&me->mid);
ft_strdel(&me->s1);
ft_strdel(&me->s2);
ft_strdel(&content);
return (1);
}
++me->str;
}
return (0);
}
@ -118,6 +116,7 @@ void delete(t_ld **tmp, t_ld **src)
else
ft_ld_del(tmp, &ft_tabdel);
}
void expand_bquote(t_glob *gl)
{
t_ld *tmp;
@ -135,11 +134,10 @@ void expand_bquote(t_glob *gl)
me.wk = &gl->m_pat;
me.esc = UCH(gl->m_pat)[1];
me.esc2 = UCH(gl->m_pat)[2];
me.str = CH(gl->m_pat)[0];
me.str = CH(gl->m_pat)[0] - 1;
if ((tmp = gl->m_pat) &&
(do_it = search_bquote(&me)) == 1)
delete(&tmp, &gl->m_pat);
// ft_ld_del(&tmp, &ft_tabdel);
if (!gl->m_pat || !gl->m_pat->next)
break ;
gl->m_pat = gl->m_pat->next;

View file

@ -6,21 +6,21 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
/* Updated: 2017/03/09 03:24:24 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:30:59 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/*
** glob return expansion of a string.
** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, **
** input parameters are :
** -char *pat -> pattern string to be looking for match
** -char *esc -> escape binary sequence of *pat
** -char **env -> env var. could be NULL
** to just expanse in local directory and not in path dir
*/
** glob return expansion of a string.
** pattern searched are *, ?, [a-z], [!a-z], [^a-z], {ab, ac}, **
** input parameters are :
** -char *pat -> pattern string to be looking for match
** -char *esc -> escape binary sequence of *pat
** -char **env -> env var. could be NULL
** to just expanse in local directory and not in path dir
*/
static int order_glob(const char *s1, const char *s2)
{
@ -96,9 +96,9 @@ char **glob(char *pat, unsigned char *esc,
gl.cur_dir = 1;
gl.pat = CH(gl.m_pat)[0];
if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/')
dir_research(&gl, ".", gl.pat, 0, 1);
dir_research(&gl, ".", gl.pat, (int[]){0, 1});
else
dir_research(&gl, "/", gl.pat + 1, 0, 1);
dir_research(&gl, "/", gl.pat + 1, (int[]){0, 1});
if (!gl.found)
ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
else

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/27 18:19:55 by wescande #+# #+# */
/* Updated: 2017/02/20 20:43:38 by ariard ### ########.fr */
/* Updated: 2017/03/14 23:11:59 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,6 +67,5 @@ unsigned char *dup_char_esc(const unsigned char *esc, const int size)
if (!(new_esc = (unsigned char *)ft_strnew(size)))
return (NULL);
new_esc = ft_memcpy(new_esc, esc, size);
return (new_esc);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
/* Updated: 2017/03/09 03:24:48 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:25:44 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -73,7 +73,7 @@ static int match_star(t_glob *gl, char *str, char *full_word)
if (gl->pat[1] == '*' &&
!is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1))
dir_research(gl, full_word, gl->pat + 1, 1, 0);
dir_research(gl, full_word, gl->pat + 1, (int[]){1, 0});
if (!*gl->pat || (*gl->pat == '*' && !*++gl->pat))
return (1);
pat = gl->pat;
@ -119,7 +119,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word)
else if (*gl->pat == '*')
return (match_star(gl, str, full_word));
else if (*gl->pat == '/' && !*str && is_directory(full_word))
return (dir_research(gl, full_word, gl->pat + 1, 0, 0));
return (dir_research(gl, full_word, gl->pat + 1, (int[]){0, 0}));
else if (*gl->pat != *str)
return (0);
++str;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
/* Updated: 2017/03/07 20:40:30 by wescande ### ########.fr */
/* Updated: 2017/03/14 23:12:20 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,5 +17,7 @@ void *tab_esc_copy(void *content)
char **ch_cont;
ch_cont = (char **)content;
return (gen_tab(ch_cont[0], (unsigned char *)ch_cont[1], (unsigned char *)ch_cont[2], 1));
return (gen_tab(ch_cont[0],
(unsigned char *)ch_cont[1],
(unsigned char *)ch_cont[2], 1));
}

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* do_job_notification.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:40:35 by jhalford ### ########.fr */
/* Updated: 2017/03/15 11:24:23 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,7 +32,11 @@ int do_job_notification(void)
ret = 1;
job_notify_change(j->id);
if (job_is_completed(j->id))
{
jlist = jlist->next;
job_remove(j->id);
continue ;
}
else
j->attrs |= JOB_NOTIFIED;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/14 23:43:12 by jhalford ### ########.fr */
/* Updated: 2017/03/15 18:12:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/14 12:45:22 by gwojda ### ########.fr */
/* Updated: 2017/03/15 15:51:30 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,8 @@ int put_job_in_foreground(t_job *j, int cont)
tcsetpgrp(STDIN, j->pgid);
if (cont)
{
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
// j->tmodes = pas initialisé !
//tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed");
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/21 21:05:23 by ariard #+# #+# */
/* Updated: 2017/03/08 18:33:31 by ariard ### ########.fr */
/* Updated: 2017/03/15 16:31:49 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,5 +19,6 @@ int insert_newline(t_list **alst)
token = token_init();
token->type = TK_NEWLINE;
ft_lsteadd(alst, ft_lstnew(token, sizeof(*token)));
free(token);
return (0);
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */
/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */
/* Updated: 2017/03/15 17:48:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
/* Updated: 2017/03/14 16:00:05 by gwojda ### ########.fr */
/* Updated: 2017/03/15 18:14:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,10 +27,10 @@ static int promt_git_status(int fd)
free(tmp);
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
if (!get_next_line(fd, &tmp))
printf("\x1b[38;5;83m %C ", L'');
ft_printf("\x1b[38;5;83m ");
else
{
printf("\x1b[38;5;1m %C ", L'');
ft_printf("\x1b[38;5;1m ");
free(tmp);
}
while (get_next_line(fd, &tmp))
@ -101,9 +101,9 @@ void ft_prompt(void)
do_job_notification();
if (ft_getenv(data_singleton()->env, "?") &&
ft_atoi(ft_getenv(data_singleton()->env, "?")))
printf("\x1b[38;5;1m%C ", L'');
ft_printf("\x1b[38;5;1m");
else
printf("\x1b[38;5;10m%C ", L'');
ft_printf("\x1b[38;5;10m");
fflush(NULL);
ft_putstr("\x1b[38;5;361m");
ret += ft_currend_dir();

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
/* Updated: 2017/03/05 19:38:09 by gwojda ### ########.fr */
/* Updated: 2017/03/15 14:07:20 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,11 +57,13 @@ char *ft_read_stdin(void)
ft_is_str();
if (data_singleton()->comp)
c_clear(data_singleton());
signal(SIGWINCH, sigwinch_resize);
while (42)
{
ret = 0;
j = 0;
read(0, &ret, sizeof(int));
DG("key hexa value = %X", ret);
if (ft_completion(ret))
continue ;
while (g_key[j].value && g_key[j].value != ret)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/14 22:19:43 by jhalford ### ########.fr */
/* Updated: 2017/03/15 03:52:15 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,11 +14,10 @@
int readline(int fd, int prompt, char **input)
{
int ret;
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
{
DG("GNL on fd=%i", fd);
return (get_next_line(fd, input) == 0);
}
return ((ret = get_next_line(fd, input)) >= 0 ? !ret : ret);
readline_init(prompt);
*input = ft_read_stdin();
if (STR)

View file

@ -6,12 +6,11 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 10:56:08 by gwojda #+# #+# */
/* Updated: 2017/03/14 12:00:29 by gwojda ### ########.fr */
/* Updated: 2017/03/15 14:25:51 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int c_dispatcher(t_data *s);
void sigwinch_resize(int sig)
{

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:39:13 by jhalford ### ########.fr */
/* Updated: 2017/03/15 16:23:18 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,13 +18,18 @@ int data_init(int ac, char **av)
{
t_data *data;
char *term_name;
char* shlvl;
data = data_singleton();
data->argc = ac;
data->argv = ft_sstrdup(av);
data->env = ft_sstrdup(environ);
data->local_var = NULL;
builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL);
set_exitstatus(0, 1);
shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1);
builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL);
ft_strdel(&shlvl);
data->comp = NULL;
data->opts = 0;
exec_reset();

View file

@ -1,11 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instruction_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/15 15:54:59 by gwojda #+# #+# */
/* Updated: 2017/03/15 16:49:10 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int instruction_free(t_list **token, t_parser *parser, t_btree **ast)
{
{
ft_lstdel(token, &token_free);
token = NULL;
ft_lstdel(&parser->stack, NULL);
btree_del(ast, &ast_free);
ft_lstdel(&parser->stack, &ft_lst_cfree);
btree_del(ast, &ft_lst_cfree);
ft_lstdel(&data_singleton()->heredoc_queue, &redir_free);
ft_lstdel(&data_singleton()->exec.op_stack, &ft_lst_cfree);
free(parser->new_sym);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/15 00:50:54 by ariard ### ########.fr */
/* Updated: 2017/03/15 17:55:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,14 +70,13 @@ int handle_instruction(int fd)
return (error_syntax(&token, &parser, &ast));
}
}
btree_print(STDBUG, ast, &ft_putast);
/* btree_print(STDBUG, ast, &ft_putast); */
if (ft_exec(&ast))
return (2);
instruction_free(&token, &parser, &ast);
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
ft_add_str_in_history(lexer.str);
ft_strdel(&lexer.str);
free(parser.new_sym);
return (0);
}
@ -95,22 +94,23 @@ int get_input_fd(char **av)
else if (data->opts & SH_OPTS_LC)
{
pipe(fds);
fd = fds[PIPE_READ];
dup2_close(fds[PIPE_READ], 10);
fd = 10;
file = *cliopts_getdata(av);
write(fds[PIPE_WRITE], file, ft_strlen(file));
close(fds[PIPE_WRITE]);
fcntl(fd, F_SETFD, FD_CLOEXEC);
return (fd);
}
else if ((file = *cliopts_getdata(av)))
else if ((file = *cliopts_getdata(av)) && !stat(file, &buf))
{
stat(file, &buf);
fd = -1;
if (S_ISDIR(buf.st_mode))
ft_printf("{red}%s: %s: is a directory\n{eoc}", g_argv[0], file);
ft_printf("{red}%s: %s: is a directory\n{eoc}", av[0], file);
else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", g_argv[0], file);
return (fd);
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", av[0], file);
if (fd > 0 && !dup2_close(fd, 10) && (fd = 10))
return (fd);
}
return (STDIN);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/14 23:25:40 by jhalford ### ########.fr */
/* Updated: 2017/03/15 13:55:49 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,6 @@ static int interactive_settings(void)
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
signal(SIGWINCH, sigwinch_resize);
*shell_pgid = getpid();
if (setpgid(*shell_pgid, *shell_pgid))
{

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/03/15 19:50:49 by ariard ### ########.fr */
/* Updated: 2017/03/15 20:07:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:15:35 by ariard #+# #+# */
/* Updated: 2017/03/13 14:41:45 by jhalford ### ########.fr */
/* Updated: 2017/03/15 04:12:31 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,6 @@ t_errormatch g_errormatch[] =
{TK_DLESSDASH, "<<-"},
{TK_AND_IF, "&&"},
{TK_OR_IF, "||"},
{TK_DSEMI, ";;"},
{TK_IF, "if"},
{TK_THEN, "then"},
{TK_ELSE, "else"},
@ -66,17 +65,14 @@ int error_syntax(t_list **lst, t_parser *parser,
{
if (g_errormatch[i].token == token->type)
{
ft_putstr_fd("syntax error near unexpected token `", 2);
ft_putstr_fd(g_errormatch[i].error, 2);
ft_putstr_fd("'\n", 2);
ft_dprintf(2, "syntax error near unexpected token « %s »\n",
g_errormatch[i].error);
instruction_free(lst, parser, ast);
return (0);
}
i++;
}
ft_putstr_fd("syntax error near unexpected token`", 2);
ft_putstr_fd(token->data, 2);
ft_putstr_fd("'\n", 2);
ft_dprintf(2, "syntax error near unexpected token « %s »\n", token->data);
instruction_free(lst, parser, ast);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/15 17:25:09 by ariard ### ########.fr */
/* Updated: 2017/03/15 19:59:19 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -56,7 +56,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
else
parser->state = UNDEFINED;
build_tree(ast, token);
// btree_print(STDBUG, *ast, &ft_putast);
/* btree_print(STDBUG, *ast, &ft_putast); */
if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token);
else