library/src/blockclass/subclasses/BP_CommandLineOptionParser.cc
// display the options as they exist
display the options as they exist
display the options as they exist
BP_ERROR_T BP_CommandLineOptionParser::displayOptionsAsJSON(BP_BOOL display_options_set_from_command_line_only = BP_TRUE, char *extra_data = NULL)
{
	if(!this->tokens)
		return ERR_FAILURE;
	if(!this->tokens_n)
		return ERR_FAILURE;
	if(extra_data)
	if(!BP_StringIsReasonablePrintableString(extra_data, bpstrlen(extra_data)))
		return ERR_FAILURE;
	if(strstr(extra_data, "\'"))
		return ERR_FAILURE;
	bool append_comma_cycle = false;
	size_t n = 0;
	for(; n < this->tokens_n; n++)
	{
		if(display_options_set_from_command_line_only == BP_TRUE)
		{
			if(!this->tokens[n].value_has_been_set_ok)
				continue;
		}
		if(append_comma_cycle == false)
		{
			printf("{", this->tokens);
			if(extra_data)
			{
				printf("\n\t\"extra_data\": '%s',", extra_data);
			}
			append_comma_cycle = true;
		}
		else
		{
			if((n+1) < this->tokens_n) printf(",");
		}
		switch(this->tokens[n].value_type)
		{
			case BP_COMMAND_LINE_ARGUMENT_STAND_ALONE_TOGGLE:
				printf("\n\t\"%s\": \"true\"", this->tokens[n].token);
				break;
			case BP_COMMAND_LINE_ARGUMENT_CHAR_STRING:
				printf("\n\t\"%s\": \"%s\"", this->tokens[n].token, tokens[n].parsed_value_as_string);
				break;
			case BP_COMMAND_LINE_ARGUMENT_SIZE_T:
				printf("\n\t\"%s\": \"%zu\"", this->tokens[n].token, tokens[n].parsed_value_as_size_t);
				break;
			case BP_COMMAND_LINE_ARGUMENT_SIGNED_INT:
				printf("\n\t\"%s\": \"%i\"", this->tokens[n].token, tokens[n].parsed_value_as_int);
				break;
			case BP_COMMAND_LINE_ARGUMENT_URL:
				printf("\n\t\"%s\": \"%s\"", this->tokens[n].token, tokens[n].parsed_value_as_string);
				break;
			default:
				break;
		}
	}
	if(append_comma_cycle)
	{
		printf("\n}");
		printf("\n");
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CommandLineOptionParser :: displayOptionsAsJSON ( BP_BOOL display_options_set_from_command_line_only = BP_TRUE , char * extra_data = NULL ) { if ( ! this -> tokens ) return ERR_FAILURE ; if ( ! this -> tokens_n ) return ERR_FAILURE ; if ( extra_data ) if ( ! BP_StringIsReasonablePrintableString ( extra_data , bpstrlen ( extra_data ) ) ) return ERR_FAILURE ; if ( strstr ( extra_data , " \' " ) ) return ERR_FAILURE ; bool append_comma_cycle = false ; size_t n = 0 ; for ( ; n < this -> tokens_n ; n ++ ) { if ( display_options_set_from_command_line_only == BP_TRUE ) { if ( ! this -> tokens [ n ] . value_has_been_set_ok ) continue ; } if ( append_comma_cycle == false ) { printf ( " " , this -> tokens ) ; if ( extra_data ) { printf ( " \n \t \" \" " , extra_data ) ; } append_comma_cycle = true ; } else { if ( ( n + 1 ) < this -> tokens_n ) printf ( " " ) ; } switch ( this -> tokens [ n ] . value_type ) { case BP_COMMAND_LINE_ARGUMENT_STAND_ALONE_TOGGLE : printf ( " \n \t \" \" \" \" " , this -> tokens [ n ] . token ) ; break ; case BP_COMMAND_LINE_ARGUMENT_CHAR_STRING : printf ( " \n \t \" \" \" \" " , this -> tokens [ n ] . token , tokens [ n ] . parsed_value_as_string ) ; break ; case BP_COMMAND_LINE_ARGUMENT_SIZE_T : printf ( " \n \t \" \" \" \" " , this -> tokens [ n ] . token , tokens [ n ] . parsed_value_as_size_t ) ; break ; case BP_COMMAND_LINE_ARGUMENT_SIGNED_INT : printf ( " \n \t \" \" \" \" " , this -> tokens [ n ] . token , tokens [ n ] . parsed_value_as_int ) ; break ; case BP_COMMAND_LINE_ARGUMENT_URL : printf ( " \n \t \" \" \" \" " , this -> tokens [ n ] . token , tokens [ n ] . parsed_value_as_string ) ; break ; default : break ; } } if ( append_comma_cycle ) { printf ( " \n " ) ; printf ( " \n " ) ; } return ERR_SUCCESS ; }
display the options as they exist
display the options as they exist
// check to see if tokens are set // if extra data was passed in, insure it's readable/printable // ensure the extra data doesn't contain any single quotes // toggle for appending commas // walk individual tokens and display argument data // if we are only displaying options set from command line, check to // ensure value is set before displaying // continue loop if value is unset // display opening bracket but only if we have tokens // add extra data to json output here (but only if we have arguments) // set the cycle indicator to true // display correct types // display the option // this->displayOption(&this->tokens[n]); // close if we have the end of our comma cycle // display closing brace and newline // return indicating success