예제 #1
0
void testing_$$_expand(bool verbose)
{
	if (verbose) {
		fprintf( stdout, "\n----- testing_$$_expand ----\n\n");
	}

	REQUIRE( next$$("$$(STUFF)", 0) == "STUFF" );
	REQUIRE( next$$_left("$$(STUFF)", 0) == "" );
	REQUIRE( next$$_right("$$(STUFF)", 0) == "" );
	REQUIRE( next$$("_$$(STUFF:a,b,c) $(BAR)", 0) == "STUFF:a,b,c" );
	REQUIRE( next$$("$$(DOLLARDOLLAR)", 0) == "DOLLARDOLLAR" );

	REQUIRE( next$$("$$([1+2])", 0) == "[1+2]" );
	REQUIRE( next$$("$$([ 1 + 2*3 ])", 0) == "[ 1 + 2*3 ]" );
	REQUIRE( next$$("$$([ splitslotname(Target.Name)[0] ])", 0) == "[ splitslotname(Target.Name)[0] ]" );

	REQUIRE( next$$("$(FOO) $$(STUFF:2) $(BAR)", 0) == "STUFF:2" );
	REQUIRE( next$$_left("$(FOO) $$(STUFF:2) $(BAR)", 0) == "$(FOO) " );
	REQUIRE( next$$_right("$(FOO) $$(STUFF:2) $(BAR)", 0) == " $(BAR)" );

	REQUIRE( next$$("_$$(STUFF:2) $$([1+2])$$(BAR)", 0) == "STUFF:2" );
	REQUIRE( next$$("_$$(STUFF:2) $$([1+2])$$(BAR)", 2) == "[1+2]" );
	REQUIRE( next$$("_$$(STUFF:2) $$([1+2])$$(BAR)", 20) == "BAR" );

	REQUIRE( next$$_left("_$$(STUFF:2) $$([1+2])$$(BAR)", 0) == "_" );
	REQUIRE( next$$_left("_$$(STUFF:2) $$([1+2])$$(BAR)", 12) == "_$$(STUFF:2) " );
	REQUIRE( next$$_left("_$$(STUFF:2) $$([1+2])$$(BAR)", 20) == "_$$(STUFF:2) $$([1+2])" );

	REQUIRE( next$$_right("_$$(STUFF:2) $$([1+2])$$(BAR)", 0) == " $$([1+2])$$(BAR)" );
	REQUIRE( next$$_right("_$$(STUFF:2) $$([1+2])$$(BAR)", 2) == "$$(BAR)" );
	REQUIRE( next$$_right("_$$(STUFF:2) $$([1+2])$$(BAR)", 20) == "" );
}
예제 #2
0
파일: last2.c 프로젝트: leon0516/fengdong
void Bluetooth() 
{ 


    if(Serial.available()>0) 
    { 
      uint8_t readbuf=Serial.read(); 
      r_buffer[num]=readbuf; 
      num++; 
      delay(2); 
      Serial.println(num); 
      if(readbuf==0X3B) 
      { 
        if(num==3) 
        { 


          recivevalue=(r_buffer[0]<<8)|(r_buffer[1]); 


        } 


        num=0; 
        mark0=1; 
      }  
    }     






    if(mark0==1) 
    { 
      mark0=0; 


      switch(recivevalue) 
      { 
      case up    : //Serial.println(up,HEX); 
        _up(); 
        break; 
      case down  : //Serial.println(down,HEX); 
        _down(); 
        break; 
      case left  :  
        _left(); 
        break; 
      case right :  
        _right(); 
        break; 
      } 
     
  } 
} 
예제 #3
0
void HeapSort::maxHeapify( int* heap, int heapSize, int parent )
{
	int largest;
	if (_left(parent) < heapSize && heap[_left(parent)] > heap[parent])
		largest = _left(parent);
	else largest = parent;

	if (_right(parent) < heapSize && heap[_right(parent)] > heap[largest])
		largest = _right(parent);

	if (largest != parent)
	{
		int tmp = heap[parent];
		heap[parent] = heap[largest];
		heap[largest] = tmp;
		++mCost;++mCost;
		maxHeapify(heap, heapSize, largest);
	}
}
예제 #4
0
/**
 * Main loop function that will handle the current auton state. This functions
 * could take a large finite amount of time to run due to the nature of the
 * robot.
 * @param hw is Hardware object to manipulate
 */
