36 #ifndef _Y_PARAM_ARRAY_C_ 37 #define _Y_PARAM_ARRAY_C_ 71 size_t size =
strlen(param_array) +9;
74 snprintf(tmp , size,
"{%s_count}" , param_array );
75 result =
atoi(lr_eval_string(tmp));
80 #define y_array_count( param_array ) lr_paramarr_len(param_array) 81 #endif // Y_COMPAT_LR_8 108 char *
y_array_get(
const char *source_param_array,
const int param_array_index )
115 if ( (param_array_index > size) || (param_array_index < 1) )
117 lr_error_message(
"Index out of bounds");
124 size_t bufsize =
strlen(source_param_array)+y_int_strlen(param_array_index)+4;
126 snprintf( tmp , bufsize,
"{%s_%d}" , source_param_array , param_array_index );
129 result = lr_eval_string(tmp);
134 #define y_array_get( source_param_array, param_array_index ) lr_paramarr_idx(source_param_array, param_array_index) 135 #endif // Y_COMPAT_LR_8 182 if ( (param_array_index >
y_array_count(source_param_array)) || (param_array_index < 1) )
184 lr_error_message(
"Parameter array %s does not exist or index %d out of bounds.", source_param_array, param_array_index);
191 size_t bufsize =
strlen(source_param_array) + y_int_strlen(param_array_index) +2;
193 snprintf(tmp, bufsize,
"%s_%d", source_param_array, param_array_index );
217 void y_array_save(
const char* value,
const char* source_param_array,
const int param_array_index)
219 if(source_param_array == NULL)
227 int len =
strlen(source_param_array) + y_int_strlen(param_array_index) +2;
229 snprintf(result, len,
"%s_%d", source_param_array, param_array_index);
230 lr_save_string(value, result);
248 if( source_param_array == NULL )
256 int len =
strlen(source_param_array) +7;
259 snprintf(result, len,
"%s_count", source_param_array);
260 lr_save_int(count, result);
282 void y_array_add(
const char* source_param_array,
const char* value )
305 void y_array_concat(
const char *source_param_array_first,
const char *source_param_array_second,
const char *result_array)
309 int size_total = size_first + size_second;
316 for(i=1; i <= size_total; i++)
321 if( i <= size_first )
332 lr_eval_string_ext_free(&value);
356 lr_log_message(
"No elements found in parameter array!");
383 lr_log_message(
"No elements found in parameter array!");
407 lr_save_string(result, source_param_array);
408 lr_eval_string_ext_free(&result);
413 lr_save_string(
"", source_param_array);
439 lr_output_message(
"{%s_%d} = %s" , source_param_array, i, msg);
440 lr_eval_string_ext_free(&msg);
486 int buflen =
strlen(source)+1;
489 memcpy(buffer, source, buflen);
491 while( next = (
char *)
strstr(next, LB) )
493 char* end =
strstr(next, RB);
496 buffer[end - buffer] =
'\0';
525 void y_array_grep(
const char *source_param_array,
const char *search,
const char *result_array)
531 for( i=1; i <= size; i++)
534 if(
strstr(item, search) )
538 lr_eval_string_ext_free(&item);
562 void y_array_filter(
const char *source_param_array,
const char *search,
const char *result_array)
568 for( i=1; i <= size; i++)
571 if(
strstr(item, search) == NULL )
575 lr_eval_string_ext_free(&item);
612 int y_array_merge(
const char *param_array_left,
const char *param_array_right,
const char *separator,
const char *result_array)
617 int seperator_size =
strlen(separator);
623 lr_error_message(
"Unable to merge arrays %s and %s - sizes unequal!", param_array_left, param_array_right);
628 for( i=1; i <= length; i++)
632 size_t size =
strlen(left)+seperator_size+
strlen(right)+1;
635 snprintf(result, size,
"%s%s%s", left, separator, right);
636 lr_eval_string_ext_free(&left);
637 lr_eval_string_ext_free(&right);
662 void y_array_split(
const char *source_param_array,
const char *separator,
const char *param_array_left,
const char *param_array_right)
669 for( i=1; i <= size; i++)
680 lr_eval_string_ext_free(&item);
718 int source_length, i;
720 if (
strcmp(source_param_array, result_array) == 0)
722 lr_error_message(
"Source and Destination parameter name can not be equal!");
728 if(source_length < 1)
730 lr_error_message(
"Cannot shuffle empty parameter arrays!");
734 else if(source_length == 1)
736 lr_log_message(
"Warning: Cannot shuffle a list with just 1 entry.");
744 for (i=1; i<=source_length; i++)
751 for(i=1; i<=source_length; i++)
754 r=(
y_rand() % (source_length))+1;
755 lr_log_message(
"shuffle r %d into i %d", r, i);
756 lr_log_message(
"swapping %d with %d", shuffle[i], shuffle[r]);
758 shuffle[i] = shuffle[r];
763 for(i=1; i<=source_length; i++)
773 #endif // _Y_PARAM_ARRAY_C_ Y-lib string function library.
void y_array_save_param_list(const char *sourceParam, const char *LB, const char *RB, const char *result_array)
Create a parameter list from a single parameter value.
void y_array_add(const char *source_param_array, const char *value)
int y_array_merge(const char *param_array_left, const char *param_array_right, const char *separator, const char *result_array)
void y_array_concat(const char *source_param_array_first, const char *source_param_array_second, const char *result_array)
Concatenate two arrays together and save the result into a third array.
#define y_array_get(source_param_array, param_array_index)
Fetch the content of a specific element from a parameter list based on index.
Standard C function headers.
int _y_random_array_index
void y_array_save_count(const int count, const char *source_param_array)
char * y_array_get_no_zeroes(const char *source_param_array, const int param_array_index)
Get the content the nth member of target parameter array, but without embedded zeroes.
void y_array_save(const char *value, const char *source_param_array, const int param_array_index)
Save a string value into an array at a specified position.
void y_array_filter(const char *source_param_array, const char *search, const char *result_array)
Search a parameter array for a specific string and and build a new result array containing only param...
char * strstr(const char *string1, const char *string2)
Documented at http://www.cplusplus.com/reference/cstring/strstr/.
char * y_mem_alloc(size_t size)
Ylib wrapper for malloc()
char * y_array_alloc(size_t length, size_t size)
Allocates a character array and initializes all elements to zero As y_mem_alloc(), but using the 'calloc' function, rather than 'malloc()'.
void * memcpy(void *dest, const void *src, size_t n)
Documented at http://www.cplusplus.com/reference/cstring/memcpy/.
char * y_array_get_random(const char *source_param_array)
Get a random element from a parameter list.
int atoi(const char *string)
Documented at http://www.cplusplus.com/reference/cstdlib/atoi/.
int strcmp(const char *string1, const char *string2)
Documented at http://www.cplusplus.com/reference/cstring/strcmp/.
void y_array_dump(const char *source_param_array)
Dump the contents of a list of saved parameters to standard output (the run log)
char * y_get_cleansed_parameter(const char *param_name, char replacement)
Get the content of a parameter without embedded null bytes (\0 characters) from the named parameter...
void y_array_split(const char *source_param_array, const char *separator, const char *param_array_left, const char *param_array_right)
char * y_array_get_random_no_zeroes(const char *source_param_array)
Get a random element from a parameter list without embedded zeroes.
#define y_array_count(param_array)
Determine the number of elements in the target parameter array.
size_t strlen(const char *string)
Documented at http://www.cplusplus.com/reference/cstring/strlen/.
Collection of miscellaneous support functions.
int y_array_pick_random(const char *source_param_array)
Choose an element at random from a saved parameter list and store it in a parameter with the same nam...
int snprintf(char *buffer, size_t n, const char *format_string,...)
Documented at http://www.cplusplus.com/reference/cstdio/snprintf/. This function was introduced by t...
long y_rand(void)
Generate a random (integer) number between 0 and Y_RAND_MAX (30 bit maxint).
char * y_get_parameter(const char *param_name)
Get the content of a parameter and return it as a char *.
void y_array_shuffle(char *source_param_array, char *result_array)
void y_array_grep(const char *source_param_array, const char *search, const char *result_array)
Search a parameter array for a specific text and build a new array containing only parameters contain...
void y_split_str(const char *original, const char *separator, char *left, char *right)
Split a string into 2 parts based on a search string.
void free(void *mem_address)
Documented at http://www.cplusplus.com/reference/cstdlib/free/.