diff --git a/xtandard.c b/xtandard.c index ef78fc8..209d7f6 100644 --- a/xtandard.c +++ b/xtandard.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic * - * Xtandard is deallocate software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. + * Xtandard is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. * And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version. * It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. */ @@ -96,12 +96,13 @@ void * memorize (int size) { void * record (void) { char * buffer = NULL; int offset = 0; + int loling = 1024; - buffer = reallocate (buffer, 1024); + buffer = reallocate (buffer, loling); do { - if ((offset + 1) % 1024 == 0) { - buffer = reallocate (buffer, ((offset + 1) / 1024 + 1) * 1024); + if ((offset + 1) % loling == 0) { + buffer = reallocate (buffer, ((offset + 1) / loling + 1) * loling); } buffer [offset] = '\0'; @@ -116,8 +117,25 @@ void * record (void) { return (buffer); } +void curses_style (int effect, int colour) { + char format [8] = "\033[ ;3 m"; + + if ((effect == -1) || (colour == -1)) { + out ("\033[0m", 5); + } else { + format [2] = (char) effect + '0'; + format [5] = (char) colour + '0'; + + out (format, 8); + } +} + +void curses_clear (void) { + out ("\033[2J", 5); +} + int string_length (char * string) { - int length; + int length = 0; fatal_failure (string == NULL, "string_length: String is null."); @@ -131,7 +149,8 @@ void string_delete (char * string) { } void string_reverse (char * string) { - int i, length; + int i = 0; + int length = 0; fatal_failure (string == NULL, "string_reverse: String is null."); @@ -143,7 +162,7 @@ void string_reverse (char * string) { } int string_compare (char * string_0, char * string_1) { - int i; + int i = 0; fatal_failure (string_0 == NULL, "string_compare: Destination string is null."); fatal_failure (string_1 == NULL, "string_compare: Source string is null."); @@ -157,23 +176,9 @@ int string_compare (char * string_0, char * string_1) { return (1); } -int string_compare_limit (char * string_0, char * string_1, int limit) { - int i; - - fatal_failure (string_0 == NULL, "string_compare: Destination string is null."); - fatal_failure (string_1 == NULL, "string_compare: Source string is null."); - - for (i = 0; (string_0 [i] != '\0') && (string_1 [i] != '\0') && (i != limit); ++i) { - if (string_0 [i] != string_1 [i]) { - return (0); - } - } - - return (1); -} - void string_copy (char * string_0, char * string_1) { - int i, length; + int i = 0; + int length = 0; fatal_failure (string_0 == NULL, "string_copy: Destination string is null."); fatal_failure (string_1 == NULL, "string_copy: Source string is null."); @@ -184,29 +189,74 @@ void string_copy (char * string_0, char * string_1) { 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."); + fatal_failure (string_1 == NULL, "string_concatenate: Source string is null."); + + length_0 = string_length (string_0); + length_1 = string_length (string_1); + + for (i = 0; i != length_1; ++i) { + string_0 [length_0 + i] = string_1 [i]; + } } -void string_remove (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."); + fatal_failure (string_1 == NULL, "string_compare_limit: Source string is null."); + + for (i = 0; (string_0 [i] != '\0') && (string_1 [i] != '\0') && (i != limit); ++i) { + if (string_0 [i] != string_1 [i]) { + return (0); + } + } + + return (1); } -int string_string (char * string_0, char * string_1) { +void string_copy_limit (char * string_0, char * string_1, int limit) { + int i = 0; + int length = 0; + fatal_failure (string_0 == NULL, "string_copy_limit: Destination string is null."); + fatal_failure (string_1 == NULL, "string_copy_limit: Source string is null."); + + if (limit <= 0) { + return; + } + + length = string_length (string_1); + + for (i = 0; (i != length) && (i != limit); ++i) { + string_0 [i] = string_1 [i]; + } } -int string_character (char * string_0, char * string_1) { +void string_concatenate_limit (char * string_0, char * string_1, int limit) { + int i = 0; + int length_0 = 0; + int length_1 = 0; + fatal_failure (string_0 == NULL, "string_concatenate_limit: Destination string is null."); + fatal_failure (string_1 == NULL, "string_concatenate_limit: Source string is null."); + + if (limit <= 0) { + return; + } + + length_0 = string_length (string_0); + length_1 = string_length (string_1); + + for (i = 0; (i != length_1) && (i != limit); ++i) { + string_0 [length_0 + i] = string_1 [i]; + } } -void string_offset (char * string, char character, int count) { - -} - -void string_replace (char * string, char character, int count) { - -} -*/ #endif diff --git a/xtandard.h b/xtandard.h index fd3f1eb..dc591d8 100644 --- a/xtandard.h +++ b/xtandard.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic * - * Xtandard is deallocate software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. + * Xtandard is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. * And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version. * It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. */ @@ -12,21 +12,26 @@ #include #include -#define TERMINAL_EFFECT_NORMAL (0) -#define TERMINAL_EFFECT_BOLD (1) -#define TERMINAL_EFFECT_ITALIC (3) -#define TERMINAL_EFFECT_UNDERLINE (4) -#define TERMINAL_EFFECT_REVERSE (7) +enum { + EFFECT_NORMAL, + EFFECT_BOLD, + EFFECT_DARK, + EFFECT_ITALIC, + EFFECT_UNDERLINE, + EFFECT_BLINK, + EFFECT_UNDEFINED, + EFFECT_REVERSE +}; enum { - TERMINAL_COLOUR_GREY, - TERMINAL_COLOUR_RED, - TERMINAL_COLOUR_GREEN, - TERMINAL_COLOUR_YELLOW, - TERMINAL_COLOUR_BLUE, - TERMINAL_COLOUR_PINK, - TERMINAL_COLOUR_CYAN, - TERMINAL_COLOUR_WHITE + COLOUR_GREY, + COLOUR_RED, + COLOUR_GREEN, + COLOUR_YELLOW, + COLOUR_BLUE, + COLOUR_PINK, + COLOUR_CYAN, + COLOUR_WHITE }; extern void in (void *, int); @@ -41,19 +46,18 @@ extern void * memorize (int); extern void * record (void); +extern void curses_style (int, int); +extern void curses_clear (void); + extern int string_length (char *); extern void string_delete (char *); extern void string_reverse (char *); -extern int string_compare (char *, char *); -extern int string_compare_limit (char *, char *, int); -extern void string_copy (char *, char *); -//~extern void string_concatenate (char *, char *); -//~extern void string_remove (char *, char *); // Remove entire 1 from 0. -//~extern int string_string (char *, char *); // Search for entire 1 inside 0. -//~extern int string_character (char *, char *); // Search for any of 1's characters inside 0. - -//~extern void string_offset (char *, char, int); // String +- count offset left right. -//~extern void string_replace (char *, char, int); // Replace count characters in string. +extern int string_compare (char *, char *); +extern void string_copy (char *, char *); +extern void string_concatenate (char *, char *); +extern int string_compare_limit (char *, char *, int); +extern void string_copy_limit (char *, char *, int); +extern void string_concatenate_limit (char *, char *, int); #endif