Beispiel #1
0
int main()
{
	// declare our strings for the two parts of input
	char* cmd= NULL;
	char* args[ARG_SIZE]= {NULL};

	int i= 0;

	while(TRUE)	
	{
		// print the prompt
		printf("# ");
	
		if (getUserCommand(&cmd, &args) != 0)
		{
			if (strcmp(cmd, "quit") == 0)
			{
				free(cmd);
				for (i= 0; i< ARG_SIZE; i++)	
					free(args[i]);

				exit(0);
			}

			else if (strcmp(cmd, "run") == 0)
			{
				if (runRun(args) == 0)
					printf("error: process not run\n");
			}
	
			else if (strcmp(cmd, "background") == 0)
			{
				pid_t pid;
				pid= runBackground(args);
				if (pid > 0)
					printf("process backgrounded, id is: %jd\n",(intmax_t) pid);
				else
					printf("error: process not backgrounded\n");
			}
	
			else if (strcmp(cmd, "murder") == 0)
			{
				runMurder(args);
			}

			else if (strcmp(cmd, "for") == 0)
			{
				runFor(args);
			}

			else
			{
				printf("no such command: %s\n", cmd);
			}
		}
		free(cmd);
		for (i= 0; i< ARG_SIZE; i++)	
			free(args[i]);
	}
}
Beispiel #2
0
/*
  This method carries out the execution of the binary code in the file specified
  by the arguments at run time. The file is loaded into the memory of the
  structure processor and then the execution is carried out in the while loop.
  The execution of terminates when an instruction with opcode HALT is reached.
  @param argv : this specifies the arguements which were given through the
                terminal when the program was run.
  @param argc : this specifes the number of arguments provided
  @return     : the method returns 0 when the method executes without any errors
*/
int main(int argc, char **argv) {
  assert("There are wrong number of arguents given" && argc==3);
  struct Processor *processor = malloc(sizeof(struct Processor));
  char *filepath = argv[1];

  memset(processor, 0, sizeof(struct Processor));

  int lineNumber = 0 ;
  
  binaryFileLoader(filepath, processor);
  printWelcomeMessage();
  char **tokens = malloc(sizeof(char) *BUFFER_SIZE);
    
  do {
    tokens = getUserCommand();    
    executeUserCommand(argv[2] , argv[1], processor, tokens);
    printf("token -> %s\n",tokens[0]); 
  }while (strcmp(tokens[0],"q")==0);
  
  printf("Thanks for using JVG debugger\n");
  
  fflush(stdout);

  return EXIT_SUCCESS;
}
Beispiel #3
0
char *getUserCommand(void) {
  printf("(jvg)");
  char *buff = malloc(BUFFER_SIZE);
  fgets(buff,BUFFER_SIZE,stdin);
  if (checkUserCommandValid(buff)) return buff;
  printf("(jvg) INVALID COMMAND: Please enter a valid command or type '--help' for help");

  /*--------------------------------------------
  
  CHECK IF  RECURSION IS OK OR SHOULD I HAVE A
  
  LOOP.
  
  --------------------------------------------*/
  
  return getUserCommand();
}
Beispiel #4
0
int main(int argc, char **argv) {
  struct Processor *proc = malloc(sizeof(struct Processor));
  assert("There are wrong number of arguents given" && argc==3);
  char *fBin = argv[2];
  char *fAssembly = argv[1];
  memset(proc,0,sizeof(struct Processor));
  binaryFileLoader(fBin,proc);
  system("clear");
  int *breakPoints = malloc(sizeof(int) *BREAKPOINTS_ARRAY_SIZE);
  memset(breakPoints,-1,sizeof(int) *BREAKPOINTS_ARRAY_SIZE);
  printWelcomeMessage();
  char **tokens = malloc(sizeof(char) *BUFFER_SIZE);
  int returnVal = 0; 
  do {
    tokens = getUserCommand();
    returnVal = executeUserCommand(fAssembly,fBin,proc,tokens,breakPoints);
    free(tokens);
  } while (!returnVal);
  printf("Thanks for using JVG debugger\n");
  system("clear");
  free(proc);
  free(breakPoints);
  return EXIT_SUCCESS;
}