int ft_check_error_parse(t_list_p *list, int status, int left, int right) { t_list_p *tmp; tmp = list; if (st_check_first_str(tmp) == -1) return (-1); while (tmp) { if (status == 0) { if (ft_status_zero(&tmp, &status, &left, &right) == -1) return (-1); } else if (status == 3 && (tmp->str[0] == '|' || tmp->str[0] == ';' || ft_strcmp(tmp->str, "&&") == 0)) return (ft_error_parse(3, -1)); else if ((tmp->str[0] == '|' || tmp->str[0] == ';' || tmp->str[0] == '>' || tmp->str[0] == '<' || ft_strcmp(tmp->str, "&&") == 0) && status != 0) return (ft_error_parse(4, -1)); else st_next_tmp(&status, &tmp); } return (st_check_error_status(status)); }
static int st_check_error_status(int status) { if (status == 1 || status == 2) return (ft_error_parse(4, -1)); else if (status == 3) return (ft_error_parse(3, -1)); else return (0); }
int check_nbr_cmd(int nb_cmd, int previous, t_cmd **tmp, t_cmd *cmd) { if (!nb_cmd && !(*tmp != cmd && previous == TYPE_CMD_SEP)) return (ft_error_parse("Invalid null command")); if (*tmp != cmd) previous = (*tmp)->type; if (*tmp != cmd) { *tmp = (*tmp)->next; if (*tmp == cmd && (*tmp)->prev->type != TYPE_CMD_SEP) return (ft_error_parse("Invalid null command")); else if (*tmp == cmd) return (previous); } return (previous); }
int check_null_cmd(t_cmd *cmd) { int nb_cmd; int previous; t_cmd *tmp; nb_cmd = 0; tmp = cmd->next; previous = TYPE_CMD_SEP; while (tmp != cmd) { nb_cmd = 0; while (tmp != cmd && tmp->type != TYPE_PIPE && tmp->type != TYPE_AND && tmp->type != TYPE_OR && tmp->type != TYPE_CMD_SEP) { if (tmp->type == TYPE_CMD) nb_cmd++; tmp = tmp->next; } if (nb_cmd == 0 && tmp != cmd && (tmp->type == TYPE_PIPE || tmp->type == TYPE_AND || tmp-> type == TYPE_OR)) return (ft_error_parse("Invalid null command")); if ((previous = check_nbr_cmd(nb_cmd, previous, &tmp, cmd)) == -1) return (-1); } return (1); }
int ft_check_error_parse_red(t_point *list) { t_point *point; t_op *op; t_pipe *pipe; point = list; if (!point || !point->op || !point->op->pipe || !point->op->pipe->list) return (-1); while (point) { op = point->op; while (op) { pipe = op->pipe; while (pipe) { if (pipe->list && (pipe->list->out || pipe->list->app) && pipe->next) return (ft_error_parse(6, -1)); pipe = pipe->next; } op = op->next; } point = point->next; } return (0); }
int find_and_replace(t_cmd *tmp, t_env *env, t_var *var) { int ret; int len; t_env *tmp_env; len = ft_strlen(tmp->word + 1); tmp_env = env->next; while (tmp_env != env) { if (ft_strncmp(tmp->word + 1, tmp_env->var, len)) { tmp->word = ft_strdup(tmp_env->var + len + 1); if (tmp->word == NULL) return (ft_error_parse("fail strdup")); return (0); } tmp_env = tmp_env->next; } if ((ret = find_and_replace_var(tmp, var, len)) == -1 || ret == 0) return (ret); ft_error_parse("Wrong variable name."); return (-2); }
int find_and_replace_var(t_cmd *tmp, t_var *var, int len) { t_var *tmp_var; tmp_var = var->next; while (tmp_var != var) { if (ft_strncmp(tmp->word + 1, tmp_var->var, len)) { tmp->word = ft_strdup(tmp_var->content); if (tmp->word == NULL) return (ft_error_parse("fail strdup")); return (0); } tmp_var = tmp_var->next; } return (-2); }
int env_opt(char *line, t_info *info) { size_t i; if (!line) return (0); if (line[0] != '-') return (0); if (ft_strequ(line, "--")) return (0); if (ft_strequ(line, "-u")) return (0); if (line[0] == '-' && line[1] == '\0') return (0); i = 1; while (i < ft_strlen(line)) { if (invalid_opt(line[i], info)) ft_error_parse(line[i]); i++; } return (1); }
static int st_check_first_str(t_list_p *tmp) { if (tmp->str[0] == '|' || ft_strcmp(tmp->str, "&&") == 0) return (ft_error_parse(3, -1)); else if (tmp->str[0] == '>' && st_is_separate(tmp) == -1) return (ft_error_parse(4, -1)); else if (tmp->str[0] == '>') { while (tmp) { if (ft_strcmp(tmp->str, "|") == 0) return (ft_error_parse(6, -1)); tmp = tmp->next; } return (ft_error_parse(3, -1)); } else if (tmp->str[0] == '<' && st_is_separate(tmp) == -1) return (ft_error_parse(4, -1)); else if (tmp->str[0] == '<') return (ft_error_parse(3, -1)); return (0); }