void print_final_board(t_list *boards, size_t w) { char *s; size_t i; size_t lstsize; s = ft_strnew(w * w); ft_memset(s, '.', w * w); lstsize = ft_lstsize(boards); while (boards) { i = 0; while (*((t_board *)boards->content)) { if (*((t_board *)boards->content) & 1 && s[i] == '.') s[i] = 'A' + lstsize - ft_lstsize(boards) - 1; i++; *((t_board *)boards->content) >>= 1; } boards = boards->next; } while (*s) { write(1, s, w); ft_putchar('\n'); s += w; } }
char *extract_parameters(int input, char *matches, int ln) { char buf[1]; t_list *list; list = NULL; while ((input != 0 || ln < 2) && read(input, buf, 1) > 0) { if (buf[0] == '\n' && ln > 0 && input == 0) ln++; else if (buf[0] == '\n') { ft_lstpush(&list, buf, 1); ln++; } else { ft_lstpush(&list, buf, 1); ln = 0; } } if (!(matches = (char*)malloc(sizeof(char) * ft_lstsize(list)))) return (NULL); matches = ft_lsttochar(list, matches); matches[ft_lstsize(list)] = '\0'; free(list); return (matches); }
void *ft_lstfold(void *in, t_list *al, void *(*f)(void*, void*)) { void *result; t_list *l; if ((*f) == NULL) return (NULL); if (ft_lstsize(al) == 0 && in == NULL) return (NULL); if (ft_lstsize(al) == 0 && in != NULL) return (in); l = al; if (in == NULL) { result = l->content; l = l->next; } else result = in; while (l != NULL) { result = (*f)(result, l->content); l = l->next; } return (result); }
int lstsize(t_list *a) { if (!a) return (0); else return (1 + ft_lstsize(a->next)); }
int minishell_history(int ac, char **av, t_shell *shell) { const int hs = (int)ft_lstsize(shell->history); (void)ac; (void)av; minishell_history_show(hs, shell->history); return (FLAG_BUILTIN); }
int b_history(t_context *context, t_list *args) { size_t arg_count; arg_count = ft_lstsize(args); if (arg_count > 3) return (builtin_error(HISTORY_BUILTIN, ERR_TOO_MANY_ARGS, 0)); if (arg_count == 1) return (history_display(context, 0, 0)); return (BUILTIN_SUCCESS); }
int b_pid(t_context *context, t_list *args) { size_t arg_count; UNUSED(context); arg_count = ft_lstsize(args); if (arg_count > 1) return (builtin_error(PID_BUILTIN, ERR_TOO_MANY_ARGS, 0)); ft_putnbr(getpid()); ft_putchar('\n'); return (BUILTIN_SUCCESS); }
void launch_visualizer(t_list *lsta, t_list *lstb) { t_mlx mlx; t_params p; if (ft_lstsize(lsta) > WIN_HEIGTH || get_big_value(lsta) > WIN_WIDTH / 2) return ; mlx.mlx_ptr = mlx_init(); mlx.win_ptr = mlx_new_window(mlx.mlx_ptr, WIN_WIDTH, WIN_HEIGTH, "Checker visualizer"); p.mlx = mlx; p.lsta = lsta; p.lstb = lstb; p.heigth_coef = WIN_HEIGTH / ft_lstsize(lsta); p.width_coef = (WIN_WIDTH / 2) / get_big_value(lsta); p.time_coef = INITIAL_REFRESH_COEF; p.acc = 0; mlx_key_hook(mlx.win_ptr, handle_key, (void*)&p); mlx_loop_hook(mlx.mlx_ptr, print_frame, (void*)&p); mlx_loop(mlx.mlx_ptr); }
int b_exit(t_context *context, t_list *args) { size_t arg_count; int exit_code; arg_count = ft_lstsize(args); if (arg_count > 2) return (builtin_error(EXIT_BUILTIN, ERR_TOO_MANY_ARGS, 0)); exit_code = EXIT_SUCCESS; if (arg_count == 2) exit_code = ft_atoi(token_value(args, 2)); shell_exit(context, exit_code); return (BUILTIN_SUCCESS); }
void find_player_position_and_create_mass(t_list *list, t_player *pl) { int i; int j; char *str; t_list *tmp; pl->len = ft_lstsize(list); pl->mass = (int**)malloc(sizeof(int*) * pl->len); i = -1; while (++i < pl->len) pl->mass[i] = (int*)malloc(sizeof(int) * pl->len); tmp = list; i = pl->len; while (tmp) { --i; j = -1; str = tmp->content; while (++j < pl->len) { pl->mass[i][j] = str[j] - '0'; pl->mass[i][j] = pl->mass[i][j] == 64 ? 0 : pl->mass[i][j]; FIND_POS(str[j], i, j); // printf("%d ", pl->mass[i][j]); } // printf("\n"); tmp = tmp->next; } ////***********//// // i = -1; // while (++i < pl->len) // { // j = -1; // while (++j < pl->len) // printf("%d ", pl->mass[i][j]); // printf("\n"); // } // printf("%f %f\n", pl->x_pos, pl->y_pos); }
int b_unsetenv(t_context *context, t_list *args) { size_t arg_count; size_t i; arg_count = ft_lstsize(args); if (arg_count == 1) return (builtin_error(UNSETENV_BUILTIN, ERR_TOO_FEW_ARGS, 0)); i = 1; while (i < arg_count) { environ_remove(context, token_value(args, i + 1)); ++i; } return (BUILTIN_SUCCESS); }
void ft_lstdelfirst(t_list **alst) { t_list *tmp_list; tmp_list = NULL; if (ft_lstsize(*alst) > 1) { tmp_list = (*alst)->next; ft_memdel(&((*alst)->content)); (*alst)->next = NULL; *alst = tmp_list; } else { ft_memdel(&((*alst)->content)); (*alst)->next = NULL; *alst = NULL; } }
int main(int argc, char **argv) { int option[13]; t_list *directory; int print; int i; ft_memset(option, 0, sizeof(option)); directory = NULL; i = 1; if (argc > 1 && (i = ft_getoptions(option, argv)) == -1) return (-1); i = (i > 1) ? i : 1; if ((directory = ft_getdirectories(argv + i)) == NULL) return (-1); else { print = (ft_lstsize(directory) > 1) ? 1 : 0; if (ft_lserrorlist(&directory) != -1) ft_ls(print, option, &directory, 1); } return (0); }
int main(int argc, char **argv) { t_list *lsta; t_list *lstb; //char options; int acc; acc = 0; //options = 0; lstb = NULL; if (argc < 2) return (1); //options = check_options(argv); //afficher etat des listes a chaque coup, forcer un algo de tri different, //imprimer les instructions dans un fichier afficher le nbr d op if (ps_build_list(argv, &lsta) == -1) { ft_putendl("Error"); return (1); } //if (argc - 1 <= 10) //insertion_sort(&lsta, &lstb); //else //{ quicksortA(&lsta, &lstb, ft_lstsize(lsta), &acc); if (PS_MODE == DEBUG_MODE) { ft_printf("END OF SORTING\n"); ft_printf("\033[4mList A\033[0m\n"); ps_print_list(lsta, A_COLOR); ft_printf("\033[4mList B\033[0m\n"); ps_print_list(lstb, B_COLOR); ft_printf("Total instruction : %d\n", acc); } //} return (0); }
int ft_lstsize(t_list *lst) { if (lst) return (ft_lstsize(lst->next) + 1); return (0); }
size_t ft_lstsize(t_list *lst) { if (!lst) return (0); return (1 + ft_lstsize(lst->next)); }
char *jobs_number_command(t_context *context, size_t n) { UNUSED(n); return (ft_itoa(ft_lstsize(context->jobs))); }