/* * @return void */ void xfree (void *ptr) { if ( ptr == NULL ) { #ifdef MEMDEBUG Warn(stderr, "xfree(): arg 1 is NULL"); #endif return; } free (ptr); }
/************************************************************************************************** ACCEPT_TCP_QUERY **************************************************************************************************/ int accept_tcp_query(int fd, int family) { struct sockaddr_in addr4; #if HAVE_IPV6 struct sockaddr_in6 addr6; #endif socklen_t addrlen; int rmt_fd; TASK *t; #if HAVE_IPV6 if (family == AF_INET6) { addrlen = sizeof(struct sockaddr_in6); if ((rmt_fd = accept(fd, (struct sockaddr *)&addr6, &addrlen)) < 0) { return Warn("%s", _("accept (TCPv6)")); } fcntl(rmt_fd, F_SETFL, fcntl(rmt_fd, F_GETFL, 0) | O_NONBLOCK); if (!(t = task_init(NEED_READ, rmt_fd, SOCK_STREAM, AF_INET6, &addr6))) return (-1); } else #endif { addrlen = sizeof(struct sockaddr_in); if ((rmt_fd = accept(fd, (struct sockaddr *)&addr4, &addrlen)) < 0) { return Warn("%s", _("accept (TCP)")); } fcntl(rmt_fd, F_SETFL, fcntl(rmt_fd, F_GETFL, 0) | O_NONBLOCK); if (!(t = task_init(NEED_READ, rmt_fd, SOCK_STREAM, AF_INET, &addr4))) return (-1); } #if DEBUG_ENABLED && DEBUG_TCP Debug("%s: TCP connection accepted", clientaddr(t)); #endif return 0; }
void WinKeyboardMouse::AddMouseEvent(float wheelValue) { CommitMouseMoveEvent(); if (changeCount >= MAX_CHANGE_BUFFER) { Warn("Too many input events!"); return; } InputEvent& ie = inputEvents[changeCount++]; ie.key = KeyName::MOUSE_WHEEL; ie.analogValue = wheelValue; mouseWheel += wheelValue; }
// // SourceTokenizerC::doCommand_warning // void SourceTokenizerC::doCommand_warning(SourceTokenC *) { SourcePosition pos(inStack.back()->getFilename(), inStack.back()->getLineCount(), inStack.back()->getColumn()); std::string msg; char c; while((c = inStack.back()->get()) != '\n') msg += c; if(isSkip()) return; Warn(pos, "#warning%s", msg.c_str()); }
void AICmdAssassinate::Verify() { super::Verify(); if ( m_hstrNode ) { AINode* pNode = g_pAINodeMgr->GetNode(m_hstrNode); if ( !pNode ) { Warn("AICmd \"%s\" - Assassinate node \"%s\" does not exist", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } else if ( pNode->GetType() != AINode::eTypeAssassinate ) { Warn("AICmd \"%s\" - Node \"%s\" is not a assassinate node", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } } else { Warn("AICmd \"%s\" - No assassinate node specified!", ::ToString(m_hstrName)); } }
void AICmdPickupObject::Verify() { super::Verify(); if ( m_hstrNode ) { AINode* pNode = g_pAINodeMgr->GetNode(m_hstrNode); if ( !pNode ) { Warn("AICmd \"%s\" - PickupObject node \"%s\" does not exist", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } else if ( pNode->GetType() != AINode::eTypeCover ) { Warn("AICmd \"%s\" - Node \"%s\" is not a pickupobject node", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } } else { Warn("AICmd \"%s\" - No pickupobject node specified!", ::ToString(m_hstrName)); } }
void AICmdPanic::Verify() { super::Verify(); if ( m_hstrNode ) { AINode* pNode = g_pAINodeMgr->GetNode(m_hstrNode); if ( !pNode ) { Warn("AICmd \"%s\" - Panic node \"%s\" does not exist", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } else if ( pNode->GetType() != AINode::eTypePanic ) { Warn("AICmd \"%s\" - Node \"%s\" is not a panic node", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } } else { Warn("AICmd \"%s\" - No panic node specified!", ::ToString(m_hstrName)); } }
void AICmdAttackFromCover::Verify() { super::Verify(); if ( m_hstrNode ) { AINode* pNode = g_pAINodeMgr->GetNode(m_hstrNode); if ( !pNode ) { Warn("AICmd \"%s\" - Cover node \"%s\" does not exist", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } else if ( pNode->GetType() != AINode::eTypeCover ) { Warn("AICmd \"%s\" - Node \"%s\" is not a cover node", ::ToString(m_hstrName), ::ToString(m_hstrNode)); } } else { Warn("AICmd \"%s\" - No cover node specified!", ::ToString(m_hstrName)); } }
/*! Perform incremental execution with a value wrap. */ void PropFlipVarVi::execIncrWrap(Wrp const & theWrp) { WatchError Warn(theWrp.itemInt() < 0 || theWrp.itemInt() > 1, eOutOfDomain); runPreExecIncr(); mValueRec->updtCurr(mTermSys.ExecClk(), theWrp.itemInt()); #if ExecUpwdLazy runPostExecIncr(); #endif CatchError }
/*! Perform incremental execution with a value. */ void PropFlipVarVi::execIncrValue(Int const & theInt) { WatchError Warn(theInt < 0 || theInt > 1, eOutOfDomain); runPreExecIncr(); mValueRec->updtCurr(mTermSys.ExecClk(), theInt); #if ExecUpwdLazy runPostExecIncr(); #endif CatchError }
/*! Perform anew execution with a value wrap. */ void PropFlipVarVi::execAnewWrap(Wrp const & theWrp) { WatchError Warn(theWrp.itemInt() < 0 || theWrp.itemInt() > 1, eOutOfDomain); runPreExecAnew(); mValueRec->initCurr(theWrp.itemInt()); #if ExecUpwdLazy runPostExecAnew(); #endif CatchError }
/*! Perform anew execution with a value. */ void PropFlipVarVi::execAnewValue(Int const & theInt) { WatchError Warn(theInt < 0 || theInt > 1, eOutOfDomain); runPreExecAnew(); mValueRec->initCurr(theInt); #if ExecUpwdLazy runPostExecAnew(); #endif CatchError }
/*! Call parameters to relist for unreck. */ void FrR::reiterEvalUndoPrms() { WatchError Warn(!this->mTermSys.mskExecMode(IncrProp), eNotExecIncrProp); Warn(!this->mEvalUndonePrms, eNullPointer); #if CompLazyHalf if (this->defered()) #endif { for(Idx tIdx = 0; tIdx < this->mBacklogPrms.tagCount(); ++tIdx) { Pos const tPos = this->mBacklogPrms.serial(tIdx); Term * const tPrmTerm = this->mPrmTerms[tPos]; Term::relistEvalUndoArg(tPrmTerm, this->mPrmLinks[tPos]); } this->mBacklogPrms.sweep(this->mTermSys.ExecClk()); this->mEvalUndonePrms->sweep(this->mTermSys.ExecClk()); } CatchError }
bool C4DefScriptHost::Parse() { bool r = C4ScriptHost::Parse(); assert(Def); // Check category if (!Def->GetPlane() && Def->Category & C4D_SortLimit) { int Plane; bool gotplane = true; switch (Def->Category & C4D_SortLimit) { case C4D_StaticBack: Plane = 100; break; case C4D_Structure: Plane = C4Plane_Structure; break; case C4D_Vehicle: Plane = 300; break; case C4D_Living: Plane = 400; break; case C4D_Object: Plane = 500; break; case C4D_StaticBack | C4D_Background: Plane = -500; break; case C4D_Structure | C4D_Background: Plane = -400; break; case C4D_Vehicle | C4D_Background: Plane = -300; break; case C4D_Living | C4D_Background: Plane = -200; break; case C4D_Object | C4D_Background: Plane = -100; break; case C4D_StaticBack | C4D_Foreground: Plane = 1100; break; case C4D_Structure | C4D_Foreground: Plane = 1200; break; case C4D_Vehicle | C4D_Foreground: Plane = 1300; break; case C4D_Living | C4D_Foreground: Plane = 1400; break; case C4D_Object | C4D_Foreground: Plane = 1500; break; default: Warn("Def %s (%s) has invalid category", Def->GetName(), Def->GetDataString().getData()); gotplane = false; break; } if (gotplane) Def->SetProperty(P_Plane, C4VInt(Plane)); } if (!Def->GetPlane()) { Warn("Def %s (%s) has invalid Plane", Def->GetName(), Def->GetDataString().getData()); Def->SetProperty(P_Plane, C4VInt(1)); } return r; }
void Job::msg( Rdma& rdma, ProcId src, JobMsg& msg ) { JobMap::iterator iter; Debug( Job, "jobId=%d type=%d\n", msg.jobId, msg.type ); pthread_mutex_lock(&m_mutex); if ( msg.type == JobMsg::Load ) { if ( m_jobMap.find( msg.jobId ) != m_jobMap.end() ) { // take care of this error Warn( Job, "duplicate job %d\n", msg.jobId ); goto ret; } Job* job = new Job( rdma, msg.jobId ); if ( ! job ) { Warn( Job, "couldn't create Job %d\n", msg.jobId ); goto ret; } iter = m_jobMap.insert( m_jobMap.begin(), std::make_pair( msg.jobId, job ) ); } else { if ( ( iter = m_jobMap.find( msg.jobId ) ) == m_jobMap.end() ) { // take care of this error Warn( Job, "couldn't find Job %d\n", msg.jobId ); goto ret; } } if ( iter->second->msg( src, msg ) ) { delete iter->second; m_jobMap.erase( iter ); } ret: pthread_mutex_unlock(&m_mutex); }
void XPath::evalFunctionIdGet ( __XPath_Functor_Args ) { __evalArgNodeSet(0); ElementRef rootElement = node.getRootElement(); if ( !rootElement.findAttr(__builtin.xemint.id_match(),AttributeType_XPath) || !rootElement.findAttr(__builtin.xemint.id_use(),AttributeType_XPath) ) { Warn ( "Document '%s' has no attribute defined as ID !\n", rootElement.getDocument().getDocumentTag().c_str() ); return; } XPath matchXPath ( xproc, rootElement, __builtin.xemint.id_match() ); XPath useXPath ( xproc, rootElement, __builtin.xemint.id_use() ); ElementMultiMapRef map = node.getDocument().getKeyMapping ( __builtin.xemint.id_map() ); if ( ! map ) { SKMapConfig config; SKMapRef::initDefaultSKMapConfig ( config ); map = node.getDocument().createKeyMapping ( __builtin.xemint.id_map(), config ); AssertBug ( map, "Could not create SKMultiMapRef !\n" ); XPath scopeXPath ( xproc ); evalFunctionKeyBuild ( rootElement, map, matchXPath, useXPath, scopeXPath, 0 ); } if ( res0.size() == 0 ) { return; } if ( ( res0.size() == 1 ) && ( res0.front().getItemType() == Item::Type_String || res0.front().getItemType() == Item::Type_Attribute ) ) { String res = res0.toString(); std::list<String> tokenList; res.tokenize ( tokenList ); while ( tokenList.size() ) { String token = tokenList.front (); tokenList.pop_front (); evalFunctionKeyGet ( map, useXPath, result, token ); } } else { evalFunctionKeyGet ( map, useXPath, result, res0 ); } }
/************************************************************************************************** READ_UDP_QUERY Returns 0 on success (a task was added), -1 on failure. **************************************************************************************************/ taskexec_t read_udp_query(int fd, int family) { struct sockaddr addr; char in[DNS_MAXPACKETLEN_UDP]; socklen_t addrlen = 0; int len = 0; TASK *t = NULL; taskexec_t rv = TASK_FAILED; memset(&addr, 0, sizeof(addr)); memset(&in, 0, sizeof(in)); /* Read message */ if (family == AF_INET) { addrlen = sizeof(struct sockaddr_in); #if HAVE_IPV6 } else if (family == AF_INET6) { addrlen = sizeof(struct sockaddr_in6); #endif } if ((len = recvfrom(fd, &in, sizeof(in), 0, &addr, &addrlen)) < 0) { if ( (errno == EINTR) #ifdef EAGAIN || (errno == EAGAIN) #else #ifdef EWOULDBLOCK || (errno == EWOULDBLOCK) #endif #endif ) { return (TASK_CONTINUE); } return Warn("%s", _("recvfrom (UDP)")); } if (len == 0) { return (TASK_FAILED); } if (!(t = IOtask_init(HIGH_PRIORITY_TASK, NEED_ANSWER, fd, SOCK_DGRAM, family, &addr))) return (TASK_FAILED); #if DEBUG_ENABLED && DEBUG_UDP DebugX("udp", 1, "%s: %d %s", clientaddr(t), len, _("UDP octets in")); #endif rv = task_new(t, (unsigned char*)in, len); if (rv < TASK_FAILED) { dequeue(t); rv = TASK_FAILED; } return rv; }
/*! Perform incremental simulation with a value. */ void PropFlipVarVi::simulIncrValue(Int const &theInt) { WatchError Warn(theInt < 0 || theInt > 1, eOutOfDomain); runPreSimulIncr(); mValueRec->initNext(mTermSys.SimulClk(), theInt); #if SimulUpwd runPostSimulIncr(); #endif CatchError }
void CCmdProcess::SendToClient(unsigned int flow, Commpack *pPack) { void * pData; int nSize; pPack->Output(pData, nSize); Message msg(flow); msg.AttachMessage((char*) pData, nSize); if (!m_RspQ.Enqueue(msg)) { Warn("enqueue failed flow=[%d]", flow); } }
/*! Perform incremental simulation with a value wrap. */ void PropFlipVarVi::simulIncrWrap(Wrp const & theWrp) { WatchError Warn(theWrp.itemInt() < 0 || theWrp.itemInt() > 1, eOutOfDomain); runPreSimulIncr(); mValueRec->initNext(mTermSys.SimulClk(), theWrp.itemInt()); #if SimulUpwd runPostSimulIncr(); #endif CatchError }
void SetWarn(char *file) { static char fnc[] = "SetWarn"; FILE *fp; if ((fp = fopen(file, "w")) == (FILE *) NULL) Warn("%s fopen(%s): %m\n", fnc, file); else _Warnfp = fp; (void) setbuf(fp, (char *) NULL); return; }
ENTRYPOINT I ipcConnectN(A afunc, A aname) { C *serviceName=getString(aname); int protocolidx; AipcService *nSrv; InitializeIfNeeded(); ipcWarn(0,"%t ipcConnectN:\n"); if (!serviceName||!QF(afunc))return -1; AipcHostPortProtocol *ahpp=new AipcHostPortProtocol(serviceName); // const C *hostName=ahpp->host(); // I port=ahpp->port(); S protocolSym=si((char *)ahpp->protocol()); ipcWarn(0,"%t ipcConnectN: name:%s host:%s port:%d protocol:%s\n", serviceName,ahpp->host(),ahpp->port(),ahpp->protocol()); protocolidx=lookupProtocol(protocolSym); switch(protocolidx) { case 0: nSrv=new pA_Connection(*ahpp,afunc); break; case 1: nSrv=new pRaw_Connection(*ahpp,afunc); break; case 4: nSrv=new pIpc_Connection(*ahpp,afunc); break; case 5: { Warn("%t ipcConnectHPP: unsupported protocol:%s\n",protocolSym->n); return -1; } case 6: nSrv=new pString_Connection(*ahpp,afunc); break; case 7: nSrv=new pSimple_Connection(*ahpp,afunc); break; default: /* unknown protocol */ Warn("%t ipcConnectN: unknown protocol:%s\n",protocolSym->n); return -1; } return nSrv->handle(); }
ENTRYPOINT I ipcConnectNHPP(A afunc, A aname, A ahost, I port, A aprotocol) { C *serviceName=getString(aname); C *hostName=getString(ahost); S protocolSym=getSymbol(aprotocol); int protocolidx; AipcService *nSrv; InitializeIfNeeded(); ipcWarn(0,"%t ipcConnectNHPP:\n"); if (!serviceName||!hostName||!protocolSym||!QF(afunc))return -1; ipcWarn(0,"%t ipcConnectNHPP: name:%s host:%s port:%d protocol:%s\n", serviceName,hostName,port,protocolSym->n); protocolidx=lookupProtocol(protocolSym); switch(protocolidx) { case 0: nSrv=new pA_Connection(serviceName,hostName,port,afunc); break; case 1: nSrv=new pRaw_Connection(serviceName,hostName,port,afunc); break; case 2: Warn("%t ipcConnectHPP: unsupported protocol:%s\n",protocolSym->n); return -1; break; case 4: nSrv=new pIpc_Connection(serviceName,hostName,port,afunc); break; case 5: Warn("%t ipcConnectHPP: unsupported protocol:%s\n",protocolSym->n); return -1; break; case 6: nSrv=new pString_Connection(serviceName,hostName,port,afunc); break; case 7: nSrv=new pSimple_Connection(serviceName,hostName,port,afunc); break; default: /* unknown protocol */ Warn("%t ipcConnectHPP: unknown protocol:%s\n",protocolSym->n); return -1; } return nSrv->handle(); }
int create_timer(on_time function, const int _interval, const int id){ pthread_t tid; if(function == NULL || _interval <= 0) { Warn("param error!function[%p] _interval[%d]", function, _interval); } st_thread_param *p = FT_MALLOC(sizeof(st_thread_param)); p->func = function; p->interval = _interval; p->id = id; FT_THREAD_CREATE(&tid, __timer_thread, p); return tid; }
void Job::start() { Debug( Job, "\n"); sendChildStart( ); m_app->Start(); if ( pthread_create( &m_thread, NULL, thread, this ) ) { Warn( Job, "pthread_create() failed, %s\n", strerror(errno) ); throw -1; } }
void AICmdInvestigate::Verify() { super::Verify(); if ( LT_INSIDE != g_pLTServer->Common()->GetPointStatus(&m_vPosition) ) { Warn("AICmd \"%s\" - Position %s is not in the world", ::ToString(m_hstrName), ::ToString(m_vPosition)); } if ( !!m_hstrEnemy ) { HOBJECT hObject; if ( LT_OK != FindNamedObject(g_pLTServer->GetStringData(m_hstrEnemy), hObject) ) { Warn("AICmd \"%s\" - Could not find enemy \"%s\"", ::ToString(m_hstrName), ::ToString(m_hstrEnemy)); } } else { Warn("AICmd \"%s\" - No enemy specified", ::ToString(m_hstrName)); } }
/* Function: read_kT() * * Purpose: Read one line from the simulated annealing schedule file. * Ignore comments (lines that start with #) and blank lines. * First field is a float, which is the kT (temperature) value, * typically ranging from 10.0 down to 0.1. * * Returns 0 when the file is empty. */ static int read_kT(FILE *schedfp, float *ret_kT) { char buffer[256]; char *sptr; float kT; do { if (fgets(buffer, 256, schedfp) == NULL) return 0; /* out of data */ } while (*buffer == '#' || (sptr = strtok(buffer, " \t\n")) == NULL); kT = atof(sptr); if (kT > 10.0) { Warn("Trying to melt it? kT reset from %.2f to 10.0", kT); kT = 10.0; } if (kT < 0.1) { Warn("kT < 0.1 may cause numerical problems; reset from %.2f to 0.1", kT); kT = 0.1; } *ret_kT = kT; return 1; }
StdBuf StdCompilerINIRead::ReadString(size_t iLength, RawCompileType eRawType, bool fAppendNull) { // Excpect valid position if (!pPos) { notFound("String"); return StdBuf(); } // Skip whitespace SkipWhitespace(); // Escaped? Go over '"' if (eRawType == RCT_Escaped && *pPos++ != '"') { notFound("Escaped string"); return StdBuf(); } // Create buffer StdBuf OutBuf; OutBuf.New(iLength + (fAppendNull ? sizeof('\0') : 0)); // Read char *pOut = getMBufPtr<char>(OutBuf); while (iLength && !TestStringEnd(eRawType)) { // Read a character if (eRawType == RCT_Escaped) *pOut++ = ReadEscapedChar(); else *pOut++ = *pPos++; // Count it iLength--; } // Escaped: Go over '"' if (eRawType == RCT_Escaped) { while (*pPos != '"') { if (!*pPos || *pPos == '\n' || *pPos == '\r') { Warn("string not terminated!"); pPos--; break; } pPos++; } pPos++; } // Nothing read? Identifiers need to be non-empty if (pOut == OutBuf.getData() && (eRawType == RCT_Idtf || eRawType == RCT_ID)) { notFound("String"); return StdBuf(); } // Append null if (fAppendNull) *pOut = '\0'; // Shrink, if less characters were read OutBuf.Shrink(iLength); // Done return OutBuf; }
bool AssetManager::LoadAsset (const csString& normpath, const csString& file, const csString& mount, iCollection* collection) { csRef<iString> path; if (!normpath.IsEmpty ()) { csRef<scfStringArray> fullPath = ConstructPath (); path = FindAsset (fullPath, normpath, file); if (!path) return Error ("Cannot find asset '%s' in the asset path!\n", normpath.GetData ()); } csString rmount; if (mount.IsEmpty ()) { rmount.Format ("/assets/__mnt_%d__/", mntCounter); mntCounter++; } else { rmount = mount; } if (path) { vfs->Mount (rmount, path->GetData ()); printf ("Mounting '%s' to '%s'\n", path->GetData (), rmount.GetData ()); fflush (stdout); } vfs->PushDir (rmount); // If the file doesn't exist we don't try to load it. That's not an error // as it might be saved later. bool exists = vfs->Exists (file); vfs->PopDir (); if (exists) { if (!LoadLibrary (rmount, file, collection)) return false; } else { Warn ("Warning! File '%s/%s' does not exist!\n", (!path) ? rmount.GetData () : path->GetData (), file.GetData ()); } //if (!path.IsEmpty ()) //vfs->Unmount (rmount, path); return true; }
/* enlist the current directory. */ F FEnlDir( register AD *pad ) { F fOk; CheckForBreak(); if (!FLoadStatus(pad, lckAll, flsExtraEd)) { Warn("not yet enlisted in %&P/C, enlist again later\n", pad); return fTrue; /* keep trying other dirs */ } if (pad->iedCur != iedNil) { Warn("directory %!&/U/Q already enlisted in %&P/C\n", pad, pad); FlushStatus(pad); return fTrue; } OpenLog(pad, fTrue); AddCurEd(pad, (pad->flags&flagGhost) != 0); FUpdateIedCache(pad->iedCur, pad); if (pad->flags&flagSyncFiles) MarkAll(pad); else MarkAllDirOnly(pad); fOk = FSyncMarked(pad, NULL); CloseLog(); FlushStatus(pad); return fOk; }