예제 #1
0
static char	*default_prompt(t_env *env)
{
  char	*hostname;
  char	*username;
  char	*pwd;
  char	*prompt;
  int	len;

  hostname = my_strdup(find_in_env(HOSTNAME_STRING, env));
  username = my_strdup(find_in_env(USERNAME_STRING, env));
  pwd = my_strdup(find_in_env(PWD_STRING, env));
  len = my_strlen(hostname) + my_strlen(username) + my_strlen(pwd) + 7;
  if ((prompt = xmalloc(sizeof(*prompt) * len)) == NULL)
    return (my_strdup(DEFAULT_PROMPT_STRING));
  if (hostname == NULL || username == NULL || pwd == NULL)
    {
      free(prompt);
      return (my_strdup(DEFAULT_PROMPT_STRING));
    }
  sprintf(prompt, "[%s@%s %s]$ ", username, hostname, pwd);
  if (hostname)
    free(hostname);
  if (username)
    free(username);
  if (pwd)
    free(pwd);
  return (prompt);
}
예제 #2
0
static int	custom_prompt(char *str, char c, int i, t_env *env)
{
  char	*custom;

  if (c == 't')
    custom = xtime();
  else if (c == 'm')
    custom = my_strdup(find_in_env(HOSTNAME_STRING, env));
  else if (c == 'u')
    custom = my_strdup(find_in_env(USERNAME_STRING, env));
  else if (c == '~')
    custom = my_strdup(find_in_env(PWD_STRING, env));
  else
    {
      str[i] = c;
      return (++i);
    }
  str = my_strcat(str, custom);
  i += my_strlen(custom);
  if (custom)
    free(custom);
  return (i);
}
예제 #3
0
파일: echo_check.c 프로젝트: desomb/42sh
t_pars	*echo_write(t_pars *pars, char **env)
{
  int i;

  i = 0;
  while (pars->tab[i] != NULL)
    {
      if (i == 0)
	i++;
      if (my_strlen(pars->tab[i]) > 0)
	{
	  if (pars->tab[i][0] == '$')
	    write(1, find_in_env(env, pars->tab[i]),
	  my_strlen(find_in_env(env, pars->tab[i])));
	  else
	    write(1, pars->tab[i], my_strlen(pars->tab[i]));
	}
      if (pars->tab[i + 1] != NULL)
	write(1, " ", 1);
      i++;
    }
  write(1, "\n", 1);
  return (NULL);
}
예제 #4
0
// Using a number of different methods, find a python installation to use
// for our dynamic loading.
int DynPy_FindPython()
{
	get_python_length();
	return find_in_env() || find_in_path() || find_in_registry();
}