int op_add(t_action *action, char *str, t_pos *pos) { int i; char c; char type; char **tab; char **list_arg; if ((c = 0) || !(pos->prog_size += 2) || !(i = -1) || !(action->identifier = 0x04) || !(action->args = malloc(sizeof(t_arg *) * 4)) || !(tab = str_to_word_tab(str, ',')) || !(list_arg = str_to_word_tab("1 1 1", ' ')) || init_args(action, 3)) return (1); while (tab[++i]) { if (i > 2 || (type = check_type(tab[i], pos)) == -1 || check_args(type, list_arg[i], pos) || fill_arg(type, tab[i], action->args[i], action->pos - i - 1)) return (1); add_prog_size(type, pos); c += (type << (6 - (i * 2))); } action->coding_byte = c; return (free_tab(tab), free_tab(list_arg), (i < 3) ? 1 : 0); }
int check_redirection(char *tab, char **env) { int i; char **arg; i = 0; while (tab[i]) { if (tab[i] == '>' && tab[i + 1] != '>') { arg = str_to_word_tab(tab, ' '); if ((redirection_fonc(arg, env)) == 1) return (1); return (0); } else if (tab[i] == '>' && tab[i + 1] == '>') { arg = str_to_word_tab(tab, ' '); if ((redirection_double_fonc(arg, env)) == 1) return (1); return (0); } i++; } return (1); }
int check_values(char **map) { int y; int x; char **tab; y = 0; while (map[y]) { x = 0; tab = str_to_word_tab(map[y]); while (tab[x]) { if (my_atoi(tab[x]) < 0 || my_atoi(tab[x]) > 70) { my_fprintf("The value %d at (%d;%d) is wrong\n", my_atoi(tab[x]), x, y); free_double_tab(tab); return (0); } x++; } free_double_tab(tab); y++; } return (1); }
int redirection_double_fonc(char **arg, char **env) { int ret; int fd; char **myarg; if ((ret = open(arg[2], O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR)) == -1) { my_putstr("Error open....\n"); exit(1); } fd = dup(1); dup2(ret, 1); myarg = str_to_word_tab(arg[0], ' '); if ((cmd(myarg, env)) == 1) return (1); close(ret); dup2(fd, 1); return (0); }
int check_name(char *str, t_action *action, t_pos *pos) { char **tab; int i; i = 0; if ((tab = str_to_word_tab ("live ld st add sub and or xor zjmp ldi sti fork lld lldi lfork aff" , ' ')) == NULL) return (write(2, "Can't perform malloc\n", 21), -1); while (tab[i]) { if (my_strcmp(tab[i], str) == 0) { action->instruction = str; free_tab(tab); return (i); } i++; } free_tab(tab); return (print_error("Syntax error\n", pos->line, -1)); }
int why_im_stupid(char **ftab, char **env) { char **tab; int i; i = 0; while (ftab[i]) { if ((check_redirection(ftab[i], env) == 0)) { if (ftab[i + 1] != NULL) i++; else return (0); } tab = str_to_word_tab(ftab[i], ' '); if ((check_builtin(tab, env)) == 1) if ((cmd(tab, env)) == 1) return (0); i++; } return (0); }