예제 #1
0
파일: history.c 프로젝트: ExPl0siF/42sh
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);
}
예제 #2
0
파일: history.c 프로젝트: ExPl0siF/42sh
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);
}
예제 #3
0
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;	
}
예제 #4
0
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);
}
예제 #5
0
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);
}
예제 #6
0
파일: msh_setenv.c 프로젝트: Aessem35/42SH
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);
}