Highlight things
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

53 lines
1.1KB

  1. /* main.c
  2. * Copyright 2023 Anon Anonson, Ognjen 'xolatile' Milan Robovic, Emil Williams
  3. * SPDX Identifier: GPL-3.0-only / NO WARRANTY / NO GUARANTEE */
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. #include "terminal_hl.h"
  10. #define ALLOCATION_CHUNK (10UL)
  11. static char * buffer = NULL;
  12. static size_t buffer_size = 0;
  13. int main(int argc,
  14. char * * argv) {
  15. UNUSED(argc);
  16. UNUSED(argv);
  17. // Buffer init
  18. buffer = realloc(buffer, ALLOCATION_CHUNK);
  19. do {
  20. if (!((buffer_size + 1) % ALLOCATION_CHUNK)) {
  21. /* Linear incremental reallocation (advanced)!
  22. */
  23. size_t chunks = (buffer_size + 1) / ALLOCATION_CHUNK;
  24. buffer = realloc(buffer, ++chunks * ALLOCATION_CHUNK);
  25. }
  26. buffer[buffer_size] = '\0';
  27. /* TODO handle me */
  28. assert(read(STDIN_FILENO, &buffer[buffer_size], sizeof (*buffer)) != -1);
  29. ++buffer_size;
  30. } while (buffer[buffer_size - 1]);
  31. buffer[buffer_size - 1] = '\0';
  32. // Highlight init
  33. terminal_hl_init();
  34. //
  35. #include "c.h"
  36. //
  37. render_string(buffer, "cterm");
  38. putchar('\n');
  39. fflush(stdout);
  40. //hl_deinit();
  41. free(buffer);
  42. return 0;
  43. }