void administrator::run(void) { ST::string inp; ST::string h; bool stop = false; while (stop == false) { cout << "> "; ST::getline (cin,10000,inp,delim); if (delim != '\n') inp = inp.replaceallsigns('\n',' '); inp = inp.eatwhitespace(); if (logout.is_open()) logout << "> " << inp << endl; stop = parse(inp); } bayesregobjects.erase(bayesregobjects.begin(),bayesregobjects.end()); }
bool administrator::parse(ST::string & in) { errormessages.clear(); ST::string objectname; ST::string firsttoken = in.getFirstToken(" ."); int pointpos = in.checksign('.'); if (firsttoken.length() > 0) { if ( (firsttoken == "quit") || (firsttoken == "exit") ) return true; else if (firsttoken == "delimeter") { vector<ST::string> token = in.strtoken(" "); if (token.size() != 3) errormessages.push_back("ERROR: invalid syntax\n"); else if (token[1] != "=") errormessages.push_back("ERROR: \"=\" expected\n"); else { if (token[2] == "newline") delim = '\n'; else if (token[2].length() > 1) errormessages.push_back("ERROR: invalid delimeter symbol\n"); else delim = token[2][0]; } return false; } // end: delimeter else if (firsttoken == "usefile") { vector<ST::string> token = in.strtoken(" "); if (token.size() < 2) errormessages.push_back("ERROR: filename expected\n"); else if (token.size() > 2) errormessages.push_back("ERROR: invalid syntax\n"); if (errormessages.empty()) { ST::string path = token[1]; if (path.isexistingfile() == 1) errormessages.push_back("ERROR: file " + path + " could not be opened\n"); else { ST::string in; ifstream infile; input = &infile; ST::open(infile,path); while (! infile.eof()) { ST::getline(infile,10000,in,delim); if (delim != '\n') in = in.replaceallsigns('\n',' '); in = in.eatwhitespace(); out("> " + in + "\n"); parse(in); } } } input = &cin; out(errormessages); return false; } else if (firsttoken == "logopen") { model m; simpleoption replace("replace",false); optionlist logoptions; logoptions.push_back(&replace); usePathWrite uw; command logopen("logopen",&m,&logoptions,&uw,notallowed,notallowed, notallowed,notallowed,optional,required); logopen.parse(in); errormessages = logopen.geterrormessages(); if (logfileopen == true) errormessages.push_back("ERROR: logfile is already open\n"); if (errormessages.empty()) { logfileopen = true; logfilepath = uw.getPath(); if ((replace.getvalue() == false) && (uw.isexisting() == true)) { ST::open(logout,logfilepath,ios::app); } else { ST::open(logout,logfilepath); } } else out(errormessages); return false; } // end: logopen else if (firsttoken == "logclose") { if (logfileopen == false) { errormessages.push_back("ERROR: currently no logfile open\n"); out(errormessages); } else { logfileopen = false; logout.close(); out("NOTE: logfile " + logfilepath + " closed\n"); } return false; } // end: logclose else if (firsttoken == "drop") { modelStandard m; optionlist dropoptions; usePathWrite uw; command drop("drop",&m,&dropoptions,&uw,required,notallowed, notallowed,notallowed,notallowed,notallowed); drop.parse(in); errormessages = drop.geterrormessages(); vector<ST::string> objectnames = m.getModelVarnamesAsVector(); if (objectnames.size() == 0) errormessages.push_back("ERROR: objectlist required\n"); if (errormessages.empty()) { int j; for (j=0;j<objectnames.size();j++) { int recognized = 0; int i=0; while ( (i < objects.size()) && (recognized == 0) ) { if ( objectnames[j] == objects[i]->getname()) { ST::string type = objects[i]->gettype(); dropobjects(objectnames[j],type); recognized = 1; } i++; } if (recognized == 0) errormessages.push_back( "ERROR: object " + objectnames[j] + " is not existing\n"); } // end: for (j=0;j<objectnames.size();j++) } // end: if (errormessages.empty()) out(errormessages); return false; } // end: drop else if (firsttoken.isinlist(objecttyps) >= 0) // create a new object { if (pointpos == -1) objectname = create(in); else objectname = create(in.substr(0,pointpos)); if ( (errormessages.empty()) && (pointpos > 0) ) { if (in.length()-1-pointpos <= 0) errormessages.push_back("ERROR: invalid syntax\n"); else parseexisting(objectname,in.substr(pointpos+1,in.length()-1-pointpos)); } out(errormessages); return false; } // end: create a new object else // existing object { if (pointpos != firsttoken.length()) errormessages.push_back("ERROR: invalid syntax\n"); else if (in.length() > pointpos+1) parseexisting(firsttoken,in.substr(pointpos+1,in.length()-pointpos-1)); else errormessages.push_back("ERROR: invalid syntax\n"); out(errormessages); return false; } } // end: if (firsttoken.length() > 0) else // empty command return false; }