library/src/datastructures/BP-HashTable.cc
// This turns a char ** into a path lookup string.  The resulting
// string is bpcalloced and must be bpfreed.
This turns a char ** into a path lookup string.  The resulting
string is bpcalloced and must be bpfreed.
This turns a char ** into a path lookup string . The resulting string is bpcalloced and must be bpfreed .
char * BP_HashRegPathArrayToStringLookup(char **path)
{
	if(!path)
		return NULL;
	if(!path[0])
		return NULL;
	size_t path_element_n = BP_CountNullTerminatedPtrArray(path);
	size_t path_idx = 0;
	for(; path_idx < path_element_n; path_idx++)
	{
		char *path_idx_str = path[path_idx];
		if(!path_idx_str)
		{
			return NULL;
		}
		if(BP_HashRegPathArrayIndexFilterTest(path_idx_str, bpstrlen(path_idx_str)) == ERR_FAILURE)
		{
			return NULL;
		}
	}
	P_BP_LINKL temp_tq = BP_CreateLinkL(".", BP_TRUE);
	for(path_idx = 0; path_idx < path_element_n; path_idx++)
	{
		tq_strndup(temp_tq, "/", 1, BPLN);
		tq_strndup(temp_tq, path[path_idx], bpstrlen(path[path_idx]), BPLN);
	}
	BP_LinkLFlattenJoinStringElements(temp_tq);
	if(temp_tq->flat_buff)
	{
		char *ret_lookup = bpstrndup((char *) temp_tq->flat_buff, temp_tq->flat_buff_n);
		BP_DestroyLinkL(temp_tq, BP_TRUE);
		return ret_lookup;
	}
	BP_DestroyLinkL(temp_tq, BP_TRUE);
	return NULL;
}
char * BP_HashRegPathArrayToStringLookup ( char * * path ) { if ( ! path ) return NULL ; if ( ! path [ 0 ] ) return NULL ; size_t path_element_n = BP_CountNullTerminatedPtrArray ( path ) ; size_t path_idx = 0 ; for ( ; path_idx < path_element_n ; path_idx ++ ) { char * path_idx_str = path [ path_idx ] ; if ( ! path_idx_str ) { return NULL ; } if ( BP_HashRegPathArrayIndexFilterTest ( path_idx_str , bpstrlen ( path_idx_str ) ) == ERR_FAILURE ) { return NULL ; } } P_BP_LINKL temp_tq = BP_CreateLinkL ( " " , BP_TRUE ) ; for ( path_idx = 0 ; path_idx < path_element_n ; path_idx ++ ) { tq_strndup ( temp_tq , " " , 1 , BPLN ) ; tq_strndup ( temp_tq , path [ path_idx ] , bpstrlen ( path [ path_idx ] ) , BPLN ) ; } BP_LinkLFlattenJoinStringElements ( temp_tq ) ; if ( temp_tq -> flat_buff ) { char * ret_lookup = bpstrndup ( ( char * ) temp_tq -> flat_buff , temp_tq -> flat_buff_n ) ; BP_DestroyLinkL ( temp_tq , BP_TRUE ) ; return ret_lookup ; } BP_DestroyLinkL ( temp_tq , BP_TRUE ) ; return NULL ; }
This turns a char ** into a path lookup string.
This turns a char ** into a path lookup string .
// basic null zero checks // count the path to determine total items in the array // run all elements through filter test before creating joined string // get pointer to path index string // printf("\n PATH ITER WAS NULL?"); // check to see if index will pass the filter test // printf("\n ARRAY INDEX FAILED FILTER"); // create temp tq // once filters are passed, build actual string // add prefixing slash // add target index // flatten the temporary tailqueue to create our final path string // if a path was created, return it here // duplicate the flat buff as the final path // destroy linkl before exiting // return the final buffer // destroy linkl before exiting // if we were unable create a path for some other reason, exit with null