From 68e0c3c29bde7e5655c115b75b3d9f77b335919f Mon Sep 17 00:00:00 2001 From: Keshav Sharma Date: Fri, 23 Jun 2017 00:37:55 +0530 Subject: [PATCH] do works --- src/cmd_do.cpp | 25 +++++++++++++++++++++++-- src/cmdengine.cpp | 14 +++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/cmd_do.cpp b/src/cmd_do.cpp index 48c0877..cf99c59 100644 --- a/src/cmd_do.cpp +++ b/src/cmd_do.cpp @@ -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; @@ -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); } @@ -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 @@ -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()) @@ -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 { @@ -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 : "<> 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"; @@ -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 ("<check_cmd(_CMD)) { if(toExecute) @@ -105,8 +108,9 @@ int cmdEngine::check(const string& _CMD,int toExecute)//toExecute set true by de 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;