int* identifyCommandsCodes(char** commands, int numberOfCommands){
	int* commandsCodes = malloc(sizeof(int) * numberOfCommands);
	for(int i = 0; i < numberOfCommands; i++){
		commandsCodes[i] = identifyCommand(*(commands + i));
	}
	return commandsCodes;
}
Exemple #2
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);
    }
  }
}