Skip to content

Commit

Permalink
do works
Browse files Browse the repository at this point in the history
  • Loading branch information
keshav2010 committed Jun 22, 2017
1 parent a8539f8 commit 68e0c3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
25 changes: 23 additions & 2 deletions src/cmd_do.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace std;
cmdEngine *CMDENGINE;
int Cmd_do::check_cmd(const string& _CMD)
{
cout << "inside cmd_do check \n";
stack Stack;
istringstream sin(_CMD);
string word;
Expand Down Expand Up @@ -42,7 +43,9 @@ int Cmd_do::check_cmd(const string& _CMD)
}
else //stack is filled, we need to accept this "[" as SUBCMD
{
cout << "word [ :";
SUBCMD += word + " ";
cout << SUBCMD << ":\n";
}
Stack.push(word);
}
Expand All @@ -61,7 +64,9 @@ int Cmd_do::check_cmd(const string& _CMD)
}
else//stack not empty so we need to accept "]" into SUBCMD
{
cout << "word ] :";
SUBCMD += word + " ";
cout << SUBCMD << "\n";
}
}
else// wrong positions
Expand All @@ -72,12 +77,21 @@ int Cmd_do::check_cmd(const string& _CMD)
}
else if (word == "<")
{
readUI = 1;
// readUI = 1;
if (!Stack.isEmpty())//if stack is not empty, we need to read it
{
readSUBCMD = 1;
SUBCMD += word+" ";
}
else//stack is empty, root command
{
readUI = 1;
}
Stack.push(word);
}
else if (word == ">")
{
if (!Stack.isEmpty())
if (!Stack.isEmpty())//if stack is not empty
{
Stack.pop();
if (Stack.isEmpty())
Expand All @@ -89,6 +103,12 @@ int Cmd_do::check_cmd(const string& _CMD)
readUI = false;
}
}
else//stack is not empty, so it mean we are still reading
{
cout << "word > :";
SUBCMD += word + " ";
cout << SUBCMD << ":\n";
}
}
else
{
Expand All @@ -99,6 +119,7 @@ int Cmd_do::check_cmd(const string& _CMD)
else if (readSUBCMD == 1 && readUI == 0)
{
SUBCMD += word + " ";
cout << "SUBCMD :" << SUBCMD << ": (stack empty : "<<Stack.isEmpty()<<"\n";
}
else if (readUI == 1)
USERINPUT += word;
Expand Down
14 changes: 9 additions & 5 deletions src/cmdengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void cmdEngine::start_cmdEngine() {
cout << "proccessed : " << cmd << "\n";
int x = check(cmd);
if (x == 0)
cout << "\n Error!!! \n";
cout << "\n check failed for "<<cmd<<"\n";
}
}
void cmdEngine::process(string& _CMD) {
Expand All @@ -53,14 +53,15 @@ void cmdEngine::process(string& _CMD) {
}
}
}//for loop [0 to _CMD.size()-1 ]
cout <<"processing done :"<< _CMD <<"|"<<endl;
cout <<"processing done :"<< _CMD <<"<"<<endl;
}
int cmdEngine::check(const string& _CMD,int toExecute)//toExecute set true by default
{
istringstream sin(_CMD);
string major_command;
int isCorrect = 0;
sin >> major_command;//read first major command , note that submajor can also be read
cout << "Major is : " << major_command << "\n";
if (major_command == "read" || major_command == "write"||major_command=="-q")
{
//cout << "detected major_command\n";
Expand All @@ -76,7 +77,7 @@ int cmdEngine::check(const string& _CMD,int toExecute)//toExecute set true by de
if (cmd_io != NULL)
delete cmd_io;
isCorrect = 0;
cout << "\n ERROR : error in command \n ";
cout << "\n ERROR : error in command ("<<major_command<<")\n ";
return 0;//check failed
}
cout << "deleting cmd-io\n";
Expand All @@ -97,16 +98,19 @@ int cmdEngine::check(const string& _CMD,int toExecute)//toExecute set true by de
}
return isCorrect;
}
cout << "initializing cmd_do\n";
Cmd_do *cmd_do=new Cmd_do;
cout << "calling check_cmd(_CMD) , _CMD is :" << _CMD << ":\n";
if(cmd_do->check_cmd(_CMD))
{
if(toExecute)
cmd_do->execute_cmd();
isCorrect=1;
}
else
{ isCorrect=0;
cout<<"\n ERROR : error in command \n";
{
isCorrect=0;
cout<<"\n ERROR : error in command do\n";
}
if(cmd_do!=NULL)
delete cmd_do;
Expand Down

0 comments on commit 68e0c3c

Please sign in to comment.