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_MergeGenericColumnizationsHorizontally(P_BP_GENERIC_STRING_COLUMNIZATION * columnizations, size_t columnization_count)
{
	if(!columnizations || !columnization_count)
		return NULL;
	size_t widest_column           = 0;
	size_t widest_column_colorized = 0;
	size_t tallest_column          = 0;
	size_t n = 0;
	size_t j = 0;
	for(; n < columnization_count; n++)
	{
		widest_column           += columnizations[n]->longest_width;
		widest_column_colorized += columnizations[n]->longest_width_colorized;
		if(columnizations[n]->column_count > tallest_column)
			tallest_column = columnizations[n]->column_count;
	}
	size_t calculated_line_length = 0;
	size_t * new_color_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (tallest_column+1), 1);
	size_t * new_space_normalization_data = (size_t *) bpcalloc(sizeof(size_t) * (tallest_column+1), 1);
	char ** new_column_data = (char **) bpcalloc(sizeof(char *) * (tallest_column+1), 1);
	size_t col_iter_idx = 0;
	for(n = 0; n < tallest_column; n++)
	{
		calculated_line_length = 0;
		P_BP_LINKL tq = BP_CreateLinkL(".", BP_FALSE);
		for( j = 0; j < columnization_count; j++)
		{
			if(col_iter_idx < columnizations[j]->column_count)
			{
				if(columnizations[j]->columns[col_iter_idx])
				{
					tq_strdup(tq, columnizations[j]->columns[col_iter_idx], BPLN);
				}
				if(columnizations[j]->color_normalization_data)
					new_color_normalization_data[col_iter_idx] += columnizations[j]->color_normalization_data[col_iter_idx];
				if(columnizations[j]->space_normalization_data)
					new_space_normalization_data[col_iter_idx] += columnizations[j]->space_normalization_data[col_iter_idx];
			}
			else
			{
				char *tmp_buff = (char *) bpcalloc(columnizations[j]->longest_width+1, 1);
				memset(tmp_buff, 0x20, columnizations[j]->longest_width);
				tq_strdup(tq, tmp_buff, BPLN);
				bpfree(tmp_buff);
			}
		}
		BP_LinkLFlattenJoinStringElements(tq);
		new_column_data[col_iter_idx] = (char *) bpstrdup((char *) tq->flat_buff);
		BP_DestroyLinkL(tq, BP_TRUE);
		col_iter_idx++;
	}
	P_BP_GENERIC_STRING_COLUMNIZATION ret_val = (P_BP_GENERIC_STRING_COLUMNIZATION) bpcalloc(sizeof(BP_GENERIC_STRING_COLUMNIZATION), 1);
	ret_val->color_normalization_data = new_color_normalization_data;
	ret_val->space_normalization_data = new_space_normalization_data;
	ret_val->columns                  = new_column_data;
	ret_val->column_count             = tallest_column;
	ret_val->longest_width            = widest_column;
	ret_val->longest_width_colorized  = widest_column_colorized;
	return ret_val;
}
P_BP_GENERIC_STRING_COLUMNIZATION BP_MergeGenericColumnizationsHorizontally ( P_BP_GENERIC_STRING_COLUMNIZATION * columnizations , size_t columnization_count ) { if ( ! columnizations || ! columnization_count ) return NULL ; size_t widest_column = 0 ; size_t widest_column_colorized = 0 ; size_t tallest_column = 0 ; size_t n = 0 ; size_t j = 0 ; for ( ; n < columnization_count ; n ++ ) { widest_column += columnizations [ n ] -> longest_width ; widest_column_colorized += columnizations [ n ] -> longest_width_colorized ; if ( columnizations [ n ] -> column_count > tallest_column ) tallest_column = columnizations [ n ] -> column_count ; } size_t calculated_line_length = 0 ; size_t * new_color_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( tallest_column + 1 ) , 1 ) ; size_t * new_space_normalization_data = ( size_t * ) bpcalloc ( sizeof ( size_t ) * ( tallest_column + 1 ) , 1 ) ; char * * new_column_data = ( char * * ) bpcalloc ( sizeof ( char * ) * ( tallest_column + 1 ) , 1 ) ; size_t col_iter_idx = 0 ; for ( n = 0 ; n < tallest_column ; n ++ ) { calculated_line_length = 0 ; P_BP_LINKL tq = BP_CreateLinkL ( " " , BP_FALSE ) ; for ( j = 0 ; j < columnization_count ; j ++ ) { if ( col_iter_idx < columnizations [ j ] -> column_count ) { if ( columnizations [ j ] -> columns [ col_iter_idx ] ) { tq_strdup ( tq , columnizations [ j ] -> columns [ col_iter_idx ] , BPLN ) ; } if ( columnizations [ j ] -> color_normalization_data ) new_color_normalization_data [ col_iter_idx ] += columnizations [ j ] -> color_normalization_data [ col_iter_idx ] ; if ( columnizations [ j ] -> space_normalization_data ) new_space_normalization_data [ col_iter_idx ] += columnizations [ j ] -> space_normalization_data [ col_iter_idx ] ; } else { char * tmp_buff = ( char * ) bpcalloc ( columnizations [ j ] -> longest_width + 1 , 1 ) ; memset ( tmp_buff , 0x20 , columnizations [ j ] -> longest_width ) ; tq_strdup ( tq , tmp_buff , BPLN ) ; bpfree ( tmp_buff ) ; } } BP_LinkLFlattenJoinStringElements ( tq ) ; new_column_data [ col_iter_idx ] = ( char * ) bpstrdup ( ( char * ) tq -> flat_buff ) ; BP_DestroyLinkL ( tq , BP_TRUE ) ; col_iter_idx ++ ; } P_BP_GENERIC_STRING_COLUMNIZATION ret_val = ( P_BP_GENERIC_STRING_COLUMNIZATION ) bpcalloc ( sizeof ( BP_GENERIC_STRING_COLUMNIZATION ) , 1 ) ; ret_val -> color_normalization_data = new_color_normalization_data ; ret_val -> space_normalization_data = new_space_normalization_data ; ret_val -> columns = new_column_data ; ret_val -> column_count = tallest_column ; ret_val -> longest_width = widest_column ; ret_val -> longest_width_colorized = widest_column_colorized ; 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 // the maximum widest column // declare iterator // this holds the calculated line length // create space to hold recalculate normalization data // create space for new column data // reset before running line calculation // run line calculation // set new color normalization data if available // create temporary buffer // set spaces // add empty line to the tailqueue // destroy the temporary buffer // flatten out the elements above // duplicate string in new column data // destroy the linkl at this point // return the filled out pointer