int main(int argc, char **argv) { char *lines; t_board c; t_piece p; t_player t; int i = 0; int fd; t_test result; fd = open("text", O_WRONLY | O_APPEND); while (ft_get_next_line(0, &lines) > 0) { if (ft_strcmp("Plateau", lines)) { ft_get_next_line(0, &lines); c.map = save_map(&lines, &c); } if (ft_strcmp("Piece", lines)) p.piece = save_piece(&lines, &p); ft_search(c.map, &t, &c); i++; } place_piece(p, c, t); close (fd); }
void ft_checkwidth(int fd, int w, int w1, t_bresen *var) { if (ft_get_next_line(fd, &(var->line))) { ft_checkline(var->line); if ((var->coord = ft_strsplit(var->line, ' ')) == NULL || !*var->coord) ft_error("Error: content"); if (!(w = ft_findw(var->coord))) ft_error("Error: width"); free(var->coord); free(var->line); } else ft_error("Empty File"); while (ft_get_next_line(fd, &var->line)) { ft_checkline(var->line); if ((var->coord = ft_strsplit(var->line, ' ')) == NULL || !*var->coord) ft_error("Error: content"); w1 = ft_findw(var->coord); if (w != w1) ft_error("Error: Width uneven"); free(var->coord); free(var->line); } }
void ft_player_play(t_connect *connect, char *in, char c) { int col; char *trim; col = 0; trim = ft_strtrim(in); if (in && in[0] && ft_str_check_digit(trim) && (col = ft_atoi(trim)) > 0) { ft_strdel(&in); ft_strdel(&trim); if (connect->w < col || connect->table[0][col - 1] != '0') ft_player_play(connect, NULL, c); else ft_put_in_table(connect->table, col, c); } else { ft_strdel(&in); ft_strdel(&trim); ft_put_icon(c); ft_putstr("Choose your column : "); ft_check_get_next_line(ft_get_next_line(0, &in), connect); ft_player_play(connect, in, c); } }
static int s_stock_map(char *name, int count_lines, size_t max_len_lines) { char **map; char *line; int fd; int i; if ((fd = open(name, O_RDONLY)) == -1) return (-1); if ((map = malloc(sizeof(char *) * (count_lines + 1))) == NULL) return (-1); i = 0; s_comb_first_end(&map[i++], max_len_lines); while (ft_get_next_line(fd, &line) > 0) { s_comb(&line, max_len_lines); map[i++] = line; } s_comb_first_end(&map[i++], max_len_lines); map[i] = NULL; if (close(fd) == -1 || count_lines <= 0) return (-1); sgt_map(map); return (0); }
void ft_stock_value(t_env *env) { char **tmp; int i; int j; i = 0; j = 0; env->tab = (int **)malloc(sizeof(int *) * (env->nbr_line + 1)); env->tab[env->nbr_line] = '\0'; while (i < env->nbr_line) { env->tab[i] = (int *)malloc(sizeof(int) * (env->nbr_col + 1)); env->tab[i][env->nbr_col] = '\0'; i++; } env->fd = open(env->av[1], O_RDONLY); while (ft_get_next_line(env->fd, &env->line)) { i = 0; tmp = ft_strsplit(env->line, ' '); while (i < env->nbr_col) { env->tab[j][i] = ft_atoi(tmp[i]); ft_putnbr(env->tab[j][i]); i++; } j++; ft_putchar('\n'); } }
static int ft_get_fd(fd_set *fd_read, int sock) { char *line; char *line2; line = NULL; if (sock != -1) { FD_ZERO(fd_read); FD_SET(sock, fd_read); FD_SET(0, fd_read); select(sock + 1, fd_read, NULL, NULL, NULL); if (FD_ISSET(sock, fd_read)) if (ft_send_fd(sock) == -1) return (-1); if (FD_ISSET(0, fd_read)) { if (ft_get_next_line(0, &line) > 0 && check_command(line, &sock)) { line2 = ft_strjoin(line, "\n"); ft_putstr_fd(line2, sock); ft_strdel(&line); ft_strdel(&line2); } } } return (1); }
void ft_zvalue(int fd, t_map *m) { int x; int j; char **coord; char *line; x = 0; m->hmax = 0; m->hmin = 0; m->map = (int **)malloc(sizeof(int *) * (m->h + 1)); while (ft_get_next_line(fd, &line)) { coord = ft_strsplit(line, ' '); m->map[x] = ft_atoimap(coord, m->w); free(coord); free(line); j = 0; while (j < m->w) { m->hmax = m->map[x][j] > m->hmax ? m->map[x][j] : m->hmax; m->hmin = m->map[x][j] < m->hmin ? m->map[x][j] : m->hmin; j++; } x++; } close(fd); }
t_obj_stats parser_count(const char *filepath) { t_obj_stats stats; int fd; char *line; ft_bzero(&stats, sizeof(t_obj_stats)); if ((fd = open(filepath, O_RDONLY)) <= 0) return (stats); while ((ft_get_next_line(fd, &line)) && (!parse_line_error(line))) { if (ft_sscanfqf(line, "v \\S%f \\S%f \\S%f") == 3) stats.vertex++; else if (parser_count_faces(line, &stats)) ; else if (ft_sscanfqf(line, "vt \\S%f \\S%f") == 2) stats.uv++; else if (ft_sscanfqf(line, "vn \\S%f \\S%f \\S%f") == 3) stats.normal++; free(line); } free(line); close(fd); ft_printf("stats: vertex: %lu / faces: %lu / uv: %lu / normal: %lu\n", stats.vertex, stats.faces, stats.uv, stats.normal); return (stats); }
int wait_msg(char *msg, int fd) { char *input; int ret; input = NULL; if (ft_get_next_line(fd, &input) == -1) return (-1); ret = ft_strequ(input, msg); free(input); return (ret); }
void ft_findwh(int fd, t_map *list) { char *line; char **coord; int y; y = 0; if (ft_get_next_line(fd, &line)) { y++; coord = ft_strsplit(line, ' '); list->w = ft_findw(coord); free(coord); free(line); } while (ft_get_next_line(fd, &line)) { y++; free(line); } list->h = y; close(fd); }
static void s_load_map(char *file_name) { int ret_gnl; int fd; char *line; if ((fd = open(file_name, O_RDONLY)) == -1) return ((void)ERR("%s", ft_strerror())); line = NULL; while ((ret_gnl = ft_get_next_line(fd, &line)) > 0) ft_lstd_push_front(&sgt_fdf()->l_line, line); if (ret_gnl == -1) ERR("%s", ft_strerror()); ft_lstd_rmap(&sgt_fdf()->l_line, &s_split); }
void ft_nbr_line_col(t_env *env) { int i; char **tmp; env->nbr_line = 0; env->nbr_col = 0; env->fd = open(env->av[1], O_RDONLY); while (ft_get_next_line(env->fd, &env->line)) { i = 0; tmp = ft_strsplit(env->line, ' '); ft_putstr(env->line); ft_putchar('\n'); while (tmp[i]) i++; env->nbr_line++; } env->nbr_col = (i - 1); }
int open_map(char *name) { char *line; int fd; int count_lines; size_t max_len_lines; if ((fd = open(name, O_RDONLY)) == -1) return (-1); line = NULL; count_lines = 0; max_len_lines = 0; while (ft_get_next_line(fd, &line) > 0) { ++count_lines; if (max_len_lines < ft_strlen(line)) max_len_lines = ft_strlen(line); ft_strdel(&line); } if (close(fd) == -1 || count_lines <= 0 || max_len_lines <= 0) return (-1); return (s_stock_map(name, count_lines + 2, max_len_lines)); }
void s_wait_server(int *port, int *sock) { char *line; char **spl; line = NULL; ft_putstr("Please choose a server [addr] [port] > "); while (ft_get_next_line(0, &line) > 0) { spl = ft_strsplit(line, ' '); if (ft_strlistlen(spl) == 2 && ft_isnumber(spl[1])) { *port = ft_atoi(spl[1]); *sock = ft_connect(spl[0], *port); if (*sock != -1) { ft_strlistdel(spl); return ; } } ft_putstr("Please choose a server [addr] [port] > "); ft_strlistdel(spl); } }
t_scene *ft_read_scene(t_data *d, int fd, char *name) { char *line; t_scene *s; if (!(s = (t_scene *)malloc(sizeof(t_scene)))) return (NULL); ft_init_scene(s, name); line = NULL; while (ft_get_next_line(fd, &line) != 0) { ft_check_scene(s, line); ft_check_camera(s, line, d); ft_check_background(s, line); if (!ft_strncmp(line, "SPOT", 4)) ft_get_spot(s, fd, line); ft_get_object(s, fd, ft_get_object_type(line, 0), line); free(line); } free(line); ft_assign_noise_tables(s); ft_init_scene_imgs(s, d); return (s); }
int get_next_line(int const fd, char **line) { if (fd < 0 || line == NULL) return (-1); return (ft_get_next_line(fd, line)); }
int main() { int fd; char *line; int vertices; char **map; char **temp; int **imap; int **level; int **parent; int i; int j; fd = open("in", O_RDONLY); ft_get_next_line(fd, &line); vertices = ft_atoi(line); map = (char**)malloc(sizeof(*map) * 13); i = 0; while (ft_get_next_line(fd, &line)) { map[i] = line; i++; } map[i] = 0; //create adjency matrix imap = (int**)malloc(sizeof(*imap) * vertices); i = 0; while (i < vertices) { imap[i] = (int*)malloc(sizeof(int) * vertices); i++; } //initialize adjency matrix values to 0 i = 0; while (i < vertices) { j = 0; while (j < vertices) { imap[i][j] = 0; j++; } i++; } //connect the vertices i = 0; while (map[i]) { temp = ft_strsplit(map[i], ' '); imap[ft_atoi(temp[0])][ft_atoi(temp[1])] = 1; imap[ft_atoi(temp[1])][ft_atoi(temp[0])] = 1; i++; } //print adjacency matrix ft_print_int_matrix(imap, vertices); //create level matrix level = (int**)malloc(sizeof(*level) * vertices); i = 0; while (i < vertices) { level[i] = (int*)malloc(sizeof(int) * vertices); i++; } i = 0; while (i < vertices) { j = 0; while (j < vertices) { level[i][j] = vertices; j++; } i++; } // ft_print_int_matrix(level, vertices); //create parent matrix parent = (int**)malloc(sizeof(*parent) * vertices); i = 0; while (i < vertices) { parent[i] = (int*)malloc(sizeof(int) * vertices); i++; } i = 0; while (i < vertices) { j = 0; while (j < vertices) { parent[i][j] = vertices; j++; } i++; } // ft_print_int_matrix(parent, vertices); // BFS : start 0 ; end 4 int start; int end; int lvl; int que[vertices]; start = 0; end = 4; ft_set_level_0_to_start(start, level, vertices); i = 0; while (i < vertices) { que[i] = 9; i++; } que[0] = 0; lvl = 1; while (que[0] != 9) { ft_find_adjacent_vertices(que, imap, level, parent, vertices, lvl); ft_recreate_que_with_adjacent_vertices_with_last_level_set(que, level, lvl); lvl++; } ft_print_int_matrix(level, vertices); ft_print_int_matrix(parent, vertices); }