Exemplo n.º 1
0
void DebugAnyCommandWidget::processCommand()
{
    if (! command->text().isEmpty()) {
        if (commands.isEmpty() || command->text() != commands.last())
            commands.append(command->text());
        currentCommandPos = commands.size();
        emit performCommand(command->text(), printCheckBox->isChecked());
        command->clear();
    } else {
        if (!commands.isEmpty())
            emit performCommand(commands.last(), printCheckBox->isChecked());
    }
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
  char mypath[MAXPATHLEN];
  unsigned long mypath_size= sizeof(mypath);
  OSStatus status;
  AuthorizationRef auth;
  int bytesRead;
  BrokerCtlCommand command;
  
  if (_NSGetExecutablePath(mypath, &mypath_size) < 0)
  {
    DEBUG("could not get my path");
    exit(BrokerCtlCommandInternalError);
  }
  
  AuthorizationExternalForm extAuth;
    
  // read bytestream with Auth data
  if (read(0, &extAuth, sizeof(extAuth)) != sizeof(extAuth))
    exit(BrokerCtlCommandInternalError);
    
  // bytestream --*poof*--> auth
  if (AuthorizationCreateFromExternalForm(&extAuth, &auth))
    exit(BrokerCtlCommandInternalError);
    
  // if we're not being ran as root, spawn a copy that will make us suid root
  if (geteuid() != 0)
  {
    printf("I'm not suided\n");
    exit(-1);
  }
  
  /* Read a command object from stdin. */
  bytesRead = read(0, &command, sizeof(BrokerCtlCommand));
  
  if (bytesRead == sizeof(BrokerCtlCommand))
  {
    const char *rightName = rightNameForCommand(&command);
    AuthorizationItem right = { rightName, 0, NULL, 0 } ;
    AuthorizationRights rights = { 1, &right };
    AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed
    | kAuthorizationFlagExtendRights;
    
    if (status = AuthorizationCopyRights(auth, &rights, kAuthorizationEmptyEnvironment, flags, NULL))
    {
      DEBUG("failed authorization in helper: %ld.\n", status);
      exit(BrokerCtlCommandAuthFailed);
    }
    
    /* Peform the requested command */
    if (!performCommand(&command))
      exit(BrokerCtlCommandOperationFailed);
  }
  else
  {
    exit(BrokerCtlCommandChildError);
  }
  
  return BrokerCtlCommandSuccess;
}
Exemplo n.º 3
0
void startShell() {

  initShell();
  printIntro();

  char initialInputChar = '\0';
  while (initialInputChar != EOF) {

    promptPrefix();
    initialInputChar = getchar();

    // User hits enter
    if (initialInputChar == '\n') {
      continue;

    // End of file symbol reached
    } else if (initialInputChar == EOF) {
      break;

    // User is typing a command
    } else {

      // Adding the 'initialInputChar' as the first character of the command
      int inputCounter = 0;
      char shellInput[INPUT_SIZE];
      shellInput[inputCounter++] = initialInputChar;

      // Waiting for more user input
      char tempChar;

      while (inputCounter < INPUT_SIZE) {
        tempChar = getchar();

        // User has finished typing command
        if (tempChar == '\n') {

          // Properly ending the input
          shellInput[inputCounter] = '\0';

          // Performing the command
          AppCommand appCommand = identifyCommand(shellInput);
          performCommand(appCommand, shellInput);
          break;

        // Forming command
        } else {
          shellInput[inputCounter++] = tempChar;
        }
      }

      // Freeing memory for the inputted string
      memset(shellInput, 0, INPUT_SIZE);
    }
  }
}
Exemplo n.º 4
0
int myPerformAuthCommand(UInt16	what, char	*file)
{
	OSStatus status;
	
	myCommand.authorizedCommandId = what;
	
	strcpy(myCommand.file, file);
	
    
	status = performCommand(authorizationRef, myCommand);
	if(myDebug) fprintf(stderr, "Performing the command returned %ld.\n", status);
	
	return(status);
}
Exemplo n.º 5
0
void parseCommand (char * cmdstr)
{
    int8_t cmd=-1;
    int16_t num=0;
    
     // Serial.print("parseCommand:"); Serial.println(cmdstr);
    char * actpos = strtok(cmdstr," ");   // see a nice explaination of strtok here:  http://www.reddit.com/r/arduino/comments/2h9l1l/using_the_strtok_function/
    if (actpos) 
    {
        strup(actpos);

        // housekeeping commands
        if (!strcmp(actpos,"ID"))   cmd=CMD_PRINT_ID;
        if (!strcmp(actpos,"SAVE"))  { actpos=strtok(NULL," "); cmd=CMD_SAVE_SLOT; }
        if (!strcmp(actpos,"LOAD"))  { actpos=strtok(NULL," "); cmd=CMD_LOAD_SLOT; }
        if (!strcmp(actpos,"NEXT"))  cmd=CMD_NEXT_SLOT;
        if (!strcmp(actpos,"CLEAR")) cmd=CMD_DELETE_SLOTS;
        if (!strcmp(actpos,"LIST"))  cmd=CMD_LIST_SLOTS;
        if (!strcmp(actpos,"IDLE"))  cmd=CMD_IDLE;
        
        //  button feature commands
        if (!strcmp(actpos,"BM")) { actpos=strtok(NULL," "); if (get_uint(actpos, &num)) cmd=CMD_BUTTON_MODE; }
        if (!strcmp(actpos,"CL")) cmd=CMD_MOUSE_CLICK_LEFT;
        if (!strcmp(actpos,"CR")) cmd=CMD_MOUSE_CLICK_RIGHT; 
        if (!strcmp(actpos,"CM")) cmd=CMD_MOUSE_CLICK_MIDDLE; 
        if (!strcmp(actpos,"CD")) cmd=CMD_MOUSE_CLICK_DOUBLE; 
        if (!strcmp(actpos,"PL")) cmd=CMD_MOUSE_PRESS_LEFT; 
        if (!strcmp(actpos,"PR")) cmd=CMD_MOUSE_PRESS_RIGHT; 
        if (!strcmp(actpos,"PM")) cmd=CMD_MOUSE_PRESS_MIDDLE; 
        if (!strcmp(actpos,"RL")) cmd=CMD_MOUSE_RELEASE_LEFT; 
        if (!strcmp(actpos,"RR")) cmd=CMD_MOUSE_RELEASE_RIGHT; 
        if (!strcmp(actpos,"RM")) cmd=CMD_MOUSE_RELEASE_MIDDLE; 
        if (!strcmp(actpos,"WU")) cmd=CMD_MOUSE_WHEEL_UP; 
        if (!strcmp(actpos,"WD")) cmd=CMD_MOUSE_WHEEL_DOWN; 
        if (!strcmp(actpos,"WS")) { actpos=strtok(NULL," "); if (get_uint(actpos, &num)) cmd=CMD_MOUSE_WHEEL_STEP; }
        if (!strcmp(actpos,"MX")) { actpos=strtok(NULL," "); if (get_int(actpos, &num)) cmd=CMD_MOUSE_MOVEX; }
        if (!strcmp(actpos,"MY")) { actpos=strtok(NULL," "); if (get_int(actpos, &num)) cmd=CMD_MOUSE_MOVEY; }
        if (!strcmp(actpos,"KW")) { actpos+=3; cmd=CMD_KEY_WRITE; }
        if (!strcmp(actpos,"KP")) { actpos+=3; cmd=CMD_KEY_PRESS; }
        if (!strcmp(actpos,"KR")) { actpos+=3; cmd=CMD_KEY_RELEASE; }
        if (!strcmp(actpos,"RA")) cmd=CMD_RELEASE_ALL;
    }
    if (cmd>-1)
    {
        // Serial.print("cmd parser found:");Serial.print(cmd); Serial.print(", "); Serial.print(num); 
        // if (actpos) {Serial.print(", "); Serial.println(actpos);} else Serial.println();   
        performCommand(cmd,num,actpos,0);        
    }
    else   Serial.println("cmd parser: ?");              
}
Exemplo n.º 6
0
/* Gets commands from the user. */
bool twitClient::getCommands()
{
    std::string line = EMPTY;
    std::stringstream stringStream;
    std::vector<std::string> tokens;
    std::getline(std::cin,line);
    splitLine(line,tokens);
    int finishVal = performCommand(tokens);
    stringStream.clear();
    tokens.clear();

    if (finishVal == FINISH)
    {
        return true;
    }
    return false;
}
Exemplo n.º 7
0
void parseCommand (char * cmdstr)
{
    int8_t cmd=-1;
    int16_t num=0;
    
    if (DebugOutput==DEBUG_FULLOUTPUT)  {
  		Serial.print("parseCommand:"); Serial.println(cmdstr); 
    }
    char * actpos = strtok(cmdstr," ");   // see a nice explaination of strtok here:  http://www.reddit.com/r/arduino/comments/2h9l1l/using_the_strtok_function/
    
    if (actpos) 
    {
        if (DebugOutput==DEBUG_FULLOUTPUT)  {
    			Serial.print("actpos:"); Serial.println(actpos);
        }
        int i;
        strup(actpos);
        
        for (i=0;(i<NUM_COMMANDS)&&(cmd==-1);i++)
        {
          if (!strcmp_FM(actpos,(uint_farptr_t_FM)atCommands[i].atCmd))  {
            // Serial.print ("partype="); Serial.println (pgm_read_byte_near(&(atCommands[i].partype)));
            switch (pgm_read_byte_near(&(atCommands[i].partype))) 
            {
               case PARTYPE_UINT: actpos=strtok(NULL," ");  if (get_uint(actpos, &num)) cmd=i ; break;
               case PARTYPE_INT:  actpos=strtok(NULL," ");  if (get_int(actpos, &num)) cmd=i ; break;
               case PARTYPE_STRING: actpos+=3; if (*actpos) cmd=i; break;
               default: cmd=i; actpos=0; break;
            }
          }
        }  
    }

    if (cmd>-1) { 
      // Serial.print("cmd:");Serial.print(cmd);Serial.print("numpar:");
      // Serial.print(num);Serial.print("stringpar:");Serial.println(actpos);
      performCommand(cmd,num,actpos,0);        
    } 
    else Serial.println("???");      // command not recognized!                
}
Exemplo n.º 8
0
int main(void)
{
    bool isRunning = true;
    char* pUserInput;
    char* userInput = NULL;
    item* it = NULL;
    userInput = malloc(sizeof(char)*1024);
    assert(userInput != NULL);
    pUserInput = userInput;
    performRotCheck();
    system(CALL_DOWNLOAD_SCRIPT);
    while(isRunning)
    {
        printf(">>");
        char command = 0;
        fgets(userInput, MAX_COMMAND_LEN-1, stdin);
        if(!decodeCommand(userInput, &command))
        {
            printf("\tCommand error.\n");
            continue;
        } else if(command != 0)
        {
            it = parseItem(userInput);
            if(it == NULL)
            {
                printf("The creation of item you provided was not successful.\n");
                continue;
            }
            if(!performCommand(command, it))
            {
                fprintf(stderr, "Error.\n");
            }
        } else {
            isRunning = false;
        }
        releaseItem(&it);
    }
    free(pUserInput);
}
void CodeEditorComponent::performPopupMenuAction (const int menuItemID)
{
    performCommand (menuItemID);
}
bool CodeEditorComponent::perform (const InvocationInfo& info)
{
    return performCommand (info.commandID);
}
Exemplo n.º 11
0
int main(int argc, char *argv[])

