void init_history(t_caps *caps) { int fd; char *str; char *path; struct passwd *pwd; caps->hist = NULL; pwd = getpwuid(getuid()); if (!(path = malloc(strlen(pwd->pw_dir) + strlen(HIST_FILE) + 2))) return ; bzero(path, strlen(pwd->pw_dir) + strlen(HIST_FILE) + 2); path = strcat(path, pwd->pw_dir); path = strcat(path, "/"); path = strcat(path, HIST_FILE); if ((fd = open(path, O_RDONLY)) < 0) return ; caps->hist = crea_list(get_next_line(fd)); while ((str = get_next_line(fd))) { add_in_list(caps->hist, str); free(str); } close(fd); }
t_history *add_history(t_history *hist, char *cmd) { char *s; s = strndup(cmd, strlen(cmd) - 1); if (hist == NULL) hist = crea_list(s); else add_in_list(hist, s); free(s); return (hist); }
EDGE * GRAPH::new_edge_c(VERTEX * from, VERTEX * to) { EDGE * e = m_e_free_list.get_free_elem(); if (e == NULL) { e = (EDGE*)_xmalloc(sizeof(EDGE)); } EDGE_from(e) = from; EDGE_to(e) = to; add_in_list(to, e); add_out_list(from, e); return e; }
t_list *list_cpy(t_list *begin) { t_list *begin_cpy; begin_cpy = NULL; while (begin != NULL) { begin_cpy = add_in_list(&begin_cpy, begin->cha); begin = begin->next; } return (begin_cpy); }
t_list *list_ncpy(t_list *begin, int n) { t_list *begin_cpy; int i; i = 0; begin_cpy = NULL; while (begin != NULL && i < n) { begin_cpy = add_in_list(&begin_cpy, begin->cha); begin = begin->next; i = i + 1; } return (begin_cpy); }
t_mysh_er new_env_variable(t_envp *envp, t_sh_token *token) { t_uint32 len; t_uint32 i; t_envl *envl; i = 0; envl = envp->envl; len = my_addr_strlen(envp->env); free(envp->env); if (!(envp->env = malloc(sizeof (char *) * (len + 2)))) return (MA_ERROR); envp->env[len + 1] = NULL; envp->env[len] = append_str_var(token->str, token->next->str, '='); while (envl) { envp->env[i] = envl->name; ++i; envl = envl->next; } add_in_list(envp, envp->env[len], len); return (SUCCES); }