Completely new stuff, to use as the base...
This commit is contained in:
parent
6c7ecaa390
commit
f2cca50f97
100
hl_xolatile.c
Normal file
100
hl_xolatile.c
Normal file
@ -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;
|
||||
}
|
8
makefile_xolatile
Normal file
8
makefile_xolatile
Normal file
@ -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].'
|
Loading…
Reference in New Issue
Block a user