int checkIfAllMemoryLocationsAreValid(char **tokens) { while(*tokens) { if (!checkIfNumber(*tokens) || atoi(*tokens) <0 || atoi(*tokens)>=MEMORY_SIZE) return 0; tokens++; } return 1; }
int checkAllRegistersAreValid(char **regs) { while (*regs) { if (!checkRegister(*regs) || !checkIfNumber(*regs+1) || getRegisterNumber(*regs) <0 || getRegisterNumber(*regs) >= NUMBER_OF_REGISTERS) { return 0; } regs++; } return 1; }
void setBreakPoints(int *breakPoints,char **tokens) { int i=0; if (strcmp(tokens[0],"-r")==0) { tokens++; while(*tokens) { if (checkIfNumber(*tokens)==0) { printInvalidCommandMessage(); return; } if (breakPoints[i]==atoi(*tokens)) { breakPoints[i] = -1; }; if (breakPoints[i] ==-1) { printInvalidCommandMessage(); printf("breakpoint does not exists"); return; } i++; tokens++; } } else if (strcmp(tokens[0],"-a")==0) { tokens++; int *temp = malloc(sizeof(int) * BREAKPOINTS_ARRAY_SIZE); while(*tokens) { if (checkIfNumber(*tokens)==0) { printInvalidCommandMessage(); return; } temp[i] = atoi(*tokens); i++; tokens++; } memcpy(breakPoints,temp,sizeof(int) * i); free(temp); } }
void searchRegister(struct Processor *proc, char **tokens) { int start =0; int end = NUMBER_OF_REGISTERS; if (!checkIfNumber(tokens[1])) { printInvalidCommandMessage(); return; } int value = atoi(tokens[1]); if (!checkAllRegistersAreValid(tokens+1)) { printInvalidCommandMessage(); return; } if (strcmp(tokens[0],"-r")==0) { start = getRegisterNumber(token[2]); end = getRegisterNumber(tokens[3]); if (start>end) { printInvalidCommandMessage(); return; } if (tokens[4]!=NULL) { printInvalidCommandMessage(); return; } } else if (strcmp(tokens[0],"-a")!=0) { printInvalidCommandMessage(); return; } printf("\n(JVG)"); for (int i = start; i<end ; i++) { if (proc->gpr[i]==value) { printf("$%i=%i ",i,getRegisterValue(getRegisterNumber)); } } printf("\n(JVG)"); }
/** * Menu for utilities to be run as specified in the project documentation. * * Function instantiates the other Utilities using the OS32Memory component and returns the new object for the scheduler * * eg: * * Utility* util = new(OS32Memory::getInstance().alloc(sizeof(Converter))) Converter(); * */ Utilities* Utilities::displayMenu(){ int runUtil = -1; Utilities* util = NULL; UI::println( "\n\n::Utilities Menu::"); UI::println("1. Converter Utility"); UI::println("2. Encryption Utility"); UI::println("3. Message of the day Utility"); UI::println("4. Palindrome Utility"); UI::println("5. Calculator Utility"); UI::println("6. Display system date/time"); UI::println("0. Quit"); UI::print("\nEnter Utility to run (1-6, 0 to Quit): "); string userInput = ""; runUtil = UI::read<int>(); if(checkIfNumber()){ flushInputStream(); switch(runUtil){ case CONVERTER_UTILITY: util = new(OS32Memory::getInstance().alloc(sizeof(Converter))) Converter(); break; case ENCRYPTION_UTILITY: util = new(OS32Memory::getInstance().alloc(sizeof(Encryption))) Encryption(); break; case MOTD_UTILITY: util = new(OS32Memory::getInstance().alloc(sizeof(Motd))) Motd(); break; case PALINDROME_UTILITY: util = new(OS32Memory::getInstance().alloc(sizeof(Palindrome))) Palindrome(); break; case CALCULATOR_UTILITY: util = new(OS32Memory::getInstance().alloc(sizeof(Calculator))) Calculator(); break; case DATE_TIME_UTILITY: UI::println("I'm the date and time!"); break; case EXIT: util = NULL; cout << "Exiting Utilites!" << endl; break; default: UI::println("Error - Please enter a valid menu selection\n"); runUtil = -1; break; } } else{ UI::println("Error - Please enter a valid menu seclection\n"); runUtil = -1; } return util; }