void auto_update(Hardware& hw){
  // Run current state and update for next update call
  switch(_state){
    case MOVE_FWD:
      _state = _forward(hw);
      break;
    case MOVE_BWD:
      _state = _backward(hw);
      break;
    case MOVE_LEFT:
      _state = _left(hw);
      break;
    case MOVE_RIGHT:
      _state = _right(hw);
      break;
    case HEAD_LEFT:
      _state = _headLeft(hw);
      break;
    case HEAD_CENTER:
      _state = _headCenter(hw);
      break;
    case HEAD_RIGHT:
      _state = _headRight(hw);
      break;
    case MEASURE_DISTANCE:
      _state = _measureDistance(hw);
      break;
    case WHICH_WAY_SLCT:
      _state = _whichWay(hw);
      break;
    case STUCK_FRONT:
      _state = _stuckFront(hw);
        break;
    case STUCK_BACK:
      _state = _stuckBack(hw);
      break;
    case DELAY_FWD_HEAD:
      _state = _delayForwardToHead(hw);
      break;
    case DELAY_BWD_HEAD:
      _state = _delayBackwardToHead(hw);
      break;
    case ERROR:
      hw.stopMoving();
      auto_reset(); // reset state-machine due to error
      break;
    default:
      hw.stopMoving();
      auto_reset(); //something broke, reset state-machine
      break;
  }
}
예제 #5
0
IPTR Register__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
{
    struct Register_DATA *data = INST_DATA(cl, obj);

    /* Before all the current page is drawn erase the part of the area covered
     * by tabs which is not erased (between _left(obj) and _mleft(obj) and so on */
    if (data->oldactive != data->active && (msg->flags & MADF_DRAWUPDATE) && (data->active/data->columns != data->oldactive/data->columns))
    {
        int left,top,width,height;

        left = _mright(obj)+1;
        top = _mtop(obj);
        width = _right(obj) - left; /* +1 - 1*/
        height = _mheight(obj);

        DoMethod(obj, MUIM_DrawBackground, left, top, width, height, left, top, 0);

        left = _left(obj)+1; /* +1 because the register frame shouldn't be ereased */
        width = _mleft(obj) - left; /* + 1 - 1 */

        DoMethod(obj, MUIM_DrawBackground, left, top, width, height, left, top, 0);

        top = _top(obj) + data->tab_height;
        height = _mtop(obj) - top; /* + 1 - 1 */
        width = _width(obj)-2;

        if (height > 0 && width > 0)
            DoMethod(obj, MUIM_DrawBackground, left, top, width, height, left, top, 0);

        top = _mbottom(obj);
        height = _bottom(obj) - top; /* + 1 - 1 */

        if (height > 0 && width > 0)
            DoMethod(obj, MUIM_DrawBackground, left, top, width, height, left, top, 0);
    }

    DoSuperMethodA(cl,obj,(Msg)msg);

    /*      D(bug("Register_Draw : flags = %d\n", msg->flags)); */
    if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE)))
        return(0);

    RenderRegisterTab(cl, obj, msg->flags);

    data->oldactive = data->active;
    return TRUE;
}
예제 #6
0
/**************************************************************************
 MUIM_HandleEvent
**************************************************************************/
IPTR Numericbutton__MUIM_HandleEvent(struct IClass *cl, Object *obj, struct MUIP_HandleEvent *msg)
{
    struct Numericbutton_DATA *data = INST_DATA(cl, obj);

    if (!msg->imsg)
    {
        return 0;
    }

    switch(msg->imsg->Class)
    {
    case IDCMP_MOUSEBUTTONS:
        switch(msg->imsg->Code)
        {
        case SELECTDOWN:
            if (_between(_left(obj), msg->imsg->MouseX, _right(obj)) &&
                    _between(_top(obj), msg->imsg->MouseY, _bottom(obj)) &&
                    (muiAreaData(obj)->mad_Flags & MADF_CANDRAW) &&
                    !data->popwin)
            {
                data->knob_clickoffset_x = msg->imsg->MouseX - _mleft(obj);

                if (MakePopupWin(obj, data))
                {
                    DoMethod(_win(obj), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
                    data->ehn.ehn_Events |= IDCMP_MOUSEMOVE;
                    DoMethod(_win(obj), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);

                    return 0;
                }
            }
            break;

        case SELECTUP:
        case MENUUP:
        case MIDDLEUP:
        default:
            if (data->popwin)
            {
                KillPopupWin(obj, data);
                if ((msg->imsg->Code == SELECTUP))
                {
                    set(obj, MUIA_Numeric_Value, data->knob_val);
                }
                return 0;
            }
            break;


        } /* switch(msg->imsg->Code) */
        break;

    case IDCMP_MOUSEMOVE:
        if (data->popwin)
        {
            DrawKnob(obj, data, FALSE);

            return 0;
        }
        break;

    } /* switch(msg->imsg->Class) */

    return 0;
}
예제 #7
0
QVariant ZStringFormatter::transform(QVariant val){
    if(method() == ZFMT_METHOD_STR_CONCAT){ //!                      concat( with )
        return _concat(val,arg("with",ZML_DEFAULT_PARAM_NAME));

    }else if(method() == ZFMT_METHOD_STR_DOWNCASE){ //!              downcase
        return _downcase(val);

    }else if(method() == ZFMT_METHOD_STR_ELIDE){ //!                 elide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_LEFT){ //!                  left( length )
        return _left(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LEFTOF){ //!                leftOf( delimiter )
        return _leftOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString());

    }else if(method() == ZFMT_METHOD_STR_LELIDE){ //!                lelide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_LPAD){ //!                  lpad( length [, symbol] )
        if(arg("symbol").isValid())
            return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar());
        else
            return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LSHIFT){ //!                lshift( places )
        return _lshift(val, arg("places", ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LTRIM){ //!                 ltrim( [pattern] )
        if(arg("pattern").isValid())
            return _ltrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _ltrim(val);

    }else if(method() == ZFMT_METHOD_STR_RELIDE){ //!                relide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_REPEAT){ //!                repeat( times )
        return _repeat(val, arg("times",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_REVERSE){ //!               reverse
        return _reverse(val);

    }else if(method() == ZFMT_METHOD_STR_RIGHT){ //!                 right( length )
        return _right(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RIGHTOF){ //!               rightOf( delimiter )
        return _rightOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString());

    }else if(method() == ZFMT_METHOD_STR_RPAD){ //!                  rpad( length [, symbol] )
        if(arg("symbol").isValid())
            return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar());
        else
            return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RSHIFT){ //!                rshift( places )
        return _rshift(val, arg("places",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RTRIM){ //!                 rtrim( [pattern] )
        if(arg("pattern").isValid())
            return _rtrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _rtrim(val);

    }else if(method() == ZFMT_METHOD_STR_SCASE){ //!                 capitalize
        return _sentenceCase(val);

    }else if(method() == ZFMT_METHOD_STR_SQUEEZE){ //!               squeeze( [symbol] )
        if(arg("symbol").isValid())
            return _squeeze(val, arg("symbol",ZML_DEFAULT_PARAM_NAME).toChar());
        else
            return _squeeze(val);

    }else if(method() == ZFMT_METHOD_STR_TCASE){ //!                 titleize
        return _titleCase(val);

    }else if(method() == ZFMT_METHOD_STR_TRIM){ //!                  trim( [pattern] )
        if(arg("pattern").isValid())
            return _trim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _trim(val);

    }else if(method() == ZFMT_METHOD_STR_UPCASE){ //!                upcase
        return _upcase(val);
    }

    return val;
}