char *ft_add(char *n1, char *n2, char *base, char *ops) { // printf("ADD : n1 == %s n2 == %s\n", n1, n2); if (ft_strcmp(n1, SYNTAXE_ERROR_MSG) == 0 || ft_strcmp(n2, SYNTAXE_ERROR_MSG) == 0) { return (SYNTAXE_ERROR_MSG); } else if (n1[0] == ops[3] && n2[0] == ops[3]) { return (ft_inter_add(&n1[1], &n2[1], base)); } else if (n1[0] == ops[3]) { return (ft_sub(n2, &n1[1], base, ops)); } else if (n2[0] == ops[3]) { return (ft_sub(n1, &n2[1], base, ops)); } else { return (ft_inter_add(n1, n2, base)); } }
int get_next_line(int const fd, char **line) { static char *chr_ret; char buf[BUFF_SIZE + 1]; int nb; if (!line) return (-1); if (fd > -1) { *line = ft_strnew(1); if (chr_ret != NULL) { *line = ft_strdup(chr_ret); free(chr_ret); } while (((chr_ret = ft_strchr(*line, '\n')) == NULL) && ((nb = read(fd, buf, BUFF_SIZE)) > 0)) ft_join(line, buf, nb); if (nb == 0 && chr_ret == NULL) return (0); nb = (nb == -1) ? -1 : 1; ft_sub(line, &chr_ret, nb); return (nb); } else return (-1); }
void exec_1(t_process **proc) { if (PROC->op == LIVE) ft_live(proc); else if (PROC->op == LD) ft_ld(proc); else if (PROC->op == ST) ft_st(proc); else if (PROC->op == ADD) ft_add(proc); else if (PROC->op == SUB) ft_sub(proc); else if (PROC->op == AND) ft_and(proc); else if (PROC->op == OR) ft_or(proc); else if (PROC->op == XOR) ft_xor(proc); }
bool load_scenes(char const *file, t_vector *dst) { t_file_in *in; t_xml_parser xml_parser; bool ret; if (file[0] == '-' && file[1] == '\0') in = ft_in_fdopen(0); else if ((in = ft_in_open(ft_sub(file, 0, -1))) == NULL) { ft_dprintf(2, "%s[Error]%s %s: Invalid file%n", C_RED, C_RESET, file); return (false); } xml_parser = XML_PARSER(V(in)); if (!(ret = parse_scenes(&xml_parser, dst))) { ft_dprintf(2, "%s[Error]%s %s:%u: %ts%n", C_RED, C_RESET, file, xml_parser.line, ft_xml_value(&xml_parser)); // TODO: destroy scenes data on error } ft_xml_clear(&xml_parser); ft_in_close(in); return (ret); }