This commit is contained in:
Jack Halford 2017-03-24 15:13:01 +01:00
parent 016d634515
commit 72bb124bce
10 changed files with 32 additions and 34 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
int error_set(int n, ...);
int ft_perror(void);
int ft_perror(char *utility);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
if (ft_strcmp(*av, "--") == 0)
return (0);
{
av++;
break ;
}
else if ((*av)[0] == '-' && (*av)[1] == '-')
{
if (cliopts_parse_long(&av, opt_map, data))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
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);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
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)
return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL));
else if ((pid = fork()) == 0)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
data.flag = 0;
if (cliopts_get((char**)av, g_export_opts, &data))
ft_perror();
ft_perror("export");
if (data.flag & BT_EXPORT_LP)
return (bt_export_print());
av = data.av_data;

View file

@ -6,14 +6,14 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
#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[] =
{
@ -36,12 +36,12 @@ int bt_read_init(t_read *data, char **av)
data->fd = 0;
data->timeout = 0;
data->input = NULL;
if ((cliopts_get(av, g_read_opts, data)))
return (ft_perror() ? 2 : 2);
if (isatty(STDIN))
data->opts |= BT_READ_INTER;
if (bt_read_terminit(data) < 0)
return (-1);
exit (1);
if ((cliopts_get(av, g_read_opts, data)))
return (ft_perror("read"));
return (0);
}
@ -89,7 +89,8 @@ int bt_read_assign(t_read *data)
tok = ft_strtok(input, ifs);
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;
tok = ft_strtok(NULL, ifs);
names++;
@ -106,16 +107,11 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
(void)envp;
ret = 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 (data.input && bt_read_assign(&data))
ret = 1;
if (ret == -1)
exit(1);
if (ret != 0)
SH_ERR("usage: read %s %s\n", US_READ, US_READ_1);
if (ret != 2)
else if (data.input && (ret = bt_read_assign(&data)))
;
bt_read_exit(&data);
return (ret);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));
if (cliopts_get((char**)av, g_jobs_opts, &data))
return (ft_perror());
return (ft_perror("jobs"));
if (!*data.av_data)
bt_jobs_all(data.flag);
else if (bt_jobs_spec(data.av_data, data.flag))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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];
cn = lexer->str[lexer->pos + 1];
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
DG("%i : '%c'", lexer->pos, cl);
ret = 0;
if ((ft_is_delim(c) && (ret = DELIM))
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/23 16:58:43 by ariard ### ########.fr */
/* Updated: 2017/03/24 14:42:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
if (cliopts_get(av, g_opts, data))
{
ft_perror();
ft_perror(NULL);
return (SH_ERR("usage: %s", SHELL_USAGE));
}
if (!isatty(STDIN) || *data->av_data)