// Sets the priority level for a spew group void SpewActivate(const char *pGroupName, int level) { Assert(pGroupName); // check for the default group first... if ((pGroupName[0] == '*') && (pGroupName[1] == '\0')) { s_DefaultLevel = level; return; } // Normal case, search in group list using binary search. // If not found, grow the list of groups and insert it into the // right place to maintain sorted order. Then set the level. int ind; if (!FindSpewGroup(pGroupName, &ind)) { // not defined yet, insert an entry. s_GroupCount++; if (s_pSpewGroups) { s_pSpewGroups = (SpewGroup_t *)realloc(s_pSpewGroups, s_GroupCount * sizeof(SpewGroup_t)); // shift elements down to preserve order int numToMove = s_GroupCount - ind - 1; memmove(&s_pSpewGroups[ind + 1], &s_pSpewGroups[ind], numToMove * sizeof(SpewGroup_t)); } else s_pSpewGroups = (SpewGroup_t *)malloc(s_GroupCount * sizeof(SpewGroup_t)); Assert(strlen(pGroupName) < MAX_GROUP_NAME_LENGTH); strcpy(s_pSpewGroups[ind].m_GroupName, pGroupName); } s_pSpewGroups[ind].m_Level = level; }
//----------------------------------------------------------------------------- // Sets the priority level for a spew group //----------------------------------------------------------------------------- void SpewActivate( const tchar* pGroupName, int level ) { Assert( pGroupName ); // check for the default group first... if ((pGroupName[0] == '*') && (pGroupName[1] == '\0')) { s_DefaultLevel = level; return; } // Normal case, search in group list using binary search. // If not found, grow the list of groups and insert it into the // right place to maintain sorted order. Then set the level. int ind; if ( !FindSpewGroup( pGroupName, &ind ) ) { // not defined yet, insert an entry. ++s_GroupCount; if ( s_pSpewGroups ) { s_pSpewGroups = (SpewGroup_t*)PvRealloc( s_pSpewGroups, s_GroupCount * sizeof(SpewGroup_t) ); // shift elements down to preserve order int numToMove = s_GroupCount - ind - 1; memmove( &s_pSpewGroups[ind+1], &s_pSpewGroups[ind], numToMove * sizeof(SpewGroup_t) ); // Update standard groups for ( int i = 0; i < GROUP_COUNT; ++i ) { if ( ( ind <= s_pGroupIndices[i] ) && ( s_pGroupIndices[i] >= 0 ) ) { ++s_pGroupIndices[i]; } } } else { s_pSpewGroups = (SpewGroup_t*)PvAlloc( s_GroupCount * sizeof(SpewGroup_t) ); } Assert( _tcslen( pGroupName ) < MAX_GROUP_NAME_LENGTH ); _tcscpy( s_pSpewGroups[ind].m_GroupName, pGroupName ); // Update standard groups for ( int i = 0; i < GROUP_COUNT; ++i ) { if ( ( s_pGroupIndices[i] < 0 ) && !_tcsicmp( s_pGroupNames[i], pGroupName ) ) { s_pGroupIndices[i] = ind; break; } } } s_pSpewGroups[ind].m_Level = level; }
// Tests to see if a particular spew is active bool IsSpewActive(const char *pGroupName, int level) { // If we don't find the spew group, use the default level. int ind; if (FindSpewGroup(pGroupName, &ind)) return s_pSpewGroups[ind].m_Level >= level; else return s_DefaultLevel >= level; }