int main( void ) { while(1){ commandPrompt(); } }
int main(){ //Signal handling: signal(SIGINT, signalHandler); char** argv; int numOfArgs = 0; std::vector<std::string> cmdHistory = {}; std::string command = ""; std::chrono::duration<double> totalTimeInChildProcesses(0); char ptime[] = "ptime"; char carat[] = "^"; char pwd[] = "pwd"; char history[] = "history"; char cd[] = "cd"; while ((command=commandPrompt()) != "exit"){ //Try if there are things in the command. try{ checkIfBlank(command); //Store every Command. storeCommand(cmdHistory, command); //Parse the commands numOfArgs = parseCommand(command, argv); if (strcmp(carat, argv[0]) == 0){ if (numOfArgs == 3){ runNthCmdInHistory(cmdHistory, argv, command); }else{ std::string error = "Error: incorrect number of arguments for '^ <history item>'."; throw error; } } if (strcmp(ptime, argv[0]) == 0){ std::cout<<"Time spent executing child processes: " << totalTimeInChildProcesses.count() <<"seconds\n"; }else if (strcmp(history, argv[0]) == 0){ listHistory(cmdHistory); }else if(strcmp(cd, argv[0]) == 0){ if (numOfArgs == 3){ changeDir(argv); }else{ std::string error = "Error: incorrect number of arguments for 'cd <directory>'."; throw error; } }else if(strcmp(pwd, argv[0]) == 0){ std::cout<<get_current_dir_name()<<std::endl; }else if(isPipeCmd(command)){ pipe(command, totalTimeInChildProcesses); }else{ runAndTimeChildProcess(argv[0], argv, totalTimeInChildProcesses); } }catch(std::string e){ std::cout<<e<<std::endl; } } return 0; }