library/src/buffer_analysis/BP-BufferAnalysis.cc
/*
 *
 * Main Buffer Analysis Routine:
 * ==================================================
 * Pass in NULL values to disable any analysis configuration subsystem.  The
 * output structure needs to be freed with BP_DestroyBufferAnalysis.
 *
 */
Main Buffer Analysis Routine.

Pass in NULL values to disable any analysis configuration subsystem.  The
output structure needs to be freed with BP_DestroyBufferAnalysis.
Main Buffer Analysis Routine . Pass in NULL values to disable any analysis configuration subsystem . The output structure needs to be freed with BP_DestroyBufferAnalysis .
P_BP_BUFFER_ANALYSIS BP_CreateBufferAnalysis
(
		unsigned char *buffer,
		size_t         buffer_n,
		P_BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config
)
{
	if(!buffer || !buffer_n)
		return NULL;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config_local;
	BP_ZERO_STACK(ascii_config_local);
	if(!ascii_config)
	{
		ascii_config = &ascii_config_local;
		ascii_config->count_ascii                      = BP_TRUE;
		ascii_config->count_extended                   = BP_TRUE;
		ascii_config->count_individual_characters      = BP_TRUE;
	}
	P_BP_BUFFER_ANALYSIS analysis = (P_BP_BUFFER_ANALYSIS) bpcalloc(sizeof(BP_BUFFER_ANALYSIS), 1);
	if(!analysis)
		return NULL;
	analysis->tq = BP_CreateLinkL("Buffer Analysis Allocator", BP_TRUE);
	if(!analysis->tq)
	{
		BP_DestroyBufferAnalysis(analysis);
		return NULL;
	}
	analysis->buffer   = buffer;
	analysis->buffer_n = buffer_n;
	if(ascii_config)
	{
		if(BP_CreateBufferAnalysisASCII(analysis, ascii_config) == ERR_FAILURE)
		{
			BP_DestroyBufferAnalysis(analysis);
			return NULL;
		}
	}
	return analysis;
}
P_BP_BUFFER_ANALYSIS BP_CreateBufferAnalysis ( unsigned char * buffer , size_t buffer_n , P_BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ) { if ( ! buffer || ! buffer_n ) return NULL ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config_local ; BP_ZERO_STACK ( ascii_config_local ) ; if ( ! ascii_config ) { ascii_config = & ascii_config_local ; ascii_config -> count_ascii = BP_TRUE ; ascii_config -> count_extended = BP_TRUE ; ascii_config -> count_individual_characters = BP_TRUE ; } P_BP_BUFFER_ANALYSIS analysis = ( P_BP_BUFFER_ANALYSIS ) bpcalloc ( sizeof ( BP_BUFFER_ANALYSIS ) , 1 ) ; if ( ! analysis ) return NULL ; analysis -> tq = BP_CreateLinkL ( " " , BP_TRUE ) ; if ( ! analysis -> tq ) { BP_DestroyBufferAnalysis ( analysis ) ; return NULL ; } analysis -> buffer = buffer ; analysis -> buffer_n = buffer_n ; if ( ascii_config ) { if ( BP_CreateBufferAnalysisASCII ( analysis , ascii_config ) == ERR_FAILURE ) { BP_DestroyBufferAnalysis ( analysis ) ; return NULL ; } } return analysis ; }
Main Buffer Analysis Routine:
Main Buffer Analysis Routine :
// ensure we have a buffer and a length count // create local buffer // zero out the structure (automagic macro) // create default ascii config if no parameter is supplied // override parameter here // set some flags in the structure (default is BP_FALSE aka 0) // attempt to create outermost allocation // ensure analysis was allocated ok // now attempt to create tailqueue allocator for this analysis // ensure that the tail queue allocator was created ok // now set buffer and buffer size values within the // analysis structure. // if the user passed in an ascii configuration option, run here // Attempt to create the analysis, if we can't create the analysis and a valid // config was provided, we've likley run out of memory, so exit after destroying // the analysis structure. // return the full buffer analysis