Example #1
0
int		main(void)
{

/* striter */
	ft_putendl("--- striter ? --- ");
	char	str[] = "abcde";
	ft_striter(str, ft_change);

/* striteri */
	ft_putendl("--- striter ? --- ");
	char	str2[] = "abcde";
	ft_striteri(str2, ft_change2);


/* strmap */
	ft_putendl("--- strmap ? --- ");
	char	str3[] = "abcde";
	ft_putendl(ft_strmap(str3, ft_change3));

/* strmapi */
	ft_putendl("--- strmapi ? --- ");
	char	str4[] = "abcde";
	ft_putendl(ft_strmapi(str4, ft_change4));

	return (0);
}
Example #2
0
int		display_dir(const char *name, int opt)
{
	DIR				*dir;
	struct dirent	*dir_p;
	t_file			*file;

	if ((dir = opendir(name)) == NULL)
	{
		ft_putstr(name);
		ft_putendl(" : directory can't be opened");
		exit (FAILURE);
	}
	if (opt == 1 && name[0] == '.' && name[1] == '\0')
	{
		while ((dir_p = readdir(dir)) != NULL)
		{
			if (dir_p->d_name[0] != '.')
				ft_putendl(dir_p->d_name);
		}
		return (SUCCESS);
	}
	dir_p = NULL;
	file = (opt % 3 == 0) ? to_tab(name, opt, dir, dir_p) : NULL;
	if (file != NULL)
		display_long(file, opt);
	else if (opt % 3 != 0 && opt % 2 == 0)
	{
		while ((dir_p = readdir(dir)) != NULL)
			ft_putendl(dir_p->d_name);
	}
	else if (opt % 3 != 0 && opt % 2 == 0)
	{
		while ((dir_p = readdir(dir)) != NULL)
		{
			if (dir_p->d_name[0] != '.')
				ft_putendl(dir_p->d_name);
		}
	}
	return (SUCCESS);
}
Example #3
0
void	built_unsetenv(char **entry)
{
	t_env	*env_line;

	if (!entry[0])
		ft_putendl("\033[33munsetenv: too few arguments.\033[0m");
	else
	{
		env_line = get_env_var(entry[0]);
		if (env_line && env_line->var)
			suppr_link(env_line->var);
	}
}
Example #4
0
char		*get_path(t_sv_prop *sv)
{
	int		i;
	char	*ret;

	ret = NULL;
	i = 0;
	while (sv->cmd->path[++i])
		if ((ret = ft_readdir(sv->cmd->cmda[0], sv->cmd->path[i])) != NULL)
			return (ret);
	ft_putendl("[command not found]");
	return (NULL);
}
Example #5
0
void			env_show(t_vector *env)
{
	int			i;
	t_env_item	*item;

	i = 0;
	while (i < env->total)
	{
		item = env->items[i];
		ft_putendl(item->full);
		i++;
	}
}
Example #6
0
int			print_ptr(void *ptr)
{
	int		size;

	size = get_size(ptr);
	puthex((size_t)ptr);
	ft_putstr(" - ");
	puthex((size_t)(ptr + size));
	ft_putstr(" : ");
	print_nbr(size);
	ft_putendl(" octets");
	return (size);
}
Example #7
0
int				ft_print_title(void)
{
	char	*color1;
	char	*color2;

	color1 = ft_strdup("\033[0m");
	color2 = ft_strdup("\033[38;5;75m");
	ft_putendl("\033[H\033[2J");
	ft_print_title_one('_', color1, color2);
	ft_strdel(&color1);
	ft_strdel(&color2);
	return (1);
}
Example #8
0
int		open_file(int *fd, char *filename)
{
	log_string("trying to open file: ", filename);
	*fd = open(filename, O_RDONLY);
	if (*fd == -1)
	{
		ft_putendl("Database not found");
		log_string("Open error(-1): ", filename);
		return (-1);
	}
	log_string("succesfully opened file: ", filename);
	return (1);
}
Example #9
0
static void		ft_death(t_cmd *cmd, t_game *g)
{
	ft_drop_all(g, cmd->num_cli);
	g->map[g->cls[cmd->num_cli].y][g->cls[cmd->num_cli].x].nb_player--;
	ft_putstr("\033[31;01mClient ");
	ft_putnbr(cmd->num_cli);
	ft_putendl(" died.\033[00m");
	ft_putendl_fd("mort", cmd->fd);
	ft_graph_pdi(g, cmd->num_cli);
	close(g->cls[cmd->num_cli].cs);
	g->cls[cmd->num_cli].cs = MORT;
	g->cls[cmd->num_cli].num_team = MORT;
}
Example #10
0
void		add_visual_effects(t_args_list *element, t_select *params)
{
	t_args_list		*current;

	current = return_current_element(params);
	if (element->selected)
		ft_tputs("mr");
	if (element == current)
		ft_tputs("us");
	ft_putendl(element->value);
	ft_tputs("me");
	ft_tputs("ue");
}
Example #11
0
void	get_play(t_rows **begin, int i)
{
    int len;

    len = ft_strlen((*begin)->line);
    if (i % 2 == 0)
        player_plays(begin);
    else
    {
        display_map(begin);
        ft_putchar('\n');
        ft_putendl("Computer turn!");
        ia_plays(begin);
        len = len - ft_strlen((*begin)->line);
        ft_putstr("Computer just removed ");
        ft_rec_putnbr(len);
        if (len > 1)
            ft_putendl(" matches");
        else
            ft_putendl(" matche");
    }
}
void		ft_print_btree(t_btree *root)
{
	t_btree	*tmp;

	tmp = root;
	if (!tmp)
	{
		ft_putendl("la creation de l'arbre a echouer");
		exit(0);
	}
	else
	 {
		ft_putstr(tmp->str);
		ft_putstr(" : ");
		ft_putnbr(tmp->key);
		ft_putendl("");
		if (tmp->left)
			ft_print_btree(tmp->left);
		if (tmp->right)
			ft_print_btree(tmp->right);
	 }
}
Example #13
0
int				ft_my_sh_exit(char *line)
{
	int		exit;
	char	**all;

	exit = -3;
	if (!(all = ft_strparse(line)))
		return (-1);
	if (!all[0])
		return (-2);
	else if (ft_strcmp(all[0], "exit") != 0)
		return (-2);
	else if (!all[1])
		exit = 0;
	else if (all[1] && all[2])
		ft_putendl("exit: too many arguments");
	else if (all[1] && !ft_is_numeric(all[1]))
		exit = ft_atoi(all[1]);
	else
		ft_putendl("exit: enter a numeric argument between 0 and 999999999");
	return (exit % 256);
}
Example #14
0
int			ft_check_grid(char *map)
{
	while (*map++)
	{
		if (!ft_isdigit(*map) && *map != ' ' && *map != '\n' &&
			*map != '\t' && *map != '\0' && *map != '-')
		{
			ft_putendl("NO VALID MAP\n");
			return (1);
		}
	}
	return (0);
}
Example #15
0
void		ft_putavl_sufix(t_avltree *root)
{
	if (root)
	{
		if (root->left)
			ft_putavl_prefix(root->left);
		if (root->right)
			ft_putavl_prefix(root->right);
		ft_putstr(root->key);
		ft_putstr(": ");
		ft_putendl(root->value);
	}
}
Example #16
0
File: cd.c Project: Fusiow/msh
int			ft_cd(char **tab)
{
	if (!tab[1])
	{
		ft_putendl(find_value_envir(g_env, "HOME"));
		tab[1] = find_value_envir(g_env, "HOME");
		if (chdir(tab[1]) == -1)
			return (cd_error(tab[1]));
		change_pwd(1);
	}
	else if (ft_strcmp("-", tab[1]) == 0)
	{
		chdir(find_value_envir(g_env, "OLDPWD"));
		ft_putendl(find_value_envir(g_env, "OLDPWD"));
		change_pwd(0);
	}
	else if (chdir(tab[1]) == -1)
		return (cd_error(tab[1]));
	else
		change_pwd(0);
	return (0);
}
Example #17
0
int					receive_file(char **path, int socket)
{
	int				ret;
	int				fd;
	char			buff[1024];
	char			*good_path;
	int				size;

	ft_bzero(buff, 1023);
	ret = recv(socket, buff, 1023, 0);
	if (ret == 1 && buff[0] == '\0')
	{
		ft_putendl("ERROR");
		return (0);
	}
	size = ft_atoi(buff);
	send(socket, "", 1, 0);
	ret = recv(socket, buff, 1023, 0);
	fd = 0;
	if (buff[0] != '\0')
	{
		buff[ret] = '\0';
		good_path = path[1];
		fd = create_file(good_path);
		if (fd <= 0)
			return (read_file(socket, fd, size));
		write(fd, buff, ft_strlen(buff));
		send(socket, "", 1, 0);
	}
	read_file(socket, fd, size);
	if (fd > 0)
	{
		ft_putendl("SUCCESS");
		close(fd);
	}
	else
		ft_putendl("ERROR");
	return (0);
}
Example #18
0
static void		display_roomlinks(t_env *e)
{
	t_room	*room;
	int		i;

	room = e->room_start;
	ft_putchar('\n');
	ft_putendl("	 -------------");
	ft_putendl("	| ROOMS LINKS |");
	ft_putendl("	 -------------");
	while (room != NULL)
	{
		ft_putendl(room->name);
		i = -1;
		while (++i < room->n_links)
		{
			ft_putchar('	');
			ft_putendl(room->t_roomlinks[i]->name);
		}
		room = room->next;
	}
}
Example #19
0
void				print_bonus(t_check *check, char **tab, t_ref *ref, int i)
{
	if (!check->flags)
		return ;
	FT_INIT(int, nb_loops, 0);
	ref->nb_ants_ref = 0;
	if (ft_strchr(check->flags, 'm'))
	{
		ft_putstr("nb movements :");
		ft_putnbr(i);
		ft_putendl("");
	}
	if (ft_strchr(check->flags, 'r'))
	{
		ft_putendl("roads :");
		while (nb_loops <= calc_last_ligne(check, ref))
		{
			ft_putendl(tab[nb_loops]);
			nb_loops++;
		}
	}
}
Example #20
0
void		comp(int *l)
{
	int	r;

	r = r_line(l);
	if (r == 0)
		exit(0);
	ft_putendl("\nComputer played:");
	if (r == 5)
		del(l, 0);
	if (r < 5)
		ia(l);
}
Example #21
0
void	ft_free_tab(char **tab, int size)
{
	int		i;

	i = 0;
	while (i < size)
	{
		ft_putendl(tab[i]);
		ft_strdel(&tab[i]);
		i++;
	}
	ft_memdel((void **)tab);
}
Example #22
0
char		*get_path(t_cl_prop *cl, char **cmda)
{
	int		i;
	char	*ret;

	ret = NULL;
	i = 0;
	while (cl->path[++i])
		if ((ret = ft_readdir(cmda[0] + 1, cl->path[i])) != NULL)
			return (ret);
	ft_putendl("command not found");
	return (NULL);
}
Example #23
0
int main(int argc, char **argv)
{
    int sock;
    t_sockaddr_in *sin;
    char *user;

    if (argc != 4)
    {
        ft_putendl("error -> bad argument");
        exit(0);
    }
    sin = (t_sockaddr_in *)malloc(sizeof(t_sockaddr_in));
    ft_bzero(sin, sizeof(t_sockaddr_in));
    sock = ft_cli_socktcp(sin, argv[3]);

    errno = 0;
    if ((connect(sock, (t_sockaddr*)sin, sizeof(t_sockaddr))))
    {
        close(sock);
        error("connect -> ");
    }
    ft_putendl("connected");
    user = getenv("USER=");
    ft_putstr_fd(user, sock);
    write(sock, "\0", 1);
    ft_commutateur(sock, argv);
    ft_putendl("send");

    char buff;
    if (argv[1][0] == 'x')
    {
        while (!size_fd(sock))
            ;
        while (read(sock, &buff, 1) && buff != '\0')
            write(1, &buff, 1);
    }
    close(sock);
    return (0);
}
Example #24
0
void	ft_nbrtrace(const char *mess, int i)
{
	ft_putstr(RED);
	if (mess)
	{
		ft_putstr(mess);
		ft_putstr(" : ");
	}
	else
		ft_putstr("trace : ");
	ft_putendl(ft_itoa(i));
	ft_putstr(DEFAULT_COLOR);
}
Example #25
0
void		run_command(t_env *env, char *command)
{
	char	**splitted;

	if (!(splitted = ft_strsplit(command, ' ')))
		ft_exit("client: can't split command", EXIT_FAILURE);
	if (splitted[0])
	{
		if (!do_run(env, splitted))
			ft_putendl("unknown command");
	}
	splitted_free(splitted);
}
Example #26
0
void				res_positive_delta(t_dis *delta)
{
	float			x1;
	float			x2;
	float			root;
	char			val[32];

	root = mt_fsqrt(delta->dis);
	x1 = (-1 * delta->coef[B_COEF] - root) / (2 * delta->coef[A_COEF]);
	x2 = (-1 * delta->coef[B_COEF] + root) / (2 * delta->coef[A_COEF]);
	ft_putendl(POS_DELTA);
	ft_putstr("X1 = ");
	if (x1 < 0)
		ft_putchar('-');
	ft_ftoa(ABS(x1), val, 6);
	ft_putendl(val);
	ft_putstr("X2 = ");
	if (x2 < 0)
		ft_putchar('-');
	ft_ftoa(ABS(x2), val, 6);
	ft_putendl(val);
}
Example #27
0
void		ft_printenv(void)
{
	int		i;
	char	**env;

	env = get_env();
	i = 0;
	while (env[i])
	{
		ft_putendl(env[i]);
		i++;
	}
}
Example #28
0
void		print_type(char *str, void *elem, int type)
{
	int		*nbr;
	char	*car;

	if (type == INT)
	{
		nbr = (int*)elem;
		ft_putstr(str);
		ft_putstr(" = [");
		ft_putnbr(*nbr);
		ft_putendl("]");
	}
	if (type == CHAR)
	{
		car = (char*)elem;
		ft_putstr(str);
		ft_putstr(" = [");
		ft_putstr(car);
		ft_putendl("]");
	}
}
Example #29
0
void	ft_puttab_endl(char **tab)
{
	int i;

	if (tab == NULL)
		return ;
	i = 0;
	while (tab[i])
	{
		ft_putendl(tab[i]);
		i++;
	}
}
Example #30
0
static int				ft_env(char **cmd, t_mlist *mlist)
{
	t_list				*tmp;

	(void)cmd;
	tmp = mlist->env;
	while (tmp)
	{
		ft_putendl((char*)tmp->content);
		tmp = tmp->next;
	}
	return (1);
}