This commit is contained in:
Jack Halford 2017-03-14 21:12:08 +01:00
commit bb9796f758
14 changed files with 88 additions and 106 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
/* Updated: 2017/03/13 14:52:53 by jhalford ### ########.fr */
/* Updated: 2017/03/14 15:22:44 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,9 +36,9 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
ft_save_termios(-1);
ft_free_hash_table();
free_history_list(data_singleton()->line.list_beg);
data_exit();
if (SH_IS_INTERACTIVE(data_singleton()->opts))
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
data_exit();
exit(status);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2017/03/14 21:10:39 by jhalford ### ########.fr */
/* Updated: 2017/03/14 21:11:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */
/* Updated: 2017/03/10 17:43:15 by gwojda ### ########.fr */
/* Updated: 2017/03/14 14:00:30 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -63,7 +63,6 @@ int c_glob_matching(void)
glob_echap = (unsigned char *)ft_strnew(ft_strlen(str) >> 3);
ft_bzero(glob_echap, ft_strlen(str) >> 3);
ss_glob = glob(current_word, glob_echap, glob_echap, 1);
// ss_glob = glob(current_word, glob_echap, glob_echap);
free(current_word);
if (!*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob)))
return (0);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 15:50:24 by gwojda #+# #+# */
/* Updated: 2017/03/14 10:10:19 by gwojda ### ########.fr */
/* Updated: 2017/03/14 17:21:37 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,7 +37,8 @@ int c_seek_env(t_comp *c, char *current_word)
match = ft_strdupi_w(current_word + 1);
while (env[i])
{
if (!ft_strncmp(match, env[i], ft_strlen(match)))
if (!ft_strncmp(match, env[i], ft_strlen(match)) &&
env[i][ft_strlen(match)] != '=')
c_storing(c, ft_strndup(env[i], ft_strchr(env[i], '=') - env[i]));
++i;
}

View file

@ -3,93 +3,53 @@
/* ::: :::::::: */
/* command_getoutput.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/03/13 23:32:52 by jhalford ### ########.fr */
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define BUF_SIZE 1024
/*static char *manage_output(int *fds)
{
int ret;
char buf[BUF_SIZE + 1];
char *output;
output = NULL;
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
{
buf[ret] = 0;
ft_strappend(&output, buf);
}
close(fds[PIPE_READ]);
return (output);
}
*/
static t_btree *gen_t_btree(const char *command)
static char *manage_output(int *fds)
{
t_btree *ast;
t_astnode item;
int len;
unsigned char *esc;
ft_bzero(&item, sizeof(t_astnode));
item.type = SUBSHELL;
ast = btree_create_node(&item, sizeof(t_astnode));
ft_bzero(&item, sizeof(t_astnode));
item.type = CMD;
len = ft_strlen(command);
esc = ft_memalloc((len >> 3) + 1);
ft_ld_pushfront(&item.data.cmd.token, gen_tab(command, esc, esc, 1));
ast->right = btree_create_node(&item, sizeof(t_astnode));
return (ast);
}
char *command_getoutput(char *command)
{
t_btree *ast;
char *output;
char buf[BUF_SIZE + 1];
t_exec *exec;
t_process p;
int ret;
int pid;
char buf[BUF_SIZE + 1];
char *output;
return (NULL);
output = NULL;
exec = &data_singleton()->exec;
DG("%p exec ?", exec);
DG("\033[38;5;46mbefore");
ast = gen_t_btree(command);
DG();
if (process_set(&p, ast))
return (NULL);
DG();
if (!(pid = plaunch_subshell(&p)))
return (NULL);
waitpid(pid, &ret, WUNTRACED);
DG();
// exec_leaf(&ast);
/*
DG();
set_process(&p, ast);
DG();
launch_process(&p);
DG();
close(p.fdout);*/
DG();
while ((ret = read(exec->fdin, buf, BUF_SIZE)) > 0)
close(fds[PIPE_WRITE]);
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
{
buf[ret] = 0;
ft_strappend(&output, buf);
}
DG();
close(exec->fdin);
DG("done with %s\033[0m", output);
close(fds[PIPE_READ]);
return (output);
}
char *command_getoutput(char *command)
{
char *output;
int ret;
int pid;
int fds[2];
if (!command)
return (NULL);
pipe(fds);
if (!(pid = fork()))
{
close(fds[PIPE_READ]);
dup2_close(fds[PIPE_WRITE], STDOUT);
execle(data_singleton()->argv[0],data_singleton()->argv[0],
"-c", command, NULL,
data_singleton()->env);
exit(1);
}
waitpid(pid, &ret, WUNTRACED);
output = manage_output(fds);
return (output);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
/* Updated: 2017/02/24 22:04:59 by ariard ### ########.fr */
/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -75,7 +75,7 @@ static char *get_output(char *command)
int len;
if (!(output = command_getoutput(command)))
return (ft_strnew(0));
return (NULL);//ft_strnew(0));
len = ft_strlen(output);
while (output[--len] == '\n')
output[len] = '\0';
@ -98,10 +98,8 @@ static int search_bquote(t_bquote *me)
me->mid = ft_strsub(sta, 1, me->str - sta - 1);
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
me->s2 = ft_strdup(me->str + 1);
content = get_output(me->mid);
DG();
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
DG();
if ((content = get_output(me->mid)))
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
ft_strdel(&me->mid);
ft_strdel(&me->s1);
ft_strdel(&me->s2);
@ -113,6 +111,13 @@ static int search_bquote(t_bquote *me)
return (0);
}
void delete(t_ld **tmp, t_ld **src)
{
if (*tmp == *src)
ft_ld_del(src, &ft_tabdel);
else
ft_ld_del(tmp, &ft_tabdel);
}
void expand_bquote(t_glob *gl)
{
t_ld *tmp;
@ -133,8 +138,9 @@ void expand_bquote(t_glob *gl)
me.str = CH(gl->m_pat)[0];
if ((tmp = gl->m_pat) &&
(do_it = search_bquote(&me)) == 1)
ft_ld_del(&tmp, &ft_tabdel);
if (!gl->m_pat->next)
delete(&tmp, &gl->m_pat);
// ft_ld_del(&tmp, &ft_tabdel);
if (!gl->m_pat || !gl->m_pat->next)
break ;
gl->m_pat = gl->m_pat->next;
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */
/* Updated: 2017/03/14 09:50:57 by gwojda ### ########.fr */
/* Updated: 2017/03/14 14:58:41 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,7 @@ void ft_add_in_history_file(char *str)
return ;
while (hist[i])
{
write(fd, hist[i], ft_strlen(str));
write(fd, hist[i], ft_strlen(hist[i]));
write(fd, "\n", 1);
++i;
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */
/* Updated: 2017/03/13 14:47:06 by jhalford ### ########.fr */
/* Updated: 2017/03/14 15:20:22 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,11 +18,15 @@ void free_history_list(t_list_history *head)
if (!head)
return ;
DG("free hist");
if (head->next)
free(head->next);
while (head)
{
ft_strdel(&head->str);
prev = head;
head = head->next;
head = head->prev;
free(prev);
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/03/13 22:29:29 by jhalford ### ########.fr */
/* Updated: 2017/03/14 20:21:46 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -42,7 +42,8 @@ static void process_format_com_long(t_list **plist)
t_process *p;
p = (*plist)->content;
(p->map.print)(p);
if (p->map.print)
(p->map.print)(p);
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
if ((*plist)->next)
ft_putstr(" |");
@ -64,7 +65,8 @@ static void process_format_com_short(t_list **plist, t_flag state)
p->attrs &= ~PROCESS_STATE_MASK;
p->attrs &= ~PROCESS_RUNNING;
}
(p->map.print)(p);
if (p->map.print)
(p->map.print)(p);
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
if ((*plist)->next)
ft_putstr(" | ");

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/13 22:19:53 by jhalford ### ########.fr */
/* Updated: 2017/03/14 20:19:22 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,7 +36,8 @@ void process_free(void *content, size_t content_size)
/* return ; */
/* if (g_freemap[p->type].f) */
/* (g_freemap[p->type].f)(p); */
(p->map.free)(p);
if (p->map.free)
(p->map.free)(p);
ft_lstdel(&p->redirs, redir_free);
free(p);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
/* Updated: 2017/03/14 12:32:38 by gwojda ### ########.fr */
/* Updated: 2017/03/14 16:00:05 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,16 +24,18 @@ static int promt_git_status(int fd)
line = ft_strdup(ft_strrchr(line, '/') + 1);
else
line = ft_strdup(line + 3);
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
free(tmp);
ft_printf("\x1b[38;5;47mgit:(\x1b[38;5;203m%s\x1b[38;5;47m)", line);
if (!get_next_line(fd, &tmp))
printf("\x1b[38;5;83m %C ", L'');
else
{
printf("\x1b[38;5;1m %C ", L'');
while (get_next_line(fd, &tmp))
free(tmp);
free(tmp);
}
while (get_next_line(fd, &tmp))
free(tmp);
free(tmp);
len = ft_strlen(line);
ft_strdel(&line);
fflush(NULL);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* data_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
/* Updated: 2017/01/22 17:20:29 by ariard ### ########.fr */
/* Updated: 2017/03/14 15:21:17 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,4 +19,6 @@ void data_exit(void)
data = data_singleton();
/* ft_strdel(&data->line.input); */
ft_sstrfree(data->env);
ft_sstrfree(data->argv);
free(data_singleton());
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/14 20:49:16 by jhalford ### ########.fr */
/* Updated: 2017/03/14 21:11:58 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,6 +79,8 @@ int handle_instruction(int fd)
instruction_free(&token, &parser, &ast);
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
ft_add_str_in_history(lexer.str);
ft_strdel(&lexer.str);
free(parser.new_sym);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/13 19:28:21 by ariard ### ########.fr */
/* Updated: 2017/03/14 15:02:34 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,6 +17,7 @@ int pop_heredoc(t_list **lst)
t_token *token;
t_list **head;
t_redir *redir;
char *tmp;
token = (*lst)->content;
if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL)
@ -34,8 +35,10 @@ int pop_heredoc(t_list **lst)
}
else
{
tmp = redir->heredoc_data;
redir->heredoc_data = ft_str3join(redir->heredoc_data,
(char*)token->data, "\n");
(char*)token->data, "\n");
ft_strdel(&tmp);
}
}
ft_lstdel(lst, &token_free);