void ft_load_texture(char *s1, char *s2, t_env *env) { int i; t_tex *tmp; tmp = NULL; if (!(tmp = ft_init_tmp(s2, env))) exit(ft_perror("malloc()", env)); if ((env->fd2 = open(s1, O_RDONLY)) < 0) exit(ft_perror("open()", env)); ft_search_line(env->fd2, &env->gnl, &(env->line)); if (env->gnl < 0) exit(ft_perror("get_next_line()", env)); i = 1; if ((env->gnl == 0) || !ft_isdigit(env->line[i])) exit(ft_put_error("ft_load_texture(): invalid XPM file.", env)); if (!ft_init_xpm(env->line, &i, &tmp->xtex)) exit(ft_put_error("ft_load_texture(): invalid XPM file.", env)); if (!ft_init_xpm(env->line, &i, &tmp->ytex)) exit(ft_put_error("ft_load_texture(): invalid XPM file.", env)); if (!ft_init_xpm(env->line, &i, tmp->ctex)) exit(ft_put_error("ft_load_texture(): invalid XPM file.", env)); if (!ft_init_xpm(env->line, &i, &tmp->ctex[1])) exit(ft_put_error("ft_load_texture(): invalid XPM file.", env)); return (ft_load_tex(tmp, env)); }
static int ft_piece(t_m *m, t_p *piece) { char **pi; char *p; int i; i = 0; get_next_line(0, &p); if (!(pi = ft_strsplit(p, ' '))) return (ft_perror("pi ")); piece->xp = ft_atoi(pi[1]); pi[2] = ft_strsub(pi[2], 0, ft_strlen(pi[2]) - 1); piece->yp = ft_atoi(pi[2]); free((void *)p); ft_free_char2(pi); if (!(piece->piece = (char **)malloc(sizeof(char *) * (piece->xp + 1)))) return (ft_perror("pi ")); while (i < piece->xp) { get_next_line(0, &p); piece->piece[i] = ft_strdup(p); free((void *)p); ++i; } piece->piece[i] = '\0'; return (ft_place_piece(m, piece)); }
int ft_map(char *p, t_m *m, t_p *piece) { char **map; int i; i = 0; if (!(map = ft_strsplit(p, ' '))) return (ft_perror("map ")); m->xm = ft_atoi(map[1]); map[2] = ft_strsub(map[2], 0, ft_strlen(map[2]) - 1); m->ym = ft_atoi(map[2]); free((void *)p); ft_free_char2(map); get_next_line(0, &p); free((void *)p); if (!(m->map = (char **)malloc(sizeof(char *) * (m->xm + 1)))) return (ft_perror("map ")); while (i < m->xm) { get_next_line(0, &p); m->map[i] = ft_strdup(p + 4); ++i; free((void *)p); } m->map[i] = '\0'; return (ft_piece(m, piece)); }
static void ft_load_tex(t_tex *tmp, t_env *env) { int i[2]; if (!(tmp->color = ft_load_color(env->fd2, tmp->ctex, env))) exit(0); ft_search_line(env->fd2, &(env->gnl), &(env->line)); i[1] = -1; while (ft_check_gnl(env->fd2, env, (i[1] += 1), BLOCK_SIZE) > 0) { if (env->line[0] != '"') exit(ft_put_error("ft_load_tex(): invalid XPM file.", env)); i[0] = -1; while ((i[0] += 1) < BLOCK_SIZE) { if (!ft_put_tex(i, env->line, tmp)) exit(ft_put_error("ft_put_tex(): invalid XPM file.", env)); } env->gnl = get_next_line(env->fd2, &(env->line)); } if (env->gnl < 0) exit(ft_perror("get_next_line()", env)); if ((env->fd2 = close(env->fd2))) exit(ft_perror("close()", env)); }
int main(int argc, char **argv, char **env) { t_env e; if (!*env) return (ft_perror("Environnement indisponible.")); else if (!(argc - 1)) return (ft_perror("Usage: ./wolf3d [map]")); ft_parser(argv[1], &e); ft_init(&e); mlx_loop(e.mlx); return (0); }
void verifdata(char *data) { int i; i = 0; if (data[i] == '-' || data[i] == '+') i++; if (ft_strcmp(ft_itoa(ft_atoi(data)), data)) ft_perror(); while (data[i]) { if (!ft_isdigit(data[i++])) ft_perror(); } }
int main(int argc, char **argv) { int i; if (argc != 2) { ft_perror("usage: ./initials <full name in quotes\"Don Vito\">\n"); return (1); } i = 0; while (argv[1][i] == ' ') i++; while (argv[1][i]) { if (i == 0 || (argv[1][i] != ' ' && argv[1][i - 1] == ' ')) { if (is_upper(argv[1][i])) { ft_putchar(argv[1][i]); } else { ft_putchar(low_to_up(argv[1][i])); } } i++; } ft_putchar('\n'); return (0); }
int main(int ac, char **av) { if (ac != 3) { ft_perror("Error: usage ./grab <word> <file>"); return (1); } from_file(av[2], av[1]); }
void ft_parser(char *file, t_env *e) { int fd; if ((fd = open(file, O_RDONLY)) == -1) exit(ft_perror("Le fichier est introuvable.")); ft_getsize(e, fd); ft_getmap(e, fd); close(fd); }
t_dlist *dlist_create(void) { t_dlist *dlist; if (!(dlist = ft_memalloc(sizeof(t_dlist)))) { ft_perror(NULL); return (NULL); } return (dlist); }
void check_nbr(t_pile *a, int number) { t_pile *tmp; tmp = a; while(tmp != NULL) { if (tmp->nbr = number) ft_perror(); } tmp = tmp->next; }
static void ft_getmap(t_env *e, int fd) { char *line; int **map; static int i; if ((map = (int **)malloc(sizeof(int *) * e->map.x)) == NULL) exit(ft_perror("[Parser]: Allocation impossible.")); while (get_next_line(fd, &line) > 0) map[i++] = ft_intsplit(line, ' '); e->map.map = map; }
static void ft_getsize(t_env *e, int fd) { int *size; char *line; if (get_next_line(fd, &line) < 1) exit(ft_perror("[Parser]: Le fichier est vide.")); size = ft_intsplit(line, ' '); e->map.x = size[0]; e->map.y = size[1]; e->player.pos.x = size[2]; e->player.pos.y = size[3]; }
void from_file(char *filename, char *src) { int fd; int ret; char buf[BUF_SIZE + 1]; fd = open(filename, O_RDONLY); if (fd == -1) { ft_perror("error in open()"); exit(1); } while ((ret = read(fd, buf, BUF_SIZE))) { buf[ret] = '\0'; str_find(buf, src); } if (close(fd) == -1) { ft_perror("error in close()"); exit(1); } }
void ft_ls_a_alone(void) { DIR *dirp; struct dirent *dir_name; const char *dir_path; dir_path = "."; if (!(dirp = opendir(dir_path))) ft_perror(0, '\0', (char *)dir_path); while ((dir_name = readdir(dirp))) { ft_putstr(dir_name->d_name); ft_putchar('\n'); } closedir(dirp); }
void ft_accept(t_env *e, int sock) { int csock; socklen_t csin_len; t_sockaddr_in csin; csin_len = sizeof(csin); if ((csock = accept(sock, (t_sockaddr *)&csin, &csin_len)) == -1) ft_perror("accept"); cleanclient(&e->clients[csock]); e->max_fd = e->max_fd > csock ? e->max_fd : csock; e->clients[csock].type = CLIENT_ATT; e->clients[csock].fct_read = ft_read; e->clients[csock].fct_write = ft_write; e->clients[csock].fct_cmd = ft_cmd; }
void ft_handler(int n) { t_env *env; int len; if (n == SIGWINCH) { env = ft_sglt(); if (tgetent(NULL, env->env) == ERROR) ft_perror(); env->screen->x = tgetnum("co"); env->screen->y = tgetnum("li"); len = ft_lstlen(); env->scroll = (len > env->screen->y) ? len - env->screen->y : 0; ft_plst(); } if (n == SIGQUIT || n == SIGINT) { ft_unsetenv(); exit(EXIT_FAILURE); } }
static int ft_get_stats(t_file *tmp, t_dir *dir, t_opt *opt) { char *path; if (dir->name[ft_strlen(dir->name) - 1] == '/') path = ft_strjoin(dir->name, tmp->name); else { path = ft_strnew(ft_strlen(dir->name) + ft_strlen(tmp->name) + 2); path = ft_strcpy(path, dir->name); path = ft_strcat(path, "/"); path = ft_strcat(path, tmp->name); } if (path == NULL) return (-1); if (lstat(path, &tmp->inf) == 0) ft_ls_l(tmp, dir, path, opt); else opt->ret = ft_perror(path, NULL); if (path) free(path); return (opt->ret); }
void initenv(t_env *e) { struct rlimit rlp; int i; int j; if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) ft_perror("getrlimit"); e->max_clients = rlp.rlim_cur; e->clients = (t_clients *)ft_memalloc(sizeof(t_clients) * e->max_clients); initenv2(e); e->oeufs = NULL; if (e->height < 1 || e->width < 1) ft_error("bad size map"); e->map = ft_memalloc(e->height * sizeof(t_case)); i = -1; while (++i < e->height && (j = -1)) { e->map[i] = ft_memalloc(e->width * sizeof(t_case)); while (++j < e->width) e->map[i][j] = genere_case(); } }