/* Read lines from the .ishrc file residing in the HOME directory
   until EOF is reached. Write each line that is read to
   stdout and execute each line. Read a line from stdin and
   execute it. Repeat until EOF. Return 0. */

{
   char acLine[MAX_LINE_SIZE];
   char *pcTemp;
   DynArray_T oHistoryList; 
   FILE *psFile;
   int i;
   void (*pfRet)(int);

   pfRet = signal(SIGINT, SIG_IGN);
   if(pfRet == SIG_ERR) {perror(argv[0]); exit(EXIT_FAILURE); }

   oHistoryList = DynArray_new(0);

   pcTemp = getIshrc();
   psFile = fopen(pcTemp, "r");
   free(pcTemp);

   while (psFile != NULL && 
          fgets(acLine, MAX_LINE_SIZE, psFile) != NULL)
   {
      /* Remove '\n' if acLine ends with '\n'. This is done so 
         the commands in the history list do not end with '\n',
         which is necessary to properly expand !commandprefix. */
      if(acLine[strlen(acLine)-1] == '\n')
         acLine[strlen(acLine)-1] = '\0';
     
      printf("%% %s\n", acLine);
      /* Explicitly flush the stdout buffer so we can test ish
         properly by redirecting the output to a file. */
      fflush(stdout);
      
      performCommand(acLine, oHistoryList, argv[0]);
   }
   printf("%% ");
   fflush(stdout);
   while (fgets(acLine, MAX_LINE_SIZE, stdin) != NULL)
   {
      /* Remove '\n' if acLine ends with '\n'. This is done so 
         the commands in the history list do not end with '\n',
         which is necessary to properly expand !commandprefix. */
      if(acLine[strlen(acLine)-1] == '\n')
         acLine[strlen(acLine)-1] = '\0';
      
      performCommand(acLine, oHistoryList, argv[0]);

      printf("%% ");
      fflush(stdout);
   }
   printf("\n");
   fflush(stdout);

   for(i = 0; i < DynArray_getLength(oHistoryList); i++)
      free(DynArray_get(oHistoryList, i));
   DynArray_free(oHistoryList);
   return 0;
}