Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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;

}

  1. What is this code's tokenizing based on (ie. what delimeter(s) separate(s) the words)?
  2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

List situational factors that influence helping behavior.

Answered: 1 week ago