Beispiel #1
0
t_uchar		run_exit(char **env,
			 char **path,
			 t_command *command,
			 t_builtin_ptr **builtins)
{
  char		exit_status;

  if (count_args(command->argv_tmp) > 2)
    {
      my_dprintf(STDERR, "exit: Expression Syntax.\n");
      return (EXIT_FAILURE);
    }
  if (command->argv_tmp == NULL || count_args(command->argv_tmp) == 1)
    exit_status = command->last_ret;
  else if (my_str_isnum(command->argv_tmp[1]) == FALSE)
    {
      my_dprintf(STDERR, "exit: Expression Syntax.\n");
      return (EXIT_FAILURE);
    }
  else
    exit_status = my_atoi(command->argv_tmp[1]);
  if (command->interactive == TRUE)
    my_dprintf(STDERR, "exit\n");
  my_free_2d_tab(env);
  my_free_2d_tab(path);
  my_free_2d_tab(command->argv);
  free(command->argv_tmp);
  free_builtins(builtins);
  exit(exit_status);
  return (EXIT_SUCCESS);
}
Beispiel #2
0
int		main(int argc, char **argv, char **environ)
{
  t_builtin_ptr	**builtins;
  t_command	command;
  t_uchar	ret;
  char		**env;

  (void)(argc + argv);
  ret = EXIT_SUCCESS;
  env = my_envcpy(environ);
  if (!(builtins = malloc(sizeof(t_builtin_ptr *) * (BUILTINS_NBR + 1)))
      || init_builtins(builtins) == 1)
    return (EXIT_FAILURE);
  while (true)
    {
      command.last_ret = ret;
      signal_handler(SETSIG, SIGINT_REGULAR);
      chkenv(&env);
      if (!get_input(&command, ret, env)
	  && !(ret = chck_command_logic(command)))
	ret = handle_command_logic(builtins, &env, command);
      my_free_2d_tab(command.argv);
    }
  return (EXIT_SUCCESS);
}