Beispiel #1
0
int main() {
    CPU_t* cpu;
    FILE* in = fopen("out.txt","r");
    CPU_ctor(cpu);
    if(!cmd_download(cpu, in)) {
        printf("Empty commands file!!\n");
        CPU_dtor(cpu);
        return 0;
    }
    CPU_run(cpu);
    CPU_dump(cpu);
    CPU_dtor(cpu);
    printf("LOL\n"); // LOL :)
    return 0;
}
Beispiel #2
0
static void console_command_mode_run(void)
{
  char szTemp[256];
  char *str = NULL;
  int len = 0, i = 0;


  OS_PRINTF("\nEnter command mode. 'help' to show command list(non specific)\n");
  OS_PRINTF("\nEnter command mode. 'spechelp' to show specific command list\n");
  
  while (1)
  {
    if(get_console_mode() == DOWNLOAD_MODE)
    {
      OS_PRINTF("> ");
    }
    else
    {
      OS_PRINTF("Cmd > ");
    }
    get_command(szTemp);
#ifdef ENABLE_CMD_HISTORY
    save_command(szTemp);
#endif
    len = strlen(szTemp);

    if(len <= 0)
    {
      // do nothing
      continue;
    }

    // trim the space at the begin of the input
    for(i = 0; i < len; i++)
    {
      if(szTemp[i] != ' ')
      {
        str = &szTemp[i];
        break;
      }
    }

    // trim the space at the end of the input
    for(i = len-1; i >= 0; i--)
    {
      if(szTemp[i] != ' ')
      {
        szTemp[i+1] = 0;
        break;
      }
    }
    
    len = strlen(str);

    if(len <= 0)
    {
      continue;
      // do nothing
    }
    else
    {
      int i = 0, j =0;
      int showhelp = 0;
      testfm_p_suite_t pSuite = NULL;
      testfm_p_cmd_t pTest = NULL;
      testfm_error_code_t res = TESTFM_SUCCESS;


      if(!(((str[0] >= 'a') && (str[0] <= 'z')) || ((str[0] >= 'A') && (str[0] <= 'Z'))))
      {
        OS_PRINTF("CMD should start with 'a-z' and 'A-Z'.\n");
        continue;
      }

      for(i = 0; i < len-1; i++)
      {
        if((j == 0) && (str[i] == ' '))
        {
          j = i;
          memset(parameter_str, 0, 256);
          memcpy(parameter_str, &str[i+1], strlen(&str[i+1]));
        }

        if((str[i] == '-') && (str[i+1]  == 'h') && (str[i-1] == ' ') 
             && (((i+2) == len) || (str[i+2] == ' ')))
        {
          showhelp = 1;
          break;
        }
      }
      if(j != 0)
        str[j] = 0;

      if(0 == memcmp(str, "help", 4))
      {
        // list all non specific command
        cmd_help();
        continue;
      }
      if(0 == memcmp(str, "wizardshelp", 11))
      {
    	  // list all specific command
    	  cmd_help_specific(PLATFORM_WIZARD);
    	  continue;
      }
      if(0 == memcmp(str, "magichelp", 9))
           {
         	  // list all specific command
         	  cmd_help_specific(PLATFORM_MAGIC);
         	  continue;
           }
      if(0 == memcmp(str, "warriorshelp", 12))
           {
         	  // list all specific command
         	  cmd_help_specific(PLATFORM_WARRIORS);
         	  continue;
           }
      if(0 == memcmp(str, "anyhelp", 7))
           {
         	  // list all specific command
         	  cmd_help_specific(PLATFORM_ANY);
         	  continue;
           }

      if(0 == memcmp(str, "read", 4))
      {
        cmd_read();
        continue;
      }

      if(0 == memcmp(str, "write", 5))
      {
        //cmd_write();
        continue;
      }

      if(get_console_mode() == DOWNLOAD_MODE)
      {
        if(0 == memcmp(str, "download", 8))
        {
          cmd_download();
          continue;
        }

        if(0 == memcmp(str, "go", 2))
        {
          cmd_go();
          continue;
        }
        
        if(0 == memcmp(str, "reboot", 6))
        {
          cmd_reboot();
          continue;
        }

        OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str);
        continue;
      }
      

      if(0 == memcmp(str, "exit", 4))
      {
        cmd_exit();
        continue;
      }

      if(0 == memcmp(str, "runall", 6))
      {
        cmd_runall();
        continue;
      }

      if(0 == memcmp(str, "statistic", 9))
      {
        cmd_statistic();
        continue;
      }

      if(0 == memcmp(str, "autorun", 7))
      {
        //cmd_autorun();
        continue;
      }

       // add the reboot cmd for white box test
      if(0 == memcmp(str, "reboot", 6))
      {
        cmd_reboot();
        continue;
      }

      if(testfm_find_cmd(str, &pSuite, &pTest) == FALSE)
      {
        OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str);
      }
      else
      {
        if(showhelp == 1)
        {
          pTest->pHelpFunc();
        }
        else
        {
          //OS_PRINTF(", name: %s\n", pTest->pName);
          res = testfm_run_cmd(pSuite, pTest);
          if(res != TESTFM_SUCCESS)
            OS_PRINTF("error code: %d\n", res);
        }
      }
 
    }
  }
}