error for + case fix close #174
This commit is contained in:
commit
d763c7304f
17 changed files with 135 additions and 82 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/22 17:29:53 by ariard ### ########.fr */
|
/* Updated: 2017/03/24 13:35:44 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -53,6 +53,7 @@ struct s_data
|
||||||
t_jobc jobc;
|
t_jobc jobc;
|
||||||
char **local_var;
|
char **local_var;
|
||||||
t_list *lst_func;
|
t_list *lst_func;
|
||||||
|
char *binary;
|
||||||
};
|
};
|
||||||
|
|
||||||
t_data *data_singleton();
|
t_data *data_singleton();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/21 14:05:04 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:11:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -41,6 +41,6 @@ extern int g_errnum;
|
||||||
extern char **g_argv;
|
extern char **g_argv;
|
||||||
|
|
||||||
int error_set(int n, ...);
|
int error_set(int n, ...);
|
||||||
int ft_perror(void);
|
int ft_perror(char *utility);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:02:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -97,7 +97,10 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data)
|
||||||
while (av && *av)
|
while (av && *av)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(*av, "--") == 0)
|
if (ft_strcmp(*av, "--") == 0)
|
||||||
return (0);
|
{
|
||||||
|
av++;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
||||||
{
|
{
|
||||||
if (cliopts_parse_long(&av, opt_map, data))
|
if (cliopts_parse_long(&av, opt_map, data))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/15 20:45:41 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:10:44 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -37,8 +37,8 @@ int error_set(int n, ...)
|
||||||
return (g_errnum);
|
return (g_errnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_perror(void)
|
int ft_perror(char *utility)
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}%s: %s{eoc}\n", g_argv[0], g_errmsg);
|
ft_dprintf(2, "{red}%s: %s{eoc}\n", utility ? utility : g_argv[0], g_errmsg);
|
||||||
return (g_errnum);
|
return (g_errnum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
verbose=0
|
||||||
|
if [ "$1" = "-v" ]
|
||||||
|
then
|
||||||
|
verbose=1
|
||||||
|
fi
|
||||||
word=$(git status -s | sed 's/.* //')
|
word=$(git status -s | sed 's/.* //')
|
||||||
red="\033[38;5;1m"
|
red="\033[38;5;1m"
|
||||||
gre="\033[38;5;2m"
|
gre="\033[38;5;2m"
|
||||||
|
|
@ -37,7 +41,6 @@ array_in_array ()
|
||||||
|
|
||||||
confirm ()
|
confirm ()
|
||||||
{
|
{
|
||||||
# call with a prompt string or use a default
|
|
||||||
echo "$cya${1:-Are you sure? [y/N]}$res"
|
echo "$cya${1:-Are you sure? [y/N]}$res"
|
||||||
read -r -p " " response
|
read -r -p " " response
|
||||||
case "$response" in
|
case "$response" in
|
||||||
|
|
@ -55,47 +58,76 @@ do_checkout ()
|
||||||
i_tmp=$(echo $i | sed 's/\//_/g')
|
i_tmp=$(echo $i | sed 's/\//_/g')
|
||||||
cp $i "$HOME/Documents/.$i_tmp.back"
|
cp $i "$HOME/Documents/.$i_tmp.back"
|
||||||
git checkout $i
|
git checkout $i
|
||||||
echo "$gre D - O - N - E $res"
|
if [ $verbose -eq 1 ]
|
||||||
echo "$cya $i was checked out. A copy still exist in $HOME/Documents/.$i_tmp.back$res\n"
|
then
|
||||||
|
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"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in $word
|
if [ $verbose -eq 1 ]
|
||||||
do
|
then
|
||||||
if [ -e $i ]
|
for i in $word
|
||||||
then
|
do
|
||||||
if [ -f $i ]
|
if [ -e $i ]
|
||||||
then
|
then
|
||||||
diff=$(git diff -U0 --exit-code --color $i)
|
if [ -f $i ]
|
||||||
if [ "$?" -eq 1 ]
|
|
||||||
then
|
then
|
||||||
nb_lines=$(echo "$diff" | wc -l)
|
diff=$(git diff -U0 --exit-code --color $i)
|
||||||
if [ "$nb_lines" -eq 7 ]
|
if [ "$?" -eq 1 ]
|
||||||
then
|
then
|
||||||
match=$(array_in_array "-9 +9 Updated: by ### ########.fr" "$diff")
|
nb_lines=$(echo "$diff" | wc -l)
|
||||||
if [ $match -eq 1 ]
|
if [ "$nb_lines" -eq 7 ]
|
||||||
then
|
then
|
||||||
echo "\n$cya CHANGES on $i :$res"
|
match=$(array_in_array "-9 +9 Updated: by ### ########.fr" "$diff")
|
||||||
echo "$diff"
|
if [ $match -eq 1 ]
|
||||||
confirm
|
|
||||||
if [ $? -eq 0 ]
|
|
||||||
then
|
then
|
||||||
do_checkout
|
echo "\n$cya CHANGES on $i :$res"
|
||||||
|
echo "$diff"
|
||||||
|
confirm
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
do_checkout
|
||||||
|
else
|
||||||
|
echo "$cya Nothing done for $i$res\n"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "$cya Nothing done for $i$res\n"
|
echo "$gre$i is not concerned (diff on the good lines)$res"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$gre$i is not concerned (diff on the good lines)$res"
|
echo "$gre$i is not concerned (diff is too big)$res"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$gre$i is not concerned (diff is too big)$res"
|
echo "$gre$i is not concerned (diff is null)$res"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$gre$i is not concerned (diff is null)$res"
|
echo "$red$i is not a regular file$res"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$red$i is not a regular file$res"
|
echo "$red$i doesn't exist$res"
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
echo "$red$i doesn't exist$res"
|
else
|
||||||
fi
|
for i in $word
|
||||||
done
|
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
|
||||||
|
do_checkout
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
|
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/22 17:17:28 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:11:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ int builtin_env(const char *path,
|
||||||
|
|
||||||
(void)envp;
|
(void)envp;
|
||||||
if (bt_env_parse(&data, (char**)argv))
|
if (bt_env_parse(&data, (char**)argv))
|
||||||
return (ft_perror() && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0);
|
return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0);
|
||||||
else if (!*data.av_data)
|
else if (!*data.av_data)
|
||||||
return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL));
|
return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL));
|
||||||
else if ((pid = fork()) == 0)
|
else if ((pid = fork()) == 0)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/20 14:44:02 by wescande ### ########.fr */
|
/* Updated: 2017/03/24 15:11:48 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ int builtin_export(
|
||||||
(void)path;
|
(void)path;
|
||||||
data.flag = 0;
|
data.flag = 0;
|
||||||
if (cliopts_get((char**)av, g_export_opts, &data))
|
if (cliopts_get((char**)av, g_export_opts, &data))
|
||||||
ft_perror();
|
ft_perror("export");
|
||||||
if (data.flag & BT_EXPORT_LP)
|
if (data.flag & BT_EXPORT_LP)
|
||||||
return (bt_export_print());
|
return (bt_export_print());
|
||||||
av = data.av_data;
|
av = data.av_data;
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/22 19:21:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:10:57 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
#define US_READ "read [-ers] [-u fd] [-t timeout] [-p prompt]"
|
#define US_READ "read [-ers] [-u fd] [-t timeout] [-p prompt]"
|
||||||
#define US_READ_1 "[-n nchars] [-d delim] [name ...]"
|
#define US_READ_1 " [-n nchars] [-d delim] [name ...]"
|
||||||
|
|
||||||
t_cliopts g_read_opts[] =
|
t_cliopts g_read_opts[] =
|
||||||
{
|
{
|
||||||
|
|
@ -36,12 +36,12 @@ int bt_read_init(t_read *data, char **av)
|
||||||
data->fd = 0;
|
data->fd = 0;
|
||||||
data->timeout = 0;
|
data->timeout = 0;
|
||||||
data->input = NULL;
|
data->input = NULL;
|
||||||
if ((cliopts_get(av, g_read_opts, data)))
|
|
||||||
return (ft_perror() ? 2 : 2);
|
|
||||||
if (isatty(STDIN))
|
if (isatty(STDIN))
|
||||||
data->opts |= BT_READ_INTER;
|
data->opts |= BT_READ_INTER;
|
||||||
if (bt_read_terminit(data) < 0)
|
if (bt_read_terminit(data) < 0)
|
||||||
return (-1);
|
exit (1);
|
||||||
|
if ((cliopts_get(av, g_read_opts, data)))
|
||||||
|
return (ft_perror("read"));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,8 @@ int bt_read_assign(t_read *data)
|
||||||
tok = ft_strtok(input, ifs);
|
tok = ft_strtok(input, ifs);
|
||||||
while (*names)
|
while (*names)
|
||||||
{
|
{
|
||||||
builtin_setenv("setenv", (char*[]){"setenv", *names, tok}, NULL);
|
if (!(builtin_setenv("setenv", (char*[]){"read", *names, tok}, NULL)))
|
||||||
|
return (1);
|
||||||
ifs = names[1] ? ifs : NULL;
|
ifs = names[1] ? ifs : NULL;
|
||||||
tok = ft_strtok(NULL, ifs);
|
tok = ft_strtok(NULL, ifs);
|
||||||
names++;
|
names++;
|
||||||
|
|
@ -106,16 +107,11 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
|
||||||
(void)envp;
|
(void)envp;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if ((ret = bt_read_init(&data, (char **)av)) != 0)
|
if ((ret = bt_read_init(&data, (char **)av)) != 0)
|
||||||
;
|
SH_ERR("usage: %s%s", US_READ, US_READ_1);
|
||||||
else if ((ret = bt_read_loop(&data)))
|
else if ((ret = bt_read_loop(&data)))
|
||||||
;
|
;
|
||||||
else if (data.input && bt_read_assign(&data))
|
else if (data.input && (ret = bt_read_assign(&data)))
|
||||||
ret = 1;
|
;
|
||||||
if (ret == -1)
|
bt_read_exit(&data);
|
||||||
exit(1);
|
|
||||||
if (ret != 0)
|
|
||||||
SH_ERR("usage: read %s %s\n", US_READ, US_READ_1);
|
|
||||||
if (ret != 2)
|
|
||||||
bt_read_exit(&data);
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
|
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/21 18:10:21 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 14:56:11 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
int plaunch_builtin(t_process *p)
|
int plaunch_builtin(t_process *p)
|
||||||
{
|
{
|
||||||
return (*p->data.cmd.execf)(
|
set_exitstatus((*p->data.cmd.execf)(
|
||||||
p->data.cmd.path,
|
p->data.cmd.path,
|
||||||
p->data.cmd.av,
|
p->data.cmd.av,
|
||||||
data_singleton()->env);
|
data_singleton()->env), 1);
|
||||||
|
return (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/22 18:26:53 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 14:56:32 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ int process_launch(t_process *p)
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
set_exitstatus(1, 1);
|
set_exitstatus(1, 1);
|
||||||
else
|
else
|
||||||
set_exitstatus(p->map.launch(p), 1);
|
p->map.launch(p);
|
||||||
shell_resetfds();
|
shell_resetfds();
|
||||||
shell_resetsig();
|
shell_resetsig();
|
||||||
process_free(p, 0);
|
process_free(p, 0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/23 03:19:23 by wescande ### ########.fr */
|
/* Updated: 2017/03/24 14:47:25 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -44,10 +44,10 @@ char *command_getoutput(char *command)
|
||||||
{
|
{
|
||||||
close(fds[PIPE_READ]);
|
close(fds[PIPE_READ]);
|
||||||
dup2_close(fds[PIPE_WRITE], STDOUT);
|
dup2_close(fds[PIPE_WRITE], STDOUT);
|
||||||
av = ft_sstradd(NULL, data_singleton()->argv[0]);
|
av = ft_sstradd(NULL, data_singleton()->binary);
|
||||||
av = ft_sstradd(av, "-c");
|
av = ft_sstradd(av, "-c");
|
||||||
av = ft_sstradd(av, command);
|
av = ft_sstradd(av, command);
|
||||||
execve(data_singleton()->argv[0], av, data_singleton()->env);
|
execve(data_singleton()->binary, av, data_singleton()->env);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
waitpid(pid, &ret, WUNTRACED);
|
waitpid(pid, &ret, WUNTRACED);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 14:08:12 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:12:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
|
||||||
}
|
}
|
||||||
ft_bzero(&data, sizeof(t_data_template));
|
ft_bzero(&data, sizeof(t_data_template));
|
||||||
if (cliopts_get((char**)av, g_jobs_opts, &data))
|
if (cliopts_get((char**)av, g_jobs_opts, &data))
|
||||||
return (ft_perror());
|
return (ft_perror("jobs"));
|
||||||
if (!*data.av_data)
|
if (!*data.av_data)
|
||||||
bt_jobs_all(data.flag);
|
bt_jobs_all(data.flag);
|
||||||
else if (bt_jobs_spec(data.av_data, data.flag))
|
else if (bt_jobs_spec(data.av_data, data.flag))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 14:20:30 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,7 +22,6 @@ t_lexstate get_state_global(t_lexer *lexer)
|
||||||
c = lexer->str[lexer->pos];
|
c = lexer->str[lexer->pos];
|
||||||
cn = lexer->str[lexer->pos + 1];
|
cn = lexer->str[lexer->pos + 1];
|
||||||
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
|
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
|
||||||
DG("%i : '%c'", lexer->pos, cl);
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if ((ft_is_delim(c) && (ret = DELIM))
|
if ((ft_is_delim(c) && (ret = DELIM))
|
||||||
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))
|
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/23 14:57:19 by ariard ### ########.fr */
|
/* Updated: 2017/03/24 13:51:24 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,28 @@
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
|
static int path_binary_save(char *binary)
|
||||||
|
{
|
||||||
|
char *directory;
|
||||||
|
|
||||||
|
if (binary[0] != '/')
|
||||||
|
{
|
||||||
|
if (!(directory = getcwd(NULL, 0)))
|
||||||
|
return (1);
|
||||||
|
while (binary[0] == '.' && binary[1] == '/')
|
||||||
|
binary += 2;
|
||||||
|
binary = ft_strjoin(
|
||||||
|
directory[ft_strlen(directory) - 1] != '/' ? "/" : "", binary);
|
||||||
|
binary = ft_strjoinf(directory, binary, 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
binary = ft_strdup(binary);
|
||||||
|
if (access(binary, F_OK | X_OK))
|
||||||
|
return (1);
|
||||||
|
data_singleton()->binary = binary;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
static int localenv_init(void)
|
static int localenv_init(void)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
|
@ -67,15 +89,16 @@ int data_init(int ac, char **av)
|
||||||
lexer_init(&data->lexer);
|
lexer_init(&data->lexer);
|
||||||
parser_init(&data->parser);
|
parser_init(&data->parser);
|
||||||
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
|
||||||
{
|
|
||||||
term_name = "dumb";
|
term_name = "dumb";
|
||||||
/* ft_dprintf(2, "{red}TERM not set\n{eoc}"); */
|
|
||||||
/* return (-1); */
|
|
||||||
}
|
|
||||||
if (tgetent(NULL, term_name) != 1)
|
if (tgetent(NULL, term_name) != 1)
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}TERM name is not a tty\n{eoc}");
|
ft_dprintf(2, "{red}TERM name is not a tty\n{eoc}");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
if (path_binary_save(av[0]))
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}Failed to resolve binary name\n{eoc}");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/24 14:55:27 by ariard ### ########.fr */
|
/* Updated: 2017/03/24 15:18:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ static int do_readline_routine(char **stream)
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
has_prompt = !(get_lexer_stack(data->lexer)
|
has_prompt = !(get_lexer_stack(data->lexer)
|
||||||
|| data->parser.state == UNDEFINED || data->lexer.state == HEREDOC);
|
|| data->parser.state == UNDEFINED || data->lexer.state == HEREDOC);
|
||||||
ret = readline(has_prompt, stream);
|
ret = readline(has_prompt, stream);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
@ -43,10 +43,9 @@ 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 ;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/22 19:36:07 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 15:12:31 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ int shell_init(int ac, char **av)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (cliopts_get(av, g_opts, data))
|
if (cliopts_get(av, g_opts, data))
|
||||||
{
|
{
|
||||||
ft_perror();
|
ft_perror(NULL);
|
||||||
return (SH_ERR("usage: %s", SHELL_USAGE));
|
return (SH_ERR("usage: %s", SHELL_USAGE));
|
||||||
}
|
}
|
||||||
if (!isatty(STDIN) || *data->av_data)
|
if (!isatty(STDIN) || *data->av_data)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
|
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/24 15:02:51 by ariard ### ########.fr */
|
/* Updated: 2017/03/24 15:18:51 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -49,7 +49,6 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
parser->state = SUCCESS;
|
parser->state = SUCCESS;
|
||||||
else
|
else
|
||||||
parser->state = UNDEFINED;
|
parser->state = UNDEFINED;
|
||||||
btree_print(STDBUG, *ast, &ft_putast);
|
|
||||||
build_tree(ast, token);
|
build_tree(ast, token);
|
||||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||||
insert_linebreak(token);
|
insert_linebreak(token);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue