int ft_setenv(t_sh *sh, t_cmd *cmd) { if (cmd) { if (!cmd->args[1]) ft_printenv(sh); else if (cmd->args[1] && cmd->args[2] && cmd->args[1][0] != '-') return (ft_setvar(sh, cmd->args[1], cmd->args[2])); else if (cmd->args[1] && !cmd->args[2] && cmd->args[1][0] != '-') return (ft_setvar(sh, cmd->args[1], NULL)); else return (-1); } return (-1); }
int ft_response(t_datas *datas) { int res; char *tmp; tmp = NULL; if (WIFEXITED(datas->status)) tmp = ft_itoa(WEXITSTATUS(datas->status)); else if (WIFSIGNALED(datas->status)) tmp = ft_itoa(WTERMSIG(datas->status)); else if (WIFSTOPPED(datas->status)) tmp = ft_itoa(WSTOPSIG(datas->status)); res = ft_setvar(&(datas->local), "?", tmp); ft_strdel(&tmp); return (res); }
int ft_setenv(t_datas *datas, char **cmd) { if (ft_strcmp(cmd[0], "setenv") != 0) return (-1); if (ft_setenv_usage(cmd) != 0) return (1); if (ft_setvar(&(datas->env), cmd[1], cmd[2]) != 0) return (ft_error(FTSH_NAME, "setenv", "memory allocation failed.")); if (ft_strcmp(cmd[1], "HOME") == 0 || (ft_strcmp(cmd[1], "CWD") != 0 && ft_strcmp(cmd[1], "OWD") != 0 && ft_strcmp(cmd[1], "$") != 0 && ft_strcmp(cmd[1], "?") != 0 && ft_getenv(datas->local, cmd[1]) != NULL && ft_strlen(cmd[1]) > 0)) ft_set(datas, cmd); return (0); }
static int ft_env_setep_dup(t_bltenv *env, char **cmd, int i, int n) { char *val; char key[FTSH_MAXLEN_LINE]; ft_bzero(key, FTSH_MAXLEN_LINE); while (n--) { ft_strncpy(key, cmd[i], ft_strichr(cmd[i], '=')); val = ft_strchr(cmd[i], '=') + 1; if (ft_setvar(&(env->ep), key, val) != 0) { ft_arrdel(&(env->ep)); return (-1); } i++; } return (i); }
static int ft_find_blt(t_datas *datas, t_fblt **fblt, char **cmd, char **tmp) { int i; int res; i = 0; while (fblt[i] != NULL) { res = (fblt[i])(datas, cmd); if (res != -1) { if (*tmp != cmd[1]) ft_strdel(tmp); *tmp = ft_itoa(res); ft_setvar(&(datas->local), "?", *tmp); ft_strdel(tmp); return (1); } i++; } if (*tmp != cmd[0]) ft_strdel(tmp); return (0); }