void TrimSpace(const char *source, char *dest) { int start, end, length; length = Q_strlen(source); for (start = 0; start < length; start++) { if (!IsWhiteSpace(source[start])) break; } for (end = length - 1; end > start; end--) { if (!IsWhiteSpace(source[end])) break; } length = end - start + 1; if (length <= 0) { dest[0] = '\0'; } else { Q_memmove(dest, &source[start], length); dest[length] = '\0'; } }
/* ============ Cbuf_Execute ============ */ void Cbuf_Execute( void ) { char *text; char line[MAX_CMD_LINE]; int i, quotes; while( cmd_text.cursize ) { // find a \n or ; line break text = (char *)cmd_text.data; quotes = 0; for( i = 0; i < cmd_text.cursize; i++ ) { if( text[i] == '"' ) quotes++; if(!( quotes & 1 ) && text[i] == ';' ) break; // don't break if inside a quoted string if( text[i] == '\n' || text[i] == '\r' ) break; } if( i >= ( MAX_CMD_LINE - 1 )) Sys_Error( "Cbuf_Execute: command string owerflow\n" ); Q_memcpy( line, text, i ); line[i] = 0; // delete the text from the command buffer and move remaining commands down // this is necessary because commands (exec) can insert data at the // beginning of the text buffer if( i == cmd_text.cursize ) { cmd_text.cursize = 0; } else { i++; cmd_text.cursize -= i; Q_memmove( text, text + i, cmd_text.cursize ); } // execute the command line Cmd_ExecuteString( line, src_command ); if( cmd_wait ) { // skip out while text still remains in buffer, // leaving it for next frame cmd_wait = false; break; } } }
// This is a generic function that takes a number of items and builds a sorted // list of the valid items. int BuildSortedActiveList( int *pList, // This is the list where the final data is placed. int nMaxItems, sortFn pSortFn, // Callbacks. isValidFn pIsValidFn, // This can be null, in which case all items are valid. void *pUserData, // Passed into the function pointers. int nItems // Number of items in the list to sort. ) { // First build the list of active items. if( nItems > nMaxItems ) nItems = nMaxItems; int nActive = 0; for( int i=0; i < nItems; i++ ) { if( pIsValidFn ) { if( !pIsValidFn( pUserData, i ) ) continue; } int j; for( j=0; j < nActive; j++ ) { Assert( pList[j] < nItems ); if( pSortFn( pUserData, i, pList[j] ) > 0 ) { break; } } // Slide everything up. if( nActive ) { Q_memmove( &pList[j+1], &pList[j], (nActive-j) * sizeof(int) ); } // Add the new item to the list. pList[j] = i; ++nActive; for (int l = 0; l < nActive ; ++l ) { Assert( pList[l] < nItems ); } } return nActive; }
/* <4f05> ../engine/cmd.c:148 */ void Cbuf_InsertTextLines(char *text) { int addLen = Q_strlen(text); int currLen = cmd_text.cursize; if (cmd_text.cursize + addLen + 2 >= cmd_text.maxsize) { Con_Printf(__FUNCTION__ ": overflow\n"); return; } #ifdef REHLDS_FIXES if (currLen) Q_memmove(cmd_text.data + addLen + 1, cmd_text.data, currLen); cmd_text.data[0] = '\n'; // TODO: Why we need leading \n, if there is no commands in the start? Q_memcpy(&cmd_text.data[1], text, addLen); cmd_text.data[addLen + 1] = '\n'; cmd_text.cursize += addLen + 2; #else char *temp = NULL; if (currLen) { temp = (char *)Z_Malloc(currLen); Q_memcpy(temp, cmd_text.data, currLen); SZ_Clear(&cmd_text); } Cbuf_AddText("\n"); // TODO: Why we need leading \n, if there is no commands in the start? Cbuf_AddText(text); Cbuf_AddText("\n"); if (currLen) { SZ_Write(&cmd_text, temp, currLen); Z_Free(temp); } #endif // REHLDS_FIXES }
void EXT_FUNC RemoveExtDll_api(void *hModule) { if (!hModule) { return; } for (auto i = 0; i < g_iextdllMac; i++) { if (g_rgextdll[i].lDLLHandle == hModule) { g_iextdllMac--; if (g_iextdllMac != i) { Q_memmove(&g_rgextdll[i], &g_rgextdll[i + 1], (g_iextdllMac - i) * sizeof(g_rgextdll[0])); i = g_iextdllMac; } Q_memset(&g_rgextdll[i], 0, sizeof(g_rgextdll[0])); break; } } }
// When a command wants to issue other commands immediately, the text is // inserted at the beginning of the buffer, before any remaining unexecuted // commands. void Cbuf_InsertText(char *text) { int addLen = Q_strlen(text); int currLen = cmd_text.cursize; if (cmd_text.cursize + addLen >= cmd_text.maxsize) { Con_Printf(__FUNCTION__ ": overflow\n"); return; } #ifdef REHLDS_FIXES if (currLen) Q_memmove(cmd_text.data + addLen, cmd_text.data, currLen); Q_memcpy(cmd_text.data, text, addLen); cmd_text.cursize += addLen; #else char *temp = NULL; if (currLen) { temp = (char *)Z_Malloc(currLen); // TODO: Optimize: better use memmove without need for a temp buffer Q_memcpy(temp, cmd_text.data, currLen); SZ_Clear(&cmd_text); } Cbuf_AddText(text); if (currLen) { SZ_Write(&cmd_text, temp, currLen); Z_Free(temp); } #endif // REHLDS_FIXES }
// Pulls off \n terminated lines of text from the command buffer and sends // them through Cmd_ExecuteString. Stops when the buffer is empty. // Normally called once per frame, but may be explicitly invoked. // Do not call inside a command function! void Cbuf_Execute(void) { int i; char *text; char line[MAX_CMD_LINE]; int quotes; while (cmd_text.cursize) { // find a \n or ; line break text = (char *)cmd_text.data; quotes = 0; for (i = 0; i < cmd_text.cursize; i++) { if (text[i] == '"') quotes++; if (!(quotes & 1) && text[i] == ';') break; // don't break if inside a quoted string if (text[i] == '\n') break; } #ifdef REHLDS_FIXES // save `i` if we truncate command int len; if (i > MAX_CMD_LINE - 1) len = MAX_CMD_LINE - 1; else len = i; Q_memcpy(line, text, len); line[len] = 0; #else // REHLDS_FIXES if (i > MAX_CMD_LINE - 1) { i = MAX_CMD_LINE - 1; } Q_memcpy(line, text, i); line[i] = 0; #endif // REHLDS_FIXES // delete the text from the command buffer and move remaining commands down // this is necessary because commands (exec, alias) can insert data at the // beginning of the text buffer if (i == cmd_text.cursize) { cmd_text.cursize = 0; } else { i++; cmd_text.cursize -= i; #ifdef REHLDS_FIXES // dst overlaps src Q_memmove(text, text + i, cmd_text.cursize); #else // REHLDS_FIXES Q_memcpy(text, text + i, cmd_text.cursize); #endif // REHLDS_FIXES } // execute the command line Cmd_ExecuteString(line, src_command); if (cmd_wait) { // skip out while text still remains in buffer, leaving it // for next frame cmd_wait = FALSE; break; } } }
qboolean Netchan_Process(netchan_t *chan) { int i; unsigned int sequence, sequence_ack; unsigned int reliable_ack, reliable_message; unsigned int fragid[MAX_STREAMS] = { 0, 0 }; qboolean frag_message[MAX_STREAMS] = { false, false }; int frag_offset[MAX_STREAMS] = { 0, 0 }; int frag_length[MAX_STREAMS] = { 0, 0 }; qboolean message_contains_fragments; if (!g_pcls.demoplayback && !g_pcls.passive) { if (!NET_CompareAdr(net_from, chan->remote_address)) return FALSE; } chan->last_received = realtime; // get sequence numbers MSG_BeginReading(); sequence = MSG_ReadLong(); sequence_ack = MSG_ReadLong(); if (sequence_ack & 0x40000000) { if (!g_modfuncs.m_pfnProcessIncomingNet) return FALSE; } if (g_modfuncs.m_pfnProcessIncomingNet) { if (!g_modfuncs.m_pfnProcessIncomingNet(chan, &net_message)) return FALSE; } reliable_message = sequence >> 31; reliable_ack = sequence_ack >> 31; message_contains_fragments = sequence & (1 << 30) ? true : false; COM_UnMunge2(&net_message.data[8], net_message.cursize - 8, sequence & 0xFF); if (message_contains_fragments) { for (i = 0; i < MAX_STREAMS; i++) { if (MSG_ReadByte()) { frag_message[i] = true; fragid[i] = MSG_ReadLong(); frag_offset[i] = MSG_ReadShort(); frag_length[i] = MSG_ReadShort(); } } if (!Netchan_Validate(chan, frag_message, fragid, frag_offset, frag_length)) return FALSE; } sequence &= ~(1 << 31); sequence &= ~(1 << 30); sequence_ack &= ~(1 << 31); sequence_ack &= ~(1 << 30); if (net_showpackets.value != 0.0 && net_showpackets.value != 3.0) { char c = (chan == &g_pcls.netchan) ? 'c' : 's'; Con_Printf( " %c <-- sz=%i seq=%i ack=%i rel=%i tm=%f\n", c, net_message.cursize, sequence, sequence_ack, reliable_message, (chan == &g_pcls.netchan) ? g_pcl.time : g_psv.time); } if (sequence <= (unsigned)chan->incoming_sequence) { if (net_showdrop.value != 0.0) { if (sequence == (unsigned)chan->incoming_sequence) Con_Printf("%s:duplicate packet %i at %i\n", NET_AdrToString(chan->remote_address), sequence, chan->incoming_sequence); else Con_Printf("%s:out of order packet %i at %i\n", NET_AdrToString(chan->remote_address), sequence, chan->incoming_sequence); } return FALSE; } // // dropped packets don't keep the message from being used // net_drop = sequence - (chan->incoming_sequence + 1); if (net_drop > 0 && net_showdrop.value != 0.0) { Con_Printf("%s:Dropped %i packets at %i\n", NET_AdrToString(chan->remote_address), net_drop, sequence); } // // if the current outgoing reliable message has been acknowledged // clear the buffer to make way for the next // if (reliable_ack == (unsigned)chan->reliable_sequence) { // Make sure we actually could have ack'd this message #ifdef REHLDS_FIXES if (sequence_ack >= (unsigned)chan->last_reliable_sequence) #else // REHLDS_FIXES if (chan->incoming_acknowledged + 1 >= chan->last_reliable_sequence) #endif // REHLDS_FIXES { chan->reliable_length = 0; // it has been received } } // // if this message contains a reliable message, bump incoming_reliable_sequence // chan->incoming_sequence = sequence; chan->incoming_acknowledged = sequence_ack; chan->incoming_reliable_acknowledged = reliable_ack; if (reliable_message) { chan->incoming_reliable_sequence ^= 1; } int statId = chan->flow[FLOW_INCOMING].current & 0x1F; chan->flow[FLOW_INCOMING].stats[statId].size = net_message.cursize + UDP_HEADER_SIZE; chan->flow[FLOW_INCOMING].stats[statId].time = realtime; chan->flow[FLOW_INCOMING].current++; Netchan_UpdateFlow(chan); if (message_contains_fragments) { for (i = 0; i < MAX_STREAMS; i++) { int j; fragbuf_t *pbuf; int inbufferid; int intotalbuffers; if (!frag_message[i]) continue; inbufferid = FRAG_GETID(fragid[i]); intotalbuffers = FRAG_GETCOUNT(fragid[i]); if (fragid[i] != 0) { pbuf = Netchan_FindBufferById(&chan->incomingbufs[i], fragid[i], true); if (pbuf) { int len = frag_length[i]; SZ_Clear(&pbuf->frag_message); SZ_Write(&pbuf->frag_message, &net_message.data[msg_readcount + frag_offset[i]], len); } else { Con_Printf("Netchan_Process: Couldn't allocate or find buffer %i\n", inbufferid); } // Count # of incoming bufs we've queued? are we done? Netchan_CheckForCompletion(chan, i, intotalbuffers); } // Rearrange incoming data to not have the frag stuff in the middle of it int wpos = msg_readcount + frag_offset[i]; int rpos = wpos + frag_length[i]; Q_memmove(net_message.data + wpos, net_message.data + rpos, net_message.cursize - rpos); net_message.cursize -= frag_length[i]; for (j = i + 1; j < MAX_STREAMS; j++) { frag_offset[j] -= frag_length[i]; // fragments order already validated } } // Is there anything left to process? if (net_message.cursize <= 16) return FALSE; } return TRUE; }
//----------------------------------------------------------------------------- // Purpose: walks the file elements in the vcproj and inserts them into configs //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractFiles( IXMLDOMDocument *pDoc ) { if (!pDoc) { return false; } Assert( m_Configurations.Count() ); // some configs must be loaded first #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pFiles; pDoc->getElementsByTagName( _bstr_t("File"), &pFiles); if (pFiles) { long len = 0; pFiles->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pFiles->get_item( i, &pNode); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol fileName = GetXMLAttribValue(pElem,"RelativePath"); if ( fileName.IsValid() ) { CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fileName.String(), type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( pElem, fileName ); // now remove the excluded ones } } }//for } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("File") ); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol fileName = GetXMLAttribValue(node,"RelativePath"); if ( fileName.IsValid() ) { char fixedFileName[ MAX_PATH ]; Q_strncpy( fixedFileName, fileName.String(), sizeof(fixedFileName) ); if ( fixedFileName[0] == '.' && fixedFileName[1] == '\\' ) { Q_memmove( fixedFileName, fixedFileName+2, sizeof(fixedFileName)-2 ); } Q_FixSlashes( fixedFileName ); FindFileCaseInsensitive( fixedFileName, sizeof(fixedFileName) ); CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fixedFileName, type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( node, fixedFileName ); // now remove the excluded ones } } }//for } #endif return true; }