Пример #1
14
void		fractal_choice(char **argv, t_struct *mystruct)
{
	if (ft_strequ(argv[1], "Julia") == 1)
	{
		mystruct->fracnum = 1;
		julia_init(mystruct);
		mlx_mouse_hook(mystruct->win, ft_zoom, mystruct);
		mlx_hook(mystruct->win, 6, (1L << 6), motion_julia, mystruct);
	}
	else if (ft_strequ(argv[1], "Mandel") == 1)
	{
		mystruct->fracnum = 2;
		mandel_init(mystruct);
		mlx_mouse_hook(mystruct->win, ft_zoom_mandel, mystruct);
		mlx_hook(mystruct->win, 6, (1L << 6), motion_mandel, mystruct);
	}
	else if (ft_strequ(argv[1], "Burning") == 1)
	{
		mystruct->fracnum = 3;
		burn_init(mystruct);
		mlx_mouse_hook(mystruct->win, ft_zoom_burning, mystruct);
		mlx_hook(mystruct->win, 6, (1L << 6), motion_burning, mystruct);
	}
	else
		error_arg();
}
Пример #2
0
int		server_do(int cs, char *cmd)
{
	if (ft_strcmp(cmd, "quit") == 0)
	{
		printf("Client %d disconnected\n", cs);
		close(cs);
		exit(0);
	}
	else if (ft_strequ(cmd, "ls"))
		server_ls(cs);
	else if (ft_strcmp(cmd, "pwd") == 0)
		server_pwd(cs);
	else if (ft_strncmp(cmd, "mkdir ", 6) == 0)
		server_mkdir(cs, cmd + 6);
	else if (ft_strncmp(cmd, "put ", 4) == 0)
		server_put(cs, cmd + 4);
	else if (ft_strncmp(cmd, "get ", 4) == 0)
		server_get(cs, cmd + 4);
	else if (ft_strncmp(cmd, "cd ", 3) == 0)
		server_cd(cs, cmd + 3);
	else if (ft_strequ(cmd, "cd"))
		server_cd(cs, "/");
	else
		server_sendbuf(cs, "ERROR: Incorrect command");
	return (0);
}
Пример #3
0
void	delete_elem_var(t_var **list, char *name)
{
	t_var	*ptr;
	t_var	*head;

	head = *list;
	if (ft_strequ(head->name, name))
	{
		ptr = head->next;
		free(head->name);
		free(head->arg);
		free(head);
		*list = ptr;
		return ;
	}
	while (head && head->next)
	{
		if (ft_strequ((head->next)->name, name))
		{
			ptr = head->next->next;
			free(head->next->name);
			free(head->next->arg);
			free(head->next);
			head->next = ptr;
		}
		head = head->next;
	}
}
Пример #4
0
static void	remove_dot(t_path **path_list)
{
	t_path	*tmp;
	t_path	*current;

	if (*path_list && ft_strequ((*path_list)->str, "."))
	{
		free((*path_list)->str);
		tmp = (*path_list)->next;
		free(*path_list);
		*path_list = tmp;
	}
	current = *path_list;
	while (current && current->next)
	{
		if (ft_strequ(current->next->str, "."))
		{
			free(current->next->str);
			tmp = current->next->next;
			free(current->next);
			current->next = tmp;
		}
		else
			current = current->next;
	}
}
Пример #5
0
static t_bool	format_and_exec_cmd(char **t, char **env)
{
	char	*tmp;
	char	*tmp2;
	char	**paths;
	int		ret_exec;

	if ((paths = take_path(env)) == NULL)
		return (ft_error(0, "PATH not found !", NULL, TRUE));
	if ((tmp = search_exe(paths, t[0])) == NULL)
		return (ft_error(0, "command not found: ", t[0], TRUE));
	ft_freetstring(&paths);
	if ((tmp2 = format_path_exe(tmp, t[0])) == NULL)
		return (TRUE);
	ft_strdel(&tmp);
	if ((ft_strequ(t[0], "env") && ft_strequ(t[1], "-i")))
	{
		if ((ret_exec = execprog(tmp2, t, NULL)) == -1)
			return (ft_error(0, "exec format error: ", t[0], TRUE));
	}
	else
	{
		if ((ret_exec = execprog(tmp2, t, env)) == -1)
			return (ft_error(0, "exec format error: ", t[0], TRUE));
	}
	free(tmp2);
	return (TRUE);
}
Пример #6
0
t_opm_option	*opm_findoption(t_vector *options, char *name)
{
	t_opm_option	*option;
	int				i;
	int				j;

	i = 0;
	while (i < options->total)
	{
		option = vector_get(options, i);
		if (ft_strequ(name, option->name))
			return (option);
		else if (option->aliases)
		{
			j = 0;
			while (option->aliases[j])
			{
				if (ft_strequ(name, option->aliases[j]))
					return (option);
				j++;
			}
		}
		i++;
	}
	return (NULL);
}
Пример #7
0
int		is_env_opt(char *arg)
{
	if (ft_strequ(arg, "-i") || ft_strequ(arg, "-P") ||
			ft_strequ(arg, "-u") || ft_strchr(arg, '='))
		return (1);
	return (0);
}
Пример #8
0
char		*set_options(int argc, char **argv, int *i)
{
	char	*str;

	if (!(str = ft_strnew(ft_strlen(ALLOWED_OPTIONS))))
		return (NULL);
	while (*i < argc)
	{
		if (ft_strequ(argv[*i], "--"))
		{
			(*i)++;
			break ;
		}
		if (argv[*i][0] != '-' || ft_strequ(argv[*i], "-"))
			break ;
		if (!add_options(str, argv, i))
		{
			ft_strdel(&(str));
			return (NULL); 
		}
		
		(*i)++;
	}
	return (str);
}
Пример #9
0
int		ft_start_after_option(char **argv, int argc, t_option *op)
{
	int		start;
	int		i;

	start = 0;
	i = 0;
	while (i < argc && (ft_strequ(argv[i], "--")
				|| (argv[i][0] == '-' && !ft_check_option(argv[i], &op))))
	{
		if (!ft_strequ(argv[i], "-"))
			start = i + 1;
		if (ft_strequ(argv[i], "--"))
		{
			i++;
			break ;
		}
		i++;
	}
	if (i < argc && argv[i][0] == '-' && ft_check_option(argv[i], &op) &&
			AR1 && AR2 && AR3 && AR4 && AR5 && AR6 && AR7 && AR8)
	{
		ft_putstr_fd("ft_ls: illegal option -- ", 2);
		ft_putchar_fd(ft_check_option(argv[i], &op), 2);
		gain_line(&start);
	}
	return (start);
}
Пример #10
0
void	check_double_names(char **line, int i)
{
	int		n;
	char	**tmpi;
	char	**tmpn;

	while (line[i] && ft_strstr(line[i], " "))
	{
		if (line[i][0] == '#')
			i++;
		n = i + 1;
		while (line[n] && ft_strstr(line[n], " "))
		{
			if (line[n][0] == '#')
				n++;
			if (!ft_strstr(line[n], " ") || !line[n])
				break ;
			tmpi = ft_strsplit(line[i], ' ');
			tmpn = ft_strsplit(line[n], ' ');
			if (ft_strequ(tmpi[0], tmpn[0]))
				exit_error("same name used twice for rooms.", 2);
			if (ft_strequ(tmpi[1], tmpn[1]) && ft_strequ(tmpi[2], tmpn[2]))
				exit_error("same position for two different rooms.", 2);
			n++;
			free_tab(tmpn);
			free_tab(tmpi);
		}
		i++;
	}
	ft_putendl("check_double_names OK");
}
Пример #11
0
int				sh_echo(t_info *info, char **env, char **args)
{
	int			i;

	(void)env;
	if (!args[0])
		ft_putchar('\n');
	else if (ft_strequ(args[0], "-n") && !args[1])
		;
	else
	{
		if (ft_strequ(args[0], "-n"))
			sh_echo_n(info);
		else
		{
			i = 0;
			while (args[i + 1])
			{
				ft_printf("%s ", args[i]);
				i++;
			}
			ft_printf("%s\n", args[i]);
		}
	}
	return (EXIT_SUCCESS);
}
Пример #12
0
t_opcode	get_op(char *s)
{
	int				i;
	static t_op		data[] = {
		{PA, "PA", "pa"},
		{PB, "PB", "pb"},
		{SA, "SA", "sa"},
		{SB, "SB", "sb"},
		{SS, "SS", "ss"},
		{RA, "RA", "ra"},
		{RB, "RB", "rb"},
		{RR, "RR", "rr"},
		{RRA, "RRA", "rra"},
		{RRB, "RRB", "rrb"},
		{RRR, "RRR", "rrr"},
		{NONE, NULL, NULL}};

	i = 0;
	while (data[i].op_lower)
	{
		if (ft_strequ(data[i].op_lower, s) ||
				ft_strequ(data[i].op_upper, s))
			return (data[i].opcode);
		++i;
	}
	return (NONE);
}
Пример #13
0
void				check_arg(char **av, t_img *img, t_frac *frac)
{
	if (av[2])
		frac->max_iter = ft_atoi(av[2]);
	init_color(frac, av);
	if (ft_strequ(av[1], "mandel") == 1)
	{
		set_mandel(frac);
		draw_mandelbrot(img, frac);
	}
	else if (ft_strequ(av[1], "julia") == 1)
	{
		set_julia(frac);
		draw_julia(img, frac);
	}
	else if (ft_strequ(av[1], "ship") == 1)
	{
		set_ship(frac);
		draw_ship(img, frac);
	}
	else if (ft_strequ(av[1], "triangle") == 1)
	{
		set_triangle(frac);
		draw_sierpinski(img, frac);
	}
	else
		exit(0);
}
Пример #14
0
static void				exec_fork_bt(pid_t father, t_bloc *bloc, t_list *envi)
{
	int					i;

	if (father > 0)
	{
		if (bloc->was_redir != -1)
			close(bloc->fd);
		waitpid(father, &bloc->success, WUNTRACED);
		if (bloc->success == 256)
			bloc->success = -1;
		if (ft_strequ(bloc->tcmd[0], "exit") == 1)
			exit(0);
	}
	if (father == 0)
	{
		if (bloc->was_redir != -1)
			ft_get_dup(bloc);
		i = 0;
		while (g_cmds[i].str)
		{
			if (ft_strequ(bloc->tcmd[0], g_cmds[i].str) == 1)
				bloc->success = g_cmds[i].func(bloc->tcmd, envi);
			i++;
		}
		exit (0);
	}
}
Пример #15
0
Файл: local.c Проект: ggila/ft_p
char	is_local_cmd(char *prog)
{
	if (ft_strequ(prog, "lcd"))
		return (LCD);
	else if (ft_strequ(prog, "lpwd"))
		return (LPWD);
	else if (ft_strequ(prog, "lls"))
		return (LLS);
	return (KO);
}
Пример #16
0
void						write_param(int argc, char **argv, t_clist *param)
{
	if (argc != 2)
		put_list();
	if (ft_strequ(argv[1], "Mandelbrot"))
		CONTENT(0) = 1;
	else if (ft_strequ(argv[1], "Julia"))
		CONTENT(0) = 2;
	else if (ft_strequ(argv[1], "Chromosome"))
		CONTENT(0) = 3;
	else
		put_list();
}
Пример #17
0
char	*ft_pwd(char *str, char *ret)
{
	DIR		*dir;

	dir = NULL;
	if (ft_strequ(str, "."))
		return (ret);
	else if (ft_strequ(str, ".."))
		ret = ft_del_pwd(ret);
	else
		ret = ft_add_pwd(ret, str);
	return (ret);
}
Пример #18
0
void			parse_lvl(t_all *all, char *dir)
{
	DIR				*rp;
	struct dirent	*fc;

	if ((rp = opendir(dir)) != NULL)
	{
		while ((fc = readdir(rp)))
			if (!ft_strequ(fc->d_name, ".") && !ft_strequ(fc->d_name, ".."))
				add_lvl(&all->lv, ft_strdup(fc->d_name));
		if (closedir(rp) == -1)
			exit(-1);
	}
}
Пример #19
0
int			choose_fractol(t_fractal *p, char *str)
{
	ft_strlower(str);
	if (ft_strequ(str, "julia"))
		init_g_julia(p);
	else if (ft_strequ(str, "mandelbrot"))
		init_g_mandelbrot(p);
	else if (ft_strequ(str, "chromosom"))
		init_g_chromosom(p);
	else if (ft_strequ(str, "rabbit"))
		init_g_noun(p);
	else
		ft_error(INVALID_ARGZ);
	return (1);
}
Пример #20
0
void	push_waiting(t_file **tmp, char *dirname, t_waiting **waiting,
					t_command *command)
{
	if (has_option(command->options, 'R') && S_ISDIR((*tmp)->infos->st_mode)
			&& !ft_strequ((*tmp)->name, ".") && !ft_strequ((*tmp)->name, ".."))
	{
		if (!has_option(command->options, 'a') && (*tmp)->name[0] == '.')
		{
			*tmp = (*tmp)->next;
			return ;
		}
		add_waiting_last(waiting, new_waiting(
			ft_strjoin(ft_strjoin(dirname, "/"), (*tmp)->name)));
	}
}
Пример #21
0
static int	remove_dotdot(t_path **path_list, t_path *current)
{
	t_path	*tmp;
	int		modif;

	modif = 0;
	while (current && ft_strcmp(current->str, "..")
			&& current->next && ft_strequ(current->next->str, ".."))
	{
		modif++;
		tmp = current->next->next;
		free(current->next->str);
		free(current->next);
		free(current->str);
		free(current);
		*path_list = tmp;
		current = tmp;
	}
	while (current && current->next)
	{
		modif += remove_dotdot(&current->next, current->next);
		current = current->next;
	}
	if (modif)
		remove_dotdot(path_list, *path_list);
	return (modif);
}
Пример #22
0
void	ft_prec_modifier(t_str_conv *sub)
{
	char	sign;
	int		i;

	sign = 0;
	if (!sub->prec && ft_strequ(sub->str_out, "0"))
	{
		sub->str_out[0] = 0;
		sub->size = 0;
	}
	else
	{
		if (sub->str_out[0] == '+' || sub->str_out[0] == '-')
			sign = sub->str_out[0];
		i = sub->prec - (sub->size - (sign && 1));
		if (i > 0)
		{
			sub->str_out = ft_strjoin_clean(ft_memset(ft_strnew(i), '0', i),
					sub->str_out);
			if (sign && (sub->str_out[0] = sign))
				sub->str_out[i] = '0';
			sub->size = sub->size + i;
		}
	}
}
Пример #23
0
int				sh_cd(t_info *info)
{
    char		*path;
    char		*oldpath;

    if (info->args[1] == NULL)
    {
        path = sh_get_in_env("HOME", info->env);
        chdir(path);
    }
    else if (ft_strequ(info->args[1], "-"))
    {
        path = sh_get_in_env("OLDPWD", info->env);
        chdir(path);
    }
    else
    {
        if (chdir(info->args[1]) != 0)
            ft_error_chdir(info->args[1]);
    }
    oldpath = ft_strjoin("OLDPWD=", info->path);
    sh_replace_env(oldpath, info->env);
    free(oldpath);
    return (1);
}
Пример #24
0
static void	go_to(char *path)
{
	static char buf[4096];
	t_hash		*pwd;

	if (ft_strequ(path, "-"))
		return (go_to(hash_getset(&g_env, "OLDPWD", "/", 2)->value));
	ft_memset(buf, 0, 4096);
	if (path[0] == '~')
	{
		ft_strcat(buf, hash_getset(&g_env, "HOME", "/", 2)->value);
		ft_strcat(buf, path + 1);
		path = ft_strdup(buf);
		go_to(path);
		return (free(path));
	}
	if (access(path, F_OK) == -1)
		return (print_error("cd: ", FNOT_FOUND, path));
	if (!isdir(path))
		return (print_error("cd: ", "not a directory: ", path));
	if (access(path, R_OK) == -1)
		return (print_error("cd: ", FORBIDDEN, path));
	pwd = hash_getset(&g_env, "PWD", getcwd(buf, 4096), ft_strlen(buf) + 1);
	hash_set(&g_env, "OLDPWD", pwd->value, pwd->size);
	chdir(path);
	hash_set(&g_env, "PWD", getcwd(buf, 4096), ft_strlen(buf) + 1);
}
Пример #25
0
int		env_builtin(t_parser *parser)
{
	int			i;
	t_node_cmd	*node;

	i = 1;
	node = (t_node_cmd *)parser->data;
	if (node->cmd[i] && ft_strcmp(node->cmd[i], "--help") == 0)
	{
		print_env_usage(node);
		return (SUCCESS);
	}
	while (node->cmd[i] && is_env_opt(node->cmd[i]))
		if (handle_env_opt(node, &i) < 0)
		{
			print_env_usage(node);
			return (FAILURE);
		}
	if (node->cmd[i] && ft_strequ(node->cmd[i], "--"))
		i++;
	if (node->cmd[i])
	{
		node->cmd = update_cmd(node->cmd, i);
		return (exec_fork(parser));
	}
	print_env(node, node->env);
	return (SUCCESS);
}
Пример #26
0
void	do_stuff(char *line, char ***e)
{
	int		i;
	char	**split;

	i = 0;
	split = ft_strsplit(line, ' ');
	if (ft_strequ(split[0], "exit"))
	{
		ft_del_tab_char(split);
		ft_strdel(&line);
		exit(0);
	}
	else if (ft_strcmp(split[0], "cd") == 0)
		*e = ft_cd(split, *e);
	else if (ft_strcmp(split[0], "env") == 0)
	{
		if (*e)
			aff_env(*e);
	}
	else if (ft_strcmp(split[0], "setenv") == 0)
		*e = ft_new_env(*e, split[1]);
	else if (ft_strcmp(split[0], "unsetenv") == 0)
		*e = ft_del_env(*e, split[1]);
	else if (split[0])
		ft_check_path(split, *e);
	else
	{
		ft_putstr("zsh: command not found: ");
		ft_putendl(split[0]);
	}
	ft_del_tab_char(split);
}
Пример #27
0
void		*htable_remove(t_htable *htable, char *str)
{
	t_list_node		*cursor;
	t_list_node		*prev;
	void			*del_node_value;
	unsigned int	hashval;

	hashval = htable->hash_ft(htable, str);
	cursor = htable->table[hashval];
	prev = NULL;
	while (cursor && ft_strequ((char *)(cursor->value), str) == 0)
	{
		prev = cursor;
		cursor = cursor->next;
	}
	if (!cursor)
		return (NULL);
	if (!prev)
		htable->table[hashval] = cursor->next;
	else
		prev->next = cursor->next;
	del_node_value = cursor->value;
	free(cursor);
	return (del_node_value);
}
Пример #28
0
void			gfx_parse_request(t_env *e, int fd, char *str)
{
	char		**req;
	int			i;

	i = 0;
	req = (char **)try_void(ft_strsplit(str, ' '), NULL, "malloc");
	if (!req[0])
		printf("Client #%d (GFX): Invalid request (too few arguments)\n", fd);
	else
	{
		while (i < 9)
		{
			if (ft_strequ(req[0], g_gfx_parse[i].cmd))
			{
				if (i < 5)
					g_gfx_parse[i].fct(e, fd, req, 0);
				else
					g_gfx_parse[i].fct(e, fd);
				break ;
			}
			i++;
		}
	}
	if (i == 9)
		suc(e, fd);
	ft_free_strtab(req);
}
Пример #29
0
int				sh_env(t_info *info)
{
	int			i;
	t_info		context;

	sh_context(info, &context);
	UNSET(context.opt, OPT_A);
	i = 1;
	while (env_opt(context.args[i], &context))
		i++;
	if (GET(context.opt, OPT_I))
		env_i(&context, i);
	else if (!context.args[1])
	{
		sh_printenv(&context);
		return (EXIT_SUCCESS);
	}
	else
		env_set(&context);
	if (ft_strequ(context.args[0], "cd"))
		return (EXIT_SUCCESS);
	else if (context.args[0])
		sh_exec(&context);
	else
		sh_printenv(&context);
	sh_clear_context(&context);
	return (EXIT_SUCCESS);
}
Пример #30
0
void	ft_str_win(t_env *init)
{
    mlx_string_put(init->mlx, init->win, 10, 5, 0xFF0000, "FRACTOL");
    mlx_string_put(init->mlx, init->win, 10, 25, 0xffffff, "Fractal :");
    mlx_string_put(init->mlx, init->win, 105, 25, 0xffffff, init->fract);
    mlx_string_put(init->mlx, init->win, 10, 45, 0xffffff, "Iteration :");
    mlx_string_put(init->mlx, init->win, 125, 45, 0xffffff,
                   ft_itoa(init->iter));
    if (ft_strequ(init->fract, "julia"))
    {
        mlx_string_put(init->mlx, init->win, 10, 65, 0xffffff, "Julia Fix :");
        mlx_string_put(init->mlx, init->win, 125, 65, 0xffffff,
                       ft_itoa(init->fixjul));
        mlx_string_put(init->mlx, init->win, 10, 85, 0xffffff,
                       "JuliaX (* 1000):");
        mlx_string_put(init->mlx, init->win, 175, 85, 0xffffff,
                       ft_itoa(init->julx * 1000));
        mlx_string_put(init->mlx, init->win, 10, 105, 0xffffff,
                       "JuliaY (* 1000):");
        mlx_string_put(init->mlx, init->win, 175, 105, 0xffffff,
                       ft_itoa(init->july * 1000));
    }
    mlx_string_put(init->mlx, init->win, 10, init->height - 50, 0xffffff,
                   "Press ESC to quit");
}