int ft_exit(t_datas *datas, int code) { ft_shell_end(datas); ft_bzero(datas->prompt.buffer, FTSH_MAXLEN_LINE); ft_arrdel(&(datas->path)); ft_arrdel(&(datas->env)); ft_arrdel(&(datas->local)); ft_history_del(&(datas->prompt.history)); if (datas->prompt.line != NULL) ft_history_del(&(datas->prompt.line)); exit(code); return (code); }
int ft_array_push_index(char ***array, char const *value, size_t index) { char **new_array; size_t total; if (!value || !array) return (-1); total = 0; while (*array && (*array)[total]) total++; if (index > total) index = total; if ((new_array = (char **)malloc(sizeof(char *) * (total + 2))) == NULL) return (s_return_and_free(new_array, 0)); if (*array && total > 0) { total = 0; if (s_iterate_on_array(*array, &new_array, index, &total) == -1) return (s_return_and_free(new_array, total)); } total = total == 0 ? 1 : total; if ((new_array[index] = ft_strdup(value)) == NULL) return (s_return_and_free(new_array, total)); new_array[total] = NULL; ft_arrdel(&(*array)); *array = new_array; return (total); }
int ft_array_push_front(char ***array, char const *value) { char **new_array; size_t total; if (!value || !array) return (-1); total = 0; if (*array) while ((*array)[total]) total++; if ((new_array = (char **)malloc(sizeof(char *) * (total + 2))) == NULL) return (s_return_and_free(new_array, 0)); if ((new_array[0] = ft_strdup(value)) == NULL) return (s_return_and_free(new_array, 0)); total = 0; if (*array) while ((*array)[total]) { if ((new_array[total + 1] = ft_strdup((*array)[total])) == NULL) return (s_return_and_free(new_array, total)); total++; } new_array[++total] = NULL; ft_arrdel(&(*array)); *array = new_array; return (total); }
char *ft_realpath(char *path) { size_t i; char *tmp; char **arr; i = 0; if (!path || (arr = ft_strsplit(path, '/')) == NULL) return (NULL); ft_bzero(path, (size_t)ft_strlen(path)); if (ft_arrsize(arr) <= 0) ft_strcat(path, "/"); while (arr[i] != NULL) { tmp = ft_strrchr(path, '/'); if (ft_strcmp(arr[i], "..") == 0 && ft_strrichr(path, '/') > 0) *tmp = '\0'; else if (ft_strcmp(arr[i], ".") != 0) { ft_strcat(path, "/"); if (ft_strcmp(arr[i], "..") != 0) ft_strcat (path, arr[i]); } i++; } ft_arrdel(&arr); return (path); }
void ft_unsetenv(t_env **env) { int i; if (array_size((*env)->av) > 1) { if ((i = is_env(*env, (*env)->av[1])) != -1) { (*env)->e = ft_arrdel((*env)->e, i); } } else ft_putendl("error"); }
static void delete_tubes(t_list *list) { t_list *tmp; if ((tmp = list) != NULL) { while (tmp != NULL) { if (tmp->content != NULL) { ft_arrdel((char ***)&tmp->content); tmp->content = NULL; } tmp = tmp->next; } } }
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_env_setep_new(t_bltenv *env, char **cmd, int i, int n) { int j; env->ep = ft_arrnew(n); if (env->ep == NULL) return (-1); j = 0; while (j < n) { env->ep[j] = ft_strdup(cmd[i]); if (env->ep[j] == NULL) { ft_arrdel(&(env->ep)); return (-1); } j++; i++; } return (i); }