trying to make files work

This commit is contained in:
Jack Halford 2017-03-03 19:05:42 +01:00
parent eac301aa16
commit 8b88d41ed9
12 changed files with 51 additions and 51 deletions

1
42sh/sample/ls Normal file
View file

@ -0,0 +1 @@
ls

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:50:48 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:02:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -76,6 +76,7 @@ int exec_cmd(t_btree **ast)
if (fds[PIPE_WRITE] != STDOUT) if (fds[PIPE_WRITE] != STDOUT)
close(fds[PIPE_WRITE]); close(fds[PIPE_WRITE]);
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{
add_new_job(job); add_new_job(job);
if (JOB_IS_FG(job->attrs)) if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0); put_job_in_foreground(job, 0);
@ -84,5 +85,6 @@ int exec_cmd(t_btree **ast)
job_notify_new(job); job_notify_new(job);
put_job_in_background(job, 0); put_job_in_background(job, 0);
} }
}
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:26:31 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:03:46 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/03 18:32:23 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:02:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,9 +17,9 @@ int mark_process_status(pid_t pid, int status)
t_list *plist; t_list *plist;
t_process *p; t_process *p;
DG("PMS pid=%i,s=%i", pid, status);
if (pid > 1) if (pid > 1)
{ {
DG("MPS pid=%i,s=%i", pid, status);
if ((plist = job_getprocess(pid))) if ((plist = job_getprocess(pid)))
{ {
p = plist->content; p = plist->content;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */ /* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:51:22 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:54:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,6 +24,5 @@ int add_new_job(t_job *job)
job->id = jobc->current_id; job->id = jobc->current_id;
job->pgid = ((t_process*)job->first_process->content)->pid; job->pgid = ((t_process*)job->first_process->content)->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
job = jobc->first_job->content;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */
/* Updated: 2017/01/31 15:07:41 by jhalford ### ########.fr */ /* Updated: 2017/03/03 19:03:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/01/31 13:44:26 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:53:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:37:10 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:56:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ void job_update_status(void)
int status; int status;
pid_t pid; pid_t pid;
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); do
while (!mark_process_status(pid, status)) pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); while (!mark_process_status (pid, status));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:38:12 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:54:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,18 +18,6 @@ int job_wait(int id)
int status; int status;
DG("job wait [%i]", id); DG("job wait [%i]", id);
/* if (job_is_stopped(id)) */
/* return (0); */
/* job_update_status(); */
/* DG("after update status"); */
/* pid = waitpid(WAIT_ANY, &status, WUNTRACED); */
/* while (!process_mark_status(pid, status) */
/* && !job_is_completed(id) */
/* && !job_is_stopped(id)) */
/* { */
/* pid = waitpid(WAIT_ANY, &status, WUNTRACED); */
/* } */
do do
pid = waitpid(WAIT_ANY, &status, WUNTRACED); pid = waitpid(WAIT_ANY, &status, WUNTRACED);
while (!mark_process_status(pid, status) while (!mark_process_status(pid, status)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:52:03 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:57:58 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,10 @@ int put_job_in_foreground(t_job *j, int cont)
{ {
t_jobc *jobc; t_jobc *jobc;
if (SH_HAS_JOBC(data_singleton()->opts))
{
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
tcsetpgrp(STDIN, j->pgid); tcsetpgrp(STDIN, j->pgid);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
if (cont) if (cont)
@ -32,5 +35,9 @@ int put_job_in_foreground(t_job *j, int cont)
tcgetattr(STDIN, &j->tmodes); tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
else
job_wait(j->id);
return (0); return (0);
} }

View file

@ -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/03 17:39:30 by jhalford ### ########.fr */ /* Updated: 2017/03/03 18:55:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:33:40 by wescande ### ########.fr */ /* Updated: 2017/03/03 19:05:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -97,7 +97,10 @@ int get_input_fd()
return (fd); return (fd);
} }
else if ((file = shell_get_avdata())) else if ((file = shell_get_avdata()))
return (open(file, O_RDONLY)); {
if (fd = open(file, O_RDONLY))
return (fd);
}
else else
return (STDIN); return (STDIN);
} }
@ -108,13 +111,13 @@ int main(int ac, char **av)
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
shell_init(ac, av); shell_init(ac, av);
DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s",
SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
if ((fd = get_input_fd()) < 0) if ((fd = get_input_fd()) < 0)
{ {
ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME); ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME);
return (1); return (1);
} }
DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s, fd=[%i]",
SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
while (handle_instruction(fd) == 0) while (handle_instruction(fd) == 0)
{ {
// lexer_clean; // lexer_clean;