Example #1
0
void
dumpCommandList(const AmCommandList *commandList)
{
    int i;
    for (i = 0; i < commandList->commandCount; i++) {
        dumpCommand(commandList->commands[i]);
    }
}
Example #2
0
int main()
{
  const char *whitespace = " \n\r\f\t\v";  //Whitespace characters.
  char buffer[81];  //Buffer to hold 80 characters plus 1 null terminator.
  List* tokens;
  Command* command;
  
  /* enter into an infinite loop, prompting user for input, processing the input,
     until user decides to exit */
  while(1)
  {
    //Read in up to 80 characters or until the newline is encountered.

    displayPrompt();

    if (!fgets(buffer, 81, stdin))
    {
      printf("\nfgets() failed.\n");
      buffer[0] = 0;

      continue;
    }

    /* first we tokenize the command by whitespace */
    tokens = tokenize(buffer, whitespace);

    /* then we turn the command into a Command object */
    command = listToCommand(tokens);

    /* then we expand the environment variables (if any) */
    if(expandEnvironmentVars(command) == 0)
    {

      /* then we setup the command for redirection, if necessary */
      setupRedirection(command);

      /* check out our command, ensure it's been processed correctly and is ready for execution  */
      if(DEBUG) dumpCommand(command); 

      executeCommand(command);
    }

    /* cleanup after ourselves */
    linkedListClear(tokens);
    if(tokens != NULL)
      free(tokens);
    
    if(command != NULL)
    {
      linkedListClear(command->command);
      if(command->command != NULL)
        free(command->command);
      if(command->infile != NULL) 
        free(command->infile);
      if(command->outfile != NULL) 
        free(command->outfile);
      
      free(command);
    }
  }

  return 0;
}