TiXmlNode * SpaceObject::WriteNode(TiXmlNode * node, const Player * viewer) const { if (!SeenBy(viewer)) return NULL; if (mAlsoHere && mAlsoHere->at(0) != this && dynamic_cast<Planet *>(mAlsoHere->at(0)) != NULL) { TiXmlElement *loc = new TiXmlElement("Location"); AddString(loc, "Planet", mAlsoHere->at(0)->GetName(NULL).c_str()); node->LinkEndChild(loc); } else Location::WriteNode(node); if (SeenBy(viewer) & SEEN_OWNER) { if (GetOwner() == NULL) AddLong(node, "Owner", 0); else AddLong(node, "Owner", GetOwner()->GetID()); } assert(mID != 0); TiXmlElement * tie = node->ToElement(); tie->SetAttribute("IDNumber", mID); if (viewer == NULL) node->LinkEndChild(Rules::WriteArray("SeenBy", "Race", "Number", mSeenBy)); return node; }
globle void StrIndexFunction( DATA_OBJECT_PTR result) { DATA_OBJECT theArgument1, theArgument2; char *strg1, *strg2; int i, j; result->type = SYMBOL; result->value = FalseSymbol; /*===================================*/ /* Check and retrieve the arguments. */ /*===================================*/ if (ArgCountCheck("str-index",EXACTLY,2) == -1) return; if (ArgTypeCheck("str-index",1,SYMBOL_OR_STRING,&theArgument1) == FALSE) return; if (ArgTypeCheck("str-index",2,SYMBOL_OR_STRING,&theArgument2) == FALSE) return; strg1 = DOToString(theArgument1); strg2 = DOToString(theArgument2); /*=================================*/ /* Find the position in string2 of */ /* string1 (counting from 1). */ /*=================================*/ if (strlen(strg1) == 0) { result->type = INTEGER; result->value = (void *) AddLong((long) strlen(strg2) + 1L); return; } for (i=1; *strg2; i++, strg2++) { for (j=0; *(strg1+j) && *(strg1+j) == *(strg2+j); j++) { /* Do Nothing */ } if (*(strg1+j) == '\0') { result->type = INTEGER; result->value = (void *) AddLong((long) i); return; } } return; }
static void ReplaceLoopCountVars( SYMBOL_HN *loopVar, EXPRESSION *exp, int depth) { while (exp != NULL) { if ((exp->type != SF_VARIABLE) ? FALSE : (strcmp(ValueToString(exp->value),ValueToString(loopVar)) == 0)) { exp->type = FCALL; exp->value = (void *) FindFunction("(get-loop-count)"); exp->argList = GenConstant(INTEGER,AddLong((long) depth)); } else if (exp->argList != NULL) { if ((exp->type != FCALL) ? FALSE : (exp->value == (void *) FindFunction("loop-for-count"))) ReplaceLoopCountVars(loopVar,exp->argList,depth+1); else ReplaceLoopCountVars(loopVar,exp->argList,depth); } exp = exp->nextArg; } }
void ParseMessage(uint64_t seqno, const char *buf) { switch (buf[1]) { case 0x21: return AddLong(seqno, buf); case 0x22: return AddShort(seqno, buf); case 0x2F: return AddExpanded(seqno, buf); case 0x23: return Executed(seqno, buf); case 0x24: return ExecutedAtPriceSize(seqno, buf); case 0x25: return ReduceLong(seqno, buf); case 0x26: return ReduceShort(seqno, buf); case 0x27: return ModifyLong(seqno, buf); case 0x28: return ModifyShort(seqno, buf); case 0x29: return Delete(seqno, buf); case 0x2A: return TradeLong(seqno, buf); case 0x2B: return TradeShort(seqno, buf); case 0x30: return TradeExpanded(seqno, buf); } }
TiXmlNode * TransportOrder::WriteNode(TiXmlNode * node) const { TiXmlElement * trans = new TiXmlElement("Transfer"); TiXmlElement * owned = new TiXmlElement("Owned"); mOwned->WriteTransport(owned); trans->LinkEndChild(owned); CargoHolder * ch; TempFleet * tf = dynamic_cast<TempFleet *>(mOther); if (tf == NULL) ch = mOther; else ch = tf->GetRealCH(); TiXmlElement * other = new TiXmlElement("Other"); if (ch == NULL) other->LinkEndChild(new TiXmlElement("Space")); else ch->WriteTransport(other); trans->LinkEndChild(other); TiXmlElement * cargo = Rules::WriteCargo(trans, "Cargo", mCargo, mPop); if (mFuel != 0) AddLong(cargo, "Fuel", mFuel); node->LinkEndChild(trans); return trans; }
TiXmlNode * WaypointOrder::WriteNode(TiXmlNode * node) const { TiXmlNode * wo = TypedListOrder<WayOrder>::WriteNode(node); if (wo != NULL) AddLong(wo, "Fleet", mFleet); return wo; }
static void UpdateType( void *buf, long obji) { #if OBJECT_SYSTEM typeArray[obji] = (void *) DefclassPointer(* (long *) buf); #else if ((* (long *) buf) > (long) INSTANCE_TYPE_CODE) { PrintWarningID("GENRCBIN",1,FALSE); PrintRouter(WWARNING,"COOL not installed! User-defined class\n"); PrintRouter(WWARNING," in method restriction substituted with OBJECT.\n"); typeArray[obji] = (void *) AddLong((long) OBJECT_TYPE_CODE); } else typeArray[obji] = (void *) AddLong(* (long *) buf); IncrementIntegerCount((INTEGER_HN *) typeArray[obji]); #endif }
TiXmlNode * Salvage::WriteNode(TiXmlNode * node, const Player * viewer) const { if (viewer != NULL && !SeenBy(viewer)) return NULL; CargoHolder::WriteNode(node, viewer); if (viewer == NULL) AddLong(node, "TurnCreated", TurnCreated); return node; }
TiXmlNode * CargoHolder::WriteTransport(TiXmlNode * node) const { const Planet * p = dynamic_cast<const Planet *>(this); if (p != NULL) { AddString(node, "Planet", p->GetName().c_str()); return node; } const Fleet * f = dynamic_cast<const Fleet *>(this); if (f != NULL) { AddLong(node, "Fleet", GetID()); AddLong(node, "Owner", GetOwner()->GetID()); return node; } // const Packet * pac = dynamic_cast<const Packet *>(this); // if (pac != NULL) { // return node; // } return node; }
void VJSONArrayWriter::AddWords(const sWORD *inArray, sLONG inCountOfElements) { if(testAssert(inArray != NULL && inCountOfElements >= 0)) { if(inCountOfElements > 0) { _ReopenIfNeeded(); for(sLONG i = 0; i < inCountOfElements; ++i) AddLong((sLONG) *inArray++); //Add(VLong( (sLONG) (*inArray++))); } } }
struct lhsParseNode *RestrictionParse( char *readSource, struct token *theToken, int multifieldSlot, struct symbolHashNode *theSlot, int slotNumber, CONSTRAINT_RECORD *theConstraints, int position) { struct lhsParseNode *topNode = NULL, *lastNode = NULL, *nextNode; int numberOfSingleFields = 0; int numberOfMultifields = 0; int startPosition = position; int error = FALSE; CONSTRAINT_RECORD *tempConstraints; /*==================================================*/ /* Keep parsing fields until a right parenthesis is */ /* encountered. This will either indicate the end */ /* of an instance or deftemplate slot or the end of */ /* an ordered fact. */ /*==================================================*/ while (theToken->type != RPAREN) { /*========================================*/ /* Look for either a single or multifield */ /* wildcard or a conjuctive restriction. */ /*========================================*/ if ((theToken->type == SF_WILDCARD) || (theToken->type == MF_WILDCARD)) { nextNode = GetLHSParseNode(); nextNode->type = theToken->type; nextNode->negated = FALSE; GetToken(readSource,theToken); } else { nextNode = ConjuctiveRestrictionParse(readSource,theToken,&error); if (nextNode == NULL) { ReturnLHSParseNodes(topNode); return(NULL); } } /*========================================================*/ /* Fix up the pretty print representation of a multifield */ /* slot so that the fields don't run together. */ /*========================================================*/ if ((theToken->type != RPAREN) && (multifieldSlot == TRUE)) { PPBackup(); SavePPBuffer(" "); SavePPBuffer(theToken->printForm); } /*========================================*/ /* Keep track of the number of single and */ /* multifield restrictions encountered. */ /*========================================*/ if ((nextNode->type == SF_WILDCARD) || (nextNode->type == SF_VARIABLE)) { numberOfSingleFields++; } else { numberOfMultifields++; } /*===================================*/ /* Assign the slot name and indices. */ /*===================================*/ nextNode->slot = theSlot; nextNode->slotNumber = slotNumber; nextNode->index = position++; /*==============================================*/ /* If we're not dealing with a multifield slot, */ /* attach the constraints directly to the node */ /* and return. */ /*==============================================*/ if (! multifieldSlot) { if (theConstraints == NULL) { if (nextNode->type == SF_VARIABLE) { nextNode->constraints = GetConstraintRecord(); } else nextNode->constraints = NULL; } else nextNode->constraints = theConstraints; return(nextNode); } /*====================================================*/ /* Attach the restriction to the list of restrictions */ /* already parsed for this slot or ordered fact. */ /*====================================================*/ if (lastNode == NULL) topNode = nextNode; else lastNode->right = nextNode; lastNode = nextNode; } /*=====================================================*/ /* Once we're through parsing, check to make sure that */ /* a single field slot was given a restriction. If the */ /* following test fails, then we know we're dealing */ /* with a multifield slot. */ /*=====================================================*/ if ((topNode == NULL) && (! multifieldSlot)) { SyntaxErrorMessage("defrule"); return(NULL); } /*===============================================*/ /* Loop through each of the restrictions in the */ /* list of restrictions for the multifield slot. */ /*===============================================*/ for (nextNode = topNode; nextNode != NULL; nextNode = nextNode->right) { /*===================================================*/ /* Assign a constraint record to each constraint. If */ /* the slot has an explicit constraint, then copy */ /* this and store it with the constraint. Otherwise, */ /* create a constraint record for a single field */ /* constraint and skip the constraint modifications */ /* for a multifield constraint. */ /*===================================================*/ if (theConstraints == NULL) { if (nextNode->type == SF_VARIABLE) { nextNode->constraints = GetConstraintRecord(); } else { continue; } } else { nextNode->constraints = CopyConstraintRecord(theConstraints); } /*==========================================*/ /* Remove the min and max field constraints */ /* for the entire slot from the constraint */ /* record for this single constraint. */ /*==========================================*/ ReturnExpression(nextNode->constraints->minFields); ReturnExpression(nextNode->constraints->maxFields); nextNode->constraints->minFields = GenConstant(SYMBOL,NegativeInfinity); nextNode->constraints->maxFields = GenConstant(SYMBOL,PositiveInfinity); nextNode->derivedConstraints = TRUE; /*====================================================*/ /* If we're not dealing with a multifield constraint, */ /* then no further modifications are needed to the */ /* min and max constraints for this constraint. */ /*====================================================*/ if ((nextNode->type != MF_WILDCARD) && (nextNode->type != MF_VARIABLE)) { continue; } /*==========================================================*/ /* Create a separate constraint record to keep track of the */ /* cardinality information for this multifield constraint. */ /*==========================================================*/ tempConstraints = GetConstraintRecord(); SetConstraintType(MULTIFIELD,tempConstraints); tempConstraints->singlefieldsAllowed = FALSE; tempConstraints->multifield = nextNode->constraints; nextNode->constraints = tempConstraints; /*=====================================================*/ /* Adjust the min and max field values for this single */ /* multifield constraint based on the min and max */ /* fields for the entire slot and the number of single */ /* field values contained in the slot. */ /*=====================================================*/ if (theConstraints->maxFields->value != PositiveInfinity) { ReturnExpression(tempConstraints->maxFields); tempConstraints->maxFields = GenConstant(INTEGER,AddLong(ValueToLong(theConstraints->maxFields->value) - numberOfSingleFields)); } if ((numberOfMultifields == 1) && (theConstraints->minFields->value != NegativeInfinity)) { ReturnExpression(tempConstraints->minFields); tempConstraints->minFields = GenConstant(INTEGER,AddLong(ValueToLong(theConstraints->minFields->value) - numberOfSingleFields)); } } /*================================================*/ /* If a multifield slot is being parsed, place a */ /* node on top of the list of constraints parsed. */ /*================================================*/ if (multifieldSlot) { nextNode = GetLHSParseNode(); nextNode->type = MF_WILDCARD; nextNode->multifieldSlot = TRUE; nextNode->bottom = topNode; nextNode->slot = theSlot; nextNode->slotNumber = slotNumber; nextNode->index = startPosition; nextNode->constraints = theConstraints; topNode = nextNode; TallyFieldTypes(topNode->bottom); } /*=================================*/ /* Return the list of constraints. */ /*=================================*/ return(topNode); }
static BOOLEAN MultifieldCardinalityViolation( struct lhsParseNode *theNode) { struct lhsParseNode *tmpNode; struct expr *tmpMax; long minFields = 0; long maxFields = 0; int posInfinity = FALSE; CONSTRAINT_RECORD *newConstraint, *tempConstraint; /*================================*/ /* A single field slot can't have */ /* a cardinality violation. */ /*================================*/ if (theNode->multifieldSlot == FALSE) return(FALSE); /*=============================================*/ /* Determine the minimum and maximum number of */ /* fields the slot could contain based on the */ /* slot constraints found in the pattern. */ /*=============================================*/ for (tmpNode = theNode->bottom; tmpNode != NULL; tmpNode = tmpNode->right) { /*====================================================*/ /* A single field variable increases both the minimum */ /* and maximum number of fields by one. */ /*====================================================*/ if ((tmpNode->type == SF_VARIABLE) || (tmpNode->type == SF_WILDCARD)) { minFields++; maxFields++; } /*=================================================*/ /* Otherwise a multifield wildcard or variable has */ /* been encountered. If it is constrained then use */ /* minimum and maximum number of fields constraint */ /* associated with this LHS node. */ /*=================================================*/ else if (tmpNode->constraints != NULL) { /*=======================================*/ /* The lowest minimum of all the min/max */ /* pairs will be the first in the list. */ /*=======================================*/ if (tmpNode->constraints->minFields->value != NegativeInfinity) { minFields += ValueToLong(tmpNode->constraints->minFields->value); } /*=========================================*/ /* The greatest maximum of all the min/max */ /* pairs will be the last in the list. */ /*=========================================*/ tmpMax = tmpNode->constraints->maxFields; while (tmpMax->nextArg != NULL) tmpMax = tmpMax->nextArg; if (tmpMax->value == PositiveInfinity) { posInfinity = TRUE; } else { maxFields += ValueToLong(tmpMax->value); } } /*================================================*/ /* Otherwise an unconstrained multifield wildcard */ /* or variable increases the maximum number of */ /* fields to positive infinity. */ /*================================================*/ else { posInfinity = TRUE; } } /*==================================================================*/ /* Create a constraint record for the cardinality of the sum of the */ /* cardinalities of the restrictions inside the multifield slot. */ /*==================================================================*/ if (theNode->constraints == NULL) tempConstraint = GetConstraintRecord(); else tempConstraint = CopyConstraintRecord(theNode->constraints); ReturnExpression(tempConstraint->minFields); ReturnExpression(tempConstraint->maxFields); tempConstraint->minFields = GenConstant(INTEGER,AddLong((long) minFields)); if (posInfinity) tempConstraint->maxFields = GenConstant(SYMBOL,PositiveInfinity); else tempConstraint->maxFields = GenConstant(INTEGER,AddLong((long) maxFields)); /*================================================================*/ /* Determine the final cardinality for the multifield slot by */ /* intersecting the cardinality sum of the restrictions within */ /* the multifield slot with the original cardinality of the slot. */ /*================================================================*/ newConstraint = IntersectConstraints(theNode->constraints,tempConstraint); if (theNode->derivedConstraints) RemoveConstraint(theNode->constraints); RemoveConstraint(tempConstraint); theNode->constraints = newConstraint; theNode->derivedConstraints = TRUE; /*===================================================================*/ /* Determine if the final cardinality for the slot can be satisfied. */ /*===================================================================*/ if (GetStaticConstraintChecking() == FALSE) return(FALSE); if (UnmatchableConstraint(newConstraint)) return(TRUE); return(FALSE); }
static struct expr *LoopForCountParse( struct expr *parse, char *infile) { struct token theToken; SYMBOL_HN *loopVar = NULL; EXPRESSION *tmpexp; int read_first_paren; struct BindInfo *oldBindList,*newBindList,*prev; /*======================================*/ /* Process the loop counter expression. */ /*======================================*/ SavePPBuffer(" "); GetToken(infile,&theToken); /* ========================================== Simple form: loop-for-count <end> [do] ... ========================================== */ if (theToken.type != LPAREN) { parse->argList = GenConstant(INTEGER,AddLong(1L)); parse->argList->nextArg = ParseAtomOrExpression(infile,&theToken); if (parse->argList->nextArg == NULL) { ReturnExpression(parse); return(NULL); } } else { GetToken(infile,&theToken); if (theToken.type != SF_VARIABLE) { if (theToken.type != SYMBOL) goto LoopForCountParseError; parse->argList = GenConstant(INTEGER,AddLong(1L)); parse->argList->nextArg = Function2Parse(infile,ValueToString(theToken.value)); if (parse->argList->nextArg == NULL) { ReturnExpression(parse); return(NULL); } } /* ============================================================= Complex form: loop-for-count (<var> [<start>] <end>) [do] ... ============================================================= */ else { loopVar = (SYMBOL_HN *) theToken.value; SavePPBuffer(" "); parse->argList = ParseAtomOrExpression(infile,NULL); if (parse->argList == NULL) { ReturnExpression(parse); return(NULL); } if (CheckArgumentAgainstRestriction(parse->argList,(int) 'i')) goto LoopForCountParseError; SavePPBuffer(" "); GetToken(infile,&theToken); if (theToken.type == RPAREN) { PPBackup(); PPBackup(); SavePPBuffer(theToken.printForm); tmpexp = GenConstant(INTEGER,AddLong(1L)); tmpexp->nextArg = parse->argList; parse->argList = tmpexp; } else { parse->argList->nextArg = ParseAtomOrExpression(infile,&theToken); if (parse->argList->nextArg == NULL) { ReturnExpression(parse); return(NULL); } GetToken(infile,&theToken); if (theToken.type != RPAREN) goto LoopForCountParseError; } SavePPBuffer(" "); } } if (CheckArgumentAgainstRestriction(parse->argList->nextArg,(int) 'i')) goto LoopForCountParseError; /*====================================*/ /* Process the do keyword if present. */ /*====================================*/ GetToken(infile,&theToken); if ((theToken.type == SYMBOL) && (strcmp(ValueToString(theToken.value),"do") == 0)) { read_first_paren = TRUE; PPBackup(); SavePPBuffer(" "); SavePPBuffer(theToken.printForm); IncrementIndentDepth(3); PPCRAndIndent(); } else if (theToken.type == LPAREN) { read_first_paren = FALSE; PPBackup(); IncrementIndentDepth(3); PPCRAndIndent(); SavePPBuffer(theToken.printForm); } else goto LoopForCountParseError; /*=====================================*/ /* Process the loop-for-count actions. */ /*=====================================*/ if (svContexts->rtn == TRUE) ReturnContext = TRUE; BreakContext = TRUE; oldBindList = GetParsedBindNames(); SetParsedBindNames(NULL); parse->argList->nextArg->nextArg = GroupActions(infile,&theToken,read_first_paren,NULL,FALSE); if (parse->argList->nextArg->nextArg == NULL) { SetParsedBindNames(oldBindList); ReturnExpression(parse); return(NULL); } newBindList = GetParsedBindNames(); prev = NULL; while (newBindList != NULL) { if ((loopVar == NULL) ? FALSE : (strcmp(ValueToString(newBindList->name),ValueToString(loopVar)) == 0)) { ClearParsedBindNames(); SetParsedBindNames(oldBindList); PrintErrorID("PRCDRPSR",1,TRUE); PrintRouter(WERROR,"Cannot rebind loop variable in function loop-for-count.\n"); ReturnExpression(parse); return(NULL); } prev = newBindList; newBindList = newBindList->next; } if (prev == NULL) SetParsedBindNames(oldBindList); else prev->next = oldBindList; if (loopVar != NULL) ReplaceLoopCountVars(loopVar,parse->argList->nextArg->nextArg,0); PPBackup(); PPBackup(); SavePPBuffer(theToken.printForm); /*================================================================*/ /* Check for the closing right parenthesis of the loop-for-count. */ /*================================================================*/ if (theToken.type != RPAREN) { SyntaxErrorMessage("loop-for-count function"); ReturnExpression(parse); return(NULL); } DecrementIndentDepth(3); return(parse); LoopForCountParseError: SyntaxErrorMessage("loop-for-count function"); ReturnExpression(parse); return(NULL); }
globle int EvaluateExpression( struct expr *problem, DATA_OBJECT_PTR returnValue) { struct expr *oldArgument; struct FunctionDefinition *fptr; #if PROFILING_FUNCTIONS struct profileFrameInfo profileFrame; #endif if (problem == NULL) { returnValue->type = SYMBOL; returnValue->value = FalseSymbol; return(EvaluationError); } switch (problem->type) { case STRING: case SYMBOL: case FLOAT: case INTEGER: #if OBJECT_SYSTEM case INSTANCE_NAME: case INSTANCE_ADDRESS: #endif #if FUZZY_DEFTEMPLATES case FUZZY_VALUE: #endif case EXTERNAL_ADDRESS: returnValue->type = problem->type; returnValue->value = problem->value; break; #if FUZZY_DEFTEMPLATES case S_FUNCTION: case PI_FUNCTION: case Z_FUNCTION: case SINGLETON_EXPRESSION: /* At some time it may be worthwhile making this into an FCALL but only when we allow user's to create functions that return fuzzy values -- this may not happen */ { struct fuzzy_value *fvptr; fvptr = getConstantFuzzyValue(problem, &EvaluationError); returnValue->type = FUZZY_VALUE; if (fvptr != NULL) { returnValue->value = (VOID *)AddFuzzyValue(fvptr); /* AddFuzzyValue makes a copy of the fuzzy value -- so remove this one */ rtnFuzzyValue(fvptr); } else { returnValue->type = RVOID; returnValue->value = CLIPSFalseSymbol; SetEvaluationError(TRUE); } } break; #endif case FCALL: { fptr = (struct FunctionDefinition *) problem->value; #if PROFILING_FUNCTIONS StartProfile(&profileFrame, &fptr->usrData, ProfileUserFunctions); #endif oldArgument = CurrentExpression; CurrentExpression = problem; switch(fptr->returnValueType) { case 'v' : (* (void (*)(void)) fptr->functionPointer)(); returnValue->type = RVOID; returnValue->value = FalseSymbol; break; case 'b' : returnValue->type = SYMBOL; if ((* (int (*)(void)) fptr->functionPointer)()) returnValue->value = TrueSymbol; else returnValue->value = FalseSymbol; break; case 'a' : returnValue->type = EXTERNAL_ADDRESS; returnValue->value = (* (void *(*)(void)) fptr->functionPointer)(); break; case 'i' : returnValue->type = INTEGER; returnValue->value = (void *) AddLong((long) (* (int (*)(void)) fptr->functionPointer)()); break; case 'l' : returnValue->type = INTEGER; returnValue->value = (void *) AddLong((* (long int (*)(void)) fptr->functionPointer)()); break; #if FUZZY_DEFTEMPLATES case 'F' : { struct fuzzy_value *fvPtr; fvPtr = (* (struct fuzzy_value * (*)(VOID_ARG)) fptr->functionPointer)(); if (fvPtr != NULL) { returnValue->type = FUZZY_VALUE; returnValue->value = (VOID *)AddFuzzyValue( fvPtr ); /* AddFuzzyValue makes a copy of fv .. so return it */ rtnFuzzyValue( fvPtr ); } else { returnValue->type = RVOID; returnValue->value = CLIPSFalseSymbol; } } break; #endif case 'f' : returnValue->type = FLOAT; returnValue->value = (void *) AddDouble((double) (* (float (*)(void)) fptr->functionPointer)()); break; case 'd' : returnValue->type = FLOAT; returnValue->value = (void *) AddDouble((* (double (*)(void)) fptr->functionPointer)()); break; case 's' : returnValue->type = STRING; returnValue->value = (void *) (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)(); break; case 'w' : returnValue->type = SYMBOL; returnValue->value = (void *) (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)(); break; #if OBJECT_SYSTEM case 'x' : returnValue->type = INSTANCE_ADDRESS; returnValue->value = (* (void *(*)(void)) fptr->functionPointer)(); break; case 'o' : returnValue->type = INSTANCE_NAME; returnValue->value = (void *) (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)(); break; #endif case 'c' : { char cbuff[2]; cbuff[0] = (* (char (*)(void)) fptr->functionPointer)(); cbuff[1] = EOS; returnValue->type = SYMBOL; returnValue->value = (void *) AddSymbol(cbuff); break; } case 'j' : case 'k' : case 'm' : case 'n' : case 'u' : (* (void (*)(DATA_OBJECT_PTR)) fptr->functionPointer)(returnValue); break; default : SystemError("EVALUATN",2); ExitRouter(EXIT_FAILURE); break; } #if PROFILING_FUNCTIONS EndProfile(&profileFrame); #endif CurrentExpression = oldArgument; break; } case MULTIFIELD: returnValue->type = MULTIFIELD; returnValue->value = ((DATA_OBJECT_PTR) (problem->value))->value; returnValue->begin = ((DATA_OBJECT_PTR) (problem->value))->begin; returnValue->end = ((DATA_OBJECT_PTR) (problem->value))->end; break; case MF_VARIABLE: case SF_VARIABLE: if (GetBoundVariable(returnValue,(SYMBOL_HN *) problem->value) == FALSE) { PrintErrorID("EVALUATN",1,FALSE); PrintRouter(WERROR,"Variable "); PrintRouter(WERROR,ValueToString(problem->value)); PrintRouter(WERROR," is unbound\n"); returnValue->type = SYMBOL; returnValue->value = FalseSymbol; SetEvaluationError(TRUE); } break; default: if (PrimitivesArray[problem->type] == NULL) { SystemError("EVALUATN",3); ExitRouter(EXIT_FAILURE); } if (PrimitivesArray[problem->type]->copyToEvaluate) { returnValue->type = problem->type; returnValue->value = problem->value; break; } if (PrimitivesArray[problem->type]->evaluateFunction == NULL) { SystemError("EVALUATN",4); ExitRouter(EXIT_FAILURE); } oldArgument = CurrentExpression; CurrentExpression = problem; #if PROFILING_FUNCTIONS StartProfile(&profileFrame, &PrimitivesArray[problem->type]->usrData, ProfileUserFunctions); #endif (*PrimitivesArray[problem->type]->evaluateFunction)(problem->value,returnValue); #if PROFILING_FUNCTIONS EndProfile(&profileFrame); #endif CurrentExpression = oldArgument; break; } PropagateReturnValue(returnValue); return(EvaluationError); }
/*-deref or pk_tpn can fill malloced space, then can use this to get to a m.f.*/ VOID tpn_to_mf(DATA_OBJECT_PTR rp) { int num=1,stride=1,*pi,offset=0,i; float *pf; double *pd; char tstr[9],type,*pc,t1[2]; VOID *mfp; t1[1]='\0'; /*get the type*/ sprintf(tstr,"%s",(char *)RtnLexeme(1)); type = tolower(tstr[0]); if(type!='i' && type!='f' && type!='d' && type!='b') { printf("[1st arg=type:i or f or d]"); return; } /*get number (& offset & stride) to put to a m.f.*/ if(RtnArgCount() > 2) num=(int)RtnLong(3); if(RtnArgCount() > 3) offset=(int)RtnLong(4); if(RtnArgCount() > 4) stride=(int)RtnLong(5); /*could use SetMultifieldErrorValue(rp); return;*/ mfp = CreateMultifield(num); /*get the ptr, and set the MF*/ switch(type) { case 'i' : pi = (int *)get_ptr(2); for(i=0; i<num; i++) { SetMFType(mfp,i,INTEGER); SetMFValue(mfp,i,AddLong(pi[offset+i])); } break; case 'f' : pf = (float *)get_ptr(2); for(i=0; i<num; i++) { printf("%f to mf,",pf[offset+i]); fflush(stdout); SetMFType(mfp,i,FLOAT); SetMFValue(mfp,i,AddDouble((double)pf[offset+i])); } break; case 'd' : pd = (double *)get_ptr(2); for(i=0; i<num; i++) { SetMFType(mfp,i,FLOAT); SetMFValue(mfp,i,AddDouble(pd[offset+i])); } break; /*this one could go per char or by stride or by space breaks*/ /*go by char for now*/ case 'b' : pc = (char *)get_ptr(2); for(i=0; i<num; i++) { SetMFType(mfp,i,SYMBOL); t1[0]=pc[offset+i]; SetMFValue(mfp,i,AddSymbol(t1)); } break; } /*gets past this and dies when printing out the result- -looks liked capped ok though*/ SetpType(rp,MULTIFIELD); SetpValue(rp,mfp); SetpDOBegin(rp,1); SetpDOEnd(rp,num); return; }
LWorkItem& LWorkItem::operator<<(long lData) { AddLong(lData); return *this; }