char *depile_all(char *base, char *operators, t_list *op, t_list *nb) { char *operator; char *expr1; char *expr2; if (my_list_size(op) > 0) { my_rev_list(&op); my_rev_list(&nb); } while (my_list_size(op) > 0) { operator = op->data; depile(&op); expr1 = nb->data; depile(&nb); if (my_list_size(nb) == 0) return (special_case_one_expr_only(base, operators, expr1, operator)); expr2 = nb->data; depile(&nb); my_put_in_list(&nb, operations(base, operators, expr1, operator, expr2)); } return (nb->data); }
/* ** fin empilage, on depile et calcul */ int depile_all(t_list *op, t_list *nb) { char *operator; char *nb1; char *nb2; char *newval; int inew_val; if (my_list_size(op) > 0) { my_rev_list(&op); my_rev_list(&nb); } while (my_list_size(op) > 0) { nb1 = nb->data; depile(&nb); nb2=nb->data; depile(&nb); operator = op->data; depile(&op); inew_val = eval(my_getnbr(nb1), *operator, my_getnbr(nb2)); newval = malloc(sizeof(*newval) * (digit_len(inew_val) + 1)); my_itoa(inew_val, newval); my_put_in_list(&nb, newval); free(newval); } return (my_getnbr(nb->data)); }
int divide_spe(t_list *nb1, t_list *nb2, char *num) { if (my_list_size(nb2) == 1 && nb2->cha == num[0]) return (-1); if (int_list(nb1, nb2, num) == 1) return (0); if (my_list_size(nb1) == 1 && nb2->cha == num[0]) return (0); return (42); }
t_list* npi_manage_operator(char** expr_tab, char* token, int* ind, t_list* stack, char* operators) { char* list_token; char op; char* temp; if(stack != 0) { temp = stack->data; op = *temp; } if(my_list_size(stack) == 0) stack = my_list_add(token, stack); else if(is_parenthesis(op, operators, 1)) stack = my_list_add(token, stack); else if(is_operator_prioritary(*token, op, operators)) stack = my_list_add(token, stack); else { list_token = my_list_pop(&stack); expr_tab[*ind] = list_token; (*ind)++; stack = my_list_add(token, stack); } return (stack); }
void my_sort_list(t_list **begin, int (*cmp)(), int w) { t_list *prev; t_list *next; t_list *curr; t_list *first; int c; c = my_list_size(*begin); while (c != 0) { init_vars(&curr, begin , &prev); while (curr->next != NULL) { next = curr->next; if (cmp((w == 0) ? curr->fword : curr->wword, (w == 0) ? next->fword : next->wword ) > 0) { curr->next = next->next; next->next = curr; save_back(&prev, &next); curr = next; } (prev == NULL) ? savFirst(&first, &curr, 1) : savFirst(&first, &curr, 0); prev = curr; curr = curr->next; } *begin = first; c--; } }
void resolv(int *i, char **tabstring, t_list **op, t_list **nb) { char *save; int new_val; char *str; my_put_in_list(op, tabstring[*i]); *i =*i + 1; if (is_operator(tabstring[*i]) == 0) my_put_in_list(nb, tabstring[*i]); if (is_operator(tabstring[*i]) == 3) my_put_in_list(nb, parenthesis_mode(i, tabstring)); //if (is_operator(tabstring[*i]) == 1) //{ //save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1)); //save = (*nb)->data; //*i = *i + 1; //my_strncat(save,(*nb)->data,my_strlen((*nb)->data)); // } //else //{ save = malloc(sizeof(*save) * (my_strlen((*nb)->data) + 1)); save =(*nb)->data; //} depile(nb); if (my_list_size(*(nb)) == 0) my_put_in_list(nb, "0"); new_val = eval(my_getnbr((*nb)->data), *(*op)->data, my_getnbr(save)); depile(op); depile(nb); str = malloc(sizeof(*str) * (digit_len(new_val) + 1)); my_itoa(new_val, str); my_put_in_list(nb, str); free(save); }
void option_d(int ac, char **av, int pos, t_options option) { t_list *begin; begin = option_dlist(ac, av, pos, option); if (option.r == 1 && my_list_size(begin) > 1) my_rev_list(&begin); ls_display(begin, option); my_free_list(&begin); }
void launch_ls(t_list *f_list, t_list *ptr, char *options, int cpt) { while (cpt < my_list_size(f_list)) { if (my_list_size(f_list) > 2 && find_in_tab(options, 'd') != 0) my_printf("%s:\n", ptr->name); { my_ls(ptr->name, options); } if (cpt + 1 < my_list_size(f_list) && (my_list_size(f_list) > 2 && find_in_tab(options, '1') == 0 && find_in_tab(options, 'd') != 0 || options[0] == '\0')) { my_putstr("\n"); } if (cpt + 1 == my_list_size(f_list) && find_in_tab(options, 'd') == 0 && find_in_tab(options, 'l') != 0) { my_putstr("\n"); } if (cpt + 1 != my_list_size(f_list) && find_in_tab(options, 'l') == 0 && find_in_tab(options, 'd') != 0 && find_in_tab(options, '1') != 0) my_putstr("\n"); ptr = ptr->next; cpt = cpt + 1; } }
int main(int ac, char **av) { char *options; t_list *f_list; t_list *ptr; f_list = NULL; ptr = malloc(sizeof(*ptr)); options = malloc(sizeof(*options) * 4); options = "ldr1"; options = find_options(av, options, 0, 1); f_list = create_list(f_list, av, 0, 1); ptr = f_list; if (my_list_size(f_list) == 1) { my_ls(".", options); if (find_in_tab(options, 'd') == 0) my_putchar('\n'); } else launch_ls(f_list, ptr, options, 1); // free(options); return (0); }