xighlight/xighlight.c

67 lines
2.8 KiB
C
Raw Normal View History

2023-08-28 09:03:47 -04:00
/*
* Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
*
* Xighlight is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
* And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
* It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
*/
2023-08-25 17:04:01 -04:00
#include <xolatile/xyntax.h>
#include <xolatile/xyntax.c>
int main (void) {
int offset = 0;
int word = 0;
2023-09-12 05:04:54 -04:00
int select = 0;
2023-08-28 09:03:47 -04:00
int length = 0;
2023-08-25 17:04:01 -04:00
char * buffer = NULL;
2023-09-10 10:16:39 -04:00
char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
2023-08-25 17:04:01 -04:00
char * c_keywords [32] = {
2023-08-28 09:03:47 -04:00
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
2023-08-25 17:04:01 -04:00
};
2023-09-12 05:04:54 -04:00
(void) syntax_define (1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
(void) syntax_define (0, 0, "#", "\n", '\\', COLOUR_PINK, EFFECT_BOLD);
(void) syntax_define (0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
(void) syntax_define (0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
(void) syntax_define (0, 0, "'", "'", '\\', COLOUR_RED, EFFECT_NORMAL);
(void) syntax_define (0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
(void) syntax_define (1, 0, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', COLOUR_CYAN, EFFECT_NORMAL);
2023-08-25 17:04:01 -04:00
2023-08-28 09:03:47 -04:00
for (word = 0; word != 32; ++word) {
2023-09-12 05:04:54 -04:00
(void) syntax_define (0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
2023-08-28 09:03:47 -04:00
}
2023-08-25 17:04:01 -04:00
2023-09-12 07:59:52 -04:00
(void) syntax_define (1, 1, "_", separator, '\0', COLOUR_GREY, EFFECT_BOLD);
2023-09-12 05:04:54 -04:00
(void) syntax_define (1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
(void) syntax_define (1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
(void) syntax_define (1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
2023-08-25 17:04:01 -04:00
2023-08-28 09:03:47 -04:00
buffer = record ();
2023-08-25 17:04:01 -04:00
2023-08-28 09:03:47 -04:00
for (offset = 0; buffer [offset] != '\0'; offset += length) {
2023-09-12 05:04:54 -04:00
select = syntax_select (& buffer [offset], & length);
2023-08-25 17:04:01 -04:00
2023-09-12 05:04:54 -04:00
if (select >= syntax_count) {
2023-09-12 05:23:59 -04:00
terminal_style (EFFECT_NORMAL, COLOUR_WHITE);
2023-08-28 09:03:47 -04:00
} else {
2023-09-12 05:23:59 -04:00
terminal_style (syntax_effect [select], syntax_colour [select]);
2023-08-28 09:03:47 -04:00
}
2023-08-25 17:04:01 -04:00
2023-08-28 09:03:47 -04:00
out (& buffer [offset], length);
2023-08-25 17:04:01 -04:00
2023-09-12 05:23:59 -04:00
terminal_style (-1, -1);
2023-08-28 09:03:47 -04:00
}
2023-08-25 17:04:01 -04:00
buffer = deallocate (buffer);
syntax_delete ();
return (EXIT_SUCCESS);
}