Ejemplo n.º 1
0
void display_prompt(t_env *env)
{
	char *line;
	pid_t papa;

	ft_putstr("\033[1;1H\033[2J");
	ft_prompt(env);
	while (42)
	{
		if (get_next_line(0, &line) > 0)
		{

			line = ft_strtrim(line);
			line = ft_supertrim(line);
			if (is_multi(line, &env) == 0 && is_builtin(line, &env) == 0)
			{
				papa = sh_fork();
				if (papa == 0)
					ft_parse(env, &line);
				else
					wait(0);
			}
			free(line);
			line = NULL;
			ft_prompt(env);
		}
	}
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: NegMozzie/42
int				main(int ac, char **av, char **env)
{
	t_shell		*shell;
	char		*line;

	if (ac == 1)
	{
		av++;
		line = NULL;
		shell = init(env);
		while (42)
		{
			re_init(shell);
			ft_prompt(shell);
			if (!shell->hist || (shell->hist->str && *shell->hist->str))
				new_hist(shell);
			else if (shell->hist && shell->hist->str)
				ft_memdel((void **)&shell->hist->str);
			line = get_line(shell, 0);
			if (line && (shell->tree = lexor_and_parsor(shell, &line)))
				main_execution(&shell);
		}
	}
	ft_putmsg(USAGE, NULL);
	return (0);
}
Ejemplo n.º 3
0
static void	ft_signal_prompt(int sig)
{
	t_line		*line;
	t_datas		*datas;

	datas = ft_getdatas(NULL);
	dprintf(datas->debug, "\nSIG:\t%i\nstatus:\t%i\n", sig, datas->status);
	line = datas->prompt.line;
	if (line != NULL && line->i != line->len - 1)
		ft_move_end(datas, line, FTSH_KEY_END);
	if (datas->prompt.line != NULL)
	{
		while (datas->prompt.line->prev != NULL)
			datas->prompt.line = line->prev;
		ft_bzero((datas->prompt.line)->buf, FTSH_MAXLEN_LINE);
		(datas->prompt.line)->i = -1;
		(datas->prompt.line)->x = 0;
		(datas->prompt.line)->y = 0;
		(datas->prompt.line)->len = 0;
	}
	if (sig == SIGINT)
		ft_putchar('\n');
	ft_prompt(datas, 0);
	if (FLAG_ISTERM(datas->flags) && FLAG_ISCOLOR(datas->flags))
		ft_putstr(FTSH_HWHITE);
}
Ejemplo n.º 4
0
static void		ft_completion(t_data *d, char **result, char *name)
{
	int		save;

	if (!result)
		return ;
	if (ft_tablen(result) == 1)
		ft_tab_replace(d, result[0], name);
	else
	{
		if (ft_prefix_completion(d, result, name))
		{
			save = d->line->len;
			ft_print_tab(result);
			ft_putchar('\n');
			ft_prompt(0);
			ft_putstr(d->line->str);
			while (save > d->line->index)
			{
				tputs(tgetstr("le", NULL), 1, ft_int_putchar);
				save--;
			}
		}
	}
}
Ejemplo n.º 5
0
void	ft_reput_prompt(int a)
{
	ft_reset();
	tputs(tgetstr("do", NULL), 1, ft_putonterm);
	tputs(tgetstr("cr", NULL), 1, ft_putonterm);
	tputs(tgetstr("cd", NULL), 1, ft_putonterm);
	ft_prompt(ft_stock(NULL, 1));
	ft_strclr(g_e.buff);
	g_e.i = 0;
	(void)a;
}
Ejemplo n.º 6
0
int				main(int argc, char **argv, char **environ)
{
	char	**env;

	argc = 0;
	argv = NULL;
	env = ft_arraydup(environ);
	signal(SIGINT, sig_handler);
	ft_prompt(PROMPT, BLUE);
	mshell(env);
	return (0);
}
Ejemplo n.º 7
0
int			ft_putstr_term(char *str, t_data *st)
{
	int		char_to_print;
	char	*term_name;

	term_name = ft_getenv(st->envtab, "TERM");
	if (term_name == NULL)
		term_name = "xterm-256color";
	tgetent(NULL, term_name);
	ft_prompt(st);
	char_to_print = st->plen + ft_strlen(str);
	st->linelen = (char_to_print / (tgetnum("co") + 1)) + 1;
	ft_putstr_fd(str, isatty(1));
	return (char_to_print);
}
Ejemplo n.º 8
0
void		ft_exec(char ***envp)
{
	char	*line;
	t_list	*tokens;
	char	*trim;

	line = NULL;
	tokens = NULL;
	ft_prompt(*envp);
	line = ft_get_cmd(*envp);
	if (!line)
		return (ft_exec(envp));
	trim = ft_strtrim(line);
	if (trim && !ft_strequ(trim, ""))
	{
		tokens = ft_tokenize(trim);
		free(trim);
		if (tokens)
			parse_cmd(tokens, envp);
	}
	return (ft_exec(envp));
}
Ejemplo n.º 9
0
static void		mshell(char **env)
{
	char	*line;
	char 	**av;
	pid_t	father;

	(void)env;
	while (get_next_line(0, &line) > 0)
	{
		father = fork();
		if (father != 0)
		{
			signal(SIGUSR1, sig_handler);
			wait(&father);
		}
		else
		{
			av = sh_lexer(&line);
		}
		free(line);
		ft_prompt(PROMPT, BLUE);
	}
}