library/src/utility/BP-StringUtilities.cc
// Merge a stack of pointers to columnizations into one columnization structure.  This
// routine will merge them vertically (one on top of the other).
Merge a stack of pointers to columnizations into one columnization structure.  This
routine will merge them vertically (one on top of the other).
Merge a stack of pointers to columnizations into one columnization structure . This routine will merge them vertically ( one on top of the other ) .
P_BP_GENERIC_STRING_COLUMNIZATION BP_MergeGenericColumnizationsVertically(P_BP_GENERIC_STRING_COLUMNIZATION * columnizations, size_t columnization_count)
{
	if(!columnizations || !columnization_count)
		return NULL;
	size_t longest_non_colorized = 0;
	size_t longest_colorized = 0;
	size_t total_lines_vertical = 0;
	size_t n = 0;
	for(; n < columnization_count; n++)
	{
		if(!columnizations[n])
			return NULL;
		total_lines_vertical+=columnizations[n]->column_count;
		if(columnizations[n]->longest_width > longest_non_colorized)
			longest_non_colorized = columnizations[n]->longest_width;
		if(columnizations[n]->longest_width_colorized > longest_colorized)
			longest_colorized = columnizations[n]->longest_width_colorized;
	}
	P_BP_GENERIC_STRING_COLUMNIZATION ret_val = (P_BP_GENERIC_STRING_COLUMNIZATION) bpcalloc(sizeof(BP_GENERIC_STRING_COLUMNIZATION), 1);
	if(!ret_val)
		return NULL;
	ret_val->column_count            = total_lines_vertical;
	ret_val->longest_width_colorized = longest_colorized;
	ret_val->longest_width           = longest_non_colorized;
	ret_val->columns = (char **) bpcalloc(sizeof(char *) * (ret_val->column_count+1), 1);
	if(!ret_val->columns)
	{
		bpfree(ret_val);
		return NULL;
	}
	ret_val->space_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (ret_val->column_count+1), 1);
	if(!ret_val->space_normalization_data)
	{
		BP_DestroyGenericColumnization(ret_val, BP_TRUE);
		return NULL;
	}
	ret_val->color_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (ret_val->column_count+1), 1);
	if(!ret_val->color_normalization_data)
	{
		BP_DestroyGenericColumnization(ret_val, BP_TRUE);
		return NULL;
	}
	 for line indexs
	size_t ret_line_idx = 0;
	size_t col_line_idx = 0;
	for(n = 0; n < columnization_count; n++)
	{
		for
		(
			col_line_idx = 0;
			col_line_idx < columnizations[n]->column_count;
			col_line_idx++
		)
		{
			if(longest_non_colorized > columnizations[n]->longest_width)
			{
				if(columnizations[n]->color_normalization_data)
				{
					ret_val->columns[ret_line_idx] = (char *) bpcalloc(longest_non_colorized + columnizations[n]->color_normalization_data[col_line_idx]+columnizations[n]->space_normalization_data[col_line_idx]+1, 1);
					memset(ret_val->columns[ret_line_idx], 0x20, longest_non_colorized + columnizations[n]->color_normalization_data[col_line_idx]);
					if((bpstrlen(ret_val->columns[ret_line_idx]) - columnizations[n]->color_normalization_data[col_line_idx]) < longest_non_colorized)
					{
					}
					memcpy(ret_val->columns[ret_line_idx], columnizations[n]->columns[col_line_idx], bpstrlen(columnizations[n]->columns[col_line_idx]));
					if(columnizations[n]->space_normalization_data)
						ret_val->space_normalization_data[ret_line_idx] = 0; 
					ret_val->color_normalization_data[ret_line_idx] = columnizations[n]->color_normalization_data[col_line_idx];
				}
				else
				{
					ret_val->columns[ret_line_idx] = (char *) bpcalloc(longest_non_colorized+1, 1);
					 to appropriate length
					memset(ret_val->columns[ret_line_idx], 0x20, longest_non_colorized);
					memcpy(ret_val->columns[ret_line_idx], columnizations[n]->columns[col_line_idx], bpstrlen(columnizations[n]->columns[col_line_idx]));
					if(columnizations[n]->space_normalization_data)
						ret_val->space_normalization_data[ret_line_idx] = 0; 
				}
			}
			else
			{
				if(columnizations[n]->color_normalization_data)
				{
					ret_val->columns[ret_line_idx] = (char *) bpcalloc(longest_non_colorized + columnizations[n]->color_normalization_data[col_line_idx]+columnizations[n]->space_normalization_data[col_line_idx]+1, 1);
					memset(ret_val->columns[ret_line_idx], 0x20, longest_non_colorized + columnizations[n]->color_normalization_data[col_line_idx]);
					memcpy(ret_val->columns[ret_line_idx], columnizations[n]->columns[col_line_idx], bpstrlen(columnizations[n]->columns[col_line_idx]));
					if(columnizations[n]->space_normalization_data)
						ret_val->space_normalization_data[ret_line_idx] = 0; 
					ret_val->color_normalization_data[ret_line_idx] = columnizations[n]->color_normalization_data[col_line_idx];
				}
				else
				{
					ret_val->columns[ret_line_idx] = (char *) bpcalloc(longest_non_colorized+1, 1);
					 to appropriate length
					memset(ret_val->columns[ret_line_idx], 0x20, longest_non_colorized);
					memcpy(ret_val->columns[ret_line_idx], columnizations[n]->columns[col_line_idx], bpstrlen(columnizations[n]->columns[col_line_idx]));
					if(columnizations[n]->space_normalization_data)
						ret_val->space_normalization_data[ret_line_idx] = 0; 
				}
			}
			ret_line_idx++;
		}
	}
	return ret_val;
}
P_BP_GENERIC_STRING_COLUMNIZATION BP_MergeGenericColumnizationsVertically ( P_BP_GENERIC_STRING_COLUMNIZATION * columnizations , size_t columnization_count ) { if ( ! columnizations || ! columnization_count ) return NULL ; size_t longest_non_colorized = 0 ; size_t longest_colorized = 0 ; size_t total_lines_vertical = 0 ; size_t n = 0 ; for ( ; n < columnization_count ; n ++ ) { if ( ! columnizations [ n ] ) return NULL ; total_lines_vertical += columnizations [ n ] -> column_count ; if ( columnizations [ n ] -> longest_width > longest_non_colorized ) longest_non_colorized = columnizations [ n ] -> longest_width ; if ( columnizations [ n ] -> longest_width_colorized > longest_colorized ) longest_colorized = columnizations [ n ] -> longest_width_colorized ; } P_BP_GENERIC_STRING_COLUMNIZATION ret_val = ( P_BP_GENERIC_STRING_COLUMNIZATION ) bpcalloc ( sizeof ( BP_GENERIC_STRING_COLUMNIZATION ) , 1 ) ; if ( ! ret_val ) return NULL ; ret_val -> column_count = total_lines_vertical ; ret_val -> longest_width_colorized = longest_colorized ; ret_val -> longest_width = longest_non_colorized ; ret_val -> columns = ( char * * ) bpcalloc ( sizeof ( char * ) * ( ret_val -> column_count + 1 ) , 1 ) ; if ( ! ret_val -> columns ) { bpfree ( ret_val ) ; return NULL ; } ret_val -> space_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( ret_val -> column_count + 1 ) , 1 ) ; if ( ! ret_val -> space_normalization_data ) { BP_DestroyGenericColumnization ( ret_val , BP_TRUE ) ; return NULL ; } ret_val -> color_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( ret_val -> column_count + 1 ) , 1 ) ; if ( ! ret_val -> color_normalization_data ) { BP_DestroyGenericColumnization ( ret_val , BP_TRUE ) ; return NULL ; } size_t ret_line_idx = 0 ; size_t col_line_idx = 0 ; for ( n = 0 ; n < columnization_count ; n ++ ) { for ( col_line_idx = 0 ; col_line_idx < columnizations [ n ] -> column_count ; col_line_idx ++ ) { if ( longest_non_colorized > columnizations [ n ] -> longest_width ) { if ( columnizations [ n ] -> color_normalization_data ) { ret_val -> columns [ ret_line_idx ] = ( char * ) bpcalloc ( longest_non_colorized + columnizations [ n ] -> color_normalization_data [ col_line_idx ] + columnizations [ n ] -> space_normalization_data [ col_line_idx ] + 1 , 1 ) ; memset ( ret_val -> columns [ ret_line_idx ] , 0x20 , longest_non_colorized + columnizations [ n ] -> color_normalization_data [ col_line_idx ] ) ; if ( ( bpstrlen ( ret_val -> columns [ ret_line_idx ] ) - columnizations [ n ] -> color_normalization_data [ col_line_idx ] ) < longest_non_colorized ) { } memcpy ( ret_val -> columns [ ret_line_idx ] , columnizations [ n ] -> columns [ col_line_idx ] , bpstrlen ( columnizations [ n ] -> columns [ col_line_idx ] ) ) ; if ( columnizations [ n ] -> space_normalization_data ) ret_val -> space_normalization_data [ ret_line_idx ] = 0 ; ret_val -> color_normalization_data [ ret_line_idx ] = columnizations [ n ] -> color_normalization_data [ col_line_idx ] ; } else { ret_val -> columns [ ret_line_idx ] = ( char * ) bpcalloc ( longest_non_colorized + 1 , 1 ) ; memset ( ret_val -> columns [ ret_line_idx ] , 0x20 , longest_non_colorized ) ; memcpy ( ret_val -> columns [ ret_line_idx ] , columnizations [ n ] -> columns [ col_line_idx ] , bpstrlen ( columnizations [ n ] -> columns [ col_line_idx ] ) ) ; if ( columnizations [ n ] -> space_normalization_data ) ret_val -> space_normalization_data [ ret_line_idx ] = 0 ; } } else { if ( columnizations [ n ] -> color_normalization_data ) { ret_val -> columns [ ret_line_idx ] = ( char * ) bpcalloc ( longest_non_colorized + columnizations [ n ] -> color_normalization_data [ col_line_idx ] + columnizations [ n ] -> space_normalization_data [ col_line_idx ] + 1 , 1 ) ; memset ( ret_val -> columns [ ret_line_idx ] , 0x20 , longest_non_colorized + columnizations [ n ] -> color_normalization_data [ col_line_idx ] ) ; memcpy ( ret_val -> columns [ ret_line_idx ] , columnizations [ n ] -> columns [ col_line_idx ] , bpstrlen ( columnizations [ n ] -> columns [ col_line_idx ] ) ) ; if ( columnizations [ n ] -> space_normalization_data ) ret_val -> space_normalization_data [ ret_line_idx ] = 0 ; ret_val -> color_normalization_data [ ret_line_idx ] = columnizations [ n ] -> color_normalization_data [ col_line_idx ] ; } else { ret_val -> columns [ ret_line_idx ] = ( char * ) bpcalloc ( longest_non_colorized + 1 , 1 ) ; memset ( ret_val -> columns [ ret_line_idx ] , 0x20 , longest_non_colorized ) ; memcpy ( ret_val -> columns [ ret_line_idx ] , columnizations [ n ] -> columns [ col_line_idx ] , bpstrlen ( columnizations [ n ] -> columns [ col_line_idx ] ) ) ; if ( columnizations [ n ] -> space_normalization_data ) ret_val -> space_normalization_data [ ret_line_idx ] = 0 ; } } ret_line_idx ++ ; } } return ret_val ; }
Merge a stack of pointers to columnizations into one columnization structure.
Merge a stack of pointers to columnizations into one columnization structure .
// ensure we have columns to count // values to precalculate // declare iterator // all columnizations must be set, if one isn't, go ahead and // exit here as we've recieved erroneous data from the stupid // programmer. // increase column count // set longest non-colorized // set longest colorized /*
	printf("\n Got Total Vertical Lines?:  %u", total_lines_vertical);
	printf("\n Got Longest Colorized:      %u", longest_colorized);
	printf("\n Got Longest Non-Colorized:  %u", longest_non_colorized);
	*/ // ensure we can create the columinzation // set widths from precalculations // allocate space for the columns // allocate space for space normalization data // allocate space for color normalization data // declare iterator for line indexs // Declare iterator for column line indexes.  This is used // to iterate through each of the columnization routine // paramaters -> columns[] values. // create output columnization from stacked data // for each index, create new items // only process if the line is longer than the output // if the row is colorized, specifiy that here // reallocate space including normalization data // set padding // printf("\n FOUND CANDIDATE?!"); // +columnizations[n]->space_normalization_data[col_line_idx] // copy in data // set space normalization data // columnizations[n]->space_normalization_data[col_line_idx]; // set color normalization data // allocate storage space // set padding to appropriate length // copy in data // set space normalization data // columnizations[n]->space_normalization_data[col_line_idx]; // if the row is colorized, specifiy that here // printf("\n Alloc: %u", longest_non_colorized ); // reallocate space including normalization data // set padding // copy in data // set space normalization data // columnizations[n]->space_normalization_data[col_line_idx]; // set color normalization data // set padding to appropriate length // printf("\n MOO???: %u - %u", longest_non_colorized, bpstrlen(columnizations[n]->columns[col_line_idx])); // copy in data // set space normalization data // columnizations[n]->space_normalization_data[col_line_idx]; // increment the return line index // return the filled out pointer