Exemplo n.º 1
0
void
execute_command(command_t c, int profiling) {
  
  switch (c->type) {
      
    case IF_COMMAND:
      execute_if(c, profiling);
      break;
    case UNTIL_COMMAND:
      execute_until(c, profiling);
      break;
    case WHILE_COMMAND:
      execute_while(c, profiling);
      break;
    case SEQUENCE_COMMAND:
      execute_sequence(c, profiling);
      break;
    case PIPE_COMMAND:
      execute_pipe(c, profiling);
      break;
    case SIMPLE_COMMAND:
      execute_simple(c, profiling);
      break;
    case SUBSHELL_COMMAND:
      execute_subshell(c, profiling);
      break;
    default:
      error (1, 0, "command not found");
  }
  
}
Exemplo n.º 2
0
int execute_command_type(command_t c)
{
    switch(c->type){
            
        case SIMPLE_COMMAND:
            execute(c);
            break;
            
        case PIPE_COMMAND:
            execute_pipe(c);
            break;
            
        case AND_COMMAND:
            // the first command already fails
            if(execute_command_type(c->u.command[0]) != 0){
                c->status = command_status(c->u.command[0]);
            }else{
                c->status = execute_command_type(c->u.command[1]);
            }
            break;
            
        case OR_COMMAND:
            if(execute_command_type(c->u.command[0]) == 0){
                c->status = 0;
            }else{
                // try the second command if the first fails
                c->status = execute_command_type(c->u.command[1]);
            }
            break;
            
        case SUBSHELL_COMMAND:
            c->status = execute_command_type(c->u.subshell_command);
            break;
            
        case SEQUENCE_COMMAND: // return the status of the last command
            execute_sequence(c);
            break;
    }
    return c->status;
}
void
execute_command (command_t c, bool time_travel)
{
	char cmd_type = ' ';
	switch(c->type) {
    case SIMPLE_COMMAND:
    	execute_simple(c);
    	cmd_type = 's';
    	break;
    case SUBSHELL_COMMAND:
    	execute_subshell(c, time_travel);
    	cmd_type = '(';
    	break;
    case AND_COMMAND:
    	execute_and(c, time_travel);
    	cmd_type = 'a';
    	break;
    case OR_COMMAND:
    	execute_or(c, time_travel);
    	cmd_type = 'o';
    	break;
    case SEQUENCE_COMMAND:
    	execute_sequence(c, time_travel);
    	cmd_type = ';';
    	break;
    case PIPE_COMMAND:
    	execute_pipe(c, time_travel);
    	cmd_type = '|';
    	break;
		default:
			return;
	}
	if (DEBUG) {
		printf("%c cmd - exit status: %d\n", cmd_type, c->status);
	}
}