libhl/source/main.c
2023-08-29 11:09:55 -06:00

51 lines
1.0 KiB
C

/* main.c
* Copyright 2023 Anon Anonson, Ognjen 'xolatile' Milan Robovic, Emil Williams
* SPDX Identifier: GPL-3.0-only / NO WARRANTY / NO GUARANTEE */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "terminal.h"
#define ALLOCATION_CHUNK (10UL)
static char * buffer = NULL;
static size_t buffer_size = 0;
int main(void) {
// Buffer init
buffer = realloc(buffer, ALLOCATION_CHUNK);
do {
if (!((buffer_size + 1) % ALLOCATION_CHUNK)) {
size_t chunks = (buffer_size + 1) / ALLOCATION_CHUNK;
buffer = realloc(buffer, ++chunks * ALLOCATION_CHUNK);
}
buffer[buffer_size] = '\0';
/* TODO handle me */
assert(read(STDIN_FILENO, &buffer[buffer_size], sizeof (*buffer)) != -1);
++buffer_size;
} while (buffer[buffer_size - 1]);
buffer[buffer_size - 1] = '\0';
// Highlight init
terminal_hl_init();
//
#include "syntax/c.h"
//
render_string(buffer, "cterm");
putchar('\n');
fflush(stdout);
//hl_deinit();
free(buffer);
//terminal_hl_deinit();
return 0;
}