예제 #1
0
파일: fog.cpp 프로젝트: kkremitzki/plantgl
ViewFogGL3::ViewFogGL3(ViewCameraGL3 *camera,QGLWidget * parent, const char * name):
  ViewRelativeObjectGL3(camera,parent,name),
  __enable(false),
  __mode(0),
  __hintmode(0),
  __color(255,255,255),
  __density(0.5),
  __start(0),
  __end(10),
  __control(new ViewDialog3(parent,"Fog Control",false)),
  __fogw(new FogWidget(__control,"Fog Control Widget"))
{
  __control->setCaption(tr("Fog Control"));
  QPixmap col(__fogw->ColorButton->size());
  col.fill(__color);
  __fogw->ColorButton->setPixmap(col);  
  __fogw->EndEdit->setText(QString::number(__end));
  __fogw->StartEdit->setText(QString::number(__start));
  __fogw->DensitySlider->setValue(50);
  QObject::connect(__fogw->OkButton,SIGNAL(pressed()), __control,SLOT(hide()));
  QObject::connect(__fogw->ModeCombo,SIGNAL(activated(int)),this,SLOT(setMode(int)));
  QObject::connect(__fogw->HintsCombo,SIGNAL(activated(int)),this,SLOT(setHints(int)));
  QObject::connect(__fogw->ColorButton,SIGNAL(pressed()),this,SLOT(changeColor()));
  QObject::connect(__fogw->DensitySlider,SIGNAL(valueChanged(int)),this,SLOT(setDensity(int)));
  QObject::connect(__fogw->StartEdit,SIGNAL(textChanged(const QString&)),this,SLOT(setStart(const QString&)));
  QObject::connect(__fogw->EndEdit,SIGNAL(textChanged(const QString&)),this,SLOT(setEnd(const QString&)));
  QObject::connect(__fogw->StartEdit,SIGNAL(returnPressed()),this,SLOT(validValue()));
  QObject::connect(__fogw->EndEdit,SIGNAL(returnPressed()),this,SLOT(validValue()));
}
void PointerSetBase::maybeResize(HashFunction hashFunc) {
    size_t newShift = internal::hashShiftAdjust(mCount, mShift);
    if (newShift == mShift) {
        // Nothing to resize
        return;
    }

    size_t capacity = 1U << mShift;
    size_t newCapacity = 1U << newShift;
    void** newItems = static_cast<void**>(
            ::calloc(newCapacity, sizeof(newItems[0])));

    for (size_t n = 0; n < capacity; ++n) {
        void* item = mItems[n];
        if (!validValue(item)) {
            continue;
        }
        size_t itemHash = hashFunc(item);
        size_t slot = probeItems(item, itemHash, newItems, newShift);
        DCHECK(!validValue(newItems[slot]));
        newItems[slot] = item;
    }

    ::free(mItems);
    mItems = newItems;
    mShift = newShift;
}
void* PointerSetBase::removeItem(void* obj, HashFunction hashFunc) {
    if (!validValue(obj)) {
        return NULL;
    }
    size_t objHash = hashFunc(obj);
    size_t pos = probeItems(obj, objHash, mItems, mShift);
    DCHECK(pos < (1U << mShift));

    void* result = mItems[pos];
    if (!validValue(result)) {
        // Item was not in the array.
        return NULL;
    }
    mItems[pos] = TOMBSTONE;
    mCount--;
    return result;
}
void* PointerSetBase::Iterator::next() {
    while (mPos < mCapacity) {
        void* item = mItems[mPos++];
        if (validValue(item)) {
            return item;
        }
    }
    return NULL;
}
bool PointerSetBase::contains(const void* obj, HashFunction hashFunc) const {
    if (!obj) {
        return false;
    }
    size_t objHash = hashFunc(obj);
    size_t pos = probeItems(obj, objHash, mItems, mShift);
    DCHECK(pos < (1U << mShift));

    return validValue(mItems[pos]);
}
void* PointerSetBase::addItem(void* obj, HashFunction hashFunc) {
    if (!validValue(obj)) {
        return NULL;
    }
    size_t objHash = hashFunc(obj);
    size_t pos = probeItems(obj, objHash, mItems, mShift);
    DCHECK(pos < (1U << mShift));

    void* result = mItems[pos];
    if (validValue(result)) {
        // Simple replacement.
        DCHECK(result == obj);
        return result;
    }
    mItems[pos] = obj;
    mCount++;

    if (result != TOMBSTONE) {
        // No need to resize when replacing tombstone.
        maybeResize(hashFunc);
    }

    return NULL;
}
AMAction3* BioXASSSRLMonochromatorRegionControl::createMoveAction(double newRegion)
{
	AMListAction3 *action = 0;

	if (value_ != newRegion && validValue(newRegion)) {

		action = new AMListAction3(new AMListActionInfo3("CrystalChange", "BioXAS SSRL Mono Crystal Change Action"), AMListAction3::Sequential);
		action->addSubAction(createCloseMaskBladesAction());
		action->addSubAction(createRemovePaddleAction());
		action->addSubAction(createWaitForKeyEnabledAction());
		action->addSubAction(createMoveBraggToCrystalChangePositionAction(int(value_)));
		action->addSubAction(createWaitForBrakeDisabledAction());
		action->addSubAction(createMoveCrystalChangeToRegionLimitAction(int(newRegion)));
		action->addSubAction(createWaitForBrakeEnabledAction());
		action->addSubAction(createMoveBraggToRegionAction(int(newRegion)));
		action->addSubAction(createWaitForKeyDisabledAction());

		// Make additional action connections.

		connect( action, SIGNAL(progressChanged(double, double)), this, SIGNAL(moveProgressChanged(double,double)) );
		connect( action, SIGNAL(currentSubActionChanged(int)), this, SLOT(onMoveStepChanged(int)) );
	}
예제 #8
0
void
ViewCameraGL::addProperties(QTabWidget * tab)
{
  QWidget * mytabWidget = new QWidget(tab);
  Ui::CameraProperties * tab2 = new Ui::CameraProperties( );
  tab2->setupUi(mytabWidget);
  tab->addTab( mytabWidget, tr( "&Camera" ) );

  tab2->ZoomEdit->setText(QString::number(__translation.x()));
  tab2->ZoomEdit->setReadOnly(true);
  tab2->XTranslationEdit->setText(QString::number(__translation.y()));
  tab2->XTranslationEdit->setReadOnly(true);
  tab2->YTranslationEdit->setText(QString::number(__translation.z()));
  tab2->YTranslationEdit->setReadOnly(true);
  tab2->AzimuthEdit->setText(QString::number(__azimuth));
  tab2->AzimuthEdit->setReadOnly(true);
  tab2->ElevationEdit->setText(QString::number(__elevation));
  tab2->ElevationEdit->setReadOnly(true);
  Vector3 pos = getPosition();
  tab2->PositionEdit->setText('<'+QString::number(pos.x())+','+QString::number(pos.y())+','+QString::number(pos.z())+'>');
  tab2->PositionEdit->setReadOnly(true);
  tab2->NearEdit->setText(QString::number(__near_plane));
  QObject::connect(tab2->NearEdit,SIGNAL(textChanged(const QString&)),this,SLOT(setNearPlane(const QString&)));
  QObject::connect(tab2->NearEdit,SIGNAL(returnPressed()),this,SLOT(validValue()));
  tab2->FarEdit->setText(QString::number(__far_plane));
  QObject::connect(tab2->FarEdit,SIGNAL(textChanged(const QString&)),this,SLOT(setFarPlane(const QString&)));
  QObject::connect(tab2->FarEdit,SIGNAL(returnPressed()),this,SLOT(validValue()));
  tab2->EyeEdit->setText(toQString(__eye));
  tab2->EyeEdit->setReadOnly(true);
  tab2->CenterEdit->setText(toQString(__center));
  tab2->CenterEdit->setReadOnly(true);
  tab2->DefaultAngleEdit->setValue(__default_view_angle);
  QObject::connect(tab2->DefaultAngleEdit,SIGNAL(valueChanged(double)),this,SLOT(setViewAngle(double)));

  tab2->CurrentAngleEdit->setText(QString::number(__view_angle));
  QObject::connect(this,SIGNAL(currentViewAngleChanged(const QString&)),
                   tab2->CurrentAngleEdit,SLOT(setText(const QString&)));
  QObject::connect(this,SIGNAL(viewAngleChanged(double)),
                   tab2->DefaultAngleEdit,SLOT(setValue(double)));
  tab2->CurrentAngleEdit->setReadOnly(true);
  tab2->ProjectionBox->setCurrentIndex(int(__projectionmode));
  QObject::connect(tab2->ProjectionBox,SIGNAL(activated(int)),this,SLOT(setProjectionMode(int)));
  tab2->CoordinatesBox->setCurrentIndex(int(__geomsys));
  QObject::connect(tab2->CoordinatesBox,SIGNAL(activated(int)),this,SLOT(setCoordSys(int)));
  tab2->ResizePolicyBox->setCurrentIndex(int(__resizePolicy));
  QObject::connect(tab2->ResizePolicyBox,SIGNAL(activated(int)),this,SLOT(setResizePolicy(int)));
  /*Matrix4 m;
  glGeomGetMatrix(GL_PROJECTION_MATRIX,m);
  CameraProp2 * tab3 = new CameraProp2( tab, "Camera Prop2" );
  tab3->MA00->setText(QString::number((fabs(m(0,0)) < GEOM_EPSILON?0:m(0,0))));
  tab3->MA01->setText(QString::number((fabs(m(0,1)) < GEOM_EPSILON?0:m(0,1))));
  tab3->MA02->setText(QString::number((fabs(m(0,2)) < GEOM_EPSILON?0:m(0,2))));
  tab3->MA03->setText(QString::number((fabs(m(0,3)) < GEOM_EPSILON?0:m(0,3))));

  tab3->MA10->setText(QString::number((fabs(m(1,0)) < GEOM_EPSILON?0:m(1,0))));
  tab3->MA11->setText(QString::number((fabs(m(1,1)) < GEOM_EPSILON?0:m(1,1))));
  tab3->MA12->setText(QString::number((fabs(m(1,2)) < GEOM_EPSILON?0:m(1,2))));
  tab3->MA13->setText(QString::number((fabs(m(1,3)) < GEOM_EPSILON?0:m(1,3))));

  tab3->MA20->setText(QString::number((fabs(m(2,0)) <GEOM_EPSILON?0:m(2,0))));
  tab3->MA21->setText(QString::number((fabs(m(2,1)) <GEOM_EPSILON?0:m(2,1))));
  tab3->MA22->setText(QString::number((fabs(m(2,2)) <GEOM_EPSILON?0:m(2,2))));
  tab3->MA23->setText(QString::number((fabs(m(2,3)) <GEOM_EPSILON?0:m(2,3))));

  tab3->MA30->setText(QString::number((fabs(m(3,0)) <GEOM_EPSILON?0:m(3,0))));
  tab3->MA31->setText(QString::number((fabs(m(3,1)) <GEOM_EPSILON?0:m(3,1))));
  tab3->MA32->setText(QString::number((fabs(m(3,2)) <GEOM_EPSILON?0:m(3,2))));
  tab3->MA33->setText(QString::number((fabs(m(3,3)) <GEOM_EPSILON?0:m(3,3))));
  glGeomGetMatrix(GL_MODELVIEW_MATRIX,m);
  tab3->MB00->setText(QString::number((fabs(m(0,0)) <GEOM_EPSILON?0:m(0,0))));
  tab3->MB01->setText(QString::number((fabs(m(0,1)) <GEOM_EPSILON?0:m(0,1))));
  tab3->MB02->setText(QString::number((fabs(m(0,2)) <GEOM_EPSILON?0:m(0,2))));
  tab3->MB03->setText(QString::number((fabs(m(0,3)) <GEOM_EPSILON?0:m(0,3))));
  tab3->MB10->setText(QString::number((fabs(m(1,0)) <GEOM_EPSILON?0:m(1,0))));
  tab3->MB11->setText(QString::number((fabs(m(1,1)) <GEOM_EPSILON?0:m(1,1))));
  tab3->MB12->setText(QString::number((fabs(m(1,2)) <GEOM_EPSILON?0:m(1,2))));
  tab3->MB13->setText(QString::number((fabs(m(1,3)) <GEOM_EPSILON?0:m(1,3))));
  tab3->MB20->setText(QString::number((fabs(m(2,0)) <GEOM_EPSILON?0:m(2,0))));
  tab3->MB21->setText(QString::number((fabs(m(2,1)) <GEOM_EPSILON?0:m(2,1))));
  tab3->MB22->setText(QString::number((fabs(m(2,2)) <GEOM_EPSILON?0:m(2,2))));
  tab3->MB23->setText(QString::number((fabs(m(2,3)) <GEOM_EPSILON?0:m(2,3))));
  tab3->MB30->setText(QString::number((fabs(m(3,0)) <GEOM_EPSILON?0:m(3,0))));
  tab3->MB31->setText(QString::number((fabs(m(3,1)) <GEOM_EPSILON?0:m(3,1))));
  tab3->MB32->setText(QString::number((fabs(m(3,2)) <GEOM_EPSILON?0:m(3,2))));
  tab3->MB33->setText(QString::number((fabs(m(3,3)) <GEOM_EPSILON?0:m(3,3))));
  tab->insertTab( tab3, tr( "&GL Matrix" ) );*/

/*  CameraProp2 * tab4 = new CameraProp2( tab, "Camera Prop4" );
  tab4->Label->setText("Camera Matrix");
  tab4->Label2->setText("Camera Vectors");
 // m = getMatrix();
  Vector3 p = getPosition();
  tab4->MA00->setText(QString::number(p.x())+','+QString::number(p.y())+','+QString::number(p.z())+','+QString::number(__azimuth)+','+QString::number(__elevation));
  QObject::connect(tab4->MA00,SIGNAL(textChanged(const QString&)),this,SLOT(setPosition(const QString&)));

  tab4->MA01->setText(QString::number((fabs(m(0,0)) < GEOM_EPSILON?0:m(0,1))));
  tab4->MA01->setText(QString::number((fabs(m(0,1)) < GEOM_EPSILON?0:m(0,1))));
  tab4->MA02->setText(QString::number((fabs(m(0,2)) < GEOM_EPSILON?0:m(0,2))));
  tab4->MA03->setText(QString::number((fabs(m(0,3)) < GEOM_EPSILON?0:m(0,3))));

  tab4->MA10->setText(QString::number((fabs(m(1,0)) < GEOM_EPSILON?0:m(1,0))));
  tab4->MA11->setText(QString::number((fabs(m(1,1)) < GEOM_EPSILON?0:m(1,1))));
  tab4->MA12->setText(QString::number((fabs(m(1,2)) < GEOM_EPSILON?0:m(1,2))));
  tab4->MA13->setText(QString::number((fabs(m(1,3)) < GEOM_EPSILON?0:m(1,3))));

  tab4->MA20->setText(QString::number((fabs(m(2,0)) <GEOM_EPSILON?0:m(2,0))));
  tab4->MA21->setText(QString::number((fabs(m(2,1)) <GEOM_EPSILON?0:m(2,1))));
  tab4->MA22->setText(QString::number((fabs(m(2,2)) <GEOM_EPSILON?0:m(2,2))));
  tab4->MA23->setText(QString::number((fabs(m(2,3)) <GEOM_EPSILON?0:m(2,3))));

  tab4->MA30->setText(QString::number((fabs(m(3,0)) <GEOM_EPSILON?0:m(3,0))));
  tab4->MA31->setText(QString::number((fabs(m(3,1)) <GEOM_EPSILON?0:m(3,1))));
  tab4->MA32->setText(QString::number((fabs(m(3,2)) <GEOM_EPSILON?0:m(3,2))));
  tab4->MA33->setText(QString::number((fabs(m(3,3)) <GEOM_EPSILON?0:m(3,3))));

  if(!__geomsys)  m = Matrix4(Matrix3(getDirection(),getUp(),getRight()));
  else m = Matrix4(Matrix3(getDirection(),getRight(),getUp()));
  Vector3 p = getPosition();
  m(0,3) = p.x();m(1,3) = p.y();m(2,3) = p.z();
  tab4->MB00->setText(QString::number((fabs(m(0,0)) <GEOM_EPSILON?0:m(0,0))));
  tab4->MB01->setText(QString::number((fabs(m(0,1)) <GEOM_EPSILON?0:m(0,1))));
  tab4->MB02->setText(QString::number((fabs(m(0,2)) <GEOM_EPSILON?0:m(0,2))));
  tab4->MB03->setText(QString::number((fabs(m(0,3)) <GEOM_EPSILON?0:m(0,3))));

  tab4->MB10->setText(QString::number((fabs(m(1,0)) <GEOM_EPSILON?0:m(1,0))));
  tab4->MB11->setText(QString::number((fabs(m(1,1)) <GEOM_EPSILON?0:m(1,1))));
  tab4->MB12->setText(QString::number((fabs(m(1,2)) <GEOM_EPSILON?0:m(1,2))));
  tab4->MB13->setText(QString::number((fabs(m(1,3)) <GEOM_EPSILON?0:m(1,3))));

  tab4->MB20->setText(QString::number((fabs(m(2,0)) <GEOM_EPSILON?0:m(2,0))));
  tab4->MB21->setText(QString::number((fabs(m(2,1)) <GEOM_EPSILON?0:m(2,1))));
  tab4->MB22->setText(QString::number((fabs(m(2,2)) <GEOM_EPSILON?0:m(2,2))));
  tab4->MB23->setText(QString::number((fabs(m(2,3)) <GEOM_EPSILON?0:m(2,3))));

  tab4->MB30->setText(QString::number((fabs(m(3,0)) <GEOM_EPSILON?0:m(3,0))));
  tab4->MB31->setText(QString::number((fabs(m(3,1)) <GEOM_EPSILON?0:m(3,1))));
  tab4->MB32->setText(QString::number((fabs(m(3,2)) <GEOM_EPSILON?0:m(3,2))));
  tab4->MB33->setText(QString::number((fabs(m(3,3)) <GEOM_EPSILON?0:m(3,3))));

  tab->insertTab( tab4, tr( "&GEOM Camera" ) );*/
}
예제 #9
0
/*
 * resToClassNew()
 *
 * Convert the user specified selection string into a string that TCL
 * may be able to process.
 *  eg:
 *  "mem > 0 || swap < 10 || type == Linux"
 *  becomes:
 *  "expr mem()>0||swap()< 10||[type "eq" "Linux"]
 */
static int
resToClassNew(char *resReq, struct resVal *resVal, struct lsInfo *lsInfo)
{
    int i;
    int s;
    int t;
    int len;
    int entry;
    int hasQuote;
    char res[MAXLINELEN];
    char val[MAXLINELEN];
    char tmpbuf[MAXLINELEN*2];
    char *sp;
    char *op;

    len = strlen(resReq);

    sp = resVal->selectStr;
    strcpy(sp,"expr ");
    s = 0;		/* Index into source string */
    t = strlen(sp);	/* Index into target string */

    while (s < len) {
        if (t >= (resVal->selectStrSize - MAXLSFNAMELEN))
            return PARSE_BAD_EXP;

        /* Skip spaces */
        if (resReq[s] == ' ') {
            s++;
            continue;
        }
        /* Copy reserved characters and numbers into target string */
        if ( resReq[s] == '(' || resReq[s] == ')' || resReq[s] == '=' ||
             resReq[s] == '!' || resReq[s] == '>' || resReq[s] == '<' ||
             resReq[s] == '|' || resReq[s] == '&' || resReq[s] == '+' ||
             resReq[s] == '-' || resReq[s] == '*' || resReq[s] == '/' ||
             resReq[s] == '.' || isdigit(resReq[s])) {

            sp[t++] = resReq[s++];
	    if( t >= resVal->selectStrSize ) {
		/* ensure we don't go beyond the bounds of the buffer */
		return(PARSE_BAD_VAL);
	    }
            continue;
        }

        if (isalpha(resReq[s])) { /* Check for a resource name */

            i = 0;
            while (isalpha(resReq[s])
                   || isdigit(resReq[s])
                   || IS_VALID_OTHER(resReq[s])) {
                res[i++] = resReq[s++];
		if (i >= MAXLINELEN) {
		    /* ensure we don't go beyond the bounds of the buffer */
		    return(PARSE_BAD_VAL);
		}
	    }
            res[i] = '\0';

            entry = getResEntry(res);

            if (entry < 0) {
                if (strncmp ("defined", res, strlen(res)) == 0) {
                    while (resReq[s] == ' ')
                        s++;
                    if (resReq[s] != '(')
                        return (PARSE_BAD_EXP);
                    i = 0;
		    s++;
                    while (isalpha(resReq[s])
                           || isdigit(resReq[s])
                           || IS_VALID_OTHER(resReq[s])) {
                        res[i++] = resReq[s++];
			if (i >= MAXLINELEN) {
			    /* ensure we don't go beyond the bounds of
			     * the buffer
			     */
			    return(PARSE_BAD_VAL);
			}
		    }
                    res[i] = '\0';
                    entry = getResEntry(res);
                    if (entry < 0)
                        return PARSE_BAD_NAME;
		    if ((snprintf(tmpbuf, MAXLINELEN*2, "[%s \"%s\" ]",
                                  "defined",
                                  lsInfo->resTable[entry].name)
			   >= MAXLINELEN*2)
		       || (strlen(tmpbuf) + t >= resVal->selectStrSize)) {
			/* ensure we don't go beyond the
			 * bounds of the buffer
			 */
			return(PARSE_BAD_VAL);
		    }
                    sp[t] = '\0';
                    strcat(sp,tmpbuf);
                    t += strlen(tmpbuf);
                    while (resReq[s] == ' ')
                           s++;
                    if (resReq[s] != ')')
                        return (PARSE_BAD_EXP);
                    s++;
                    continue;
                }
                return PARSE_BAD_NAME;
            }
            switch(lsInfo->resTable[entry].valueType) {
	    case LS_NUMERIC:
            case LS_BOOLEAN:
                strcat(res,"()");
                sp[t] = '\0';
                strcat(sp,res);
                t += strlen(res);
		break;
	    case LS_STRING:
                /* Skip spaces */
                while(resReq[s] == ' ')
                    s++;

                /* Should have at least a operator and value */
                if (resReq[s] == '\0' || resReq[s+1] == '\0')
                    return(PARSE_BAD_EXP);

                /* Get the operator */
                op = NULL;
                if (resReq[s] == '=' && resReq[s+1] == '=') {
                    op = "eq";
                    s += 2;
                } else if (resReq[s] == '!' && resReq[s+1] == '=') {
                    op = "ne";
                    s += 2;
                } else if (resReq[s] == '>' && resReq[s+1] == '=') {
                    op = "ge";
                    s += 2;
                } else if (resReq[s] == '<' && resReq[s+1] == '=') {
                    op = "le";
                    s += 2;
                } else if (resReq[s] == '<') {
                    op = "lt";
                    s += 1;
                } else if (resReq[s] == '>') {
                    op = "gt";
                    s += 1;
                } else { /* Not a valid operator */
                    return -1;
                }

                while (resReq[s] == ' ')
                    s++;
                /* Get the value */
                if (resReq[s] == '\''){
                    hasQuote = TRUE;
                    s++; /* skip over quote */
                } else
                    hasQuote = FALSE;
                i = 0;
                if (!hasQuote){
                    while(isalpha(resReq[s])
                          || isdigit(resReq[s])
                          || IS_VALID_OTHER(resReq[s])) {
                        val[i++] = resReq[s++];
			if (i >= MAXLINELEN) {
			    /* ensure we don't go beyond the bounds of
			     * the buffer
			     */
			    return(PARSE_BAD_VAL);
			}
		    }
                } else {
                    while(resReq[s] && resReq[s] != '\'' && i < MAXLINELEN) {
                        val[i++] = resReq[s++];
			if (i >= MAXLINELEN) {
			    /* ensure we don't go beyond the bounds of
			     * the buffer
			     */
			    return(PARSE_BAD_VAL);
			}
		    }
                    if (resReq[s] == '\'')
                         s++; /* skip over quote */
                }
                val[i] = '\0';
                if (i == 0) { 	/* No value given */
                    return(PARSE_BAD_VAL);
                }
                /* Check if the value is valid for this resource */
                if (validValue(val, lsInfo, entry) < 0) {
                    return(PARSE_BAD_VAL);
                }
                /* Now combine them all together */
                if ((snprintf(tmpbuf,
                              MAXLINELEN * 2,
                              "[%s \"%s\" \"%s\"]",
                              lsInfo->resTable[entry].name,
                              op,
                              val) >= MAXLINELEN*2)
                    || (strlen(tmpbuf) + t >= resVal->selectStrSize)) {
		    /* ensure we don't go beyond the bounds of
		     * the buffer
		     */
		    return(PARSE_BAD_VAL);
		}
                sp[t] = '\0';
                strcat(sp,tmpbuf);
                t += strlen(tmpbuf);
                default:
                    break;
            }
        } else { 	/* Character we don't recognize */
            return (PARSE_BAD_EXP);
        }

    }
    sp[t] = '\0';
    resVal->options |= PR_SELECT;
    return(PARSE_OK);

}
예제 #10
0
/* Old pre 2.0 resource request format long time obsolete
 */
static int
resToClassOld(char *resReq, struct resVal *resVal, struct lsInfo *lsInfo)
{
    int i, m, entry;
    char *token;
    char tmpbuf[MAXLINELEN];
    float value;
    char  negate, valueSpecified;
    int t;

    if ((i=strlen(resReq)) == 0)
        return PARSE_OK;

    for (m=0; m<i; m++)
	if (resReq[m] != ' ')
	    break;

    if (m == i)
	return PARSE_OK;

    if (resReq[0] == ':' || resReq[0] == '=')
        return PARSE_BAD_EXP;

    strcpy(resVal->selectStr, "expr ");
    t = strlen(resVal->selectStr);

    while ((token = getNextToken(&resReq)) != NULL) {

        negate = FALSE;

        if (t >= (resVal->selectStrSize - MAXLSFNAMELEN))
            return PARSE_BAD_EXP;

        if (isdigit(token[0]))
            return(PARSE_BAD_EXP);

        if (token[0] == '-') {
            if (token[1] == '\0') {
                sprintf(tmpbuf,"[type \"eq\" \"%s\"] &&", WILDCARD_STR);
                strcat(resVal->selectStr, tmpbuf);
                t += strlen(tmpbuf);
                continue;
            }
            token++;
            negate = TRUE;
        }

        entry = getResEntry(token);
	if (entry < 0)
            return(PARSE_BAD_NAME);

        if (lsInfo->resTable[entry].valueType == LS_BOOLEAN) {
 	    if (negate)
                sprintf(tmpbuf,"!%s()&&",lsInfo->resTable[entry].name);
	    else
                sprintf(tmpbuf,"%s()&&",lsInfo->resTable[entry].name);
            strcat(resVal->selectStr, tmpbuf);
            t += strlen(tmpbuf);
            continue;
        }

        if (negate)
            return(PARSE_BAD_EXP);

        if (lsInfo->resTable[entry].valueType == LS_NUMERIC) {

            valueSpecified = FALSE;
            if (resReq[0] == '=') {
                if (getVal(&resReq, &value) < 0 || value < 0.0)
                    return (PARSE_BAD_VAL);

                if (lsInfo->resTable[entry].flags & RESF_DYNAMIC)
                    resVal->val[entry] = value;
                valueSpecified = TRUE;
            }

            if (!valueSpecified && entry == IT) {
                valueSpecified = TRUE;
 		value = IDLETIME;
                resVal->val[entry] = value;
     	    }


            if (valueSpecified) {
                if (lsInfo->resTable[entry].orderType == INCR)
                    sprintf(tmpbuf,"%s()<=%6.2f&&",lsInfo->resTable[entry].name,value);
                else
                    sprintf(tmpbuf,"%s()>=%6.2f&&",lsInfo->resTable[entry].name,value);
            } else {
                sprintf(tmpbuf,"%s()&&",lsInfo->resTable[entry].name);
            }
            strcat(resVal->selectStr, tmpbuf);
            t += strlen(tmpbuf);
            continue;
        }

        if (lsInfo->resTable[entry].valueType == LS_STRING) {

            if(resReq[0] != '=')
                return(PARSE_BAD_EXP);

	    if ((token = getNextToken(&resReq)) == NULL)
                return(PARSE_BAD_EXP) ;


            if (validValue(token, lsInfo, entry) < 0)
                return (PARSE_BAD_VAL);

            sprintf(tmpbuf,"[%s \"eq\" \"%s\"]&&",lsInfo->resTable[entry].name,token);
            strcat(resVal->selectStr, tmpbuf);
            t += strlen(tmpbuf);
            continue;
        }
    }
    sprintf(tmpbuf,"1");
    strcat(resVal->selectStr, tmpbuf);

    resVal->options |= PR_SELECT;
    return(PARSE_OK);

}
예제 #11
0
static int
resToClassNew(char *resReq, struct resVal *resVal, struct lsInfo *lsInfo)
{
    int i, s, t, len, entry, hasFunction = FALSE, hasQuote;
    char res[MAXLSFNAMELEN], val[MAXLSFNAMELEN];
    char tmpbuf[MAXLSFNAMELEN*2];
    char *sp, *op;

    len = strlen(resReq);

    sp = resVal->selectStr;
    strcpy(sp,"expr ");
    s = 0;
    t = strlen(sp);

    while (s < len) {
        if (t >= (resVal->selectStrSize - MAXLSFNAMELEN))
            return PARSE_BAD_EXP;


        if (resReq[s] == ' ') {
            s++;
            continue;
        }

        if ( resReq[s] == '(' || resReq[s] == ')' || resReq[s] == '=' ||
             resReq[s] == '!' || resReq[s] == '>' || resReq[s] == '<' ||
             resReq[s] == '|' || resReq[s] == '&' || resReq[s] == '+' ||
             resReq[s] == '-' || resReq[s] == '*' || resReq[s] == '/' ||
             resReq[s] == '.' || IS_DIGIT(resReq[s])) {

            sp[t++] = resReq[s++];
            continue;
        }

        if (IS_LETTER(resReq[s])) {

            i = 0;
            while(IS_LETTER(resReq[s]) || IS_DIGIT(resReq[s]) ||
                  IS_VALID_OTHER(resReq[s]))
                res[i++] = resReq[s++];
            res[i] = '\0';

            entry = getResEntry(res);

            if (entry < 0) {
                if (strncmp ("defined", res, strlen (res)) == 0) {
                    while (resReq[s] == ' ')
                        s++;
                    if (resReq[s] != '(')
                        return (PARSE_BAD_EXP);
                    i = 0;
		    s++;
                    while (IS_LETTER(resReq[s]) || IS_DIGIT(resReq[s]) ||
                           IS_VALID_OTHER(resReq[s]))
                        res[i++] = resReq[s++];
                    res[i] = '\0';
                    entry = getResEntry(res);
                    if (entry < 0)
                        return PARSE_BAD_NAME;
		    sprintf(tmpbuf,"[%s \"%s\" ]",
                            "defined", lsInfo->resTable[entry].name);
                    sp[t] = '\0';
                    strcat(sp,tmpbuf);
                    t += strlen(tmpbuf);
                    while (resReq[s] == ' ')
                        s++;
                    if (resReq[s] != ')')
                        return (PARSE_BAD_EXP);
                    s++;
                    continue;
                }
                return PARSE_BAD_NAME;
            }
            switch(lsInfo->resTable[entry].valueType) {
                case LS_NUMERIC:
                case LS_BOOLEAN:
                    strcat(res,"()");
                    sp[t] = '\0';
                    strcat(sp,res);
                    t += strlen(res);
                    break;
                case LS_STRING:

                    while(resReq[s] == ' ')
                        s++;


                    if (resReq[s] == '\0' || resReq[s+1] == '\0')
                        return(PARSE_BAD_EXP);


                    op = NULL;
                    if (resReq[s] == '=' && resReq[s+1] == '=') {
                        op = "eq";
                        s += 2;
                    } else if (resReq[s] == '!' && resReq[s+1] == '=') {
                        op = "ne";
                        s += 2;
                    } else if (resReq[s] == '>' && resReq[s+1] == '=') {
                        op = "ge";
                        s += 2;
                    } else if (resReq[s] == '<' && resReq[s+1] == '=') {
                        op = "le";
                        s += 2;
                    } else if (resReq[s] == '<') {
                        op = "lt";
                        s += 1;
                    } else if (resReq[s] == '>') {
                        op = "gt";
                        s += 1;
                    } else {
                        return -1;
                    }

                    while(resReq[s] == ' ')
                        s++;

                    if (resReq[s] == '\''){
                        hasQuote = TRUE;
                        s++;
                    } else
                        hasQuote = FALSE;
                    i = 0;
                    if (!hasQuote){
                        while(IS_LETTER(resReq[s]) || IS_DIGIT(resReq[s]) ||
                              IS_VALID_OTHER(resReq[s]))
                            val[i++] = resReq[s++];
                    } else {
                        while(resReq[s] && resReq[s] != '\'' && i < MAXLSFNAMELEN)
                            val[i++] = resReq[s++];
                        if (i-1 == MAXLSFNAMELEN)
                            return(PARSE_BAD_VAL);
                        if (resReq[s] == '\'')
                            s++;
                    }
                    val[i] = '\0';
                    if (i == 0) {
                        return(PARSE_BAD_VAL);
                    }

                    if (validValue(val, lsInfo, entry) < 0) {
                        return(PARSE_BAD_VAL);
                    }

                    sprintf(tmpbuf,"[%s \"%s\" \"%s\"]",lsInfo->resTable[entry].name
                            ,op,val);
                    sp[t] = '\0';
                    strcat(sp,tmpbuf);
                    t += strlen(tmpbuf);
                default:
                    break;
            }
	    hasFunction = FALSE;
        } else {
            return (PARSE_BAD_EXP);
        }

    }
    sp[t] = '\0';
    resVal->options |= PR_SELECT;
    return(PARSE_OK);
}
예제 #12
0
void IniReader::checkValid( const char* section, const char* key ) const
{
	CHECK( validValue( section, key ), 
		"INI file '%s.ini' cound not find section '%s', key '%s'", 
		m_fileName.c_str(), section, key );
}