diff --git a/xtandard.c b/xtandard.c index abdf8d7..00440f8 100644 --- a/xtandard.c +++ b/xtandard.c @@ -15,32 +15,32 @@ It is distributed in the hope that it will be useful or harmful, it really depen #include #include -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); } diff --git a/xtandard.h b/xtandard.h index f442427..521509b 100644 --- a/xtandard.h +++ b/xtandard.h @@ -9,67 +9,70 @@ It is distributed in the hope that it will be useful or harmful, it really depen #ifndef XTANDARD_HEADER #define XTANDARD_HEADER -#define SIGNAL_DELETE (0X7F) -#define SIGNAL_ARROW_UP (0X415B1B) -#define SIGNAL_ARROW_DOWN (0X425B1B) -#define SIGNAL_ARROW_RIGHT (0X435B1B) -#define SIGNAL_ARROW_LEFT (0X445B1B) - -#define SIGNAL_CONTROL (0X1000000) -#define SIGNAL_SHIFT (0X2000000) -#define SIGNAL_ALTERNATE (0X4000000) -#define SIGNAL_SYSTEM (0X8000000) +#define signal_delete (0X7F) +#define signal_arrow_up (0X415B1B) +#define signal_arrow_down (0X425B1B) +#define signal_arrow_right (0X435B1B) +#define signal_arrow_left (0X445B1B) + +#define signal_control (0X1000000) +#define signal_shift (0X2000000) +#define signal_alternate (0X4000000) +#define signal_system (0X8000000) + +#ifndef null +#define null ((void *) 0) +#endif enum { - FALSE, - TRUE + false, + true }; enum { - LOG_SUCCESS, LOG_WARNING, LOG_FAILURE, LOG_COMMENT, - LOG_COUNT + log_success, log_warning, log_failure, log_comment, + log_count }; enum { - FILE_TYPE_TEXT, FILE_TYPE_COMMON_ASSEMBLY, FILE_TYPE_FLAT_ASSEMBLY, FILE_TYPE_GNU_ASSEMBLY, - FILE_TYPE_NETWIDE_ASSEMBLY, FILE_TYPE_YET_ANOTHER_ASSEMBLY, FILE_TYPE_C_SOURCE, FILE_TYPE_C_HEADER, - FILE_TYPE_ADA_BODY, FILE_TYPE_ADA_SPECIFICATION, FILE_TYPE_CPP_SOURCE, FILE_TYPE_CPP_HEADER, - FILE_TYPE_COUNT + file_type_text, file_type_common_assembly, file_type_flat_assembly, file_type_gnu_assembly, + file_type_netwide_assembly, file_type_yet_another_assembly, file_type_c_source, file_type_c_header, + file_type_ada_body, file_type_ada_specification, file_type_cpp_source, file_type_cpp_header, + file_type_count }; enum { - EFFECT_NORMAL, EFFECT_BOLD, EFFECT_ITALIC, EFFECT_UNDERLINE, EFFECT_BLINK, EFFECT_REVERSE, - EFFECT_COUNT + effect_normal, effect_bold, effect_italic, effect_underline, effect_blink, effect_reverse, + effect_count }; enum { - COLOUR_GREY, COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW, COLOUR_BLUE, COLOUR_PINK, COLOUR_CYAN, COLOUR_WHITE, - COLOUR_COUNT + colour_grey, colour_red, colour_green, colour_yellow, colour_blue, colour_pink, colour_cyan, colour_white, + colour_count }; enum { - CHARACTER_NULL, CHARACTER_START_HEADER, CHARACTER_START_TEXT, CHARACTER_END_TEXT, - CHARACTER_END_TRANSMISSION, CHARACTER_ENQUIRY, CHARACTER_ACKNOWLEDGE, CHARACTER_BELL, - CHARACTER_BACKSPACE, CHARACTER_TAB_HORIZONTAL, CHARACTER_LINE_FEED, CHARACTER_TAB_VERTICAL, - CHARACTER_FORM_FEED, CHARACTER_CARRIAGE_RETURN, CHARACTER_SHIFT_OUT, CHARACTER_SHIFT_IN, - CHARACTER_DATA_LINK_ESCAPE, CHARACTER_DEVICE_CONTROL_1, CHARACTER_DEVICE_CONTROL_2, CHARACTER_DEVICE_CONTROL_3, - CHARACTER_DEVICE_CONTROL_4, CHARACTER_NOT_ACKNOWLEDGE, CHARACTER_SYNCHRONOUS_IDLE, CHARACTER_END_TRANSMISSION_BLOCK, - CHARACTER_CANCEL, CHARACTER_END_MEDIUM, CHARACTER_SUBSTITUTE, CHARACTER_ESCAPE, - CHARACTER_FILE_SEPARATOR, CHARACTER_GROUP_SEPARATOR, CHARACTER_RECORD_SEPARATOR, CHARACTER_UNIT_SEPARATOR, - CHARACTER_COUNT + character_null, character_start_header, character_start_text, character_end_text, + character_end_transmission, character_enquiry, character_acknowledge, character_bell, + character_backspace, character_tab_horizontal, character_line_feed, character_tab_vertical, + character_form_feed, character_carriage_return, character_shift_out, character_shift_in, + character_data_link_escape, character_device_control_1, character_device_control_2, character_device_control_3, + character_device_control_4, character_not_acknowledge, character_synchronous_idle, character_end_transmission_block, + character_cancel, character_end_medium, character_substitute, character_escape, + character_file_separator, character_group_separator, character_record_separator, character_unit_separator }; enum { - SIGNAL_NONE, - SIGNAL_ANY, - SIGNAL_A, SIGNAL_B, SIGNAL_C, SIGNAL_D, SIGNAL_E, SIGNAL_F, SIGNAL_G, SIGNAL_H, - SIGNAL_I, SIGNAL_J, SIGNAL_K, SIGNAL_L, SIGNAL_M, SIGNAL_N, SIGNAL_O, SIGNAL_P, - SIGNAL_Q, SIGNAL_R, SIGNAL_S, SIGNAL_T, SIGNAL_U, SIGNAL_V, SIGNAL_W, SIGNAL_X, - SIGNAL_Y, SIGNAL_Z, SIGNAL_0, SIGNAL_1, SIGNAL_2, SIGNAL_3, SIGNAL_4, SIGNAL_5, - SIGNAL_6, SIGNAL_7, SIGNAL_8, SIGNAL_9, SIGNAL_ESCAPE, SIGNAL_TABULATOR, SIGNAL_RETURN, SIGNAL_NEW_LINE, - SIGNAL_SLASH, SIGNAL_BACKSLASH, SIGNAL_QUOTE, SIGNAL_BACKQUOTE, SIGNAL_SPACE, SIGNAL_BACKSPACE, SIGNAL_DOT, SIGNAL_COMMA, - SIGNAL_CITE, SIGNAL_CAPS_LOCK, SIGNAL_L_BRACKET, SIGNAL_R_BRACKET, SIGNAL_MINUS, SIGNAL_EQUAL, - SIGNAL_COUNT + signal_none, + signal_any, + signal_a, signal_b, signal_c, signal_d, signal_e, signal_f, signal_g, signal_h, + signal_i, signal_j, signal_k, signal_l, signal_m, signal_n, signal_o, signal_p, + signal_q, signal_r, signal_s, signal_t, signal_u, signal_v, signal_w, signal_x, + signal_y, signal_z, signal_0, signal_1, signal_2, signal_3, signal_4, signal_5, + signal_6, signal_7, signal_8, signal_9, signal_escape, signal_tabulator, signal_return, signal_new_line, + signal_slash, signal_backslash, signal_quote, signal_backquote, signal_space, signal_backspace, signal_dot, signal_comma, + signal_cite, signal_caps_lock, signal_l_bracket, signal_r_bracket, signal_minus, signal_equal, + signal_count }; extern void in (void * data, int size);