From f2cca50f970a0d80d288b32c02f8666fd04b5f13 Mon Sep 17 00:00:00 2001 From: xolatile Date: Fri, 18 Aug 2023 17:33:35 -0400 Subject: [PATCH] Completely new stuff, to use as the base... --- hl_xolatile.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile_xolatile | 8 +++++ 2 files changed, 108 insertions(+) create mode 100644 hl_xolatile.c create mode 100644 makefile_xolatile diff --git a/hl_xolatile.c b/hl_xolatile.c new file mode 100644 index 0000000..1a04cd5 --- /dev/null +++ b/hl_xolatile.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include + +#define UNUSED(x) ((void) (x)) + +#define ALLOCATION_CHUNK (10UL) + +enum { + NORMAL, BOLD, DARKNESS, ITALIC, + UNDERLINE, BLINK, DUNNO_6, REVERSE, + INVISIBLE +}; + +enum { + GREY, RED, GREEN, YELLOW, + BLUE, PINK, CYAN, WHITE, + CANCEL +}; + +static char * buffer = NULL; +static size_t buffer_size = 0; + +static void render_character(char * character) { + write(STDOUT_FILENO, character, sizeof (*character)); +} + +static void render_string(char * string) { + write(STDOUT_FILENO, string, strlen(string)); +} + +static void render_colour(int colour, + int effect) { + char format[8] = "\033[ ;3 m"; + + format[2] = (char) (effect % 9) + '0'; + format[5] = (char) (colour % 8) + '0'; + + render_string(format); +} + +static void render_cancel(void) { + render_string("\033[0m"); +} + +static int is_separator(char character) { + if (( isascii(character)) + && (!isalnum(character)) + && (character != '_')) { + return 1; + } else { + return 0; + } +} + +static int compare_multiple_strings(char * string, + const char * * strings, + const int count) { + int i = 0; + + do { + if (!strcmp(string, strings[i])) { + return 1; + } + } while (++i != count); + + return 0; +} + +int main(int argc, + char * * argv) { + UNUSED(argc); + UNUSED(argv); + + buffer = realloc(buffer, ALLOCATION_CHUNK); + + do { + if (!((buffer_size + 1) % ALLOCATION_CHUNK)) { + // Linear incremental reallocation (advanced)! + size_t chunks = (buffer_size + 1) / ALLOCATION_CHUNK; + buffer = realloc(buffer, ++chunks * ALLOCATION_CHUNK); + } + buffer[buffer_size] = '\0'; + read(STDIN_FILENO, &buffer[buffer_size], sizeof (*buffer)); + ++buffer_size; + } while (buffer[buffer_size - 1]); + + buffer[buffer_size - 1] = '\0'; + + render_colour(RED, BOLD); + render_string(buffer); + render_cancel(); + + free (buffer); + + return 0; +} diff --git a/makefile_xolatile b/makefile_xolatile new file mode 100644 index 0000000..7ca689d --- /dev/null +++ b/makefile_xolatile @@ -0,0 +1,8 @@ +default: + gcc -g -Wall -Wextra -Wpedantic -o hl hl_xolatile.c + clang -g -Weverything -o hl hl_xolatile.c + +# 'This shit requires to be in /usr/bin currently...' +# 'There are unused functions that will be used, ignore now.' +# 'Next please do [$ sudo cp hl /usr/bin/hl].' +# 'Then test it with example [$ echo ABCDEF | valgrind hl].'