Esempio n. 1
0
void do_loop (void)
/***** do_loop
	do a loop command in a UDF.
	loop value to value; .... ; end
*****/
{	int h;
	char *jump;
	header *init,*end;
	long vend,oldindex;
	if (!udfon)
	{	output("Loop only allowed in functions!\n");
		error=57; return;
	}
	init=scan(); if (error) return;
	init=getvalue(init); if (error) return;
	if (init->type!=s_real)
	{	output("Startvalue must be real!\n"); error=72; return;
	}
	oldindex=loopindex;
	loopindex=(long)*realof(init);
	scan_space(); if (strncmp(next,"to",2))
	{	output("Endvalue missing in loop!\n"); error=73; goto end;
	}
	next+=2;
	end=scan(); if (error) goto end;
	end=getvalue(end); if (error) goto end;
	if (end->type!=s_real)
	{	output("Endvalue must be real!\n"); error=73; goto end;
	}
	vend=(long)*realof(end);
	if (loopindex>vend) { scan_end(); goto end; }
	newram=endlocal;
	scan_space(); if (*next==';' || *next==',') next++;
	jump=next;
	while (!error)
	{	if (*next==1)
		{	output("End missing in loop!\n");
			error=401; goto end;
		}
		h=command();
		if (udfon!=1 || h==c_return) break;
		if (h==c_break) { scan_end(); break; }
		if (h==c_end)
		{	loopindex++;
			if (loopindex>vend) break;
			else next=jump;
			if (test_key()==escape)
			{	output("User interrupted!\n");
				error=1; break;
			}
		}
	}
	end : loopindex=oldindex;
}
Esempio n. 2
0
void scan_end (void)
/***** scan_end
	scan for "end".
*****/
{	int comn;
	commandtyp *com;
	char *oldline=udfline;
	while (1)
	{	switch (*next)
		{	case 1 :
				output("End missing!\n");
				error=110; udfline=oldline; return;
			case 0 : udfline=next+1; next++; break;
			case 2 : next+=1+sizeof(double); break;
			case 3 : next++;
				memmove((char *)(&comn),next,sizeof(int));
				next+=sizeof(int);
				com=command_list+comn;
				if (com->nr==c_end)
				{	if (trace>0) trace_udfline(udfline);
				    return;
				}
				else if (com->nr==c_repeat || com->nr==c_loop ||
					com->nr==c_for)
				{	scan_end(); 
					if (error) return;
				}
				break;
			default : next++;
		}
	}
}
Esempio n. 3
0
void do_repeat (void)
/***** do_loop
	do a loop command in a UDF.
	for value to value; .... ; endfor
*****/
{	int h;
	char *jump;
	if (!udfon)
	{	output("Repeat only allowed in functions!\n");
		error=57; return;
	}
	newram=endlocal;
	scan_space(); if (*next==';' || *next==',') next++;
	jump=next;
	while (!error)
	{	if (*next==1)
		{	output("End missing in repeat statement!\n");
			error=401; break;
		}
		h=command();
		if (udfon!=1 || h==c_return) break;
		if (h==c_break) { scan_end(); break; }
		if (h==c_end)
		{	next=jump;
			if (test_key()==escape)
			{   output1("User interrupted\n");
				error=1; break;
			}
		}
	}
}
Esempio n. 4
0
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;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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();
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
/*(*** http_parse_request_line */
int http_parse_request_line(http_request_line *rl, char *p, int m)
{
  scanbuf sb;
  int i;
  int method_i, method_j;
  int uri_i, uri_j;
  int major_i, major_j;
  int minor_i, minor_j;

  char *method;
  char *uri;
  char *major, *minor;

  scan_init(&sb, p, m);

#define check(x) if((x) < 0) return 0;

  method_i = 0;
  method_j = scan_alphabet_plus  (&sb, method_i, is_valid_alpha);   check(method_j);
  uri_i    = scan_alphabet_plus  (&sb, method_j, is_valid_space);   check(uri_i);
  uri_j    = scan_alphabet_plus  (&sb, uri_i, is_valid_uri_char);   check(uri_j);
  i        = scan_alphabet_plus  (&sb, uri_j, is_valid_space);      check(i);
  major_i  = scan_convert_nulstr (&sb, i, toupper, "HTTP/");        check(i);
  major_j  = scan_alphabet_plus  (&sb, major_i, is_valid_digit);    check(major_j);
  minor_i  = scan_char           (&sb, major_j, '.');               check(minor_i);
  minor_j  = scan_alphabet_plus  (&sb, minor_i, is_valid_digit);    check(minor_j);
  i        = scan_end            (&sb, minor_j);                    check(i);

  method   = scan_extract(&sb, method_i, method_j - 1);
  uri      = scan_extract(&sb, uri_i,    uri_j    - 1);
  major    = scan_extract(&sb, major_i,  major_j  - 1);
  minor    = scan_extract(&sb, minor_i,  minor_j  - 1);

#undef check

  scan_upperify(method);

  rl->hrl_allocated = 1;
  rl->hrl_method    = method;
  rl->hrl_uri       = uri;
  rl->hrl_major     = major;
  rl->hrl_minor     = minor;

  return 1;
}
Esempio n. 12
0
static void
scan_curchan_task(void *arg, int pending)
{
	struct ieee80211_scan_state *ss = arg;
	struct scan_state *ss_priv = SCAN_PRIVATE(ss);
	struct ieee80211com *ic = ss->ss_ic;
	struct ieee80211_channel *chan;
	unsigned long maxdwell;
	int scandone;

	IEEE80211_LOCK(ic);
end:
	scandone = (ss->ss_next >= ss->ss_last) ||
	    (ss_priv->ss_iflags & ISCAN_CANCEL) != 0;

	IEEE80211_DPRINTF(ss->ss_vap, IEEE80211_MSG_SCAN,
	    "%s: loop start; scandone=%d\n",
	    __func__,
	    scandone);

	if (scandone || (ss->ss_flags & IEEE80211_SCAN_GOTPICK) ||
	    (ss_priv->ss_iflags & ISCAN_ABORT) ||
	     ieee80211_time_after(ticks + ss->ss_mindwell, ss_priv->ss_scanend)) {
		ss_priv->ss_iflags &= ~ISCAN_RUNNING;
		scan_end(ss, scandone);
		return;
	} else
		ss_priv->ss_iflags |= ISCAN_RUNNING;

	chan = ss->ss_chans[ss->ss_next++];

	/*
	 * Watch for truncation due to the scan end time.
	 */
	if (ieee80211_time_after(ticks + ss->ss_maxdwell, ss_priv->ss_scanend))
		maxdwell = ss_priv->ss_scanend - ticks;
	else
		maxdwell = ss->ss_maxdwell;

	IEEE80211_DPRINTF(ss->ss_vap, IEEE80211_MSG_SCAN,
	    "%s: chan %3d%c -> %3d%c [%s, dwell min %lums max %lums]\n",
	    __func__,
	    ieee80211_chan2ieee(ic, ic->ic_curchan),
	    ieee80211_channel_type_char(ic->ic_curchan),
	    ieee80211_chan2ieee(ic, chan),
	    ieee80211_channel_type_char(chan),
	    (ss->ss_flags & IEEE80211_SCAN_ACTIVE) &&
		(chan->ic_flags & IEEE80211_CHAN_PASSIVE) == 0 ?
		"active" : "passive",
	    ticks_to_msecs(ss->ss_mindwell), ticks_to_msecs(maxdwell));

	/*
	 * Potentially change channel and phy mode.
	 */
	ic->ic_curchan = chan;
	ic->ic_rt = ieee80211_get_ratetable(chan);
	IEEE80211_UNLOCK(ic);
	/*
	 * Perform the channel change and scan unlocked so the driver
	 * may sleep. Once set_channel returns the hardware has
	 * completed the channel change.
	 */
	ic->ic_set_channel(ic);
	ieee80211_radiotap_chan_change(ic);

	/*
	 * Scan curchan.  Drivers for "intelligent hardware"
	 * override ic_scan_curchan to tell the device to do
	 * the work.  Otherwise we manage the work ourselves;
	 * sending a probe request (as needed), and arming the
	 * timeout to switch channels after maxdwell ticks.
	 *
	 * scan_curchan should only pause for the time required to
	 * prepare/initiate the hardware for the scan (if at all).
	 */
	ic->ic_scan_curchan(ss, maxdwell);
	IEEE80211_LOCK(ic);

	/* XXX scan state can change! Re-validate scan state! */

	ss_priv->ss_chanmindwell = ticks + ss->ss_mindwell;
	/* clear mindwell lock and initial channel change flush */
	ss_priv->ss_iflags &= ~ISCAN_REP;

	if (ss_priv->ss_iflags & (ISCAN_CANCEL|ISCAN_ABORT)) {
		taskqueue_cancel_timeout(ic->ic_tq, &ss_priv->ss_scan_curchan,
		    NULL);
		goto end;
	}

	IEEE80211_DPRINTF(ss->ss_vap, IEEE80211_MSG_SCAN, "%s: waiting\n",
	    __func__);
	IEEE80211_UNLOCK(ic);
}
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));
}
Esempio n. 14
0
void do_for (void)
/***** do_for
	do a for command in a UDF.
	for i=value to value step value; .... ; end
*****/
{	int h,signum;
	char name[16],*jump;
	header *hd,*init,*end,*step;
	double vend,vstep;
	struct { header hd; double value; } rv;
	if (!udfon)
	{	output("For only allowed in functions!\n"); error=57; return;
	}
	rv.hd.type=s_real; *rv.hd.name=0;
	rv.hd.size=sizeof(header)+sizeof(double); rv.value=0.0;
	scan_space(); scan_name(name); if (error) return;
	kill_local(name);
	newram=endlocal;
	hd=new_reference(&rv.hd,name); if (error) return;
	endlocal=newram=(char *)hd+hd->size;
	scan_space(); if (*next!='=')
	{	output("Syntax error in for.\n"); error=71; goto end;
	}
	next++; init=scan(); if (error) goto end;
	init=getvalue(init); if (error) goto end;
	if (init->type!=s_real)
	{	output("Startvalue must be real!\n"); error=72; goto end;
	}
	rv.value=*realof(init);
	scan_space(); if (strncmp(next,"to",2))
	{	output("Endvalue missing in for!\n"); error=73; goto end;
	}
	next+=2;
	end=scan(); if (error) goto end;
	end=getvalue(end); if (error) goto end;
	if (end->type!=s_real)
	{	output("Endvalue must be real!\n"); error=73; goto end;
	}
	vend=*realof(end);
	scan_space();
	if (!strncmp(next,"step",4))
	{	next+=4;
		step=scan(); if (error) goto end;
		step=getvalue(step); if (error) goto end;
		if (step->type!=s_real)
		{	output("Stepvalue must be real!\n"); error=73; goto end;
		}
		vstep=*realof(step);
	}
	else vstep=1.0;
	signum=(vstep>=0)?1:-1;
	vend=vend+signum*epsilon;
	if (signum>0 && rv.value>vend) { scan_end(); goto end; }
	else if (signum<0 && rv.value<vend) { scan_end(); goto end; }
	newram=endlocal;
	scan_space(); if (*next==';' || *next==',') next++;
	jump=next;
	while (!error)
	{	if (*next==1)
		{	output("End missing!\n");
			error=401; goto end;
		}
		h=command();
		if (udfon!=1 || h==c_return) break;
		if (h==c_break) { scan_end(); break; }
		if (h==c_end)
		{	rv.value+=vstep;
			if (signum>0 && rv.value>vend) break;
			else if (signum<0 && rv.value<vend) break;
			else next=jump;
			if (test_key()==escape)
			{   output("User interrupted!\n");
				error=1; break;
			}
		}
	}
	end : kill_local(name);
}