commit
9cb51bbd8c
18 changed files with 62 additions and 114 deletions
|
|
@ -13,7 +13,7 @@
|
|||
NAME = 42sh
|
||||
|
||||
CC = gcc
|
||||
FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden
|
||||
FLAGS = -Wall -Wextra -Werror -fsanitize=address#-fvisibility=hidden
|
||||
D_FLAGS = -g
|
||||
|
||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||
|
|
@ -48,7 +48,6 @@ builtin/builtin_read.c\
|
|||
builtin/builtin_setenv.c\
|
||||
builtin/builtin_unset.c\
|
||||
builtin/builtin_unsetenv.c\
|
||||
builtin/error_msg.c\
|
||||
builtin/is_builtin.c\
|
||||
completion/c_arrow.c\
|
||||
completion/c_clear.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 01:24:42 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 04:03:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ typedef struct s_readopt t_readopt;
|
|||
|
||||
struct s_read
|
||||
{
|
||||
t_flag opts;
|
||||
t_flag flag;
|
||||
char **names;
|
||||
char delim;
|
||||
int nchars;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/24 18:38:35 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 03:22:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -67,12 +67,6 @@ int word_is_assignment(char **content);
|
|||
void *tab_esc_copy(void *content);
|
||||
char *get_output(char *command);
|
||||
|
||||
/*
|
||||
** return TRUE if path file is a directory.
|
||||
*/
|
||||
|
||||
int is_directory(const char *path);
|
||||
|
||||
/*
|
||||
** return TRUE if char at str_pos in ini_str is escape.
|
||||
** five the possibility to set if the char is esc or not.
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ char/ft_isprint.c\
|
|||
char/ft_tolower.c\
|
||||
char/ft_toupper.c\
|
||||
cliopts/cliopts_get.c\
|
||||
cliopts/cliopts_has.c\
|
||||
cliopts/cliopts_getmap.c\
|
||||
color/ft_color_mk.c\
|
||||
color/ft_color_mkif.c\
|
||||
color/ft_color_reset.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 01:18:54 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -37,6 +37,8 @@ struct s_data_template
|
|||
};
|
||||
|
||||
int cliopts_get(char **av, t_cliopts opt_map[], void *data);
|
||||
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg);
|
||||
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg);
|
||||
int cliopts_has(char **av, char c);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 04:07:20 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:12:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ char *ft_getenv(char **env, char *key);
|
|||
|
||||
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm);
|
||||
int is_directory(const char *path);
|
||||
char *create_direcotry(const char *path, const char *old_pathnames);
|
||||
char *create_directory(const char *path, const char *old_pathnames);
|
||||
|
||||
int dup2_close(int fd1, int fd2);
|
||||
int fd_replace(int fd1, int fd2);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 02:02:09 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:00:35 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,10 +21,6 @@ static char *check_required(char ***av, char *arg)
|
|||
{
|
||||
char *ret;
|
||||
|
||||
DG("%p, av", av);
|
||||
DG("%p, *av", *av);
|
||||
DG("%p, arg", arg);
|
||||
DG("%s, *arg", arg);
|
||||
if (!av || !*av)
|
||||
return (NULL);
|
||||
if (!arg || !*arg || !*(arg + 1))
|
||||
|
|
@ -33,28 +29,6 @@ static char *check_required(char ***av, char *arg)
|
|||
return (ret);
|
||||
}
|
||||
|
||||
static t_cliopts *get_map_long(t_cliopts opt_map[], char *arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (opt_map[++i].c)
|
||||
if (!ft_strcmp(opt_map[i].str, arg))
|
||||
return (&opt_map[i]);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static t_cliopts *get_map_short(t_cliopts opt_map[], char arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (opt_map[++i].c)
|
||||
if (opt_map[i].c == arg)
|
||||
return (&opt_map[i]);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int cliopts_parse_short(
|
||||
char ***av, t_cliopts opt_map[], void *data)
|
||||
{
|
||||
|
|
@ -67,8 +41,10 @@ static int cliopts_parse_short(
|
|||
i = -1;
|
||||
while (arg[++i] && !(tmp = NULL))
|
||||
{
|
||||
if (!(map = get_map_short(opt_map, arg[i])))
|
||||
if (!(map = cliopts_getmap_short(opt_map, arg[i])))
|
||||
return (ERR_SET(E_CO_INV, arg[i]));
|
||||
((t_data_template*)data)->flag |= map->flag_on;
|
||||
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||
if (map->get)
|
||||
{
|
||||
if (map->arg_required && !(tmp = check_required(av, arg + i)))
|
||||
|
|
@ -79,8 +55,6 @@ static int cliopts_parse_short(
|
|||
if (map->arg_required)
|
||||
break ;
|
||||
}
|
||||
((t_data_template*)data)->flag |= map->flag_on;
|
||||
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||
}
|
||||
return (++(*av) ? 0 : 0);
|
||||
}
|
||||
|
|
@ -94,7 +68,7 @@ static int cliopts_parse_long(
|
|||
|
||||
arg = **av + 2;
|
||||
tmp = NULL;
|
||||
if (!(map = get_map_long(opt_map, arg)))
|
||||
if (!(map = cliopts_getmap_long(opt_map, arg)))
|
||||
return (ERR_SET(E_CO_INVL, arg));
|
||||
((t_data_template*)data)->flag |= map->flag_on;
|
||||
((t_data_template*)data)->flag &= ~map->flag_off;
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cliopts_has.c :+: :+: :+: */
|
||||
/* cliopts_getmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 20:03:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 15:48:57 by jhalford ### ########.fr */
|
||||
/* Created: 2017/03/25 14:59:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 15:01:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cliopts.h"
|
||||
|
||||
int cliopts_has(char **av, char c)
|
||||
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg)
|
||||
{
|
||||
if (!av)
|
||||
return (0);
|
||||
while (*av)
|
||||
{
|
||||
if (ft_strcmp(*av, "--") == 0)
|
||||
return (0);
|
||||
else if ((*av)[0] == '-' && (*av)[1] == '-')
|
||||
av++;
|
||||
else if ((*av)[0] == '-')
|
||||
{
|
||||
if (ft_strchr(*av + 1, c))
|
||||
return (1);
|
||||
av++;
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
return (0);
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (opt_map[++i].c)
|
||||
if (!ft_strcmp(opt_map[i].str, arg))
|
||||
return (&opt_map[i]);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (opt_map[++i].c)
|
||||
if (opt_map[i].c == arg)
|
||||
return (&opt_map[i]);
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/07 15:22:09 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:03:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 03:18:18 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/25 04:13:15 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:12:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ char *create_directory(const char *path, const char *old_pathnames)
|
|||
if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path)))
|
||||
ft_strdel(&newdir);
|
||||
else
|
||||
break;
|
||||
break ;
|
||||
new_pathnames += ft_strlen(new_pathnames) + 1;
|
||||
}
|
||||
ft_strdel(&temp);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 02:26:43 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm)
|
|||
{
|
||||
int fd;
|
||||
|
||||
if (a_flag & F_OK && access(file, F_OK) != 0)
|
||||
if (a_flag & F_OK && access(file, F_OK) != 0)
|
||||
return (-ERR_SET(E_SYS_NOFILE, file));
|
||||
if (is_directory(file))
|
||||
return (-ERR_SET(E_SYS_ISDIR, file));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 01:27:06 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 04:00:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,6 +18,7 @@ int bt_read_getdelim(char *opt_arg, t_read *data)
|
|||
return (1);
|
||||
if (data)
|
||||
data->delim = *opt_arg;
|
||||
DG("delim=%c", data->delim);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/22 19:21:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/25 04:20:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,15 +26,13 @@ int bt_read_terminit(t_read *data)
|
|||
struct termios term;
|
||||
|
||||
term = bt_read_term(1);
|
||||
if (!(data->opts & BT_READ_INTER))
|
||||
if (!(data->flag & BT_READ_INTER))
|
||||
return (0);
|
||||
term.c_lflag = ECHO | ECHOE | ECHOK | ICANON;
|
||||
{
|
||||
term.c_lflag &= data->timeout ? ~ICANON : ~0;
|
||||
term.c_cc[VTIME] = data->timeout * 10;
|
||||
term.c_cc[VMIN] = !data->timeout;
|
||||
}
|
||||
if (data->opts & BT_READ_LS)
|
||||
term.c_lflag &= data->timeout ? ~ICANON : ~0;
|
||||
term.c_cc[VTIME] = data->timeout * 10;
|
||||
term.c_cc[VMIN] = data->timeout ? 0 : 1;
|
||||
if (data->flag & BT_READ_LS)
|
||||
term.c_lflag &= ~ECHO;
|
||||
term.c_cc[VEOL] = data->delim;
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/25 02:10:38 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:10:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,8 +15,6 @@
|
|||
#define ENV_USAGE "env [-i] [name=value]... [utility [argument...]]"
|
||||
#define ENV_NOFILE "env: %s: No such file or directory"
|
||||
#define ENV_NOPERM "env: %s: Permission denied"
|
||||
/* # define BT_ENV_LI (1 << 0) */
|
||||
/* # define BT_ENV_LU (1 << 1) */
|
||||
|
||||
static t_cliopts g_env_opts[] =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/24 15:03:02 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/24 17:11:50 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:08:37 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 01:28:33 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 15:10:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ t_cliopts g_read_opts[] =
|
|||
|
||||
int bt_read_init(t_read *data, char **av)
|
||||
{
|
||||
data->opts = 0;
|
||||
data->flag = 0;
|
||||
data->delim = '\n';
|
||||
data->nchars = -1;
|
||||
data->prompt = NULL;
|
||||
|
|
@ -37,11 +37,11 @@ int bt_read_init(t_read *data, char **av)
|
|||
data->timeout = 0;
|
||||
data->input = NULL;
|
||||
if (isatty(STDIN))
|
||||
data->opts |= BT_READ_INTER;
|
||||
if (bt_read_terminit(data) < 0)
|
||||
exit(1);
|
||||
data->flag |= BT_READ_INTER;
|
||||
if ((cliopts_get(av, g_read_opts, data)))
|
||||
return (ft_perror("read"));
|
||||
if (bt_read_terminit(data) < 0)
|
||||
exit(1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ int bt_read_loop(t_read *data)
|
|||
|
||||
esc = 0;
|
||||
i = 0;
|
||||
if (data->prompt && (data->opts & BT_READ_INTER))
|
||||
if (data->prompt && (data->flag & BT_READ_INTER))
|
||||
ft_printf(data->prompt);
|
||||
while (42)
|
||||
{
|
||||
|
|
@ -63,12 +63,12 @@ int bt_read_loop(t_read *data)
|
|||
buf[ret] = 0;
|
||||
if (!esc && *buf == data->delim)
|
||||
break ;
|
||||
esc = esc ? 0 : !(data->opts & BT_READ_LR) && (*buf == '\\');
|
||||
esc = esc ? 0 : !(data->flag & BT_READ_LR) && (*buf == '\\');
|
||||
ft_strappend(&data->input, buf);
|
||||
if (*buf == '\n' && !(data->opts &
|
||||
if (*buf == '\n' && !(data->flag &
|
||||
(BT_READ_LR | BT_READ_LS | BT_READ_INTER)))
|
||||
ft_putstr("> ");
|
||||
if ((data->opts & BT_READ_LN) && ++i >= data->nchars)
|
||||
if ((data->flag & BT_READ_LN) && ++i >= data->nchars)
|
||||
break ;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* error_msg.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 23:21:37 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/21 15:20:26 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int error_msg(char *msg)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s{eoc}", msg);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ void data_exit(void)
|
|||
data = data_singleton();
|
||||
ft_strdel(&data->line.input);
|
||||
ft_strdel(&data->binary);
|
||||
exec_popfds();
|
||||
ft_sstrfree(data->env);
|
||||
ft_sstrfree(data->local_var);
|
||||
ft_sstrfree(data->argv);
|
||||
|
|
|
|||
Loading…
Reference in a new issue