|
|
@@ -15,32 +15,32 @@ It is distributed in the hope that it will be useful or harmful, it really depen |
|
|
|
#include <unistd.h> |
|
|
|
#include <fcntl.h> |
|
|
|
|
|
|
|
static char * log_notify = NULL; |
|
|
|
static char * log_notify = null; |
|
|
|
|
|
|
|
static int argument_count = 0; |
|
|
|
static char * * argument_nick = NULL; |
|
|
|
static char * * argument_name = NULL; |
|
|
|
static char * argument_input = NULL; |
|
|
|
static char * argument_output = NULL; |
|
|
|
static char * * argument_nick = null; |
|
|
|
static char * * argument_name = null; |
|
|
|
static char * argument_input = null; |
|
|
|
static char * argument_output = null; |
|
|
|
|
|
|
|
static void (* * argument_function) (void) = NULL; |
|
|
|
static void (* * argument_function) (void) = null; |
|
|
|
|
|
|
|
static int file_list_active = 0; |
|
|
|
static int file_list_count = 0; |
|
|
|
static int * file_list_mark = NULL; |
|
|
|
static int * file_list_size = NULL; |
|
|
|
static char * * file_list_name = NULL; |
|
|
|
static char * * file_list_data = NULL; |
|
|
|
static int * file_list_mark = null; |
|
|
|
static int * file_list_size = null; |
|
|
|
static char * * file_list_name = null; |
|
|
|
static char * * file_list_data = null; |
|
|
|
|
|
|
|
void in (void * data, int size) { |
|
|
|
fatal_failure (data == NULL, "in: Failed to read from standard input, data is null pointer."); |
|
|
|
fatal_failure (data == null, "in: Failed to read from standard input, data is null pointer."); |
|
|
|
fatal_failure (size == 0, "in: Failed to read from standard input, size is zero."); |
|
|
|
|
|
|
|
(void) read (STDIN_FILENO, data, (unsigned long int) size); |
|
|
|
} |
|
|
|
|
|
|
|
void out (void * data, int size) { |
|
|
|
fatal_failure (data == NULL, "out: Failed to write to standard output, data is null pointer."); |
|
|
|
fatal_failure (data == null, "out: Failed to write to standard output, data is null pointer."); |
|
|
|
fatal_failure (size == 0, "out: Failed to write to standard output, size is zero."); |
|
|
|
|
|
|
|
(void) write (STDOUT_FILENO, data, (unsigned long int) size); |
|
|
@@ -49,14 +49,14 @@ void out (void * data, int size) { |
|
|
|
void log_in (int type, int flag, char * data) { |
|
|
|
int start; |
|
|
|
|
|
|
|
char * type_mark [LOG_COUNT] = { |
|
|
|
char * type_mark [log_count] = { |
|
|
|
"[\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)) { |
|
|
|
if ((flag == 0) || (type <= -1) || (type >= log_count)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -78,7 +78,7 @@ void log_out (char * name) { |
|
|
|
} |
|
|
|
|
|
|
|
void echo (char * data) { |
|
|
|
if (data == NULL) { |
|
|
|
if (data == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -88,12 +88,12 @@ void echo (char * data) { |
|
|
|
void dump (char * name, char * data) { |
|
|
|
int file = -1; |
|
|
|
|
|
|
|
if (name == NULL) { |
|
|
|
if (name == null) { |
|
|
|
echo (data); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (data == NULL) { |
|
|
|
if (data == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -121,7 +121,7 @@ void fatal_failure (int condition, char * message) { |
|
|
|
} |
|
|
|
|
|
|
|
void limit (int * value, int minimum, int maximum) { |
|
|
|
if (value == NULL) { |
|
|
|
if (value == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -135,15 +135,15 @@ void limit (int * value, int minimum, int maximum) { |
|
|
|
} |
|
|
|
|
|
|
|
void * allocate (int size) { |
|
|
|
char * data = NULL; |
|
|
|
char * data = null; |
|
|
|
|
|
|
|
if (size <= 0) { |
|
|
|
return (NULL); |
|
|
|
return (null); |
|
|
|
} |
|
|
|
|
|
|
|
data = calloc ((unsigned long int) size, sizeof (* data)); |
|
|
|
|
|
|
|
fatal_failure (data == NULL, "standard : allocate : Failed to allocate memory, internal function 'calloc' returned null pointer."); |
|
|
|
fatal_failure (data == null, "standard : allocate : Failed to allocate memory, internal function 'calloc' returned null pointer."); |
|
|
|
|
|
|
|
return ((void *) data); |
|
|
|
} |
|
|
@@ -155,7 +155,7 @@ void * reallocate (void * data, int size) { |
|
|
|
|
|
|
|
data = realloc (data, (unsigned long int) size); |
|
|
|
|
|
|
|
fatal_failure (data == NULL, "standard : reallocate: Failed to reallocate memory, internal function 'realloc' returned null pointer."); |
|
|
|
fatal_failure (data == null, "standard : reallocate: Failed to reallocate memory, internal function 'realloc' returned null pointer."); |
|
|
|
|
|
|
|
/* Set new data to 0. */ |
|
|
|
|
|
|
@@ -163,16 +163,16 @@ void * reallocate (void * data, int size) { |
|
|
|
} |
|
|
|
|
|
|
|
void * deallocate (void * data) { |
|
|
|
if (data != NULL) { |
|
|
|
if (data != null) { |
|
|
|
free (data); |
|
|
|
} |
|
|
|
|
|
|
|
return (NULL); |
|
|
|
return (null); |
|
|
|
} |
|
|
|
|
|
|
|
void * memorize (int size) { /* I broke this for testing something out... */ |
|
|
|
static char * buffer = NULL; |
|
|
|
char * points = NULL; |
|
|
|
static char * buffer = null; |
|
|
|
char * points = null; |
|
|
|
static int length = 0; |
|
|
|
static int chunks = 0; |
|
|
|
static int loling = 1024; |
|
|
@@ -180,11 +180,11 @@ void * memorize (int size) { /* I broke this for testing something out... */ |
|
|
|
if (size == 0) { |
|
|
|
free (buffer); |
|
|
|
|
|
|
|
buffer = NULL; |
|
|
|
buffer = null; |
|
|
|
length = 0; |
|
|
|
chunks = 0; |
|
|
|
|
|
|
|
return (NULL); |
|
|
|
return (null); |
|
|
|
} |
|
|
|
|
|
|
|
for (; length + size > chunks * loling; ) { |
|
|
@@ -194,7 +194,7 @@ void * memorize (int size) { /* I broke this for testing something out... */ |
|
|
|
|
|
|
|
buffer = realloc (buffer, (unsigned long int) (chunks * loling)); |
|
|
|
|
|
|
|
fatal_failure (buffer == NULL, "memorize: Oh no..."); |
|
|
|
fatal_failure (buffer == null, "memorize: Oh no..."); |
|
|
|
|
|
|
|
for (i = (chunks - 1) * loling; i != chunks * loling; ++i) { |
|
|
|
buffer [i] = '\0'; |
|
|
@@ -209,7 +209,7 @@ void * memorize (int size) { /* I broke this for testing something out... */ |
|
|
|
} |
|
|
|
|
|
|
|
void * record (void) { |
|
|
|
char * buffer = NULL; |
|
|
|
char * buffer = null; |
|
|
|
int offset = 0; |
|
|
|
int loling = 1024; |
|
|
|
|
|
|
@@ -233,9 +233,9 @@ void * record (void) { |
|
|
|
} |
|
|
|
|
|
|
|
void argument_define (char * nick, char * name, void (* function) (void)) { |
|
|
|
fatal_failure (nick == NULL, "argument_define: Failed to define an argument, nick is null pointer."); |
|
|
|
fatal_failure (name == NULL, "argument_define: Failed to define an argument, name is null pointer."); |
|
|
|
fatal_failure (function == NULL, "argument_define: Failed to define an argument, function is null pointer."); |
|
|
|
fatal_failure (nick == null, "argument_define: Failed to define an argument, nick is null pointer."); |
|
|
|
fatal_failure (name == null, "argument_define: Failed to define an argument, name is null pointer."); |
|
|
|
fatal_failure (function == null, "argument_define: Failed to define an argument, function is null pointer."); |
|
|
|
|
|
|
|
++argument_count; |
|
|
|
|
|
|
@@ -256,7 +256,7 @@ void argument_select (int count, char * * array) { |
|
|
|
int index_a = 0; |
|
|
|
int index_b = 0; |
|
|
|
|
|
|
|
if ((count == 1) || (array == NULL)) { |
|
|
|
if ((count == 1) || (array == null)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -300,7 +300,7 @@ void argument_delete (void) { |
|
|
|
int file_open (char * name, int mode) { |
|
|
|
int descriptor = -1; |
|
|
|
|
|
|
|
fatal_failure (name == NULL, "file_open: Failed to open file, name is null pointer."); |
|
|
|
fatal_failure (name == null, "file_open: Failed to open file, name is null pointer."); |
|
|
|
|
|
|
|
descriptor = open (name, mode); |
|
|
|
|
|
|
@@ -318,7 +318,7 @@ int file_close (int file) { |
|
|
|
|
|
|
|
void file_read (int file, void * data, int size) { |
|
|
|
fatal_failure (file == -1, "file_read: Failed to read from file, invalid descriptor."); |
|
|
|
fatal_failure (data == NULL, "file_read: Failed to read from file, data is null pointer."); |
|
|
|
fatal_failure (data == null, "file_read: Failed to read from file, data is null pointer."); |
|
|
|
fatal_failure (size == 0, "file_read: Failed to read from file, size is zero."); |
|
|
|
|
|
|
|
(void) read (file, data, (unsigned long int) size); |
|
|
@@ -326,7 +326,7 @@ void file_read (int file, void * data, int size) { |
|
|
|
|
|
|
|
void file_write (int file, void * data, int size) { |
|
|
|
fatal_failure (file == -1, "file_write: Failed to write to file, invalid descriptor."); |
|
|
|
fatal_failure (data == NULL, "file_write: Failed to write to file, data is null pointer."); |
|
|
|
fatal_failure (data == null, "file_write: Failed to write to file, data is null pointer."); |
|
|
|
fatal_failure (size == 0, "file_write: Failed to write to file, size is zero."); |
|
|
|
|
|
|
|
(void) write (file, data, (unsigned long int) size); |
|
|
@@ -354,7 +354,7 @@ int file_size (char * name) { |
|
|
|
} |
|
|
|
|
|
|
|
int file_type (char * name) { |
|
|
|
char * file_type_data [FILE_TYPE_COUNT] = { |
|
|
|
char * file_type_data [file_type_count] = { |
|
|
|
".txt", ".s", ".fasm", ".gasm", ".nasm", ".yasm", ".c", ".h", |
|
|
|
".adb", ".ads", ".cpp", ".hpp" |
|
|
|
}; |
|
|
@@ -365,7 +365,7 @@ int file_type (char * name) { |
|
|
|
++name; |
|
|
|
} |
|
|
|
|
|
|
|
for (type = 0; type != FILE_TYPE_COUNT; ++type) { |
|
|
|
for (type = 0; type != file_type_count; ++type) { |
|
|
|
if (string_compare (name, file_type_data [type]) != 0) { |
|
|
|
return (type); |
|
|
|
} |
|
|
@@ -377,9 +377,9 @@ int file_type (char * name) { |
|
|
|
void * file_record (char * name) { |
|
|
|
int file = -1; |
|
|
|
int size = -1; |
|
|
|
char * data = NULL; |
|
|
|
char * data = null; |
|
|
|
|
|
|
|
fatal_failure (name == NULL, "file_import: Failed to import file, name is null pointer."); |
|
|
|
fatal_failure (name == null, "file_import: Failed to import file, name is null pointer."); |
|
|
|
|
|
|
|
file = file_open (name, O_RDONLY); |
|
|
|
size = file_size (name); |
|
|
@@ -395,9 +395,9 @@ void * file_record (char * name) { |
|
|
|
char * file_import (char * name) { |
|
|
|
int file = -1; |
|
|
|
int size = -1; |
|
|
|
char * data = NULL; |
|
|
|
char * data = null; |
|
|
|
|
|
|
|
fatal_failure (name == NULL, "file_import: Failed to import file, name is null pointer."); |
|
|
|
fatal_failure (name == null, "file_import: Failed to import file, name is null pointer."); |
|
|
|
|
|
|
|
file = file_open (name, O_RDONLY); |
|
|
|
size = file_size (name) + 1; |
|
|
@@ -418,7 +418,7 @@ void file_export (char * name, void * data) { |
|
|
|
} |
|
|
|
|
|
|
|
void file_list_import (char * name) { |
|
|
|
fatal_failure (name == NULL, "file_list_import: Failed to import file, name is null pointer."); |
|
|
|
fatal_failure (name == null, "file_list_import: Failed to import file, name is null pointer."); |
|
|
|
|
|
|
|
++file_list_count; |
|
|
|
|
|
|
@@ -431,8 +431,8 @@ void file_list_import (char * name) { |
|
|
|
|
|
|
|
file_list_mark [file_list_active] = -1; |
|
|
|
file_list_size [file_list_active] = -1; |
|
|
|
file_list_name [file_list_active] = NULL; |
|
|
|
file_list_data [file_list_active] = NULL; |
|
|
|
file_list_name [file_list_active] = null; |
|
|
|
file_list_data [file_list_active] = null; |
|
|
|
|
|
|
|
file_list_name [file_list_active] = allocate (string_length (name) + 1); |
|
|
|
|
|
|
@@ -456,7 +456,7 @@ void file_list_import (char * name) { |
|
|
|
} |
|
|
|
|
|
|
|
void file_list_export (char * name) { |
|
|
|
fatal_failure (name == NULL, "file_list_export: Failed to export file, name is null pointer."); |
|
|
|
fatal_failure (name == null, "file_list_export: Failed to export file, name is null pointer."); |
|
|
|
|
|
|
|
file_list_mark [file_list_active] = open (name, O_WRONLY | O_CREAT | O_TRUNC); |
|
|
|
|
|
|
@@ -586,7 +586,7 @@ int character_count (char * string, char this, int from, int to, char stop) { |
|
|
|
int string_length (char * string) { |
|
|
|
int length; |
|
|
|
|
|
|
|
if (string == NULL) { |
|
|
|
if (string == null) { |
|
|
|
return (0); |
|
|
|
} |
|
|
|
|
|
|
@@ -598,7 +598,7 @@ int string_length (char * string) { |
|
|
|
char * string_reverse_limit (char * string, int limit) { |
|
|
|
int i; |
|
|
|
|
|
|
|
fatal_failure (string == NULL, "string_reverse: String is null pointer."); |
|
|
|
fatal_failure (string == null, "string_reverse: String is null pointer."); |
|
|
|
|
|
|
|
for (i = 0; i < limit / 2; ++i) { |
|
|
|
char temporary = string [i]; |
|
|
@@ -616,7 +616,7 @@ char * string_reverse (char * string) { |
|
|
|
char * string_delete (char * string, int length) { |
|
|
|
int i; |
|
|
|
|
|
|
|
if ((string == NULL) || (length <= 0)) { |
|
|
|
if ((string == null) || (length <= 0)) { |
|
|
|
return (string); |
|
|
|
} |
|
|
|
|
|
|
@@ -630,8 +630,8 @@ char * string_delete (char * string, int length) { |
|
|
|
int string_compare (char * string_0, char * string_1) { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_compare: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_compare: Source string is null pointer."); |
|
|
|
fatal_failure (string_0 == null, "string_compare: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_compare: Source string is null pointer."); |
|
|
|
|
|
|
|
for (i = 0; (string_0 [i] != '\0') && (string_1 [i] != '\0'); ++i) { |
|
|
|
if (string_0 [i] != string_1 [i]) { |
|
|
@@ -645,8 +645,8 @@ int string_compare (char * string_0, char * string_1) { |
|
|
|
char * string_copy (char * string_0, char * string_1) { |
|
|
|
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."); |
|
|
|
fatal_failure (string_0 == null, "string_copy: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_copy: Source string is null pointer."); |
|
|
|
|
|
|
|
for (i = 0; i != string_length (string_1) + 1; ++i) { |
|
|
|
string_0 [i] = string_1 [i]; |
|
|
@@ -656,8 +656,8 @@ char * string_copy (char * string_0, char * string_1) { |
|
|
|
} |
|
|
|
|
|
|
|
char * string_concatenate (char * string_0, char * string_1) { |
|
|
|
fatal_failure (string_0 == NULL, "string_concatenate: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_concatenate: Source string is null pointer."); |
|
|
|
fatal_failure (string_0 == null, "string_concatenate: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_concatenate: Source string is null pointer."); |
|
|
|
|
|
|
|
string_0 += string_length (string_0); |
|
|
|
|
|
|
@@ -675,8 +675,8 @@ char * string_concatenate (char * string_0, char * string_1) { |
|
|
|
int string_compare_limit (char * string_0, char * string_1, int limit) { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_compare_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_compare_limit: Source string is null pointer."); |
|
|
|
fatal_failure (string_0 == null, "string_compare_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_compare_limit: Source string is null pointer."); |
|
|
|
|
|
|
|
for (i = 0; i != limit; ++i) { |
|
|
|
if (string_0 [i] != string_1 [i]) { |
|
|
@@ -690,8 +690,8 @@ int string_compare_limit (char * string_0, char * string_1, int limit) { |
|
|
|
char * string_copy_limit (char * string_0, char * string_1, int limit) { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_copy_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_copy_limit: Source string is null pointer."); |
|
|
|
fatal_failure (string_0 == null, "string_copy_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_copy_limit: Source string is null pointer."); |
|
|
|
|
|
|
|
if (limit <= 0) { |
|
|
|
return (string_0); |
|
|
@@ -709,8 +709,8 @@ char * string_concatenate_limit (char * string_0, char * string_1, int limit) { |
|
|
|
int length_0 = 0; |
|
|
|
int length_1 = 0; |
|
|
|
|
|
|
|
fatal_failure (string_0 == NULL, "string_concatenate_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == NULL, "string_concatenate_limit: Source string is null pointer."); |
|
|
|
fatal_failure (string_0 == null, "string_concatenate_limit: Destination string is null pointer."); |
|
|
|
fatal_failure (string_1 == null, "string_concatenate_limit: Source string is null pointer."); |
|
|
|
|
|
|
|
if (limit <= 0) { |
|
|
|
return (string_0); |
|
|
@@ -730,7 +730,7 @@ int string_split_space (char * string) { |
|
|
|
int i = 0; |
|
|
|
int count = 0; |
|
|
|
|
|
|
|
fatal_failure (string == NULL, "string_split_space: Source string is null pointer."); |
|
|
|
fatal_failure (string == null, "string_split_space: Source string is null pointer."); |
|
|
|
|
|
|
|
for (i = 0; string [i] != '\0'; ++i) { |
|
|
|
if ((string [i] == ' ') || (string [i] == '\t') || (string [i] == '\n')) { |
|
|
@@ -765,7 +765,7 @@ void memory_delete (void * memory, int length) { |
|
|
|
|
|
|
|
char * cast = (char *) memory; |
|
|
|
|
|
|
|
fatal_failure (memory == NULL, "memory_delete: Memory is null pointer."); |
|
|
|
fatal_failure (memory == null, "memory_delete: Memory is null pointer."); |
|
|
|
|
|
|
|
if (length <= 0) { |
|
|
|
return; |
|
|
@@ -782,8 +782,8 @@ int memory_compare (void * memory, void * source, int length) { |
|
|
|
char * cast_0 = (char *) memory; |
|
|
|
char * cast_1 = (char *) source; |
|
|
|
|
|
|
|
fatal_failure (memory == NULL, "memory_compare: Memory is null pointer."); |
|
|
|
fatal_failure (source == NULL, "memory_compare: Source is null pointer."); |
|
|
|
fatal_failure (memory == null, "memory_compare: Memory is null pointer."); |
|
|
|
fatal_failure (source == null, "memory_compare: Source is null pointer."); |
|
|
|
|
|
|
|
if (length <= 0) { |
|
|
|
return (-1); |
|
|
@@ -804,8 +804,8 @@ void memory_copy (void * memory, void * source, int length) { |
|
|
|
char * cast_0 = (char *) memory; |
|
|
|
char * cast_1 = (char *) source; |
|
|
|
|
|
|
|
fatal_failure (memory == NULL, "memory_copy: Memory is null pointer."); |
|
|
|
fatal_failure (source == NULL, "memory_copy: Source is null pointer."); |
|
|
|
fatal_failure (memory == null, "memory_copy: Memory is null pointer."); |
|
|
|
fatal_failure (source == null, "memory_copy: Source is null pointer."); |
|
|
|
|
|
|
|
if (length <= 0) { |
|
|
|
return; |
|
|
@@ -823,8 +823,8 @@ void terminal_clear (void) { |
|
|
|
void terminal_colour (int colour, int effect) { |
|
|
|
char format [8] = "\033[ ;3 m"; |
|
|
|
|
|
|
|
format [2] = (char) (effect % EFFECT_COUNT) + '0'; |
|
|
|
format [5] = (char) (colour % COLOUR_COUNT) + '0'; |
|
|
|
format [2] = (char) (effect % effect_count) + '0'; |
|
|
|
format [5] = (char) (colour % colour_count) + '0'; |
|
|
|
|
|
|
|
echo (format); |
|
|
|
} |
|
|
|