Esempio n. 1
0
int		main(void)
{
		t_list	*list1;
		t_list	*list2;
		char	*s1 = "unu";
		char	*s2 = "doi";
		char	*s3 = "trei";
		char	*s4 = "patru";
		char	*s5 = "cinci";
		char	*s6 = "sase";

		list1 = NULL;
		list2 = NULL;
		ft_list_push_back(&list1, s1);
		ft_list_push_back(&list1, s2);
		ft_list_push_back(&list1, s3);
		ft_list_push_back(&list2, s4);
		ft_list_push_back(&list2, s5);
		ft_list_push_back(&list2, s6);
		ft_putstr("List 1:\n");
		ft_print_list(list1);
		ft_putstr("List 2:\n");
		ft_print_list(list2);
		ft_list_merge(&list1, &list2);
		ft_putstr("List 1 + 2:\n");
		ft_print_list(list1);
		ft_putstr("Dim 1:\n");
		ft_putnbr(ft_list_size(list1));
		ft_putchar('\n');
		ft_putstr("Dim 2:\n");
		ft_putnbr(ft_list_size(list2));
		ft_putchar('\n');
		return (0);
}
Esempio n. 2
0
int					main(int ac, char **av)
{
	t_swap	*ba;
	t_swap	*bb;
	int		op;

	op = ft_check_params(ac, av);
	ba = ft_creat_list(ac - 1, av);
	bb = NULL;
	if (op)
	{
		ft_sorted(ba) ? write(1, "fini", 4) : ft_putstr("start");
		ft_print_list(ba, 1);
		ft_print_list(bb, 0);
	}
	if (ft_sorted(ba))
		return (0);
	call_algo(&ba, &bb, (ac - 1), av);
	if (op)
	{
		ft_putstr("fini");
		ft_print_list(ba, 1);
		ft_print_list(bb, 0);
	}
	return (0);
}
Esempio n. 3
0
int		main(int ac, char **av)
{
		t_list	*list1;
		t_list	*list2;
		char	**tab1;
		char	**tab2;

		if (ac == 3)
		{
				tab1 = ft_split_whitespaces(av[1]);
				tab2 = ft_split_whitespaces(av[2]);
				list1 = ft_list_push_params(tab_len(tab1), tab1);
				list2 = ft_list_push_params(tab_len(tab2), tab2);
				ft_list_sort(&list1, &ft_strcmp);
				ft_list_sort(&list2, &ft_strcmp);
				ft_putstr("List1:\n");
				ft_print_list(list1);
				ft_putstr("List2:\n");
				ft_print_list(list2);
				ft_putstr("List1 + List2:\n");
				ft_sorted_list_merge(&list1, list2, &ft_strcmp);
				ft_print_list(list1);
		}
		return (0);
}
Esempio n. 4
0
void		ft_print_param(t_swap **ba, unsigned int i, char op)
{
    if (op)
    {
        ra(ba);
        ft_putstr("ra ");
    }
    i ? ft_print_list(*ba, 1) : 0;
    i ? ft_print_list(NULL, 0) : 0;
}
Esempio n. 5
0
t_list	*ft_move_down(t_list *l)
{
	if (l->next)
	{
		l = l->next;
		ft_print_list(ft_list_get_first(l), l);
	}
	else if (l->prev)
	{
		l = ft_list_get_first(l);
		ft_print_list(ft_list_get_first(l), l);
	}
	return (l);
}
int		main(int argc, char **argv)
{
	int j;
	int i;
	int fd;
	int ret;
	t_list *list;
	char buf;
	//ssize_t read (int fd, void *buf, size_t count);
	i = 1;
	while(i < argc)
	{
		fd = open(argv[i], O_RDONLY);
		if (fd == -1)
		{
			ft_putstr("open (): failed, try again!");
		}
		while (read(fd, &buf, BUF_SIZE))
		{
			ft_list_push_back(&list, buf);
		}
		ft_print_list(list);
		if (close(fd) == -1)
		{
			ft_putstr("close (): failed, try again!");
			return (1);
		}
		i++;
	}
	return (0);
}
Esempio n. 7
0
int		ft_check_size(t_truc *c)
{
	if ((c->nb_row - 1) < c->count[LINE])
	{
		tputs(tgetstr("cl", NULL), 1, ft_putchar_auto);
		ft_putstr_fd("Window too small.", 2);
		ft_putnbr_fd(c->count[LINE], 2);
		ft_putstr_fd(" elements, lines available: ", 2);
		ft_putnbr_fd(c->nb_row, 2);
		return (1);
	}
	else if (c->nb_col < c->count[COL])
	{
		tputs(tgetstr("cl", NULL), 1, ft_putchar_auto);
		ft_putstr_fd("Window too small.", 2);
		ft_putnbr_fd(c->count[COL], 2);
		ft_putstr_fd(" characters needed, columns available : ", 2);
		ft_putnbr_fd(c->nb_col, 2);
		return (1);
	}
	else
	{
		tputs(tgetstr("cl", NULL), 1, ft_putchar_auto);
		ft_print_list(c);
	}
	return (0);
}
Esempio n. 8
0
static void		ft_handle(int num)
{
	t_select	*select;
	char		ch[2];

	if (num == SIGINT)
		ft_exit();
	else if (num == SIGTSTP)
	{
		signal(SIGTSTP, SIG_DFL);
		select = ft_save_and_load(NULL, 1);
		ft_reset_term_behavior(&(select->term));
		ch[0] = select->term.c_cc[VSUSP];
		ch[1] = '\0';
		ioctl(0, TIOCSTI, ch);
	}
	else if (num == SIGCONT)
	{
		signal(SIGTSTP, ft_handle);
		select = ft_save_and_load(NULL, 1);
		ft_change_term_behavior(&(select->term));
		ft_print_list(select);
	}
	else if (num == SIGWINCH)
		ft_win_change();
	else
		ft_exit();
}
Esempio n. 9
0
void			multiple_args(int argc, char **argv, int i, int flag)
{
	t_car_list	*debut;
	t_car_list	*temp;
	DIR			*dip;
	int			compt[2];

	debut = NULL;
	compt[0] = 0;
	class_args(argc, argv, i);
	while (i < argc)
	{
		if (((dip = opendir(argv[i])) == NULL) || (test_open(argv[i]) == 1))
			if ((compt[1] = analyse_error(argv[i])) == 1)
			{
				compt[0]++;
				temp = scan(&debut, argv[i]);
				ft_inspect_file(&temp, argv[i]);
			}
		if (dip != NULL)
			closedir(dip);
		i++;
	}
	if (debut != NULL)
		ft_print_list(debut, flag);
	if (compt[0] != argc)
		ft_reclass(argv, argc, flag, compt[0]);
}
Esempio n. 10
0
File: ft_act.c Progetto: jalcim/42sh
int		ft_act(t_list **list, t_list **beg, t_coor *cr, char *r_ch)
{
	int	ret;

	ret = 0;
	signal(SIGWINCH, knowresize);
	signal(SIGTSTP, interrupt);
	signal(SIGINT, ctrlc);
	signal(SIGQUIT, ctrlc);
	while (*(unsigned int *)r_ch != ESC && !ret)
	{
		ft_bzero(r_ch, 5);
		read(0, r_ch, 4);
		if (*(unsigned int *)r_ch == RETURN)
			ret++;
		else if ((*(unsigned int *)r_ch == DEL
				|| *(unsigned int *)r_ch == DEL2)
				&& *list == (*list)->next)
			*(unsigned int *)r_ch = ESC;
		else
		{
			ft_moov((char *)r_ch, list, beg, cr);
			winsize(cr);
			ft_print_list(*list, *beg, cr);
		}
	}
	return (ret);
}
Esempio n. 11
0
void		ft_list_and_print_folder(t_args *ls)
{
	if (ls->l)
		ft_print_total(ls->all_files, ls);
	ft_print_list(ls->all_files, ls);
	if (ls->rmaj)
		ft_use_recursive(ls);
}
Esempio n. 12
0
File: ft_act.c Progetto: jalcim/42sh
void	knowresize(int sig)
{
	struct winsize	wn;
	t_coor			cr;

	(void)sig;
	tputs(tgetstr("cl", NULL), 1, tputs_putchar);
	ioctl(0, TIOCGWINSZ, &wn);
	cr.y = wn.ws_row;
	cr.x = wn.ws_col;
	ft_print_list(NULL, NULL, &cr);
}
Esempio n. 13
0
int		ft_loop(char **av, t_truc *c)
{
	ft_argv_list(av, c);
	if (!ft_check_size(c))
		ft_print_list(c);
	ft_restruct(c, 0);
	while (1)
	{
		if (!ft_command(c))
			return (0);
	}
	return (0);
}
Esempio n. 14
0
void		ft_put_sol(unsigned int i, char op, t_swap **ba, t_swap **bb)
{
	if (i / 8)
		ft_put_sol(i / 8, op, ba, bb);
	if (i % 8 == 0)
	{
		ft_putstr("sa ");
		op ? sa(ba) : 0;
	}
	else if (i % 8 == 1)
	{
		ft_putstr("ra ");
		op ? ra(ba) : 0;
	}
	else if (i % 8 == 2)
	{
		ft_putstr("rra ");
		op ? rra(ba) : 0;
	}
	ft_suite_de_merde(i, op, ba, bb);
	op ? ft_print_list(*ba, 1) : 0;
	op ? ft_print_list(*bb, 0) : 0;
}
Esempio n. 15
0
int			ft_read_term(t_arg_list **begin, int fd)
{
	int		ret;
	char	*buf;
	int		i;

	buf = ft_strnew(10);
	ft_print_list(*begin, fd);
	ret = read(fd, buf, 9);
	i = ft_interpret(buf, ret, begin, fd);
	free(buf);
	if (i == 1)
		ft_return(*begin);
	return (i);
}
Esempio n. 16
0
void	ft_set_options(DIR *dir, t_file *begin, char **path, int path_size)
{
	int i;
	int *options;
	char *tmp;

	i = 1;
	options = ft_detect_option(path[i]);
	if (options[5] != 2)
		i++;
	if (options[0] == 1)
	{
		tmp = ft_strdup(path[2]);
		(path[2][ft_strlen(path[2])] == '/') ? tmp[ft_strlen(path[2])] = '\0' : 0;
		ft_R_option(tmp, options);
	}
	else
	{
	if (i == path_size)
	{
		path_size++;
		path[i] = ".";
	}
	while (i < path_size)
	{
		dir = opendir(path[i]);
		if (!dir)
			ft_error(path[i]);
		if (options && options[4] == 1)
			ft_l_option(path[i], begin, dir, options);
		else
		{
			ft_putchar('A');
			begin = ft_retrieve(dir, begin, path[i]);
			ft_putchar('B');
			begin = ft_sort_lex(begin);
			ft_putchar('C');
			ft_print_list(begin, options[1], options[2]);
			ft_putchar('D');
		}
		i++;
	}
	}
}
Esempio n. 17
0
t_file	*ft_retrieves_n_display(t_file *ptr, char *path, int *options, DIR *dir)
{
	if (!dir)
	{
		ft_R_error(path);
		return(NULL);
	}
	if (options && options[4] == 1)
	{
		ptr = ft_l_option(path, ptr, dir, options);
	}
	else
	{
		ptr = ft_retrieve(dir, ptr, path);
		ptr = ft_sort_lex(ptr);
		ft_print_list(ptr, options[1], options[2]);
	}
	return (ptr);
}
t_list			*ft_delete_item_list(t_list *l)
{
	t_list	*tmp;

	tmp = NULL;
	if (l->prev)
		l->prev->next = l->next;
	if (l->next)
		l->next->prev = l->prev;
	if (l->prev == NULL && l->next == NULL)
		ft_exit(0);
	if (l->next)
		tmp = l->next;
	else if (l->prev)
		tmp = l->prev;
	if (l->next)
		l = l->next;
	ft_print_list(ft_list_get_first(l), tmp);
	return (tmp);
}
Esempio n. 19
0
int		main(int argc, char **argv)
{
	int			*l_a;
	int			*l_b;
	t_pslist	*ops;

	ops = NULL;
	l_a = (int*)malloc(sizeof(*l_a) * (argc - 1));
	l_b = (int*)malloc(sizeof(*l_b) * (argc - 1));
	if (argc < 2)
		ft_error_and_exit();
	else
	{
		ft_validate_input(argc, argv);
		ft_add_parameters_to_l_a(l_a, (argc - 1), argv);
		ft_push_swap(l_a, argc - 1, l_b, &ops);
		ft_print_list(ops);
	}
	return (0);
}
Esempio n. 20
0
int		ft_backspace(t_data *d)
{
	char	*tmp;

	if (d->line && d->line->index > 0)
	{
		tmp = ft_strnew(d->line->len);
		ft_strncpy(tmp, d->line->str, d->line->index - 1);
		ft_strcat(tmp, d->line->str + d->line->index);
		ft_strdel(&d->line->str);
		d->line->str = tmp;
		d->line->index--;
		d->line->len--;
		tputs(tgetstr("le", NULL), 1, ft_int_putchar);
		tputs(tgetstr("dm", NULL), 1, ft_int_putchar);
		tputs(tgetstr("dc", NULL), 1, ft_int_putchar);
		tputs(tgetstr("ed", NULL), 1, ft_int_putchar);
	}
	ft_print_list(d);
	return (1);
}
Esempio n. 21
0
int		main(void)
{
	char	*exname;
	int		exnb = 0;
	t_list	*link;
	t_list	*base;

	(void)link;
	base = ft_create_elem("ABC");
	base->next = ft_create_elem("012");
	base->next->next = ft_create_elem("xyz");
	start_day(11);
#ifdef ex00
	exname = "ft_create_elem";
	start_exo(exnb);

	link = ft_create_elem("A");
	link->next = ft_create_elem("B");
	ft_print_list(link);
	printf("expected:\n");
	printf("[ A ] -> [ B ] -> NULL\n");
#endif

	exnb++;
#ifdef ex01
	exname = "ft_list_push_back";
	start_exo(exnb);
	ft_warning1();
	link = NULL;
	ft_list_push_back(&link, "A");
	ft_list_push_back(&link, "B");
	ft_list_push_back(&link, "C");
	ft_print_list(link);
	printf("expected:\n");
	printf("[ A ] -> [ B ] -> [ C ] -> NULL\n");
#endif

	exnb++;
#ifdef ex02
	exname = "ft_list_push_front";
	start_exo(exnb);
	ft_warning1();
	link = NULL;
	ft_list_push_front(&link, "C");
	ft_list_push_front(&link, "B");
	ft_list_push_front(&link, "A");
	ft_print_list(link);
	printf("expected:\n");
	printf("[ A ] -> [ B ] -> [ C ] -> NULL\n");
#endif

	exnb++;
#ifdef ex03
	start_exo(exnb);
	exname = "ft_list_size";
	ft_warning1();
	printf("list : ");
	ft_print_list(base);
	printf("%s = %i\n", exname, ft_list_size(base));
	printf("\nlist : ");
	ft_print_list(NULL);
	printf("%s = %i\n", exname, ft_list_size(NULL));
#endif

	exnb++;
#ifdef ex04
	start_exo(exnb);
	exname = "ft_list_last";
	ft_warning1();

	printf("list : ");
	ft_print_list(base);
	printf("%s = ", exname);
	ft_print_list(ft_list_last(base));

	printf("\nlist : ");
	ft_print_list(NULL);
	printf("%s = ", exname);
	ft_print_list(ft_list_last(NULL));
#endif

	exnb++;
#ifdef ex05
	start_exo(exnb);
	exname = "ft_list_push_params";
	printf("pas encore de suite de tests pour cet exercice :(\n");
#endif

	exnb++;
#ifdef ex06
	start_exo(exnb);
	exname = "ft_list_clear";

	printf("%s\n", exname);
	printf("avant : ");
	ft_print_list(base);
	ft_list_clear(&base);
	printf("apres : ");
	ft_print_list(base);
	base = ft_create_elem("ABC");
	base->next = ft_create_elem("012");
	base->next->next = ft_create_elem("xyz");
#endif

	exnb++;
#ifdef ex07
	start_exo(exnb);
	exname = "ft_list_at";
	ft_warning1();

	printf("list : ");
	ft_print_list(base);
	printf("%s(list, 0) = ", exname);
	ft_print_list(ft_list_at(base, 0));

	printf("\nlist : ");
	ft_print_list(base);
	printf("%s(list, 1) = ", exname);
	ft_print_list(ft_list_at(base, 1));

	printf("\n%s(NULL, 0) = ", exname);
	ft_print_list(ft_list_at(NULL, 0));

	printf("\n%s(NULL, 1) = ", exname);
	ft_print_list(ft_list_at(NULL, 1));
#endif

	exnb++;
#ifdef ex08
	start_exo(exnb);
	exname = "ft_list_reverse";

	printf("%s\n", exname);
	printf("avant : ");
	ft_print_list(base);
	ft_list_reverse(&base);
	printf("apres : ");
	ft_print_list(base);
#endif


	exnb++;
#ifdef ex09
	start_exo(exnb);
	exname = "ft_list_foreach";
	base = ft_create_elem("012");
	base->next = ft_create_elem("ABC");
	base->next->next = ft_create_elem("xyz");

	printf("%s, avec la fonction ft_putstr()\n", exname);
	printf("list : ");
	ft_print_list(base);
	printf("%s : ", exname);
	fflush(stdout);
	ft_list_foreach(base, &corr_ft_putstr);
#endif

	exnb++;
#ifdef ex10
	start_exo(exnb);
	exname = "ft_list_foreach_if";

	printf("list : ");
	ft_print_list(base);
	printf("%s(list, &ft_putstr, '012', &strcmp) = ", exname);
	fflush(stdout);
	ft_list_foreach_if(base, &corr_ft_putstr, "012", &strcmp);
	printf(" (012 attendu)");
#endif

	exnb++;
#ifdef ex11
	start_exo(exnb);
	exname = "ft_list_find";
	base = ft_create_elem("012");
	base->next = ft_create_elem("ABC");
	base->next->next = ft_create_elem("xyz");

	printf("list : ");
	ft_print_list(base);
	printf("%s(list, 'ABC', &strcmp) = ", exname);
	fflush(stdout);
	ft_print_list(ft_list_find(base, "ABC", &strcmp));
#endif

	exnb++;
#ifdef ex12
	start_exo(exnb);
	exname = "ft_list_remove_if";
	base = ft_create_elem("012");
	base->next = ft_create_elem("ABC");
	base->next->next = ft_create_elem("xyz");

	printf("list : ");
	ft_print_list(base);
	printf("%s(list, 'ABC', &strcmp) = ", exname);
	fflush(stdout);
	ft_list_remove_if(&base, "ABC", &strcmp);
	ft_print_list(base);
#endif

t_list	*list1;
t_list	*list2;
	
	(void)list1;
	(void)list2;
	exnb++;
#ifdef ex13
	start_exo(exnb);
	exname = "ft_list_merge";
	ft_warning1();

	list1 = NULL;
	list2 = NULL;
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_list_merge(&list1, list2);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = NULL;
	list2 = ft_create_elem("012");
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_list_merge(&list1, list2);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = ft_create_elem("012");
	list2 = NULL;
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_list_merge(&list1, list2);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = ft_create_elem("012");
	list1->next = ft_create_elem("345");
	list2 = ft_create_elem("abc");
	list2->next = ft_create_elem("def");
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_list_merge(&list1, list2);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
#endif

	exnb++;
#ifdef ex14
	start_exo(exnb);
	exname = "ft_list_sort";
	printf("%s\n", exname);
	ft_warning1();

	base = NULL;
	printf("avant : ");
	fflush(stdout);
	ft_print_list(base);
	ft_list_sort(&base, &strcmp);
	printf("apres : ");
	fflush(stdout);
	ft_print_list(base);
	printf("\n");

	base = ft_create_elem("3");
	base->next = ft_create_elem("1");
	base->next->next = ft_create_elem("2");
	printf("avant : ");
	fflush(stdout);
	ft_print_list(base);
	ft_list_sort(&base, &strcmp);
	printf("apres : ");
	fflush(stdout);
	ft_print_list(base);
#endif

	exnb++;
#ifdef ex15
	start_exo(exnb);
	exname = "ft_list_reverse_fun";

	base = NULL;
	printf("%s\n", exname);
	printf("avant : ");
	ft_print_list(base);
	ft_list_reverse_fun(base);
	printf("apres : ");
	ft_print_list(base);
	printf("\n");

	base = ft_create_elem("1");
	base->next = ft_create_elem("2");
	base->next->next = ft_create_elem("3");
	printf("avant : ");
	ft_print_list(base);
	ft_list_reverse_fun(base);
	printf("apres : ");
	ft_print_list(base);
	printf("\n");

	base = ft_create_elem("1");
	base->next = ft_create_elem("2");
	base->next->next = ft_create_elem("3");
	base->next->next->next = ft_create_elem("4");
	printf("avant : ");
	ft_print_list(base);
	ft_list_reverse_fun(base);
	printf("apres : ");
	ft_print_list(base);
#endif

	exnb++;
#ifdef ex16
	start_exo(exnb);
	exname = "ft_sorted_list_insert";
	printf("%s\n", exname);
	ft_warning1();

	base = ft_create_elem("2");
	base->next = ft_create_elem("3");
	base->next->next = ft_create_elem("5");
	printf("avant : ");
	fflush(stdout);
	ft_print_list(base);
	ft_sorted_list_insert(&base, "7", &strcmp);
	printf("apres : ");
	fflush(stdout);
	ft_print_list(base);

	base = NULL;
	printf("\navant : ");
	fflush(stdout);
	ft_print_list(base);
	ft_sorted_list_insert(&base, "0", &strcmp);
	printf("apres : ");
	fflush(stdout);
	ft_print_list(base);

#endif

	exnb++;
#ifdef ex17
	start_exo(exnb);
	exname = "ft_sorted_list_merge";
	printf("%s\n", exname);
	ft_warning1();

	list1 = NULL;
	list2 = NULL;
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_sorted_list_merge(&list1, list2, &strcmp);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = NULL;
	list2 = ft_create_elem("0");
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_sorted_list_merge(&list1, list2, &strcmp);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = ft_create_elem("0");
	list2 = NULL;
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_sorted_list_merge(&list1, list2, &strcmp);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("\n");

	list1 = ft_create_elem("0");
	list1->next = ft_create_elem("2");
	list2 = ft_create_elem("1");
	list2->next = ft_create_elem("3");
	printf("list1 : ");
	fflush(stdout);
	ft_print_list(list1);
	printf("list2 : ");
	fflush(stdout);
	ft_print_list(list2);
	ft_sorted_list_merge(&list1, list2, &strcmp);
	printf("merge : ");
	fflush(stdout);
	ft_print_list(list1);
#endif
}