コード例 #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
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
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
ファイル: list_cpy.c プロジェクト: Frozenhorns/project
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
ファイル: list_cpy.c プロジェクト: Frozenhorns/project
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);
}