Example #1
0
int shell (int argc, char *argv[]) {

  char *s = malloc(INPUT_STRING_SIZE+1);			/* user input string */
  tok_t *t;			/* tokens parsed from input */
  int lineNum = 0;
  int fundex = -1;
  pid_t pid = getpid();		/* get current processes PID */
  pid_t ppid = getppid();	/* get parents PID */
  pid_t cpid, tcpid, cpgid;
  char cwd[1024];
   int status;
                                                                        
 
   printf("%s running as PID %d under %d\n",argv[0],pid,ppid);
  
    lineNum=0;
    fprintf(stdout, "%d%s:",lineNum,getcwd(cwd,sizeof(cwd)));
    init_shell();

  while ((s = freadln(stdin))){
  
        char * temp;
        temp = concat(s,"");
  
    t = getToks(s); /* break the line into tokens */
    fundex = lookup(t[0]); /* Is first token a shell literal */
    if(fundex >= 0) cmd_table[fundex].fun(&t[1]);
     
    else {
       
     if ((pid = fork()) < 0) {     /* fork a child process           */
          printf("*** ERROR: forking child process failed\n");
          exit(1);
     }

     else if (pid == 0) {    /* for the child process:         */
      process * new =create_process(temp);
          add_process(new);
             launch_process(new);
      

      int i;
      char * command1=">", * command2= "<";
      char *amp ="&";
    for(i=0;i<MAXTOKS && t[i];i++){
              if(strcmp(t[i],amp)== 0){
                t[i]=NULL;
            cmd_and(t[i],amp);
   }
            
      
	if (strcmp(t[i],command1)==0){
	   t[i]=NULL;
	    Redirecting_In_Out(t,t[i+1],command1);	
          }
        if(strcmp(t[i],command2)==0){
           t[i]=NULL;
            Redirecting_In_Out(t,t[i+1],command2);
	    }
	  }
	  
          path(t);


        }
        
      else {    /* for the parent:      */
	wait(&status);
         /* wait for completion  */
           
    }
      
      fprintf(stdout, "This shell only supports built-ins. Replace this to run programs as commands.\n");
     
     }
Example #2
0
void LedController::process_command() {
  current_instruction_pc = pc;
  uint8_t cmd = program[pc++]; 
  switch(cmd) {

    case CMD_GROUP_SET:
      cmd_group_set();
      break;
      
    case CMD_GROUP_CLEAR:
      cmd_group_clear();
      break;

    case CMD_CLEAR_GROUPS:
      cmd_clear_groups();
      break;

    case CMD_DISABLE_ACTIONS:
      cmd_disable_actions();
      break;
          
    case CMD_LOAD_REG_CONST:
      cmd_load_reg_const();
      break;

    case CMD_LDAA8:
      cmd_load_reg_8(0);
      break;
    
    case CMD_LDAB8:
      cmd_load_reg_8(1);
      break;
    
    case CMD_LDAC8:
      cmd_load_reg_8(2);
      break;
    
    case CMD_LDAD8:
      cmd_load_reg_8(3);
      break;
    
    case CMD_LDAE8:
      cmd_load_reg_8(4);
      break;
    
    case CMD_LDAA16:
      cmd_load_reg_16(0);
      break;
    
    case CMD_LDAB16:
      cmd_load_reg_16(1);
      break;
    
    case CMD_LDAC16:
      cmd_load_reg_16(2);
      break;
    
    case CMD_LDAD16:
      cmd_load_reg_16(3);
      break;
        
    case CMD_LDAE16:
      cmd_load_reg_16(4);
      break;
        
    case CMD_LOAD_REG_MAV:
      cmd_load_reg_mav();
      break;
      
    case CMD_PAUSE:
      cmd_pause();
      break;
          
    case CMD_YIELD:
      cmd_yield();
      break;
      
    case CMD_JUMP_ABS:
      cmd_jump_absolute();
      break;

    case CMD_JUMP_REL:
      cmd_jump_relative();
      break;

    case CMD_BZ_REL:
      cmd_bz_relative();
      break;
      
    case CMD_BNZ_REL:
      cmd_bnz_relative();
      break;
      
    case CMD_MOVE_REG:
      cmd_move_register();
      break;
               
    case CMD_SETCOLOR:
      cmd_set_color();
      break;    
      
    case CMD_SETFLASH:
      cmd_set_flash();
      break;
      
    case CMD_SETWAVE:
      cmd_set_wave();
      break;
      
    case CMD_SETBOUNCE:
      cmd_set_bounce();
      break;
      
    case CMD_SETRANDOM:
      cmd_set_random();
      break;
      
    case CMD_SETBAR:
      cmd_set_bar();
      break;     
       
    case CMD_SETOFF:
      cmd_set_off();
      break;

    case CMD_SETFILL:
      cmd_set_fill();
      break;
    case CMD_0EQ1:
      cmd_0eq1();
      break;

    case CMD_0NE1:
      cmd_0ne1();
      break;

    case CMD_0LT1:
      cmd_0lt1();
      break;
    
    case CMD_0LE1:
      cmd_0le1();
      break;
    
    case CMD_0GT1:
      cmd_0gt1();
      break;
    
    case CMD_0GE1:
      cmd_0ge1();
      break;

    case CMD_PUSH:
      cmd_push();
      break;
      
    case CMD_POP:
      cmd_pop();
      break;
      
    case CMD_AND:
      cmd_and();
      break;

    case CMD_OR:
      cmd_or();
      break;
      
    default:
      if(console != NULL)
      {
        console->console_print("Invalid program instruction %d at pc:%d\r\n", cmd, pc);
      }    
  }
}