library/src/blockclass/subclasses/BP_CommandLineOptionParser.cc
// option lookup (attempts to resolve a token to a value, automatically works with either short
// or long options(eg: -a --a=b)
option lookup (attempts to resolve a token to a value, automatically works with either short
or long options
option lookup ( attempts to resolve a token to a value automatically works with either short or long options
P_BP_COMMAND_LINE_PARSER_TOKENS BP_CommandLineOptionParser::optionLookup(char * option_value)
{
	if(!option_value)
		return NULL;
	if(!this->tokens_n)
		return NULL;
	if(!this->tokens)
		return NULL;
	size_t option_length = (size_t) strnlen(option_value, 65535);
	if(option_length < 2)
		return NULL;
	size_t n = 0;
	char ** split_buffer = NULL;
	if(option_length == 2)
	{
		for(; n < this->tokens_n; n++)
		{
			if(!this->tokens[n].token_is_long_form)
			{
				if(bpstrlen(this->tokens[n].token) == option_length)
				{
					if(memcmp(this->tokens[n].token, option_value, option_length) == 0)
						return &this->tokens[n];
				}
			}
		}
	}
	else
	{
		for(; n < this->tokens_n; n++)
		{
			if(this->tokens[n].token_is_long_form)
			{
				char ** split_buffer = BP_SplitBufferBin(option_value, option_length, "=", 1);
				if(!split_buffer)
				if(memcmp(this->tokens[n].token, option_value, option_length) == 0)
					return &this->tokens[n];
				if(!split_buffer)
				{
				}
				else
				{
					if(bpstrlen(this->tokens[n].token) == strnlen(split_buffer[0], 65535))
					{
						if(memcmp(this->tokens[n].token, split_buffer[0], strnlen(split_buffer[0], 65535)) == 0)
						{
							if(split_buffer[0])
								bpfree(split_buffer[0]);
							if(split_buffer[1])
								bpfree(split_buffer[1]);
							bpfree(split_buffer);
							return &this->tokens[n];
						}
					}
				}
				 if necessary
				if(split_buffer)
				{
					if(split_buffer[0])
						bpfree(split_buffer[0]);
					if(split_buffer[1])
						bpfree(split_buffer[1]);
					bpfree(split_buffer);
					split_buffer = NULL;
				}
			}
		}
	}
	 if necessary
	if(split_buffer)
	{
		if(split_buffer[0])
			bpfree(split_buffer[0]);
		if(split_buffer[1])
			bpfree(split_buffer[1]);
		bpfree(split_buffer);
	}
	return NULL;
}
P_BP_COMMAND_LINE_PARSER_TOKENS BP_CommandLineOptionParser :: optionLookup ( char * option_value ) { if ( ! option_value ) return NULL ; if ( ! this -> tokens_n ) return NULL ; if ( ! this -> tokens ) return NULL ; size_t option_length = ( size_t ) strnlen ( option_value , 65535 ) ; if ( option_length < 2 ) return NULL ; size_t n = 0 ; char * * split_buffer = NULL ; if ( option_length == 2 ) { for ( ; n < this -> tokens_n ; n ++ ) { if ( ! this -> tokens [ n ] . token_is_long_form ) { if ( bpstrlen ( this -> tokens [ n ] . token ) == option_length ) { if ( memcmp ( this -> tokens [ n ] . token , option_value , option_length ) == 0 ) return & this -> tokens [ n ] ; } } } } else { for ( ; n < this -> tokens_n ; n ++ ) { if ( this -> tokens [ n ] . token_is_long_form ) { char * * split_buffer = BP_SplitBufferBin ( option_value , option_length , " " , 1 ) ; if ( ! split_buffer ) if ( memcmp ( this -> tokens [ n ] . token , option_value , option_length ) == 0 ) return & this -> tokens [ n ] ; if ( ! split_buffer ) { } else { if ( bpstrlen ( this -> tokens [ n ] . token ) == strnlen ( split_buffer [ 0 ] , 65535 ) ) { if ( memcmp ( this -> tokens [ n ] . token , split_buffer [ 0 ] , strnlen ( split_buffer [ 0 ] , 65535 ) ) == 0 ) { if ( split_buffer [ 0 ] ) bpfree ( split_buffer [ 0 ] ) ; if ( split_buffer [ 1 ] ) bpfree ( split_buffer [ 1 ] ) ; bpfree ( split_buffer ) ; return & this -> tokens [ n ] ; } } } if ( split_buffer ) { if ( split_buffer [ 0 ] ) bpfree ( split_buffer [ 0 ] ) ; if ( split_buffer [ 1 ] ) bpfree ( split_buffer [ 1 ] ) ; bpfree ( split_buffer ) ; split_buffer = NULL ; } } } } if ( split_buffer ) { if ( split_buffer [ 0 ] ) bpfree ( split_buffer [ 0 ] ) ; if ( split_buffer [ 1 ] ) bpfree ( split_buffer [ 1 ] ) ; bpfree ( split_buffer ) ; } return NULL ; }
option lookup (attempts to resolve a token to a value, automatically works with either short
or long options(eg: -a --a=b)
option lookup ( attempts to resolve a token to a value automatically works with either short or long options ( eg : - a -- a = b )
// check to ensure we have an option value // ensure we have a token count // ensure we have tokens to work with // calculate option length // ensure we have at minimum length of two (aka -a) // iterator used for searching // used to hold a split buffer if necessary // if else to handle long form or short form options // look for short-form options here // check for long form, skip if so // ensure that the string length matches the option (prevents undercutting) // if the option matches the token, return the structure as a pointer // look for long form options here // check for long form, process if so // split the buffer if possible // add this to the below if statement if something broke // if(this->tokens[n].value_type == BP_COMMAND_LINE_ARGUMENT_STAND_ALONE_TOGGLE) // if it's a stand alone toggle, there is no split buffer available, so we // can immediately run cascading checks and return the lookup if available // if the buffer cannot be split along delimited lines, return NULL // to indicate that the attempt failed. // printf("\n SHEEEEET: %s - %s", option_value, this->tokens[n].token); // ensure that the string length matches the option (prevents undercutting) // if the option matches the token, return the structure as a pointer // destroy split buffer entries // destroy the split buffer // if the token was matched successfully, return here // destroy split buffer entries if necessary // destroy the split buffer // nullify on loop // continue loop // destroy split buffer entries if necessary // destroy the split buffer // if no match is found, return NULL