More powerful...?
This commit is contained in:
parent
474d3fdb35
commit
9a9817d6ae
87
xighlight.c
87
xighlight.c
@ -1,11 +1,34 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <xolatile/xyntax.h>
|
||||
#include <xolatile/xyntax.c>
|
||||
|
||||
int main (void) {
|
||||
int offset = 0;
|
||||
int word = 0;
|
||||
int index = 0;
|
||||
int length = 0;
|
||||
char * buffer = NULL;
|
||||
|
||||
int preprocessor = 0;
|
||||
int line_comment = 0;
|
||||
int multiline_comment = 0;
|
||||
int character = 0;
|
||||
int string = 0;
|
||||
int bracket = 0;
|
||||
int operator = 0;
|
||||
int keyword = 0;
|
||||
int digit = 0;
|
||||
int uppercase = 0;
|
||||
int lowercase = 0;
|
||||
int underscore = 0;
|
||||
|
||||
char separator [29] = ".,:;<=>+-*/%!&~^()[]{}'\" \t\r\n";
|
||||
|
||||
char * c_keywords [32] = {
|
||||
@ -15,48 +38,38 @@ int main (void) {
|
||||
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
||||
};
|
||||
|
||||
char * c_preprocessor [8] = {
|
||||
"#include", "#define", "#ifdef", "#ifndef", "#undef", "#elif", "#if", "#endif"
|
||||
};
|
||||
syntax_define (& preprocessor, 0, 0, "#", "\n", '\\', COLOUR_RED, EFFECT_BOLD);
|
||||
syntax_define (& line_comment, 0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||
syntax_define (& multiline_comment, 0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||
syntax_define (& character, 0, 0, "'", "'", '\\', COLOUR_PINK, EFFECT_BOLD);
|
||||
syntax_define (& string, 0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
|
||||
syntax_define (& bracket, 1, 0, "()[]{}", "", '\0', COLOUR_GREEN, EFFECT_BOLD);
|
||||
syntax_define (& operator, 1, 0, ".,:;<=>+-*/%!&~^", "", '\0', COLOUR_BLUE, EFFECT_BOLD);
|
||||
|
||||
char * c_common [4] = {
|
||||
"NULL", "FILE", "size_t", "ssize_t"
|
||||
};
|
||||
for (word = 0; word != 32; ++word) {
|
||||
syntax_define (& keyword, 0, 1, c_keywords [word], separator, '\0', COLOUR_YELLOW, EFFECT_BOLD);
|
||||
}
|
||||
|
||||
syntax_define (0, 0, 0, "#", "\n", '\\', TERMINAL_COLOUR_RED, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 0, 0, "/*", "*/", '\0', TERMINAL_COLOUR_GREY, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 0, 0, "//", "\n", '\0', TERMINAL_COLOUR_GREY, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 0, 0, "'", "'", '\\', TERMINAL_COLOUR_PINK, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 0, 0, "\"", "\"", '\\', TERMINAL_COLOUR_RED, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 1, 0, "()[]{}", "", '\0', TERMINAL_COLOUR_GREEN, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 1, 0, ".,:;<=>+-*/%!&~^", "", '\0', TERMINAL_COLOUR_BLUE, TERMINAL_EFFECT_BOLD);
|
||||
|
||||
do {
|
||||
syntax_define (0, 0, 1, c_keywords [word], separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_BOLD);
|
||||
} while (++word != 32);
|
||||
|
||||
word = 0;
|
||||
|
||||
do {
|
||||
syntax_define (0, 0, 1, c_preprocessor [word], separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_NORMAL);
|
||||
} while (++word != 8);
|
||||
|
||||
word = 0;
|
||||
|
||||
do {
|
||||
syntax_define (0, 0, 1, c_common [word], separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_ITALIC);
|
||||
} while (++word != 4);
|
||||
|
||||
syntax_define (0, 1, 1, "0123456789", separator, '\0', TERMINAL_COLOUR_CYAN, TERMINAL_EFFECT_BOLD);
|
||||
syntax_define (0, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', TERMINAL_COLOUR_PINK, TERMINAL_EFFECT_ITALIC);
|
||||
syntax_define (0, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', TERMINAL_COLOUR_WHITE, TERMINAL_EFFECT_ITALIC);
|
||||
syntax_define (0, 0, 1, "_", separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_ITALIC);
|
||||
syntax_define (& digit, 1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
|
||||
syntax_define (& uppercase, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
|
||||
syntax_define (& lowercase, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
|
||||
syntax_define (& underscore, 0, 1, "_", separator, '\0', COLOUR_YELLOW, EFFECT_ITALIC);
|
||||
|
||||
buffer = record ();
|
||||
|
||||
do {
|
||||
offset += syntax_output (& buffer [offset]);
|
||||
} while (buffer [offset] != '\0');
|
||||
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
||||
syntax_select (& buffer [offset], & index, & length);
|
||||
|
||||
if (index >= syntax_count) {
|
||||
curses_style (EFFECT_NORMAL, COLOUR_WHITE);
|
||||
} else {
|
||||
curses_style (syntax_effect [index], syntax_colour [index]);
|
||||
}
|
||||
|
||||
out (& buffer [offset], length);
|
||||
|
||||
curses_style (-1, -1);
|
||||
}
|
||||
|
||||
buffer = deallocate (buffer);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user