Beispiel #1
0
int ntexture_driver::parse()
{
  scan_begin();
  yy::ntexture_parser parser(*this);
  parser.set_debug_level(trace_parsing);
  int res = parser.parse();
  scan_end();
  return res;
}
int sqlparser_driver::parse(const std::string &f){
	file = f;
	scan_begin();
	yy::sqlparser parser(*this);
	parser.set_debug_level(trace_parsing);
	int res = parser.parse();
	scan_end();
	return res;
}
Beispiel #3
0
int KaleidoDriver::parse_file(const std::string &f) {
  file = f;
  scan_begin();
  KaleidoParser parser(*this);
  parser.set_debug_level(trace_parsing);
  int res = parser.parse();
  scan_end();
  return res;
}
Beispiel #4
0
void ExprDriver::parse(const std::string &input)
{
    _input = input;
    scan_begin();
    yy::ExprParser parser(*this);
    parser.set_debug_level(_traceParsing);
    parser.parse();
    scan_end();
}
Beispiel #5
0
int Driver::parse(const std::string& filename_)
{
  filename = filename_;
  scan_begin();
  yy::Parser parser(*this);
  parser.set_debug_level(trace_parsing);
  int res = parser.parse();
  scan_end();
  return res;
}
Beispiel #6
0
int KaleidoDriver::parse(const std::string &literal) {
  file = "<LITERAL>";
  parse_on_the_fly = true;
  scan_begin();
  KaleidoParser parser(*this);
  parser.set_debug_level(trace_parsing);
  int res = parser.parse();
  scan_end();
  return res;
}
int
ParseDriver::parse (const std::string &f)
{
  file = f;
  scan_begin ();
  yy::SceneParser parser (*this);
  parser.set_debug_level (garg_debug_trace_parsing);
  int res = parser.parse ();
  scan_end ();
  return res;
}
Beispiel #8
0
int main(int argc, char **argv) {
    struct scan_ctx *scan;
    struct scan_chunk_data chunk_data[2];
    struct analyze_ctx *analyze;
    int fd, result;

    analyze = analyze_open(argv[2], argv[1]);
    if (!analyze) {
	perror("analyze_init");
	return EXIT_FAILURE;
    }

    scan = scan_init();
    if (!scan) {
	perror("scan_init");
	return EXIT_FAILURE;
    }

    fd = open(argv[1], O_RDWR);
    if (fd < 0) {
	perror("open");
	return EXIT_FAILURE;
    }
    scan_set_fd(scan, fd);
    scan_set_aio(scan);

    if (!scan_begin(scan))
	return EXIT_FAILURE;
    do {
	result = scan_read_chunk(scan, chunk_data);
	if (result & SCAN_CHUNK_FOUND)
	    store_chunk(analyze, chunk_data);
	else {
	    fputs("Scan error\n", stderr);
	    return EXIT_FAILURE;
	}
    } while (!(result & SCAN_CHUNK_LAST));
    analyze_close(analyze);
    scan_free(scan);

    return EXIT_SUCCESS;
}
void
RPG_Net_Protocol_Module_IRCSplitter::handleDataMessage(RPG_Net_Protocol_Message*& message_inout,
                                                       bool& passMessageDownstream_out)
{
  RPG_TRACE(ACE_TEXT("RPG_Net_Protocol_Module_IRCSplitter::handleDataMessage"));

  // init return value(s), default behavior is to pass all messages along...
  // --> we don't want that !
  passMessageDownstream_out = false;

  // sanity check(s)
  ACE_ASSERT(message_inout);
  ACE_ASSERT(myIsInitialized);

  // perhaps we already have part of this message ?
  if (myCurrentBuffer)
    myCurrentBuffer->cont(message_inout); // chain the buffer
  myCurrentBuffer = message_inout;

  // scan the bytestream for frame bounds "\r\n"

  // do we know where to start ?
  if (myCurrentMessage == NULL)
    myCurrentMessage = myCurrentBuffer; // start scanning at offset 0...

  // *NOTE*: the scanner checks sequences of >= 2 bytes (.*\r\n)
  // --> make sure we have a minimum amount of data...
  // --> more sanity check(s)
  if (myCurrentMessage->total_length() < RPG_NET_PROTOCOL_IRC_FRAME_BOUNDARY_SIZE)
    return; // don't have enough data, cannot proceed
  if (myCurrentBuffer->length() < RPG_NET_PROTOCOL_IRC_FRAME_BOUNDARY_SIZE)
  {
    // *sigh*: OK, so this CAN actually happen...
    // case1: if we have anything OTHER than '\n', there's nothing to do
    //        --> wait for more data
    // case2: if we have an '\n' we have to check the trailing character
    //        of the PRECEDING buffer:
    //        - if it's an '\r' --> voilà, we've found a frame boundary
    //        - else            --> wait for more data
    if (((*myCurrentBuffer->rd_ptr()) == '\n') &&
        (myCurrentMessage != myCurrentBuffer))
    {
      ACE_Message_Block* preceding_buffer = myCurrentMessage;
      for (;
           preceding_buffer->cont() != myCurrentBuffer;
           preceding_buffer = preceding_buffer->cont());
      if (*(preceding_buffer->rd_ptr() + (preceding_buffer->length() - 1)) == '\r')
      {
        // OK, we have all of it !
        if (myCrunchMessages)
        {
          myCurrentMessage->crunch();
        } // end IF

        // --> push it downstream...
        if (put_next(myCurrentMessage, NULL) == -1)
        {
          ACE_DEBUG((LM_ERROR,
                     ACE_TEXT("failed to ACE_Task::put_next(): \"%m\", continuing\n")));

          // clean up
          myCurrentMessage->release();
        } // end IF

        // bye bye...
        myCurrentMessageLength = 0;
        myCurrentMessage = NULL;
        myCurrentBuffer = NULL;

        return;
      } // end IF
    } // end IF

    return; // don't have enough data, cannot proceed
  } // end IF

  // OK, init scanner...

  // *WARNING*: cannot use yy_scan_buffer(), as flex modifies the data... :-(
//   // *NOTE*: in order to accomodate flex, the buffer needs two trailing
//   // '\0' characters...
//   // --> make sure it has this capacity
//   if (myCurrentBuffer->space() < RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE)
//   {
//     // *sigh*: (try to) resize it then...
//     if (myCurrentBuffer->size(myCurrentBuffer->size() + RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE))
//     {
//       ACE_DEBUG((LM_ERROR,
//                  ACE_TEXT("failed to ACE_Message_Block::size(%u), aborting\n"),
//                  (myCurrentBuffer->size() + RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE)));
//
//       // what else can we do ?
//       return;
//     } // end IF
//     myCurrentBufferIsResized = true;
//
//     // *WARNING*: beyond this point, make sure we resize the buffer back
//     // to its original length...
//     // *NOTE*: this is safe, as realloc() just crops the trailing bytes again...
//   } // end IF
// //   for (int i = 0;
// //        i < RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE;
// //        i++)
// //     *(myCurrentBuffer->wr_ptr() + i) = YY_END_OF_BUFFER_CHAR;
//   *(myCurrentBuffer->wr_ptr()) = '\0';
//   *(myCurrentBuffer->wr_ptr() + 1) = '\0';
//
//   if (!scan_begin(myCurrentBuffer->rd_ptr(),
//                   myCurrentBuffer->length() + RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE))
  if (!scan_begin(myCurrentBuffer->rd_ptr(),
                  myCurrentBuffer->length()))
  {
    ACE_DEBUG((LM_ERROR,
               ACE_TEXT("failed to scan_begin(%@, %u), aborting\n"),
               myCurrentBuffer->rd_ptr(),
               myCurrentBuffer->length()));

//     // clean up
//     if (myCurrentBufferIsResized)
//     {
//       if (myCurrentBuffer->size(myCurrentBuffer->size() - RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE))
//         ACE_DEBUG((LM_ERROR,
//                    ACE_TEXT("failed to ACE_Message_Block::size(%u), continuing\n"),
//                    (myCurrentBuffer->size() - RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE)));
//       myCurrentBufferIsResized = false;
//     } // end IF

    // what else can we do ?
    return;
  } // end IF

//   // debug info
//   ACE_DEBUG((LM_DEBUG,
//              ACE_TEXT("[%u]: scanning %u byte(s)\n\"%s\"\n"),
//              myCurrentBuffer->getID(),
//              myCurrentBuffer->length(),
//              std::string(myCurrentBuffer->rd_ptr(), myCurrentBuffer->length()).c_str()));

  // scan it !
  myCurrentNumFrames = 0;
  bool finished_scanning = false;
  int scanned_bytes = 0;
  int scanned_chunk = 0;
//   while (myCurrentMessageLength = myScanner.yylex())
  do
  {
    scanned_chunk = RPG_Net_Protocol_IRCBisect_lex(myScannerContext);
//    scanned_chunk = IRCBisectlex(myScannerContext);
    switch (scanned_chunk)
    {
      case 0:
      {
        // --> finished scanning this buffer
        finished_scanning = true; // no (more) frame boundaries found

        // remember how much data was scanned so far...
        myCurrentMessageLength += scanned_bytes;

        break;
      }
      case -1:
      {
        // found a frame border scanned_bytes bytes into the buffer

        // *NOTE*: if scanned_bytes == 0, then it's the corner
        // case where the current buffer starts with either:
        // - a '\n'
        // - a "\r\n"
        // *NOTE*: in EITHER case, a new frame has been found...
        if ((scanned_bytes == 0) &&
            (*myCurrentBuffer->rd_ptr() == '\n'))
        {
          scanned_bytes = 1;
          myCurrentMessageLength += RPG_NET_PROTOCOL_IRC_FRAME_BOUNDARY_SIZE;
        } // end IF
        else
        {
          scanned_bytes += RPG_NET_PROTOCOL_IRC_FRAME_BOUNDARY_SIZE;
          myCurrentMessageLength += scanned_bytes;
        } // end IF

//         ACE_DEBUG((LM_DEBUG,
//                    ACE_TEXT("buffer (ID: %u, length: %u): frame boundary [#%u] @ offset %u\n\"%s\"\n"),
//                    myCurrentBuffer->getID(),
//                    myCurrentMessageLength,
//                    myCurrentNumFrames,
//                    (scanned_bytes + (myCurrentBuffer->rd_ptr() - myCurrentBuffer->base())),
//                    std::string(myCurrentBuffer->rd_ptr(), scanned_bytes).c_str()));

        RPG_Net_Protocol_Message* message = myCurrentMessage;
        if (myCurrentMessageLength < myCurrentMessage->total_length())
        {
          // more data to scan...

          // *NOTE*: copy ctor shallow-copies the current data block
          myCurrentMessage = dynamic_cast<RPG_Net_Protocol_Message*>(myCurrentBuffer->duplicate());
          ACE_ASSERT(myCurrentMessage);
          // adjust wr_ptr (point to one-past-the-end of the current message)
          myCurrentBuffer->wr_ptr(myCurrentBuffer->rd_ptr() + scanned_bytes);
          ACE_ASSERT(myCurrentMessageLength == message->total_length());
          // adjust rd_ptr (point to the beginning of the next message)
          myCurrentMessage->rd_ptr(scanned_bytes);
        } // end IF
        else
        {
          // NO more data to scan...
          ACE_ASSERT(myCurrentMessageLength == myCurrentMessage->total_length());

          // set new message head
          myCurrentMessage = NULL;
        } // end ELSE

        if (myCrunchMessages)
        {
          message->crunch();
        } // end IF

//         ACE_DEBUG((LM_DEBUG,
//                    ACE_TEXT("processing message (ID: %u - %u byte(s))...\n"),
//                    message->getID(),
//                    message->total_length()));

        // --> push it downstream...
        if (put_next(message, NULL) == -1)
        {
          ACE_DEBUG((LM_ERROR,
                     ACE_TEXT("failed to ACE_Task::put_next(): \"%m\", continuing\n")));

          // clean up
          message->release();
        } // end IF

        // set new current buffer
        myCurrentBuffer = myCurrentMessage;
        // reset state
        myCurrentMessageLength = 0;
        scanned_bytes = 0;

        // ...continue scanning !
        break;
      }
      default:
      {
        // scanned one/some character(s)...
        scanned_bytes += scanned_chunk;

        break;
      }
    } // end SWITCH
  } while (!finished_scanning);

  // clean up
  scan_end();
//   // *NOTE*: that even if we've sent some frames downstream in the meantime,
//   // we're still referencing the same buffer we resized earlier - it's always
//   // the new "head" message...
//   if (myCurrentBufferIsResized)
//   {
//     if (myCurrentBuffer->size(myCurrentBuffer->size() - RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE))
//       ACE_DEBUG((LM_ERROR,
//                  ACE_TEXT("failed to ACE_Message_Block::size(%u), continuing\n"),
//                  (myCurrentBuffer->size() - RPG_NET_PROTOCOL_FLEX_BUFFER_BOUNDARY_SIZE)));
//     myCurrentBufferIsResized = false;
//   } // end IF

//   ACE_DEBUG((LM_DEBUG,
//              ACE_TEXT("found %u frame bound(s)...\n"),
//              myCurrentNumFrames));
}