static int ft_p_u_check(char **cmd, int *i, int j, t_opt *opt) { char **old; char *tmp; if (cmd[*i][j] == 'P') { opt->p = 1; tmp = opt->path; if ((opt->path = ft_env_opt_p(cmd, i, j + 1, opt)) == tmp) return (ft_env_error("malloc failed.", 0)); return (1); } else if (cmd[*i][j] == 'u') { opt->u = 1; old = opt->ptr; if ((opt->ptr = ft_env_opt_u(cmd, i, j + 1, opt)) == old) return (ft_env_error("malloc failed.", 0)); return (1); } else return (ft_env_error("illegal option", cmd[*i][j])); return (0); }
int control_size(t_elem *l) { char *termtype; int lin; termtype = getenv("TERM"); if (!termtype) ft_env_error(); tgetent(NULL, termtype); tputs(tgetstr("cl", NULL), 1, int_char); lin = tgetnum("li"); l->len = ft_list_len(l); if (l->len > lin - 1) { tputs(tgetstr("cl", NULL), 1, int_char); ft_putendl_red("Please Resize window"); return (0); } else { tputs(tgetstr("cl", NULL), 1, int_char); display_list(l); } return (1); }
void ft_env(t_env **env, t_env *tmpenv, char **cmd) { int i; char *tmp; i = -1; if (!cmd[1]) print_list(*env); else if (cmd[1] && cmd[1][0] == '-') ft_env_opt(*env, tmpenv, cmd); else if (cmd[1] && cmd[1][0] != '-') { tmp = getvarname(cmd[1]); while (cmd[1][++i]) if (cmd[1][i] == '=') { already_exist(&tmpenv, tmp); tmpenv = add_var(tmpenv, cmd[1]); print_list(tmpenv); ft_strdel(&tmp); return ; } ft_strdel(&tmp); ft_env_error(cmd[1]); } }
static void ft_env_u(t_env *env, char **cmd) { int i; i = 1; if (!cmd[2]) { ft_env_usage(cmd[1][i]); return ; } else if (cmd[3]) { ft_env_error(cmd[3]); return ; } else if (cmd[1][i] == 'u' && cmd[2]) { ft_unsetenv(&env, cmd[2]); print_list(env); } }
int ft_env_check_opt_plus(char **cmd, t_opt *opt, int i) { char **table; int k; while (ft_strchr(cmd[i], '=')) { if ((table = ft_tabnew(ft_tablen(opt->extra) + 2)) == NULL) return (ft_env_error("malloc failed", 0)); k = 0; while (opt->extra && opt->extra[k]) { table[k] = opt->extra[k]; k++; } table[k] = cmd[i]; table[k + 1] = NULL; free(opt->extra); opt->extra = table; i++; } return (i); }