|
|
@@ -47,24 +47,24 @@ void out (void * data, int size) { |
|
|
|
} |
|
|
|
|
|
|
|
void log_in (int type, int flag, char * data) { |
|
|
|
int start; |
|
|
|
|
|
|
|
char * type_mark [LOG_COUNT] = { |
|
|
|
"[\033[0;32mSuccess\033[0m] ", |
|
|
|
"[\033[0;33mWarning\033[0m] ", |
|
|
|
"[\033[0;31mFailure\033[0m] ", |
|
|
|
"[\033[0;34mComment\033[0m] " |
|
|
|
"[\033[1;32mSuccess\033[0m] ", |
|
|
|
"[\033[1;33mWarning\033[0m] ", |
|
|
|
"[\033[1;31mFailure\033[0m] ", |
|
|
|
"[\033[1;30mComment\033[0m] " |
|
|
|
}; |
|
|
|
|
|
|
|
if ((flag == 0) || (type <= -1) || (type >= LOG_COUNT)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (log_notify == NULL) { |
|
|
|
log_notify = allocate (string_length (type_mark [type]) + string_length (data) + 2); |
|
|
|
} else { |
|
|
|
log_notify = reallocate (log_notify, string_length (log_notify) + string_length (type_mark [type]) + string_length (data) + 2); |
|
|
|
start = string_length (log_notify); |
|
|
|
|
|
|
|
log_notify [string_length (log_notify)] = '\0'; |
|
|
|
} |
|
|
|
log_notify = reallocate (log_notify, start + string_length (type_mark [type]) + string_length (data) + 2); |
|
|
|
|
|
|
|
log_notify [start] = '\0'; |
|
|
|
|
|
|
|
string_concatenate (log_notify, type_mark [type]); |
|
|
|
string_concatenate (log_notify, data); |
|
|
@@ -85,9 +85,6 @@ void echo (char * data) { |
|
|
|
out (data, string_length (data)); |
|
|
|
} |
|
|
|
|
|
|
|
void echo_new_line (void) { |
|
|
|
out ("\n", 1); |
|
|
|
} |
|
|
|
|
|
|
|
void echo_byte (int byte) { |
|
|
|
out ("0123456789ABCDEF" + (byte % 256) / 16, 1); |
|
|
@@ -97,7 +94,7 @@ void echo_byte (int byte) { |
|
|
|
|
|
|
|
void fatal_failure (int condition, char * message) { |
|
|
|
if (condition != 0) { |
|
|
|
echo ("\033[1;31m[FATAL_FAILURE]\033[0m "); |
|
|
|
echo ("[\033[1;31mExiting\033[0m] "); |
|
|
|
echo (message); |
|
|
|
echo ("\n"); |
|
|
|
|
|
|
@@ -106,6 +103,10 @@ void fatal_failure (int condition, char * message) { |
|
|
|
} |
|
|
|
|
|
|
|
void limit (int * value, int minimum, int maximum) { |
|
|
|
if (value == NULL) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (* value <= minimum) { |
|
|
|
* value = minimum; |
|
|
|
} |
|
|
@@ -124,7 +125,7 @@ void * allocate (int size) { |
|
|
|
|
|
|
|
data = calloc ((unsigned long int) size, sizeof (* data)); |
|
|
|
|
|
|
|
fatal_failure (data == NULL, "allocate: Failed to allocate memory, function calloc returned null pointer."); |
|
|
|
fatal_failure (data == NULL, "standard : allocate : Failed to allocate memory, internal function 'calloc' returned null pointer."); |
|
|
|
|
|
|
|
return ((void *) data); |
|
|
|
} |
|
|
@@ -136,7 +137,7 @@ void * reallocate (void * data, int size) { |
|
|
|
|
|
|
|
data = realloc (data, (unsigned long int) size); |
|
|
|
|
|
|
|
fatal_failure (data == NULL, "reallocate: Failed to reallocate memory, function recalloc returned null pointer."); |
|
|
|
fatal_failure (data == NULL, "standard : reallocate: Failed to reallocate memory, internal function 'realloc' returned null pointer."); |
|
|
|
|
|
|
|
/* Set new data to 0. */ |
|
|
|
|
|
|
@@ -244,26 +245,21 @@ void argument_select (int count, char * * array) { |
|
|
|
for (index_a = 1; index_a != count; ++index_a) { |
|
|
|
for (index_b = 0; index_b != argument_count; ++index_b) { |
|
|
|
if ((string_compare (array [index_a], "-h") != 0) || (string_compare (array [index_a], "--help") != 0)) { |
|
|
|
echo ("Printing help...\n"); |
|
|
|
for (index_b = 0; index_b != argument_count; ++index_b) { |
|
|
|
echo ("\t"); echo (argument_nick [index_b]); |
|
|
|
echo (" "); echo (argument_name [index_b]); |
|
|
|
echo ("\n"); |
|
|
|
} |
|
|
|
fatal_failure (1, "Help printed, terminating..."); |
|
|
|
} else if ((string_compare (array [index_a], "-i") != 0) || (string_compare (array [index_a], "--input") != 0)) { |
|
|
|
++index_a; |
|
|
|
argument_input = array [index_a]; |
|
|
|
echo ("Selecting input: "); echo (argument_input); echo ("\n"); |
|
|
|
break; |
|
|
|
} else if ((string_compare (array [index_a], "-o") != 0) || (string_compare (array [index_a], "--output") != 0)) { |
|
|
|
++index_a; |
|
|
|
argument_output = array [index_a]; |
|
|
|
echo ("Selecting output: "); echo (argument_output); echo ("\n"); |
|
|
|
break; |
|
|
|
} else if ((string_compare (array [index_a], argument_nick [index_b]) != 0) || (string_compare (array [index_a], argument_name [index_b]) != 0)) { |
|
|
|
argument_function [index_b] (); |
|
|
|
echo ("Executing: "); echo (argument_name [index_b]); echo ("\n"); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|