|
|
@@ -9,17 +9,20 @@ |
|
|
|
#ifndef XTANDARD_SOURCE |
|
|
|
#define XTANDARD_SOURCE |
|
|
|
|
|
|
|
#include "xtandard.h" |
|
|
|
#include <xolatile/xtandard.h> |
|
|
|
|
|
|
|
char * program_name = NULL; |
|
|
|
char * program_mode = NULL; |
|
|
|
char * program_license = NULL; |
|
|
|
|
|
|
|
int argument_count = 0; |
|
|
|
char * * argument_nick = NULL; |
|
|
|
char * * argument_name = NULL; |
|
|
|
char * argument_input = NULL; |
|
|
|
char * argument_output = NULL; |
|
|
|
char * log_notify = NULL; |
|
|
|
|
|
|
|
int argument_count = 0; |
|
|
|
char * * argument_nick = NULL; |
|
|
|
char * * argument_name = NULL; |
|
|
|
char * argument_input = NULL; |
|
|
|
char * argument_output = NULL; |
|
|
|
|
|
|
|
void (* * argument_function) (void) = NULL; |
|
|
|
|
|
|
|
int file_list_active = 0; |
|
|
@@ -43,7 +46,42 @@ void out (void * data, int size) { |
|
|
|
(void) write (STDOUT_FILENO, data, (unsigned long int) size); |
|
|
|
} |
|
|
|
|
|
|
|
void log_in (int type, int flag, char * data) { |
|
|
|
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] " |
|
|
|
}; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
log_notify [string_length (log_notify)] = '\0'; |
|
|
|
} |
|
|
|
|
|
|
|
string_concatenate (log_notify, type_mark [type]); |
|
|
|
string_concatenate (log_notify, data); |
|
|
|
string_concatenate (log_notify, "\n"); |
|
|
|
} |
|
|
|
|
|
|
|
void log_out (void) { |
|
|
|
echo (log_notify); |
|
|
|
|
|
|
|
log_notify = deallocate (log_notify); |
|
|
|
} |
|
|
|
|
|
|
|
void echo (char * data) { |
|
|
|
if (data == NULL) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
out (data, string_length (data)); |
|
|
|
} |
|
|
|
|
|
|
@@ -59,7 +97,7 @@ void echo_byte (int byte) { |
|
|
|
|
|
|
|
void fatal_failure (int condition, char * message) { |
|
|
|
if (condition != 0) { |
|
|
|
echo ("\033[1;31m[!]\033[0m "); |
|
|
|
echo ("\033[1;31m[FATAL_FAILURE]\033[0m "); |
|
|
|
echo (message); |
|
|
|
echo ("\n"); |
|
|
|
|
|
|
@@ -80,7 +118,9 @@ void limit (int * value, int minimum, int maximum) { |
|
|
|
void * allocate (int size) { |
|
|
|
char * data = NULL; |
|
|
|
|
|
|
|
fatal_failure (size == 0, "allocate: Failed to allocate memory, size is zero."); |
|
|
|
if (size <= 0) { |
|
|
|
return (NULL); |
|
|
|
} |
|
|
|
|
|
|
|
data = calloc ((unsigned long int) size, sizeof (* data)); |
|
|
|
|
|
|
@@ -90,7 +130,9 @@ void * allocate (int size) { |
|
|
|
} |
|
|
|
|
|
|
|
void * reallocate (void * data, int size) { |
|
|
|
fatal_failure (size == 0, "reallocate: Failed to reallocate memory, size is zero."); |
|
|
|
if (size <= 0) { |
|
|
|
return (data); |
|
|
|
} |
|
|
|
|
|
|
|
data = realloc (data, (unsigned long int) size); |
|
|
|
|
|
|
@@ -102,9 +144,9 @@ void * reallocate (void * data, int size) { |
|
|
|
} |
|
|
|
|
|
|
|
void * deallocate (void * data) { |
|
|
|
fatal_failure (data == NULL, "deallocate: Failed to deallocate memory, data is null pointer."); |
|
|
|
|
|
|
|
free (data); |
|
|
|
if (data != NULL) { |
|
|
|
free (data); |
|
|
|
} |
|
|
|
|
|
|
|
return (NULL); |
|
|
|
} |
|
|
@@ -467,7 +509,9 @@ int character_compare_array (char character, char * character_array, int count) |
|
|
|
int string_length (char * string) { |
|
|
|
int length = 0; |
|
|
|
|
|
|
|
fatal_failure (string == NULL, "string_length: String is null pointer."); |
|
|
|
if (string == NULL) { |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
|
for (length = 0; string [length] != '\0'; ++length); |
|
|
|
|
|
|
@@ -490,8 +534,9 @@ void string_reverse (char * string) { |
|
|
|
void string_delete (char * string, int length) { |
|
|
|
int i; |
|
|
|
|
|
|
|
fatal_failure (string == NULL, "string_delete: String is null pointer."); |
|
|
|
fatal_failure (length == 0, "string_delete: String length is zero."); |
|
|
|
if ((string == NULL) || (length <= 0)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i != length; ++i) { |
|
|
|
string [i] = '\0'; |
|
|
@@ -514,33 +559,29 @@ int string_compare (char * string_0, char * string_1) { |
|
|
|
} |
|
|
|
|
|
|
|
void string_copy (char * string_0, char * string_1) { |
|
|
|
int i = 0; |
|
|
|
int length = 0; |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_copy: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_copy: Source string is null pointer."); |
|
|
|
|
|
|
|
length = string_length (string_1); |
|
|
|
|
|
|
|
for (i = 0; i != length; ++i) { |
|
|
|
for (i = 0; i != string_length (string_1) + 1; ++i) { |
|
|
|
string_0 [i] = string_1 [i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void string_concatenate (char * string_0, char * string_1) { |
|
|
|
int i = 0; |
|
|
|
int length_0 = 0; |
|
|
|
int length_1 = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_concatenate: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_concatenate: Source string is null pointer."); |
|
|
|
|
|
|
|
length_0 = string_length (string_0); |
|
|
|
length_1 = string_length (string_1); |
|
|
|
string_0 += string_length (string_0); |
|
|
|
|
|
|
|
for (i = 0; i != length_1; ++i) { |
|
|
|
string_0 [length_0 + i] = string_1 [i]; |
|
|
|
while (* string_1 != '\0') { |
|
|
|
* string_0++ = * string_1++; |
|
|
|
/*++string_0; |
|
|
|
++string_1;*/ |
|
|
|
} |
|
|
|
|
|
|
|
* string_0 = '\0'; |
|
|
|
} |
|
|
|
|
|
|
|
int string_compare_limit (char * string_0, char * string_1, int limit) { |
|
|
@@ -635,7 +676,7 @@ int memory_compare (void * memory, void * source, int length) { |
|
|
|
fatal_failure (source == NULL, "memory_compare: Source is null pointer."); |
|
|
|
|
|
|
|
if (length <= 0) { |
|
|
|
return; |
|
|
|
return (-1); |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; (cast_0 [i] != '\0') && (cast_1 [i] != '\0'); ++i) { |
|
|
@@ -702,7 +743,12 @@ int encode_byte (char * byte) { |
|
|
|
} |
|
|
|
|
|
|
|
char * decode_byte (int byte) { |
|
|
|
static char * decode = " "; |
|
|
|
char * decode = " "; |
|
|
|
|
|
|
|
fatal_failure ((byte <= -1) || (byte >= 256), "decode_byte: Byte is out of range."); |
|
|
|
|
|
|
|
decode [0] = byte / 16; |
|
|
|
decode [1] = byte % 16; |
|
|
|
|
|
|
|
return (decode); |
|
|
|
} |
|
|
|