library/src/utility/BP-StringUtilities.cc
// Add a border to a buffer.  Returns a newly allocated string columnization structure (aka
// you must destroy the old one)
Add a border to a buffer.  Returns a newly allocated string columnization structure (aka
you must destroy the old one)
Add a border to a buffer . Returns a newly allocated string columnization structure ( aka you must destroy the old one )
P_BP_GENERIC_STRING_COLUMNIZATION BP_BorderizeStringColumnization(P_BP_GENERIC_STRING_COLUMNIZATION string_columnization, P_BP_STRING_ROW_BORDER_SET border_set)
{
	if(!string_columnization)
		return NULL;
	if(!border_set)
		return NULL;
	if(!string_columnization->columns)
		return NULL;
	P_BP_GENERIC_STRING_COLUMNIZATION ret_val = (P_BP_GENERIC_STRING_COLUMNIZATION) bpcalloc(sizeof(BP_GENERIC_STRING_COLUMNIZATION), 1);
	ret_val->column_count = string_columnization->column_count;
	size_t current_str_idx = 0;
	size_t left_border_len  = 0;
	size_t right_border_len = 0;
	size_t top_left_corner_len  = 0;
	size_t top_right_corner_len = 0;
	size_t bottom_left_corner_len  = 0;
	size_t bottom_right_corner_len = 0;
	if(border_set->border_top_left_corner)
		top_left_corner_len  = bpstrlen(border_set->border_top_left_corner);
	if(border_set->border_top_right_corner)
		top_right_corner_len = bpstrlen(border_set->border_top_right_corner);
	if(border_set->border_bottom_left_corner)
		bottom_left_corner_len  = bpstrlen(border_set->border_bottom_left_corner);
	if(border_set->border_bottom_right_corner)
		bottom_right_corner_len = bpstrlen(border_set->border_bottom_right_corner);
	if(border_set->border_left)
		left_border_len = bpstrlen(border_set->border_left);
	if(border_set->border_right)
		right_border_len = bpstrlen(border_set->border_right);
	size_t n = 0;
	if(border_set->border_top_enabled)
		ret_val->column_count++;
	if(border_set->border_bottom_enabled)
		ret_val->column_count++;
	ret_val->columns = (char **) bpcalloc(sizeof(char *) * (ret_val->column_count+1), 1);
	ret_val->color_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (ret_val->column_count+1), 1);
	ret_val->space_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (ret_val->column_count+1), 1);
	if(border_set->border_top_enabled)
	if(border_set->border_top_right_corner || border_set->border_top_left_corner)
	{
		P_BP_LINKL top_tq = BP_CreateLinkL(".", BP_FALSE);
		if(border_set->border_top_left_corner)
			tq_strdup(top_tq, border_set->border_top_left_corner, BPLN);
		for(n = 0; n < string_columnization->longest_width - (top_left_corner_len + top_right_corner_len) + (right_border_len + left_border_len); n++)
		{
			tq_strndup(top_tq, border_set->border_top_char, 1, BPLN);
		}
		if(border_set->border_top_right_corner)
			tq_strdup(top_tq, border_set->border_top_right_corner, BPLN);
		BP_LinkLFlattenJoinStringElements(top_tq);
		ret_val->color_normalization_data[current_str_idx] = 0;
		ret_val->space_normalization_data[current_str_idx] = 0;
		ret_val->columns[current_str_idx] = (char *) bpstrndup((char *) top_tq->flat_buff, top_tq->flat_buff_n);
		current_str_idx++;
		BP_DestroyLinkL(top_tq, BP_TRUE);
	}
	for(n = 0; n < string_columnization->column_count; n++)
	{
		P_BP_LINKL tq = BP_CreateLinkL(".", BP_FALSE);
		if(border_set->border_left)
			tq_strdup(tq, border_set->border_left, BPLN);
		tq_strdup(tq, string_columnization->columns[n], BPLN);
		if(border_set->border_right)
			tq_strdup(tq, border_set->border_right, BPLN);
		BP_LinkLFlattenJoinStringElements(tq);
		ret_val->columns[current_str_idx] = (char *) bpstrndup((char *) tq->flat_buff, tq->flat_buff_n);
		if(string_columnization->color_normalization_data)
		{
			ret_val->color_normalization_data[current_str_idx] = string_columnization->color_normalization_data[n];
			if(bpstrlen(ret_val->columns[current_str_idx]) > ret_val->longest_width_colorized)
				ret_val->longest_width_colorized = bpstrlen(ret_val->columns[current_str_idx]);
		}
		if(string_columnization->space_normalization_data)
			ret_val->space_normalization_data[current_str_idx] = string_columnization->space_normalization_data[n];
		if
		(
			(bpstrlen(ret_val->columns[current_str_idx]) - ret_val->color_normalization_data[current_str_idx]) > ret_val->longest_width
		)
		{
			ret_val->longest_width = bpstrlen(ret_val->columns[current_str_idx]) - ret_val->color_normalization_data[current_str_idx];
		}
		current_str_idx++;
		BP_DestroyLinkL(tq, BP_TRUE);
	}
	if(border_set->border_bottom_enabled)
	if(border_set->border_bottom_right_corner || border_set->border_bottom_left_corner)
	{
		P_BP_LINKL bottom_tq = BP_CreateLinkL(".", BP_FALSE);
		if(border_set->border_bottom_left_corner)
			tq_strdup(bottom_tq, border_set->border_bottom_left_corner, BPLN);
		for(n = 0; n < string_columnization->longest_width - (bottom_left_corner_len + bottom_right_corner_len) + (right_border_len + left_border_len); n++)
		{
			tq_strndup(bottom_tq, border_set->border_bottom_char, 1, BPLN);
		}
		if(border_set->border_bottom_right_corner)
			tq_strdup(bottom_tq, border_set->border_bottom_right_corner, BPLN);
		BP_LinkLFlattenJoinStringElements(bottom_tq);
		ret_val->columns[current_str_idx] = (char *) bpstrndup((char *) bottom_tq->flat_buff, bottom_tq->flat_buff_n);
		ret_val->longest_width = bpstrlen(ret_val->columns[current_str_idx]);
		current_str_idx++;
		BP_DestroyLinkL(bottom_tq, BP_TRUE);
	}
	return ret_val;
}
P_BP_GENERIC_STRING_COLUMNIZATION BP_BorderizeStringColumnization ( P_BP_GENERIC_STRING_COLUMNIZATION string_columnization , P_BP_STRING_ROW_BORDER_SET border_set ) { if ( ! string_columnization ) return NULL ; if ( ! border_set ) return NULL ; if ( ! string_columnization -> columns ) return NULL ; P_BP_GENERIC_STRING_COLUMNIZATION ret_val = ( P_BP_GENERIC_STRING_COLUMNIZATION ) bpcalloc ( sizeof ( BP_GENERIC_STRING_COLUMNIZATION ) , 1 ) ; ret_val -> column_count = string_columnization -> column_count ; size_t current_str_idx = 0 ; size_t left_border_len = 0 ; size_t right_border_len = 0 ; size_t top_left_corner_len = 0 ; size_t top_right_corner_len = 0 ; size_t bottom_left_corner_len = 0 ; size_t bottom_right_corner_len = 0 ; if ( border_set -> border_top_left_corner ) top_left_corner_len = bpstrlen ( border_set -> border_top_left_corner ) ; if ( border_set -> border_top_right_corner ) top_right_corner_len = bpstrlen ( border_set -> border_top_right_corner ) ; if ( border_set -> border_bottom_left_corner ) bottom_left_corner_len = bpstrlen ( border_set -> border_bottom_left_corner ) ; if ( border_set -> border_bottom_right_corner ) bottom_right_corner_len = bpstrlen ( border_set -> border_bottom_right_corner ) ; if ( border_set -> border_left ) left_border_len = bpstrlen ( border_set -> border_left ) ; if ( border_set -> border_right ) right_border_len = bpstrlen ( border_set -> border_right ) ; size_t n = 0 ; if ( border_set -> border_top_enabled ) ret_val -> column_count ++ ; if ( border_set -> border_bottom_enabled ) ret_val -> column_count ++ ; ret_val -> columns = ( char * * ) bpcalloc ( sizeof ( char * ) * ( ret_val -> column_count + 1 ) , 1 ) ; ret_val -> color_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( ret_val -> column_count + 1 ) , 1 ) ; ret_val -> space_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( ret_val -> column_count + 1 ) , 1 ) ; if ( border_set -> border_top_enabled ) if ( border_set -> border_top_right_corner || border_set -> border_top_left_corner ) { P_BP_LINKL top_tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( border_set -> border_top_left_corner ) tq_strdup ( top_tq , border_set -> border_top_left_corner , BPLN ) ; for ( n = 0 ; n < string_columnization -> longest_width - ( top_left_corner_len + top_right_corner_len ) + ( right_border_len + left_border_len ) ; n ++ ) { tq_strndup ( top_tq , border_set -> border_top_char , 1 , BPLN ) ; } if ( border_set -> border_top_right_corner ) tq_strdup ( top_tq , border_set -> border_top_right_corner , BPLN ) ; BP_LinkLFlattenJoinStringElements ( top_tq ) ; ret_val -> color_normalization_data [ current_str_idx ] = 0 ; ret_val -> space_normalization_data [ current_str_idx ] = 0 ; ret_val -> columns [ current_str_idx ] = ( char * ) bpstrndup ( ( char * ) top_tq -> flat_buff , top_tq -> flat_buff_n ) ; current_str_idx ++ ; BP_DestroyLinkL ( top_tq , BP_TRUE ) ; } for ( n = 0 ; n < string_columnization -> column_count ; n ++ ) { P_BP_LINKL tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( border_set -> border_left ) tq_strdup ( tq , border_set -> border_left , BPLN ) ; tq_strdup ( tq , string_columnization -> columns [ n ] , BPLN ) ; if ( border_set -> border_right ) tq_strdup ( tq , border_set -> border_right , BPLN ) ; BP_LinkLFlattenJoinStringElements ( tq ) ; ret_val -> columns [ current_str_idx ] = ( char * ) bpstrndup ( ( char * ) tq -> flat_buff , tq -> flat_buff_n ) ; if ( string_columnization -> color_normalization_data ) { ret_val -> color_normalization_data [ current_str_idx ] = string_columnization -> color_normalization_data [ n ] ; if ( bpstrlen ( ret_val -> columns [ current_str_idx ] ) > ret_val -> longest_width_colorized ) ret_val -> longest_width_colorized = bpstrlen ( ret_val -> columns [ current_str_idx ] ) ; } if ( string_columnization -> space_normalization_data ) ret_val -> space_normalization_data [ current_str_idx ] = string_columnization -> space_normalization_data [ n ] ; if ( ( bpstrlen ( ret_val -> columns [ current_str_idx ] ) - ret_val -> color_normalization_data [ current_str_idx ] ) > ret_val -> longest_width ) { ret_val -> longest_width = bpstrlen ( ret_val -> columns [ current_str_idx ] ) - ret_val -> color_normalization_data [ current_str_idx ] ; } current_str_idx ++ ; BP_DestroyLinkL ( tq , BP_TRUE ) ; } if ( border_set -> border_bottom_enabled ) if ( border_set -> border_bottom_right_corner || border_set -> border_bottom_left_corner ) { P_BP_LINKL bottom_tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( border_set -> border_bottom_left_corner ) tq_strdup ( bottom_tq , border_set -> border_bottom_left_corner , BPLN ) ; for ( n = 0 ; n < string_columnization -> longest_width - ( bottom_left_corner_len + bottom_right_corner_len ) + ( right_border_len + left_border_len ) ; n ++ ) { tq_strndup ( bottom_tq , border_set -> border_bottom_char , 1 , BPLN ) ; } if ( border_set -> border_bottom_right_corner ) tq_strdup ( bottom_tq , border_set -> border_bottom_right_corner , BPLN ) ; BP_LinkLFlattenJoinStringElements ( bottom_tq ) ; ret_val -> columns [ current_str_idx ] = ( char * ) bpstrndup ( ( char * ) bottom_tq -> flat_buff , bottom_tq -> flat_buff_n ) ; ret_val -> longest_width = bpstrlen ( ret_val -> columns [ current_str_idx ] ) ; current_str_idx ++ ; BP_DestroyLinkL ( bottom_tq , BP_TRUE ) ; } return ret_val ; }
Add a border to a buffer.
Add a border to a buffer .
// create columnization return data // set the initial column count here // this is used for indexing data // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Border Counters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // border left len // top corner lengths // bottom corner lengths // calculate top and right & left items // calculate bottom right & left items // calculate left and right border lengths /*
	if((top_left_corner_len + top_right_corner_len) >  string_columnization->longest_width)
	{

		printf("\n Failing her?: %u", string_columnization->longest_width);
		return NULL;
	}
*/ // line iterator // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Allocate Storage Spaces %%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add storage space for top and bottom if necessary // create space for columns // allocate space for color normalization data // allocate space for space normalization data // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Top Border if Necessary %%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocator for top tailqueue // add left corner // add character spaces // add right corner // flatten the join // since we're not doing any color normalization, set that here // since we're not doing any space normalization, set that here // set column data // increment the current string index // destroy the tailqueue // Now add columns // create flattener // add left border if set // now add string // add right border if set // flatten the elements // set column data // set color normalization data if we have a valid array to set from // set the longest width if necessary // set space normalization data if we have a valid array to set from // set longest width here // increment the string index // destroy the flattener // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Bottom Border if Necessary %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // allocator for bottom tailqueue // add left corner // add character spaces // add right corner // flatten the join // set column data // the longest (uncolorized) width will always be the bottom line length // increment the current string index // destroy the tailqueue // printf("\n %%%%%%%%% DIE %%%%%%%%%%%"); // return the data here