some norme

This commit is contained in:
Jack Halford 2017-03-22 19:36:22 +01:00
parent 5547d38afa
commit b8e6fc6f95
26 changed files with 45 additions and 150 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:25:08 by jhalford ### ########.fr */ /* Updated: 2017/03/22 18:36:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,83 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_input.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
/* Updated: 2017/03/22 17:51:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_INPUT_H
# define FT_INPUT_H
/*
* Input code mapping (!!!!LINUX!!!!)
* TODO Same for MACOSX
*/
# ifdef __linux__
# define RL_INSERT_CODE 0x7e325b1b
# define RL_CLEAR_CODE 0xc
# define RL_NL_CODE 0xa
# define RL_COMP_CODE 0x9
# define RL_LEFT_CODE 0x445b1b
# define RL_RIGHT_CODE 0x435b1b
# define RL_WLEFT_CODE 0x44323b315b1b
# define RL_WRIGHT_CODE 0x43323b315b1b
# define RL_HOME_CODE 0x485b1b
# define RL_END_CODE 0x465b1b
# define RL_PAGEUP_CODE 0x7e355b1b
# define RL_PAGEDOWN_CODE 0x7e365b1b
# define RL_SELECT_RIGHT_CODE 0x43333b315b1b
# define RL_SELECT_LEFT_CODE 0x44333b315b1b
# define RL_SELECT_PAGEUP_CODE 0x7e333b355b1b
# define RL_SELECT_PAGEDOWN_CODE 0x7e333b365b1b
# define RL_SELECT_HOME_CODE 0x48333b315b1b
# define RL_SELECT_END_CODE 0x46333b315b1b
# define RL_SELECT_WRIGHT_CODE 0x43343b315b1b
# define RL_SELECT_WLEFT_CODE 0x44343b315b1b
# define RL_RETARR_CODE 0x7f
# define RL_SUPPR_CODE 0x7e335b1b
# define RL_ESC_CODE 0x5c
# define RL_QUOTE_CODE 0x27
# define RL_DQUOTE_CODE 0x22
# define RL_COPY_CODE 0x631b
# define RL_CUT_CODE 0x781b
# define RL_PASTE_CODE 0x761b
# endif
# ifdef __APPLE__
# define RL_INSERT_CODE 0x53323b315b1b
# define RL_CLEAR_CODE 0xc
# define RL_NL_CODE 0xa
# define RL_COMP_CODE 0x9
# define RL_LEFT_CODE 0x445b1b
# define RL_RIGHT_CODE 0x435b1b
# define RL_WLEFT_CODE 0x44323b315b1b
# define RL_WRIGHT_CODE 0x43323b315b1b
# define RL_HOME_CODE 0x485b1b
# define RL_END_CODE 0x465b1b
# define RL_PAGEUP_CODE 0x7e355b1b
# define RL_PAGEDOWN_CODE 0x7e365b1b
# define RL_SELECT_RIGHT_CODE 0x435b1b1b
# define RL_SELECT_LEFT_CODE 0x445b1b1b
# define RL_SELECT_PAGEUP_CODE 0x7e355b1b1b
# define RL_SELECT_PAGEDOWN_CODE 0x7e365b1b1b
# define RL_SELECT_HOME_CODE 0X48393b315b1b
# define RL_SELECT_END_CODE 0X46393b315b1b
# define RL_SELECT_WRIGHT_CODE 0x4330313b315b1b
# define RL_SELECT_WLEFT_CODE 0x4430313b315b1b
# define RL_RETARR_CODE 0x7f
# define RL_SUPPR_CODE 0x7e335b1b
# define RL_ESC_CODE 0x5c
# define RL_QUOTE_CODE 0x27
# define RL_DQUOTE_CODE 0x22
# define RL_COPY_CODE 0xa7c3
# define RL_CUT_CODE 0x8889e2
# define RL_PASTE_CODE 0x9a88e2
# endif
#endif

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/22 17:53:46 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:21:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,8 +30,6 @@
# include <dirent.h> # include <dirent.h>
# include <locale.h> # include <locale.h>
# include "ft_input.h"
# define FLECHE_HAUT 4283163 # define FLECHE_HAUT 4283163
# define FLECHE_BAS 4348699 # define FLECHE_BAS 4348699
# define FLECHE_GAUCHE 4479771 # define FLECHE_GAUCHE 4479771

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:30:06 by ariard ### ########.fr */ /* Updated: 2017/03/22 19:17:46 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
/* Updated: 2017/03/22 16:48:34 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:21:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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 16:50:14 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:21:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -54,7 +54,7 @@ int bt_read_loop(t_read *data)
esc = 0; esc = 0;
i = 0; i = 0;
if (data->prompt && data->opts & BT_READ_INTER) if (data->prompt && (data->opts & BT_READ_INTER))
ft_printf(data->prompt); ft_printf(data->prompt);
while (42) while (42)
{ {

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/21 20:15:59 by ariard ### ########.fr */ /* Updated: 2017/03/22 18:27:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/22 16:09:10 by jhalford ### ########.fr */ /* Updated: 2017/03/22 18:26:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */ /* Updated: 2017/03/22 19:30:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/21 18:10:08 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:23:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,5 @@ int plaunch_if(t_process *p)
{ {
data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH; data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH;
ft_exec(&p->data.d_if.content); ft_exec(&p->data.d_if.content);
/* set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?"))); */
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
/* Updated: 2017/03/22 18:04:44 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:22:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,6 @@ int plaunch_until(t_process *p)
ret = 0; ret = 0;
ft_exec(&p->data.d_until.condition); ft_exec(&p->data.d_until.condition);
/* signal(SIGINT, sigint_handler); */
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
{ {
ft_exec(&p->data.d_until.content); ft_exec(&p->data.d_until.content);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/22 18:01:02 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:23:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,6 @@ int plaunch_while(t_process *p)
ret = 0; ret = 0;
ft_exec(&p->data.d_while.condition); ft_exec(&p->data.d_while.condition);
signal(SIGINT, sigint_handler);
while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")))
{ {
ft_exec(&p->data.d_while.content); ft_exec(&p->data.d_while.content);

View file

@ -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 17:52:47 by jhalford ### ########.fr */ /* Updated: 2017/03/22 18:26:53 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/22 16:24:18 by gwojda ### ########.fr */ /* Updated: 2017/03/22 18:26:37 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */ /* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:26:47 by gwojda ### ########.fr */ /* Updated: 2017/03/22 18:24:31 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */ /* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
/* Updated: 2017/03/20 15:10:32 by wescande ### ########.fr */ /* Updated: 2017/03/22 19:24:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 22:18:46 by wescande #+# #+# */ /* Created: 2017/01/31 22:18:46 by wescande #+# #+# */
/* Updated: 2017/03/21 18:13:25 by gwojda ### ########.fr */ /* Updated: 2017/03/22 19:24:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,7 +66,7 @@ unsigned char **ft_strsplit_esc(const char *str,
if ((pos = -1) && !str) if ((pos = -1) && !str)
return (NULL); return (NULL);
if (!(s1 = (unsigned char **)ft_malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1)))) if (!(s1 = ft_malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1))))
return (NULL); return (NULL);
i = 0; i = 0;
fix = str; fix = str;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */
/* Updated: 2017/03/16 16:49:06 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:29:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,7 @@ int builtin_bg(const char *path, char *const av[], char *const envp[])
(void)envp; (void)envp;
if (!SH_HAS_JOBC(data_singleton()->opts)) if (!SH_HAS_JOBC(data_singleton()->opts))
{ {
ft_dprintf(2, "{red}bg: %s{eoc}\n", SH_MSG_NOJOBC); SH_ERR("bg: %s", SH_MSG_NOJOBC);
return (-1); return (-1);
} }
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
@ -35,8 +35,8 @@ int builtin_bg(const char *path, char *const av[], char *const envp[])
return (0); return (0);
} }
else if (av[1]) else if (av[1])
ft_dprintf(2, "{red}bg: job not found: %i{eoc}\n", id); SH_ERR("bg: job not found: [%i]", id);
else else
ft_dprintf(2, "{red}bg: no current job{eoc}\n"); SH_ERR("bg: no current job");
return (1); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
/* Updated: 2017/03/22 16:30:05 by gwojda ### ########.fr */ /* Updated: 2017/03/22 19:31:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,21 +28,15 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
} }
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
job_getrank(&rank); job_getrank(&rank);
if (av[1] ? (id = *av[1]) : 0) id = av[1] ? ft_atoi(av[1]) : rank[0];
{
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
job_run(jlist->content, 1);
else
SH_ERR("{red}fg: job not found: [%i]", id);
}
else
{ {
if ((jlist = ft_lst_find(jobc->first_job, &rank[0], job_cmp_id)))
job_run(jlist->content, 1); job_run(jlist->content, 1);
else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id))) return (0);
job_run(jlist->content, 1); }
else else if (av[1])
SH_ERR("fg: no current job"); SH_ERR("fg: job not found: [%i]", id);
} else
SH_ERR("fg: no current job");
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/21 01:30:10 by wescande ### ########.fr */ /* Updated: 2017/03/22 19:36:16 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,6 @@ int job_addprocess(t_process *p)
job_update_id(); job_update_id();
job->id = jobc->current_id; job->id = jobc->current_id;
job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ?
/* p->pid : data_singleton()->jobc.shell_pgid; */
p->pid : getpgid(0); p->pid : getpgid(0);
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:24:09 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:30:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/21 20:49:32 by ariard ### ########.fr */ /* Updated: 2017/03/22 18:15:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */
/* Updated: 2017/03/22 18:04:22 by jhalford ### ########.fr */ /* Updated: 2017/03/22 18:17:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 16:29:35 by jhalford #+# #+# */ /* Created: 2017/03/05 16:29:35 by jhalford #+# #+# */
/* Updated: 2017/03/22 18:13:49 by jhalford ### ########.fr */ /* Updated: 2017/03/22 18:15:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/22 17:44:44 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:18:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,11 +6,12 @@
/* 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 16:08:21 by jhalford ### ########.fr */ /* Updated: 2017/03/22 19:36:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#define SHELL_USAGE "42sh [-c command | [<]script] [--no-jobcontrol]"
static t_cliopts g_opts[] = static t_cliopts g_opts[] =
{ {
@ -42,16 +43,12 @@ static int get_input_fd(t_data *data)
} }
else if ((file = *data->av_data)) else if ((file = *data->av_data))
{ {
DG("file=%s", file);
if (stat(file, &buf) < 0) if (stat(file, &buf) < 0)
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SH_ERR("%s: No such file or directory", file);
data->argv[0], file);
else if (S_ISDIR(buf.st_mode)) else if (S_ISDIR(buf.st_mode))
ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], SH_ERR("%s: is a directory", file);
file);
else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0) else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0)
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SH_ERR("%s: No such file or directory", file);
data->argv[0], file);
} }
else else
return (STDIN); return (STDIN);
@ -75,8 +72,7 @@ static int interactive_settings(void)
shell_resetsig(); shell_resetsig();
if (setpgid(*shell_pgid, *shell_pgid)) if (setpgid(*shell_pgid, *shell_pgid))
{ {
ft_dprintf(2, SH_ERR("setpgid(): %s", strerror(errno));
"{red}Couldnt put the shell in it's own process group{eoc}\n");
return (-1); return (-1);
} }
tcsetpgrp(STDIN, *shell_pgid); tcsetpgrp(STDIN, *shell_pgid);
@ -84,12 +80,6 @@ static int interactive_settings(void)
return (0); return (0);
} }
static int usage(void)
{
ft_dprintf(2, "usage: 42sh [-c command | [<]script] [--no-jobcontrol]\n");
return (0);
}
int shell_init(int ac, char **av) int shell_init(int ac, char **av)
{ {
t_data *data; t_data *data;
@ -99,8 +89,8 @@ 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))
{ {
usage(); ft_perror();
return (ft_perror()); return (SH_ERR("usage: %s", SHELL_USAGE));
} }
if (!isatty(STDIN) || *data->av_data) if (!isatty(STDIN) || *data->av_data)
data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);