library/src/blockclass/subclasses/BP_ApplicationHelpGenerator.cc
// Builds the application usage examples.
Builds the application usage examples.
Builds the application usage examples .
BP_ERROR_T BP_ApplicationHelpGenerator::buildApplicationUsageExamples()
{
	if(!this->sfsc)
		return ERR_FAILURE;
	if(!this->usage_examples || ! this->usage_example_n)
		return ERR_FAILURE;
	P_BP_AHG_USAGE_EXAMPLE curr_usage_example = NULL;
	sfsc->addRowGroup   ();
	sfsc->addRow        ();
	sfsc->addColumnGroup();
	sfsc->addColumn     ();
	sfsc->addStringEntry("empty padding","     ",5,	5,NULL,	BP_FALSE,3,	0,NULL);
	size_t n = 0;
	for(; n < this->usage_example_n; n++)
	{
		curr_usage_example = &this->usage_examples[n];
		sfsc->addRowGroup   ();
		sfsc->addRow        ();
		sfsc->addColumnGroup();
		sfsc->addColumn     ();
		BP_COLOR_CODE_SET_T tmp_usage_colors;
		tmp_usage_colors.fg = BP_COLOR_CODE_FG_YELLOW;
		tmp_usage_colors.bg = BP_COLOR_CODE_BG_BLACK;
		sfsc->addStringEntry
		(
			"curr_group",
			curr_usage_example->name,
			bpstrlen(curr_usage_example->name),
			60,
			&tmp_usage_colors,
			BP_FALSE,
			0,
			0,
			&BP_STSBS_border_set_underline_1
		);
		sfsc->addStringEntry
		(
			"curr_description",
			curr_usage_example->description,
			bpstrlen(curr_usage_example->description),
			80,
			NULL,
			BP_FALSE,
			0,
			0,
			&BP_STSBS_border_set_onlypadding_5
		);
		char *joiner[4];
		char *joined = NULL;
		BP_ZERO_STACK(joiner);
		joiner[0] = this->clop->argv[0];
		joiner[1] = " ";
		joiner[2] = curr_usage_example->usage_string;
		joined = BP_JoinStringArray(joiner, 3, NULL);
		BP_COLOR_CODE_SET_T tmp_usage_string_colors;
		tmp_usage_string_colors.fg = BP_COLOR_CODE_FG_GREEN;
		tmp_usage_string_colors.bg = BP_COLOR_CODE_BG_NONE;
		sfsc->addStringEntry
		(
				"curr_usage_string",
				joined,
				bpstrlen(joined),
				100,
				&tmp_usage_string_colors,
				BP_FALSE,
				0,
				0,
				&BP_STSBS_border_set_onlypadding_5
		);
		sfsc->addRowGroup   ();
		sfsc->addRow        ();
		sfsc->addColumnGroup();
		sfsc->addColumn     ();
		sfsc->addStringEntry("empty padding","     ",5,	5,NULL,	BP_FALSE,1,	0,NULL);
		if(joined)
			bpfree(joined);
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_ApplicationHelpGenerator :: buildApplicationUsageExamples ( ) { if ( ! this -> sfsc ) return ERR_FAILURE ; if ( ! this -> usage_examples || ! this -> usage_example_n ) return ERR_FAILURE ; P_BP_AHG_USAGE_EXAMPLE curr_usage_example = NULL ; sfsc -> addRowGroup ( ) ; sfsc -> addRow ( ) ; sfsc -> addColumnGroup ( ) ; sfsc -> addColumn ( ) ; sfsc -> addStringEntry ( " " , " " , 5 , 5 , NULL , BP_FALSE , 3 , 0 , NULL ) ; size_t n = 0 ; for ( ; n < this -> usage_example_n ; n ++ ) { curr_usage_example = & this -> usage_examples [ n ] ; sfsc -> addRowGroup ( ) ; sfsc -> addRow ( ) ; sfsc -> addColumnGroup ( ) ; sfsc -> addColumn ( ) ; BP_COLOR_CODE_SET_T tmp_usage_colors ; tmp_usage_colors . fg = BP_COLOR_CODE_FG_YELLOW ; tmp_usage_colors . bg = BP_COLOR_CODE_BG_BLACK ; sfsc -> addStringEntry ( " " , curr_usage_example -> name , bpstrlen ( curr_usage_example -> name ) , 60 , & tmp_usage_colors , BP_FALSE , 0 , 0 , & BP_STSBS_border_set_underline_1 ) ; sfsc -> addStringEntry ( " " , curr_usage_example -> description , bpstrlen ( curr_usage_example -> description ) , 80 , NULL , BP_FALSE , 0 , 0 , & BP_STSBS_border_set_onlypadding_5 ) ; char * joiner [ 4 ] ; char * joined = NULL ; BP_ZERO_STACK ( joiner ) ; joiner [ 0 ] = this -> clop -> argv [ 0 ] ; joiner [ 1 ] = " " ; joiner [ 2 ] = curr_usage_example -> usage_string ; joined = BP_JoinStringArray ( joiner , 3 , NULL ) ; BP_COLOR_CODE_SET_T tmp_usage_string_colors ; tmp_usage_string_colors . fg = BP_COLOR_CODE_FG_GREEN ; tmp_usage_string_colors . bg = BP_COLOR_CODE_BG_NONE ; sfsc -> addStringEntry ( " " , joined , bpstrlen ( joined ) , 100 , & tmp_usage_string_colors , BP_FALSE , 0 , 0 , & BP_STSBS_border_set_onlypadding_5 ) ; sfsc -> addRowGroup ( ) ; sfsc -> addRow ( ) ; sfsc -> addColumnGroup ( ) ; sfsc -> addColumn ( ) ; sfsc -> addStringEntry ( " " , " " , 5 , 5 , NULL , BP_FALSE , 1 , 0 , NULL ) ; if ( joined ) bpfree ( joined ) ; } return ERR_SUCCESS ; }
Builds the application usage examples.
Builds the application usage examples .
// ensure we have a sfsc to work with // ensure that we have groups and a group count // current group and entry // add a padding row before the usage examples to distinguish them // walk groups and generate options // set the current group // use empty (random uuid) values // create joiner array to join argv[0] with the usage // example. // set the join elements // join the strings // add a padding row before the usage examples to distinguish them // if the join was ok, free it // return indicating success