コード例 #1
0
ファイル: else.c プロジェクト: kamiky/gunk-and-junk
int			cond(char **tab, char **path)
{
  int			i;

  i = 0;
  if (my_strcmp(tab[0], "env") == 0)
    {
      my_env();
      return (1);
    }
  if (my_strcmp(tab[0], "setenv") == 0)
    {
      if (tab[1] == NULL)
	return (my_env());
      else if (tab[2] != NULL)
	return (my_setenv(tab[1], tab[2]));
    }
  if (my_strcmp(tab[0], "unsetenv") == 0 && tab[1] != NULL)
    return (my_unsetenv(tab[1]));
  if (my_strcmp(tab[0], "exit") == 0)
    {
      free(path);
      exit(EXIT_SUCCESS);
    }
  return (0);
}
コード例 #2
0
ファイル: env.c プロジェクト: person-m/couver-shell
int		my_setenv(char **tab, t_shell *sh)
{
  int		i;

  i = -1;
  sh->bol = 0;
  if (!exit_setenv(tab))
    return (-1);
  if (!tab[1])
    return (my_env(sh));
  while (sh->env[++i])
    {
      if (!strncmp(sh->env[i], tab[1], strlen(tab[1]))
	  && sh->env[i][strlen(tab[1])] == '=')
	{
	  free(sh->env[i]);
	  sh->env[i] = concat_str(tab[1], tab[2], '=');
	  sh->bol = 1;
	}
    }
  if (!sh->bol)
    {
      sh->env = my_realloc(sh->env, ((tab_len(sh->env) + 2) * sizeof(char *)));
      sh->env[i] = concat_str(tab[1], tab[2], '=');
      sh->env[i + 1] = NULL;
    }
  return (0);
}
コード例 #3
0
ファイル: my_check.c プロジェクト: Ankirama/Epitech
/*
** brief: we will try to find the good command
** @env: our env list
** @arr: contain the command and values
** return: 1 if we found our cmd but it's not cd, 0 if the cmd is not found
** and 2 if we have change the dir and 43 if exit
*/
static int	_my_builtin_fun(char **arr, t_list *env)
{
  char		*pwd;

  if (my_strcmp(arr[0], "exit", 0))
    return (my_exit(env, arr));
  else if (my_strcmp(arr[0], "env", 0))
    my_env(env, arr);
  else if (my_strcmp(arr[0], "cd", 0))
    return (my_cd(arr) + 1);
  else if (my_strcmp(arr[0], "pwd", 0))
    {
      pwd = my_find_element(env, "PWD");
      write(1, pwd, my_strlen(pwd));
      write(1, "\n", 1);
      return (1);
    }
  else if (my_strcmp(arr[0], "setenv", 0))
    my_setenv(env, arr);
  else if (my_strcmp(arr[0], "unsetenv", 0))
    my_unsetenv(env, arr);
  else
    return (0);
  return (1);
}
コード例 #4
0
ファイル: setenv.c プロジェクト: cohen-h/projects
int	my_setenv(t_system *sys)
{
  int	tmp;
  char	*path;
  int	ac;

  ac = wordtab_len(sys->cmd->cmd);
  if (ac == 1)
    return (my_env(sys));
  tmp = builtin_setenv(&(sys->env),
		       sys->cmd->cmd[1], ac > 2 ? sys->cmd->cmd[2] : "");
  path = my_getenv(sys->env, "PATH");
  if (path)
    sys->path = my_str_to_wordtab(path, 0, 0);
  return (tmp);
}