示例#1
0
bool ComponentReader::read(Component& component) {
    enum {
        eStart,
        eId,
        eGap,
    };

    static boost::regex reg(">component[ \t]+(\\d+)");

    if (_stream) {
        component.contigs.clear();
        component.gaps.clear();

        int state = eStart;
        std::string buf;
        boost::char_separator< char > sep(" ,\t");

        while (std::getline(_stream, buf)) {
            if (state == eStart) {
                boost::smatch what;
                if (boost::regex_match(buf, what, reg)) {
                    state = eId;
                    component.id = boost::lexical_cast< size_t >(what[1]);
                } else {
                    LOG4CXX_WARN(logger, boost::format("fa=>invalid line for not start with >: %s") % buf);
                    return false;
                }
            } else if (state == eId) {
                boost::tokenizer< boost::char_separator< char > > toker(buf, sep);
                BOOST_FOREACH(const std::string& id, toker)  {
                    component.contigs.push_back( boost::lexical_cast< size_t > (id));
                }
                state = eGap;
            } else if (state == eGap) {
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing ActionsAndRules class\n "
            << std::string(30,'=') << std::endl;

  try
  {
    //std::queue<std::string> resultsQ;
    PrintPreproc pp;
    PreprocStatement pps;
    pps.addAction(&pp);

    FunctionDefinition fnd;
    PrintFunction prt;
    fnd.addAction(&prt);

    Toker toker("../ActionsAndRules.h");
    SemiExp se(&toker);
    Parser parser(&se);
    parser.addRule(&pps);
    parser.addRule(&fnd);
    while(se.get())
      parser.parse();
    std::cout << "\n\n";
  }
  catch(std::exception& ex)
  {
    std::cout << "\n\n  " << ex.what() << "\n\n";
  }
}
示例#3
0
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing XmlParts class\n "
            << std::string(23,'=') << std::endl;
  std::cout
    << "\n  Note that quotes are returned as single tokens\n\n";

  if(argc < 2)
  {
    std::cout 
      << "\n  please enter name of file to process on command line\n\n";
    return 1;
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n\n";
    try
    {
      Toker toker(argv[i]);
      toker.setMode(Toker::xml);
      XmlParts parts(&toker);
    //parts.verbose();                 // uncomment to show token details
      while(parts.get())
        std::cout << parts.show().c_str() << std::endl;
      std::cout << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}
示例#4
0
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing ActionsAndRules class\n "
            << std::string(30,'=') << std::endl;

  try
  {
    std::queue<std::string> resultsQ;


    Toker toker("../ActionsAndRules.h");
    SemiExp se(&toker);
    Parser parser(&se);

    while(se.get())
      parser.parse();
    size_t len = resultsQ.size();
    for(size_t i=0; i<len; ++i)
    {
      std::cout << "\n  " << resultsQ.front().c_str();
      resultsQ.pop();
    }
    std::cout << "\n\n";
  }
  catch(std::exception& ex)
  {
    std::cout << "\n\n  " << ex.what() << "\n\n";
  }
}
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing SemiExp class\n "
            << std::string(23,'=') << std::endl;
  std::cout
    << "\n  Note that comments and quotes are returned as single tokens\n\n";

  if(argc < 2)
  {
    std::cout 
      << "\n  please enter name of file to process on command line\n\n";
    return 1;
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n\n";
    try
    {
  	  Toker toker(argv[i]);
      toker.returnComments();
      SemiExp se(&toker);
      se.makeCommentSemiExp();
//    se.verbose();                 // uncomment to show token details
      while(se.getSemiExp())
        std::cout << se.showSemiExp().c_str() << std::endl;
      std::cout << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}
示例#6
0
static PyObject *
process_postData(PyObject *self, PyObject *args)
{
        const char *doc_buffer;
    std::string processed_doc = "";

    if (!PyArg_ParseTuple(args, "s", &doc_buffer))
        return NULL;

    try
    {
      Toker toker(doc_buffer, false);
      toker.setMode(Toker::xml);
      XmlParts parts(&toker);
      HtmlParts scraper(&parts);

      while(scraper.get())
      {
          // Building a (partial) tree
          // Search for closing tag to select all content in between
          if ( scraper.isPostTitle() )
          {
              processed_doc += scraper.toString();
              while ( scraper.get() && !(scraper.isClosingTag() && scraper.isH2()) )
                  processed_doc += scraper.toString();

              processed_doc += scraper.toString();
          }

          if (scraper.isPostBody())
          {
              /*
               * Note: this will fail if there are nested <div></div>
               */
              while ( scraper.get() && !(scraper.isClosingTag() && scraper.isDiv()) )
              {
                  // String value of current node
                   processed_doc += scraper.toString();
              }
          }
      }

    }
    catch(std::runtime_error ex)
    {
      std::cout << "\n " << ex.what() << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }

    return Py_BuildValue("s", processed_doc.c_str());
}
示例#7
0
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing SemiExp class\n "
            << std::string(23,'=') << std::endl;
  
  std::cout << "\n  testing SemiExp::find()";
  std::cout << "\n -------------------------";
  SemiExp semi(0);
  semi.push_back("one");
  semi.push_back("two");
  semi.push_back("three");
  semi.push_back("four");
  std::cout << "\n" << semi.show();
  size_t pos = semi.find("two");
  std::cout << "\n  position of \"two\" is " << pos;
  pos = semi.find("foobar");
  std::cout << "\n  position of \"foobar\" is " << pos;
  std::cout << "\n\n";

  std::cout << "\n  Note that comments and quotes are returned as single tokens\n";

  if(argc < 2)
  {
    std::cout 
      << "\n  please enter name of file to process on command line\n\n";
    return 1;
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n\n";
    try
    {
  	  Toker toker(argv[i]);
      toker.returnComments();
      SemiExp se(&toker);
      se.makeCommentSemiExp();
//    se.verbose();                 // uncomment to show token details
      while(se.get())
        std::cout << se.show().c_str() << std::endl;
      std::cout << "\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing ActionsAndRules class\n "
            << std::string(30,'=') << std::endl;

  RelationshipAnal* p = new RelationshipAnal;
	TypeAnal* q = new TypeAnal;

  try
  {
    PrintPreproc pp;
    PreprocStatement pps;
    pps.addAction(&pp);

    FunctionDefinition fnd;
    PrintFunction prt;
    fnd.addAction(&prt);

	ClassStructEnumDefinition cls1;
	std::vector<std::string> classResult;
	PrintClass cls2(&classResult);
	cls1.addAction(&cls2);

	
	InheritanceDetection* cls3 = new InheritanceDetection; 
	InheritanceAction* cls4 = new InheritanceAction(q, p);
	cls3->addAction(cls4);


    Toker toker("../ActionsAndRules.h");
    SemiExp se(&toker);
    Parser parser(&se);
    parser.addRule(&pps);
    parser.addRule(&fnd);
	parser.addRule(&cls1);
	parser.addRule(cls3);
    while(se.get())
      parser.parse();
    std::cout << "\n\n";
  }
  catch(std::exception& ex)
  {
    std::cout << "\n\n  " << ex.what() << "\n\n";
  }
}
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing ActionsAndRules class\n "
            << std::string(30,'=') << std::endl;

  try
  {
    std::queue<std::string> resultsQ;
    PreprocToQ ppq(resultsQ);

	//Modified Pallavi
	PrintPreproc ppq;
    
	PreprocStatement pps;
    pps.addAction(&ppq);

    FunctionDefinition fnd;
	PrettyPrintToQ pprtQ(resultsQ);

	//Modified Pallavi
	PrettyPrintFunction pprtQ;
    
	fnd.addAction(&pprtQ);

    Toker toker("../ActionsAndRules.h");
    SemiExp se(&toker);
    Parser parser(&se);
    parser.addRule(&pps);
    parser.addRule(&fnd);
    while(se.get())
      parser.parse();
    size_t len = resultsQ.size();
    for(size_t i=0; i<len; ++i)
    {
      std::cout << "\n  " << resultsQ.front().c_str();
      resultsQ.pop();
    }
    std::cout << "\n\n";
  }
  catch(std::exception& ex)
  {
    std::cout << "\n\n  " << ex.what() << "\n\n";
  }
}
示例#10
0
int main(int argc, char* argv[])
{ 
  std::cout << "\n  XML Document Object Model \n "<< std::string(20,'=') << std::endl;
  if(argc < 2)  
  { 
    std::cout << "\n  please enter name of file to process on command line\n\n";
    return 1;  
  }    
  for(int i=1; i<argc; ++i)
  { 
    std::cout << "\n  Processing  " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n";
    try
    { 
        Toker toker(argv[i]); 
	      toker.setMode(Toker::xml);  
        XmlParts parts(&toker);
        Parser sc(parts);
	      XmlTree t;
	      t.makeRoot(sc.walkScopes());
	      t.show(t.getRoot());
	      t.clearMarks();
	      std::cout << "\n\n"; 
	      t.addtoid("testId");
        std::cout<<"\nThe new tree after adding testTag to testId :-)"<<std::endl;
        t.show(t.getRoot()); 
	      t.clearMarks();
	      std::cout << "\n\n";
        t.removebytag("testTag");
        std:: cout << "--The new TREE after removing testTag"<< "\n\n";
	      t.show(t.getRoot());
	      t.clearMarks();
	      std::cout << "\n\n"<<"Finding the tag title\n\n";
        t.findbytag("testTag");
        std::cout << "\n\n"<<"Finding the id testId\n\n";
        t.findbyid("testId");
    }
  
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}
示例#11
0
static PyObject *
process_linkTitles(PyObject *self, PyObject *args)
{
    const char *doc_buffer;
    std::string processed_doc = "";

    if (!PyArg_ParseTuple(args, "s", &doc_buffer))
        return NULL;

    try
    {
      Toker toker(doc_buffer, false);
      toker.setMode(Toker::xml);
      XmlParts parts(&toker);
      HtmlParts scraper(&parts);

      bool listHead = true;

      while(scraper.get())
      {
          // identify product links
          if (scraper.isProductLink())
          {
              if (listHead) {
                  processed_doc += scraper.attributes["href"];
                  listHead = false;
              }
              else
              processed_doc +=  "<br/>" + scraper.attributes["href"];
          }
      }

    }
    catch(std::runtime_error ex)
    {
      std::cout << "\n " << ex.what() << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }

    return Py_BuildValue("s", processed_doc.c_str());
}
示例#12
0
// Прочитать входной файл. Заполняется массив пользователей и график дежурств.
InputParser::InputParser(const std::string& filename):
    filename(filename) 
{
    std::cout << boost::format("[InputParser] Input file: %s\n") % filename;

    std::ifstream input(filename.c_str());
    std::string s, firstWord;
    while(std::getline(input, s)) {
        // skip comments
        if (s[0] == '#') {
            continue;
        }

        boost::tokenizer<> toker(s);
        boost::tokenizer<>::iterator t = toker.begin();

        firstWord = (std::string)(*t);


        if (firstWord == "person") {
            t++;
            std::string name = *t; 
            t++;
            std::string surname = *t;
            t++;
            bool male = ((std::string)(*t) == "male");
            DutyManager::addDutyPerson(name, surname, male);
        } 
        else if (firstWord == "event") {
            t++;
            std::string name = *t; 
            t++;
            int f_req = boost::lexical_cast<int>(*t);
            t++;
            int m_req = boost::lexical_cast<int>(*t);
            DutyManager::addDutyEvent(name, f_req, m_req);
        }
        else {
            std::cout << "[InputParser] Cannot parse config line: " << s;
        }

    }
}
std::vector<std::string> XmlParts::gettokens(std::string argument)
{
	std::vector<std::string> tokens;
	try
	{
		Toker toker(argument);
		toker.setMode(Toker::xml);
		XmlParts parts(&toker);
		//parts.verbose();                 // uncomment to show token details
		while (parts.get())
			//std::cout << parts.show().c_str() << std::endl;
			tokens.push_back(parts.show());
		//std::cout << "\n\n";
	}
	catch (std::exception ex)
	{
		std::cout << "\n  " << ex.what() << "\n\n";
	}
	return tokens;
}
示例#14
0
/*
 Return only plain text, no tags
 */
static PyObject *
process_getPlainText(PyObject *self, PyObject *args)
{
    const char *doc_buffer;
    std::string processed_doc = "";


    if (!PyArg_ParseTuple(args, "s", &doc_buffer))
        return NULL;

    try
    {
      Toker toker(doc_buffer, false);
      toker.setMode(Toker::xml);
      XmlParts parts(&toker);
      HtmlParts scraper(&parts);

      while(scraper.get())
      {
          // Extra spacing doesn't matter
          if ( scraper.isPlainText() )
          {
              processed_doc += " " + scraper.toString() + " ";
          }
      }

    }
    catch(std::runtime_error ex)
    {
      std::cout << "\n " << ex.what() << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }

    return Py_BuildValue("s", processed_doc.c_str());
}
示例#15
0
ParametersVectorType ReadParametersFile(std::string filename) {
	ParametersVectorType result;

	std::ifstream file(filename.c_str());
	std::string line;

	typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
	boost::char_separator<char> sep(",;| []");

	unsigned int classId = 0;

	while ( getline(file, line)) {
		size_t pos = line.find("#");

		if( pos!=0 ) {
			line = line.substr(0,pos);

			tokenizer toker(line, sep);
			tokenizer::iterator iterator = toker.begin();
			std::vector<float> classStats;

			while (iterator != toker.end()) {
				float val = boost::lexical_cast<float>(*iterator++);
				classStats.push_back(val);
			}

			ParametersType statsArray(classStats.size());
			std::copy(classStats.begin(), classStats.end(), statsArray.begin());
			result.push_back(statsArray);
			classId++;
		}
	}

	file.close();

	return result;
}
示例#16
0
void
SBRS_Server_Connection::handle_read(const error_code& error, size_t bytes_transferred)
{
	this->cancel_timer();
	if ( error )
	{
		//ACE_OS::printf("read error:%s\n", error.message().c_str()); //@
		return this->close();
	}

	//ACE_OS::printf("read completed: %d\n", bytes_transferred); //@

	mb_.wr_ptr(bytes_transferred);
	// read greetings
	while( mb_.length() > 0 )
	{
		aos::bcstr data = io_.read_request(mb_);
	}
	// keep reading
	if ( io_.read_state() != SBRS_Server_IO::RD_OK )
	{
		mb_.reset();
		this->read(mb_, timeout_);
		return;
	}
	// read completed
	else
	{
		// write command
		//ACE_OS::printf("C:%s", io_.buf().c_str()); //@

		// parse command
		aos::Multi_String params;
		aos::Tokenizer toker(io_.buf().c_str(), io_.buf().size());
		toker.set_separator(" \t\r\n");
		int ch = toker.next();
		if ( toker.size() )
		{
			params.push_back(toker.token(), toker.size());
			ch = toker.next();
			if ( toker.size() )
			{
				params.push_back(toker.token(), toker.size());
			}
		}

		if ( ACE_OS::strncasecmp(params[0], "SRL", 3) == 0 && params.size() == 2 )
		{
			ACE_UINT32 ipv4 = IPv4::to_uint32(params[1]);
			double score = -1.0;

			ACE_OS::printf("ip_int:%u\n", ipv4);
			size_t n_map = server_->maps_.size();
			int idx = ipv4 % n_map;
			SBRS_MAP::iterator iter = (server_->maps_[idx])->find(ipv4);
			if ( iter != (server_->maps_[idx])->end() )
				score = (double) iter->second / 255;

			io_.write_score(mb_, score);
			this->write(mb_, timeout_);
		}
		else
		{
			return this->close();
		}
	}
}
int main(int argc, char* argv[])
{
  std::cout << "\n  Demonstrating Scope Analysis\n "
            << std::string(30,'=') << std::endl;
  if(argc < 2)
  {
    std::cout 
      << "\n  please enter name of file to process on command line\n\n";
    return 1;
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-');
    try
    {
  	  Toker toker(argv[i]);
      SemiExp se(&toker);
      ScopeStack<element> stack;
      while(se.get())
      {
        if(se.length() < 1)
          continue;
        //std::cout << se.show().c_str() << std::endl;
        if(se[se.length() - 1] == "}")
        {
          stack.pop();
          showStack<element>(stack);
        }
        if(se.length() < 3)
          continue;
        if(se[se.length() - 1] == "{")
        {
          element item;
          size_t pos = se.find("(");
          if(pos < se.length())
          {
            if(isSpecialKeyWord(se[pos-1]))
              item.type = "control";
            else
              item.type = "function";
            item.name = se[pos-1];
            stack.push(item);
            showStack<element>(stack);
          }
          else
          {
            item.type = se[se.length()-3];
            item.name = se[se.length()-2];
            stack.push(item);
            showStack<element>(stack);
          }
        }
      }
      std::cout << "\n\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}
int main(int argc, char* argv[])
{
  std::cout << "\n  Testing SemiExp class\n "
            << std::string(23,'=') << std::endl;

  try {
  std::cout << "\n  testing SemiExp::get(...)";
  std::cout << "\n -----------------------------";
  Toker toker1(argv[1]);
  toker1.returnComments(false);
  SemiExp test1(&toker1);
  test1.get();
  std::cout << "\n  " << test1.show();
  test1.get(false);
  std::cout << "\n  " << test1.show();
  test1.get();
  std::cout << "\n  " << test1.show();
  test1.get(false);
  std::cout << "\n  " << test1.show() << std::endl;

  std::cout << "\n  testing SemiExp::merge(...)";
  std::cout << "\n -----------------------------";
  SemiExp test2(0);
  test2.push_back("one");
  test2.push_back("two");
  test2.push_back("three");
  test2.push_back("four");
  test2.push_back("five");
  std::cout << "\n  " << test2.show();
  test2.merge("two","five");
  std::cout << "\n  " << test2.show() << std::endl;
  
  std::cout << "\n  testing SemiExp::find()";
  std::cout << "\n -------------------------";
  SemiExp semi(0);
  semi.push_back("one");
  semi.push_back("two");
  semi.push_back("three");
  semi.push_back("four");
  std::cout << "\n" << semi.show();
  size_t pos = semi.find("two");
  std::cout << "\n  position of \"two\" is " << pos;
  pos = semi.find("foobar");
  std::cout << "\n  position of \"foobar\" is " << pos;
  std::cout << "\n\n";

  std::cout << "\n  Note that comments and quotes are returned as single tokens\n";
  }
  catch(std::exception& ex)
  {
    std::cout << "\n\n  " << ex.what() << "\n\n";
    return 1;
  }
  if(argc < 2)
  {
    std::cout 
      << "\n  please enter name of file to process on command line\n\n";
    return 1;
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n\n";
    try
    {
  	  Toker toker(argv[i]);
      toker.returnComments();
      SemiExp se(&toker);
      se.makeCommentSemiExp();
      //se.verbose();                 // uncomment to show token details
      while(se.get())
      {
        std::cout << se.show(true).c_str() << std::endl;
        for(size_t i=0; i<se.length(); ++i)
          if(se[i] == "")
            std::cout << "\n\n----blank token----\n";
      }
      std::cout << "\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }

  for(int i=1; i<argc; ++i)
  {
    std::cout << "\n  Processing file " << argv[i];
    std::cout << "\n  " << std::string(16 + strlen(argv[i]),'-') << "\n\n";
    try
    {
  	  Toker toker(argv[i]);
      toker.returnComments();
      SemiExp se(&toker);
      se.makeCommentSemiExp();
      se.returnNewLines(false);
      //se.verbose();                 // uncomment to show token details
      while(se.get())
      {
        for(size_t i=0; i<se.length(); ++i)
          if(se[i] == "")
            std::cout << "\n\n----blank token----\n";
        std::cout << se.show(true).c_str() << std::endl;
      }
      std::cout << "\n";
    }
    catch(std::exception ex)
    {
      std::cout << "\n  " << ex.what() << "\n\n";
    }
  }
}