long expression2() { long result = expression3(); while (peek() == '!' || peek() == '~') if (peek() == '!' && our_string[placeholder +1] != '=') { get(); result = !expression3(); } else if (peek() == '~') { get(); result = ~expression3(); } else return result; return result; }
long expression3() { if (peek() >= '0' && peek() <= '9') return expression4(); else if (peek() == '(') { get(); long result = expression_8(); get(); return result; } else if (peek() == '-') { get(); return -expression3(); } return 0; }
int main(int argc, char ** argv) { if (argc < 2) { std::cout << "ps7a [input file]" << std::endl; return -1; } std::ifstream inputfile(argv[1]); ///< Opens input file based on argv[1] if (!inputfile) { std::cout << "Could not open " << argv[1] << std::endl; return -1; } std::ofstream outputfile; ///< Opens output file based on argv[1] w/ .rpt std::string outputfilename = argv[1]; outputfilename += ".rpt"; outputfile.open(outputfilename.c_str()); if (!outputfile) { std::cout << "Could not open output file" << std::endl; return -1; } int linenum = 0; ///< Keeps track of line number in file std::string temp; ///< Stores line to use regex with bool test = false; ///< To help determine if failure or not std::string tdatet; ///< Stores the terminating time std::string datet; ///< Stores the beginning time boost::regex expression(".*\\(log\\.c\\.166\\) server started"); boost::regex expression2("[0-9]{2}:[0-6][0-9]:[0-9]{2}"); boost::regex expression3 (".*oejs\\.AbstractConnector:Started SelectChannelConnector"); boost::smatch fmatch; boost::smatch dmatch; boost::smatch sumatch; /** * This while loop gets a line from the file * * It then increases the line count since the linenum starts at * 0 but the file starts at line 1 * * The loop then checks to see if we already found success denoted by test. If * test is true we then check to see if we match the correct terminating command * If the command matches using regex, we than extract the time and subtract it from * The starting time, we set test to false, and we output all this to the file. * * If test is true and we find another instance of the server starting, there was a failure * * The most important part of this loop tests to see when (log.c.166) is called which * is an instance of the server starting. We record the line number its on, when it starts * and then we move on to our checks by setting test to true. * */ while (std::getline(inputfile, temp)) { ++linenum; if (test) { if (boost::regex_search(temp, sumatch, expression3)) { outputfile << " success"; tdatet = sumatch[0]; if (boost::regex_search(tdatet, dmatch, expression2)) { tdatet = dmatch[0]; boost::posix_time::time_duration time2 (boost::posix_time::duration_from_string(datet)); boost::posix_time::time_duration time1 (boost::posix_time::duration_from_string(tdatet)); time2 = time1 - time2; std::string time = to_simple_string(time2); outputfile << " " << time << std::endl; } test = false; } else { if (boost::regex_search(temp, fmatch, expression)) { outputfile << " failure" << std::endl; test = false; } } } else { if (boost::regex_search(temp, fmatch, expression)) { datet = fmatch[0]; if (boost::regex_search(datet, dmatch, expression2)) { outputfile << linenum << " " << datet; datet = dmatch[0]; test = true; } } } } /** * * If for some reason we reach the end of the file and the server was never * properly shutdown, we get a success as it will do that automatically. * */ if (test) { outputfile << " success" << std::endl; } outputfile.close(); inputfile.close(); return 0; }