library/src/decoders/HTML/BP-HTMLDecoder.cc
// This routine generates an anchor substitution string.
This routine generates an anchor substitution string.
This routine generates an anchor substitution string .
char * HTMLGenerateAnchorSubstitutionString
(
	P_BP_HTML_ANCHOR_LIST     anchor,
	P_BP_HTML_ANCHOR_VAR_LIST anchor_vars,
	char *                    sub_var_name,
	char *                    replace_var_name,
	char *                    replace_var_value,
	BP_BOOL                   generate_relative_path,
	P_BP_LINKL                tq_in
)
{
	if(!anchor)
		return NULL;
	if(!anchor_vars)
		return NULL;
	P_BP_HTML_ANCHOR_VAR_LIST sub_var_name_list  = NULL;
	P_BP_LINKL tq = BP_CreateLinkL("tmp", BP_FALSE);
	if(sub_var_name)
	{
		sub_var_name_list = HTMLGetAnchorVarByNameI(anchor_vars, sub_var_name);
		if(!sub_var_name_list)
			return NULL;
	}
	char * builder_str = NULL;
	builder_str = BP_JoinStrings(anchor->script, "?", tq);
	for
	(
		anchor_vars = anchor_vars->first;
		anchor_vars;
		anchor_vars = anchor_vars->next
	)
	{
		if(anchor_vars == sub_var_name_list)
		{
			if(replace_var_name)
				builder_str = BP_JoinStrings(builder_str, replace_var_name, tq);
			else
				builder_str = BP_JoinStrings(builder_str, anchor_vars->name, tq);
			builder_str = BP_JoinStrings(builder_str, "=", tq);
			if(replace_var_value)
				builder_str = BP_JoinStrings(builder_str, replace_var_value, tq);
			else
				builder_str = BP_JoinStrings(builder_str, anchor_vars->content, tq);
		}
		else
		{
			builder_str = BP_JoinStrings(builder_str, anchor_vars->name, tq);
			builder_str = BP_JoinStrings(builder_str, "=", tq);
			builder_str = BP_JoinStrings(builder_str, anchor_vars->content, tq);
		}
		if(!anchor_vars->next)
			break;
		builder_str = BP_JoinStrings(builder_str, "&", tq);
	}
	char * ret_val = NULL;
	if(tq_in)
		ret_val =  tq_strdup(tq_in, builder_str, BPLN);
	else
		ret_val =  bpstrdup(builder_str);
	BP_DestroyLinkL(tq, BP_TRUE);
	return ret_val;
}
char * HTMLGenerateAnchorSubstitutionString ( P_BP_HTML_ANCHOR_LIST anchor , P_BP_HTML_ANCHOR_VAR_LIST anchor_vars , char * sub_var_name , char * replace_var_name , char * replace_var_value , BP_BOOL generate_relative_path , P_BP_LINKL tq_in ) { if ( ! anchor ) return NULL ; if ( ! anchor_vars ) return NULL ; P_BP_HTML_ANCHOR_VAR_LIST sub_var_name_list = NULL ; P_BP_LINKL tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( sub_var_name ) { sub_var_name_list = HTMLGetAnchorVarByNameI ( anchor_vars , sub_var_name ) ; if ( ! sub_var_name_list ) return NULL ; } char * builder_str = NULL ; builder_str = BP_JoinStrings ( anchor -> script , " " , tq ) ; for ( anchor_vars = anchor_vars -> first ; anchor_vars ; anchor_vars = anchor_vars -> next ) { if ( anchor_vars == sub_var_name_list ) { if ( replace_var_name ) builder_str = BP_JoinStrings ( builder_str , replace_var_name , tq ) ; else builder_str = BP_JoinStrings ( builder_str , anchor_vars -> name , tq ) ; builder_str = BP_JoinStrings ( builder_str , " " , tq ) ; if ( replace_var_value ) builder_str = BP_JoinStrings ( builder_str , replace_var_value , tq ) ; else builder_str = BP_JoinStrings ( builder_str , anchor_vars -> content , tq ) ; } else { builder_str = BP_JoinStrings ( builder_str , anchor_vars -> name , tq ) ; builder_str = BP_JoinStrings ( builder_str , " " , tq ) ; builder_str = BP_JoinStrings ( builder_str , anchor_vars -> content , tq ) ; } if ( ! anchor_vars -> next ) break ; builder_str = BP_JoinStrings ( builder_str , " " , tq ) ; } char * ret_val = NULL ; if ( tq_in ) ret_val = tq_strdup ( tq_in , builder_str , BPLN ) ; else ret_val = bpstrdup ( builder_str ) ; BP_DestroyLinkL ( tq , BP_TRUE ) ; return ret_val ; }
This routine generates an anchor substitution string.
This routine generates an anchor substitution string .
// ensure we have an anchor and anchor vars // these are used for lookups // create a tailqueue so we can just repeat joins without // saving references. // if we're planning to sub out a variable name, set here // string used for building // create the initial string // walk anchors and perform replacements // if we've found our replacement, run substitutions // add seperator // set content // break if we have no next element // add trailing ampersand if we have a next element // create the return value at this point // destroy the linkl before exiting // return the filled out value