/**
 * Parse a simple command (internal, environment variable assignment,
 * external command).
 */
static int parse_simple( simple_command_t *s, int level, command_t *father)
{
	int size;
	char** comanda;
	comanda=get_argv(s,&size);
	/*daca este comanda interna(cd, exit, quit) */
	if(strcmp(comanda[0],"cd") == 0){
		if(s->out != NULL){
			creat(s->out->string,00700);
			return shell_cd(s->params);
			}
		else return shell_cd(s->params);
		}
	else if( ( strcmp( comanda[0], "exit") == 0) || strcmp(comanda[0],"quit") == 0){
		 shell_exit();
	
	/* daca o comanda de initializare a unei variabile de sistem */
	}else if(s->verb != NULL && s->verb->next_part != NULL){
		if( strcmp( s->verb->next_part->string, "=" ) == 0)
			return var_sys( s->verb->string, s->verb->next_part->next_part->string);
	}
	/* daca este o alta comanda */
	else{
		return ext_comand(comanda,s);
	}
	
	return 0; 
}
예제 #2
0
파일: shell.c 프로젝트: uoaerg/wise
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_exit_process, ev, data)
{
  PROCESS_BEGIN();

  shell_exit();

  PROCESS_END();
}
예제 #3
0
static int builtin_source(shell_context_t *ctx, int argc, char *argv[]) {
	int ret = shell_source(ctx, argv[1]);

	if(ret == -1) {
		fprintf(stderr, "Error while sourcing file %s: %s\n", argv[1], strerror(errno));
	}

	shell_exit(ctx, 0);

	return ret;
}
예제 #4
0
enum shell_reply
shell_exec_quit(struct gnutella_shell *sh, int argc, const char *argv[])
{
	shell_check(sh);
	g_assert(argv);
	g_assert(argc > 0);
	
	shell_set_msg(sh, _("Good bye"));
	shell_exit(sh);
	return REPLY_BYE;
}
예제 #5
0
파일: exit.c 프로젝트: bensisko69/projet_42
int			b_exit(t_context *context, t_list *args)
{
	size_t	arg_count;
	int		exit_code;

	arg_count = ft_lstsize(args);
	if (arg_count > 2)
		return (builtin_error(EXIT_BUILTIN, ERR_TOO_MANY_ARGS, 0));
	exit_code = EXIT_SUCCESS;
	if (arg_count == 2)
		exit_code = ft_atoi(token_value(args, 2));
	shell_exit(context, exit_code);
	return (BUILTIN_SUCCESS);
}
예제 #6
0
int			builtin_exit(t_list *environ, char **cmds)
{
	t_sh	*sh;

	sh = t_sh_recover();
	UNUSED(environ);
	if (cmds[1])
	{
		if (assert_digit(cmds[1]) && !cmds[2])
		{
			sh->last_res = ft_atoi(cmds[1]);
			shell_exit();
			return (ft_atoi(cmds[1]));
		}
		else
		{
			builtin_exit_error_digit(cmds[1]);
			return (2);
		}
	}
	else
		shell_exit();
	return (sh->last_res);
}
예제 #7
0
파일: tty.c 프로젝트: bensisko69/projet_42
static int		open_tty(void)
{
	char		*tty_file_name;
	int			fd;

	if (isatty(STDIN))
	{
		tty_file_name = ttyname(STDIN);
		fd = open(tty_file_name, O_RDWR);
		if (fd != -1 && isatty(fd))
			return (fd);
	}
	shell_error(ERR_NO_TTY, 0);
	shell_exit(get_context(), EXIT_ERROR);
	return (-1);
}
예제 #8
0
/**
* execute internal command in child process
* pipe_end: write end of pipe to notify parent of errnos
* key: indicates the internal command
* jman: job manager
* args: array of args string to command
* returns: status
**/
_BOOL execute_internal(int pipe_end,short key,JMANAGER* jman,char **args){
  if(jman == NULL || args == NULL){errno = EINVAL; return FALSE;}
  if(pipe_end != -1){
    if(close(pipe_end) ==-1){
	    _exit(EXIT_FAILURE);
    }
  }
  _BOOL ret = FALSE;
  switch(key){
    case JOBS:
        ret = shell_dump(jman,args);
        break;
    case FG:
        ret = shell_foreground(jman,args);
        break;
    case BG:
        ret = shell_background(jman,args);
        break;
    case SHEXIT:
        ret = shell_exit(FALSE,NULL,NULL);
    case ECHO:
        ret = shell_echo(jman,args);
        break;
    case HELP:
        ret = shell_help("\r%s\n",args);
        break;
    default:
      errno = EINVAL;
      return FALSE;
      break;
    if(ret)
	_exit(EXIT_SUCCESS);
    else
	return FALSE;

  }

  return TRUE;

}
예제 #9
0
static int builtin_exit(shell_context_t *ctx, int argc, char *argv[]) {
	shell_exit(ctx, 1);

	return 0;
}