Question
#include HALmod.h int main(){ string tokens [MAX_COMMAND_LINE_ARGUMENTS]; int tokenCount; do{ tokenCount = GetCommand (tokens); } while (ProcessCommand (tokens, tokenCount)); return 0; } HALmod.h #include #include
#include "HALmod.h"
int main(){
string tokens [MAX_COMMAND_LINE_ARGUMENTS];
int tokenCount;
do{
tokenCount = GetCommand (tokens);
} while (ProcessCommand (tokens, tokenCount));
return 0;
}
HALmod.h
#include
#include
#include
#include
#include
#include
using namespace std;
//The following two lines come from HALglobals.h
const int MAX_COMMAND_LINE_ARGUMENTS = 8;
const int SLEEP_DELAY = 100000;
int GetCommand (string tokens []);
int TokenizeCommandLine (string tokens [], string commandLine);
bool CheckForCommand ();
int ProcessCommand (string tokens [], int tokenCount);
static volatile sig_atomic_t cullProcess = 0;
int GetCommand (string tokens [])
{
string commandLine;
bool commandEntered;
int tokenCount;
do
{
cout << "HALshell> ";
while (1)
{
getline (cin, commandLine);
commandEntered = CheckForCommand ();
if (commandEntered)
{
break;
}
}
} while (commandLine.length () == 0);
tokenCount = TokenizeCommandLine (tokens, commandLine);
return tokenCount;
}
int ProcessCommand (string tokens [], int tokenCount)
{
if (tokens [0] == "shutdown" || tokens [0] == "restart")
{
if (tokenCount > 1)
{
cout << "HALshell: " << tokens [0] << " does not require any arguments" << endl;
return 1;
}
cout << endl;
cout << "HALshell: terminating ..." << endl;
return 0;
}
else
return 1;
}
- What is this code's tokenizing based on (ie. what delimeter(s) separate(s) the words)?
- What are two reasons why the tokens are strings instead of c strings
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started