예제 #1
0
파일: main.c 프로젝트: jmunozz/minishell
int				main(int ac, char **av, char **envp)
{
	char	**cmd;
	int		i;
	int		exit;

	av[ac] = 0;
	i = 0;
	g_envtmp = NULL;
	g_env = ft_tabdup(envp);
	set_signals(0);
	while (i < 2)
	{
		g_pid = 0;
		ft_putstr("$> ");
		cmd = ft_get_cmd();
		exit = do_cmd(cmd, &i);
		ft_freetab(&cmd);
	}
	ft_freetab(&g_env);
	return (exit);
}
예제 #2
0
파일: ft_shell.c 프로젝트: kperreau/42
int				ft_parse_stdin(char *line, t_list **lenv)
{
	char	**cmd;
	char	**cmds;
	int		i;
	t_pfunc	f;

	ft_init_f(f);
	cmds = ft_strsplit(line, ';');
	i = 0;
	while (cmds[i])
	{
		cmd = ft_splitword(cmds[i]);
		if (!cmd || !*cmd)
			return (0);
		(f[ft_find_func(*cmd)])(cmd, lenv);
		++i;
		ft_freetab(cmd);
	}
	ft_freetab(cmds);
	return (0);
}
예제 #3
0
int client_side_command(char *command)
{
	char **args;
	int i;

	if (command[0] != '/')
		return (0);
	i = 0;
	args = ft_strsplit(command, '\t', ' ');
	while (g_func[i].name != NULL)
	{
		if (!ft_strcmp(args[0] + 1, g_func[i].name))
		{
			g_func[i].func(args + 1);
			ft_freetab(args);
			return (1);
		}
		i++;
	}
	ft_freetab(args);
	return (0);
}
예제 #4
0
파일: option_l.c 프로젝트: FantzFoXx/ft_ls
static t_litem	*get_date(t_dir_item *item)
{
    char	**tmp;
    t_litem	*date;
    char	**cur_time;
    time_t	today;

    date = NULL;
    today = time(0);
    cur_time = ft_strsplit(ctime(&today), ' ');
    tmp = ft_strsplit(ctime(&item->prop.st_mtime), ' ');
    t_litem_push(&date, t_litem_new(ft_strdup(tmp[1])));
    t_litem_push(&date, t_litem_new(ft_strdup(tmp[2])));
    if ((today - item->prop.st_mtime) >= 15768000
            || (today - item->prop.st_mtime) < 0)
        t_litem_push(&date, t_litem_new(ft_strsub(tmp[4], 0
                                        , ft_strchr(tmp[4], '\n') - tmp[4])));
    else
        t_litem_push(&date, t_litem_new(ft_strsub(tmp[3], 0, 5)));
    ft_freetab(tmp);
    ft_freetab(cur_time);
    return (date);
}
예제 #5
0
파일: exec_file.c 프로젝트: dlageist42/42
static void	run_cmd(char **cmd)
{
	pid_t	father;
	char	**tab;

	father = fork();
	if (father)
	{
		g_process_running = TRUE;
		wait(NULL);
		g_process_running = FALSE;
	}
	else
	{
		execve(cmd[0], cmd, (tab = build_env_tab()));
		ft_freetab((void **)tab);
	}
}
예제 #6
0
void		ft_check_file(t_gen *gen)
{
	char	*line;
	char	**split;
	int 	fd;

	fd = open(gen->filename, O_RDONLY);
	gen->x = 0;
	gen->y = 0;
	while (get_next_line(fd, &line))
	{
		if (gen->y == 0)
			split = ft_strsplit(line, ' ');
		gen->y++;
		free(line);
	}
	while (split[gen->x])
		gen->x++;
	close(fd);
	ft_freetab(split);
}
예제 #7
0
void		ft_save_line(char *line, t_gen *gen)
{
	char	**split;
	int		i;

	i = 0;
	gen->map[gen->y] = malloc(sizeof(t_point*) * gen->x);
	split = ft_strsplit(line, ' ');
	while (split[i])
	{
		gen->map[gen->y][i] = malloc(sizeof(t_point));
		gen->map[gen->y][i]->x = i;
		gen->map[gen->y][i]->y = gen->y;
		gen->map[gen->y][i]->z = ft_atoi(split[i]);
		gen->map[gen->y][i]->o = 1;
		gen->map[gen->y][i]->old_z = gen->map[gen->y][i]->z;
		if (gen->map[gen->y][i]->z > gen->z)
			gen->z = gen->map[gen->y][i]->z;
		i++;
	}
	if (i != gen->x)
		ft_error_map(NULL);
	ft_freetab(split);
}
예제 #8
0
t_obj		*load_obj(const char *file)
{
	t_obj		*obj;
	int			fd;
	char		*line;
	char		**tmp;
	t_object	*object;
	char		*mtllib;
	char		last;
	int			offset;
	int			i;

	mtllib = NULL;
	last = 0;
	offset = 0;
	i = 0;
	object = new_object();
	if ((obj = ft_memalloc(sizeof(t_obj))) == NULL)
		return (NULL);
	obj->transform = new_transform();
	if ((fd = open(file, O_RDONLY)) == -1)
	{
		exit_error("Can't find .obj");
		return (NULL);
	}
	while (get_next_line(fd, &line) != 0)
	{
		i++;
		tmp = ft_strsplit(line, ' ');
		if (ft_strlen(line) == 1 && last == 'f')
		{
			gen_buffers(object);
			offset += object->vertex.size;
			add_elem(&obj->objects, object);
			last = 0;
			object = new_object();
			ft_freetab((void **)tmp);
			ft_memdel((void **)&line);
			continue ;
		}
		if (ft_tabsize((void **)tmp) < 2)
		{
			ft_freetab((void **)tmp);
			ft_memdel((void **)&line);
			continue ;
		}
		if (ft_strcmp(tmp[0], "usemtl") == 0)
			object->usemtl = ft_strdup(tmp[1]);
		if (!add_v_f(object, tmp, &last, offset) && ft_strcmp(tmp[0], "mtllib") == 0)
			mtllib = ft_strdup(line + 7);
		ft_freetab((void **)tmp);
		ft_memdel((void **)&line);
	}
	if (line)
		ft_memdel((void **)&line);
	gen_buffers(object);
	add_elem(&obj->objects, object);
	if (mtllib)
	{
		load_material_lib(obj, mtllib, (char *)file);
		ft_memdel((void **)&mtllib);
	}
	return (obj);
}