int ft_parse(char *file, t_env *e) { int fd; int obj_nb; int spot_nb; char *line; if ((fd = ft_parse_2(e, file)) < 0) return (-1); while (get_next_line(fd, &line) > 0 && (line[0] == '/' || line[0] == 0)) ; line = delete_spaces(line, ' '); if (!verif_vect(line)) return (-1); e->cam_ray = ft_fill_vect(line, e->cam_ray); if (!ft_parse_init(&obj_nb, &spot_nb, e, fd)) return (-1); if (!the_parse(fd, obj_nb, spot_nb, e)) return (-1); e->spot[spot_nb] = NULL; e->types[obj_nb] = NULL; e->objects[obj_nb] = NULL; free(line); if (close(fd) == -1) return (-1); return (0); }
string MergeNames(size_t index, string name1, string name2) { if(name1[0] == '@') name1 = name1.substr(1, name1.size() - 1); stringstream ss; ss << "@" << index << "_merged_read_" << delete_spaces(name1); return ss.str(); }
int ft_parse_init(int *obj_nb, int *spot_nb, t_env *e, int fd) { char *line; while (COMMENT) ; line = delete_spaces(line, ' '); if ((*obj_nb = verif_number(line)) < 0) return (0); while (COMMENT) ; line = delete_spaces(line, ' '); if ((*spot_nb = verif_number(line)) < 0) return (0); if ((e->objects = (t_sp**)malloc(sizeof(t_sp*) * (*obj_nb + 1))) == NULL) return (0); if ((e->types = (char**)malloc(sizeof(char*) * (*obj_nb + 1))) == NULL) return (0); if ((e->spot = (t_sp**)malloc(sizeof(t_sp*) * (*spot_nb + 1))) == NULL) return (0); return (1); }
static int ft_parse_2(t_env *e, char *file) { char *line; int fd; line = ft_strnew(0); if ((fd = open(file, O_RDONLY)) == -1 || (read(fd, line, 0) == -1)) return (-1); while (get_next_line(fd, &line) > 0 && (line[0] == '/' || line[0] == 0)) ; line = delete_spaces(line, ' '); if (!verif_real(line)) return (-1); e->fov = ft_atoi_float(line); return (fd); }
char *ft_quote(char *line) { char *str; str = NULL; line = delete_spaces(line); if (line[ft_strlen(line) - 1] == '\\' && ((((int)ft_strlen(line) - 2) >= 0 && line[ft_strlen(line) - 2] != '\\') || (ft_strlen(line) == 1))) { while (line[ft_strlen(line) - 1] == '\\' && ((ft_strlen(line) == 1) || (((int)ft_strlen(line) - 2) >= 0 && line[ft_strlen(line) - 2] != '\\'))) { line = fn_delete(line, ft_strlen(line) - 1); str = ft_termcaps(ft_printf("> ")); line = ft_strjoin(line, str); } } if (ft_strchr(line, '"') || ft_strchr(line, '\'') || ft_strchr(line, '`')) line = the_quotes(line); line = ft_parentheses(line, str); return (line); }