library/src/utility/BP-StringFormattingSessions.cc
// Generates a string entry from an ascii character string
Generates a string entry from an ascii character string
Generates a string entry from an ascii character string
P_BP_SFS_STRING_ENTRY BP_GenerateStringEntryFromCharString
(
		P_BP_SF_SESSION sfs,
		char * string_entry_identifier,
		char * string,
		size_t string_len,
		size_t display_width,
		P_BP_COLOR_CODE_SET_T initial_colors,
		size_t pad_lines_below,
		size_t pad_lines_above,
		P_BP_STRING_ROW_BORDER_SET border_set
)
{
	if(!sfs)
		return NULL;
	if(!sfs->tq)
		return NULL;
	if(!string || !string_len || !string_entry_identifier)
		return NULL;
	P_BP_SFS_CHAR_ENTRY char_entries = (P_BP_SFS_CHAR_ENTRY) tq_calloc
	(
		sfs->tq,
		sizeof(BP_SFS_CHAR_ENTRY) * string_len,
		1,
		BPLN
	);
	if(!char_entries)
		return NULL;
	P_BP_SFS_STRING_ENTRY str_entry = (P_BP_SFS_STRING_ENTRY) tq_calloc
	(
		sfs->tq,
		sizeof(BP_SFS_STRING_ENTRY),
		1,
		BPLN
	);
	if(!str_entry)
	{
		tq_free(sfs->tq, char_entries);
		return NULL;
	}
	str_entry->string_entry_identifier = tq_strdup(sfs->tq, string_entry_identifier, BPLN);
	if(!str_entry->string_entry_identifier)
	{
		tq_free(sfs->tq, char_entries);
		tq_free(sfs->tq, str_entry);
		return NULL;
	}
	str_entry->string_entry_identifier_len = bpstrlen(str_entry->string_entry_identifier);
	size_t n = 0;
	for(; n < string_len; n++)
	{
		char_entries[n].character = (char) string[n];
		if(initial_colors)
		{
			char_entries[n].color_info.bg = initial_colors->bg;
			char_entries[n].color_info.fg = initial_colors->fg;
		}
	}
	str_entry->string        = char_entries;
	str_entry->string_length = string_len;
	str_entry->marked_display_disabled = BP_FALSE;
	str_entry->display_max_width = display_width;
	str_entry->pad_lines_above = pad_lines_above;
	str_entry->pad_lines_below = pad_lines_below;
	if(border_set)
	{
		str_entry->border_set.border_left  = tq_strdup(sfs->tq, border_set->border_left, BPLN);
		str_entry->border_set.border_right = tq_strdup(sfs->tq, border_set->border_right, BPLN);
		str_entry->border_set.border_top_enabled           = border_set->border_top_enabled;
		str_entry->border_set.border_top_char              = tq_strdup(sfs->tq, border_set->border_top_char,   BPLN);
		str_entry->border_set.border_top_left_corner       = tq_strdup(sfs->tq, border_set->border_top_left_corner, BPLN);
		str_entry->border_set.border_top_right_corner      = tq_strdup(sfs->tq, border_set->border_top_right_corner, BPLN);
		str_entry->border_set.border_bottom_enabled        = border_set->border_bottom_enabled;
		str_entry->border_set.border_bottom_char           = tq_strdup(sfs->tq, border_set->border_bottom_char,         BPLN);
		str_entry->border_set.border_bottom_left_corner    = tq_strdup(sfs->tq, border_set->border_bottom_left_corner,  BPLN);
		str_entry->border_set.border_bottom_right_corner   = tq_strdup(sfs->tq, border_set->border_bottom_right_corner, BPLN);
	}
	else
	{
		str_entry->border_set.border_left  = tq_strdup(sfs->tq, "", BPLN);
		str_entry->border_set.border_right = tq_strdup(sfs->tq, "", BPLN);
		str_entry->border_set.border_top_enabled           = BP_FALSE;
		str_entry->border_set.border_top_char              = tq_strdup(sfs->tq, " ",   BPLN);
		str_entry->border_set.border_top_left_corner       = tq_strdup(sfs->tq, "   ", BPLN);
		str_entry->border_set.border_top_right_corner      = tq_strdup(sfs->tq, "   ", BPLN);
		str_entry->border_set.border_bottom_enabled        = BP_FALSE;
		str_entry->border_set.border_bottom_char           = tq_strdup(sfs->tq, " ",   BPLN);
		str_entry->border_set.border_bottom_left_corner    = tq_strdup(sfs->tq, "   ", BPLN);
		str_entry->border_set.border_bottom_right_corner   = tq_strdup(sfs->tq, "   ", BPLN);
	}
	return str_entry;
}
P_BP_SFS_STRING_ENTRY BP_GenerateStringEntryFromCharString ( P_BP_SF_SESSION sfs , char * string_entry_identifier , char * string , size_t string_len , size_t display_width , P_BP_COLOR_CODE_SET_T initial_colors , size_t pad_lines_below , size_t pad_lines_above , P_BP_STRING_ROW_BORDER_SET border_set ) { if ( ! sfs ) return NULL ; if ( ! sfs -> tq ) return NULL ; if ( ! string || ! string_len || ! string_entry_identifier ) return NULL ; P_BP_SFS_CHAR_ENTRY char_entries = ( P_BP_SFS_CHAR_ENTRY ) tq_calloc ( sfs -> tq , sizeof ( BP_SFS_CHAR_ENTRY ) * string_len , 1 , BPLN ) ; if ( ! char_entries ) return NULL ; P_BP_SFS_STRING_ENTRY str_entry = ( P_BP_SFS_STRING_ENTRY ) tq_calloc ( sfs -> tq , sizeof ( BP_SFS_STRING_ENTRY ) , 1 , BPLN ) ; if ( ! str_entry ) { tq_free ( sfs -> tq , char_entries ) ; return NULL ; } str_entry -> string_entry_identifier = tq_strdup ( sfs -> tq , string_entry_identifier , BPLN ) ; if ( ! str_entry -> string_entry_identifier ) { tq_free ( sfs -> tq , char_entries ) ; tq_free ( sfs -> tq , str_entry ) ; return NULL ; } str_entry -> string_entry_identifier_len = bpstrlen ( str_entry -> string_entry_identifier ) ; size_t n = 0 ; for ( ; n < string_len ; n ++ ) { char_entries [ n ] . character = ( char ) string [ n ] ; if ( initial_colors ) { char_entries [ n ] . color_info . bg = initial_colors -> bg ; char_entries [ n ] . color_info . fg = initial_colors -> fg ; } } str_entry -> string = char_entries ; str_entry -> string_length = string_len ; str_entry -> marked_display_disabled = BP_FALSE ; str_entry -> display_max_width = display_width ; str_entry -> pad_lines_above = pad_lines_above ; str_entry -> pad_lines_below = pad_lines_below ; if ( border_set ) { str_entry -> border_set . border_left = tq_strdup ( sfs -> tq , border_set -> border_left , BPLN ) ; str_entry -> border_set . border_right = tq_strdup ( sfs -> tq , border_set -> border_right , BPLN ) ; str_entry -> border_set . border_top_enabled = border_set -> border_top_enabled ; str_entry -> border_set . border_top_char = tq_strdup ( sfs -> tq , border_set -> border_top_char , BPLN ) ; str_entry -> border_set . border_top_left_corner = tq_strdup ( sfs -> tq , border_set -> border_top_left_corner , BPLN ) ; str_entry -> border_set . border_top_right_corner = tq_strdup ( sfs -> tq , border_set -> border_top_right_corner , BPLN ) ; str_entry -> border_set . border_bottom_enabled = border_set -> border_bottom_enabled ; str_entry -> border_set . border_bottom_char = tq_strdup ( sfs -> tq , border_set -> border_bottom_char , BPLN ) ; str_entry -> border_set . border_bottom_left_corner = tq_strdup ( sfs -> tq , border_set -> border_bottom_left_corner , BPLN ) ; str_entry -> border_set . border_bottom_right_corner = tq_strdup ( sfs -> tq , border_set -> border_bottom_right_corner , BPLN ) ; } else { str_entry -> border_set . border_left = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_right = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_top_enabled = BP_FALSE ; str_entry -> border_set . border_top_char = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_top_left_corner = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_top_right_corner = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_bottom_enabled = BP_FALSE ; str_entry -> border_set . border_bottom_char = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_bottom_left_corner = tq_strdup ( sfs -> tq , " " , BPLN ) ; str_entry -> border_set . border_bottom_right_corner = tq_strdup ( sfs -> tq , " " , BPLN ) ; } return str_entry ; }
Generates a string entry from an ascii character string
Generates a string entry from an ascii character string
// ensure we have a session to allocate from // ensure we have a string with a length (colors are optional) // allocate space for the individual entries // ensure we have allocated space for the entries // now create string entry // if we couldn't create the string entry, free character entry // and return. // allocate space for the identifier // ensure we could allocate the entry // set the length directly // Now that all allocations have completed, we can start // copying in data. // walk the string length and add entries // add character entry // set initial characters if necessary // set string member // set marked for display to default // set the display width // set pad lines // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Border Info %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set left and right borders // border top items // border bottom items // default border is just spaces/padding // set left and right borders // border top items // border bottom items // return the filled in string entry