]> git.xolatile.top Git - public-libhl.git/commitdiff
Completely new stuff, to use as the base...
authorxolatile <xolatile@proton.me>
Fri, 18 Aug 2023 21:33:35 +0000 (17:33 -0400)
committerxolatile <xolatile@proton.me>
Fri, 18 Aug 2023 21:33:35 +0000 (17:33 -0400)
hl_xolatile.c [new file with mode: 0644]
makefile_xolatile [new file with mode: 0644]

diff --git a/hl_xolatile.c b/hl_xolatile.c
new file mode 100644 (file)
index 0000000..1a04cd5
--- /dev/null
@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+
+#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 (file)
index 0000000..7ca689d
--- /dev/null
@@ -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].'