36 #define concat_2str(str1,str2) \ 38 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 39 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 40 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+1); \ 41 strcpy(__res__, s1); \ 42 strcat(__res__, s2); \ 57 #define concat_3str(str1,str2,str3) \ 59 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 60 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 61 char* s3 = (str3) == NULL ? (char*)"" : (char*)(str3); \ 62 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+strlen(s3)+1); \ 63 strcpy(__res__, s1); \ 64 strcat(__res__, s2); \ 65 strcat(__res__, s3); \ 81 #define concat_4str(str1,str2,str3,str4) \ 83 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 84 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 85 char* s3 = (str3) == NULL ? (char*)"" : (char*)(str3); \ 86 char* s4 = (str4) == NULL ? (char*)"" : (char*)(str4); \ 87 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+1); \ 88 strcpy(__res__, s1); \ 89 strcat(__res__, s2); \ 90 strcat(__res__, s3); \ 91 strcat(__res__, s4); \ 108 #define concat_5str(str1,str2,str3,str4,str5) \ 110 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 111 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 112 char* s3 = (str3) == NULL ? (char*)"" : (char*)(str3); \ 113 char* s4 = (str4) == NULL ? (char*)"" : (char*)(str4); \ 114 char* s5 = (str5) == NULL ? (char*)"" : (char*)(str5); \ 115 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+strlen(s5)+1); \ 116 strcpy(__res__, s1); \ 117 strcat(__res__, s2); \ 118 strcat(__res__, s3); \ 119 strcat(__res__, s4); \ 120 strcat(__res__, s5); \ 138 #define concat_6str(str1,str2,str3,str4,str5,str6) \ 140 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 141 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 142 char* s3 = (str3) == NULL ? (char*)"" : (char*)(str3); \ 143 char* s4 = (str4) == NULL ? (char*)"" : (char*)(str4); \ 144 char* s5 = (str5) == NULL ? (char*)"" : (char*)(str5); \ 145 char* s6 = (str6) == NULL ? (char*)"" : (char*)(str6); \ 146 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+strlen(s5)+strlen(s6)+1); \ 147 strcpy(__res__, s1); \ 148 strcat(__res__, s2); \ 149 strcat(__res__, s3); \ 150 strcat(__res__, s4); \ 151 strcat(__res__, s5); \ 152 strcat(__res__, s6); \ 171 #define concat_7str(str1,str2,str3,str4,str5,str6,str7) \ 173 char* s1 = (str1) == NULL ? (char*)"" : (char*)(str1); \ 174 char* s2 = (str2) == NULL ? (char*)"" : (char*)(str2); \ 175 char* s3 = (str3) == NULL ? (char*)"" : (char*)(str3); \ 176 char* s4 = (str4) == NULL ? (char*)"" : (char*)(str4); \ 177 char* s5 = (str5) == NULL ? (char*)"" : (char*)(str5); \ 178 char* s6 = (str6) == NULL ? (char*)"" : (char*)(str6); \ 179 char* s7 = (str7) == NULL ? (char*)"" : (char*)(str7); \ 180 char* __res__ = (char*)alloca(strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+strlen(s5)+strlen(s6)+strlen(s7)+1); \ 181 strcpy(__res__, s1); \ 182 strcat(__res__, s2); \ 183 strcat(__res__, s3); \ 184 strcat(__res__, s4); \ 185 strcat(__res__, s5); \ 186 strcat(__res__, s6); \ 187 strcat(__res__, s7); \ 199 #define int2str(num) \ 201 char* __res__ = (char*)alloca(numDigits((int)num)+1); \ 202 sprintf(__res__, "%d", (int)num); \ 220 #define int2nstr(num, len) \ 222 require (len > 0, concat_3str("invalid length value (", int2str(len), ")")); \ 223 int d = numDigits((int)num); \ 226 char* __res__ = (char*)alloca(d+1); \ 227 sprintf(__res__, "%0*d", d, (int)num); \ 242 #define perc2str(percentage) \ 244 require (percentage >= 0 && percentage <= 100, concat_3str("invalid percentage value (", int2str(percentage), ")")); \ 245 char* __res__ = (char*)alloca(4+1); \ 246 sprintf(__res__, "%3d%%", (int)percentage); \ 257 #define length_vargs_string_list(first) \ 261 va_start(ap, first); \ 265 __res__ += strlen(t); \ 266 t = va_arg(ap, char*); \ 272 #ifdef EXCEPTION_POLICY 273 #define not_null(pnt) \ 276 throw string_concat(NULL, 0, (char*)"Null pointer error", (char*)", pointer: \"", #pnt, (char*)"\", function: \"", __FUNCTION__, (char*)"\":", int2str(__LINE__), (char*)", file: \"", __FILE__, (char*)"\"\n", NULL); \ 297 #define not_null(pnt) \ 301 fprintf (stderr, "Null pointer error, pointer: \"%s\", function: \"%s\":%d, file: \"%s\"\n", \ 302 #pnt, __FUNCTION__, __LINE__ , __FILE__); \ 448 char*
string_concat(
char* res,
int max_length,
char* text, ...);
574 int numDigits(
int num);
void mem_free(void *pnt)
A replacement for free function.
int string_count_char(char *text, char *ch)
Counts the number of occurrences of an UTF8 character in a text.
char * string_clone(char *str)
Replicates a string.
int string_list_length(char **list)
Number of elements of a NULL terminated list of strings.
char ** string_list_free(char **list)
Frees the memory allocated to a NULL terminated list of strings.
int random_boolean(int trueProb)
Generates a random boolean value.
Design-by-Contract module.
int string_num_lines(char *text)
Number of lines of a string.
int string_ends_with(char *text, char *suffix)
Tests if a string ends with a suffix.
void show_cursor()
Shows the terminal cursor.
char * percentage2string(char *res, int percentage)
Converts an int percentage to a string.
void clear_console()
Clears the terminal.
void move_cursor(int line, int column)
Moves the cursor to a position in terminal.
void * mem_alloc(int size)
A replacement for malloc function.
int string_starts_with(char *text, char *prefix)
Tests if a string starts with a prefix.
char * int2nstring(char *res, int num, int len)
Converts an int value to a string.
char * random_string(char **list, int *used, int length)
Returns a random string from a given string list.
int string_num_columns(char *text)
Maximum number of columns of a string (not counting character `'\n'`).
char ** string_list_clone(char **list)
Replicates a NULL terminated list of strings.
int random_int(int min, int max)
Generates a random integer value within a given interval.
void hide_cursor()
Hides the terminal cursor.
char * string_concat(char *res, int max_length, char *text,...)
Concatenates a NULL terminated list of string arguments.