Synchronized changes with xyntax...
This commit is contained in:
parent
5083f3f594
commit
f3a71ba518
45
xighlight.c
45
xighlight.c
@ -14,23 +14,10 @@
|
|||||||
int main (void) {
|
int main (void) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int word = 0;
|
int word = 0;
|
||||||
int index = 0;
|
int select = 0;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
char * buffer = NULL;
|
char * buffer = NULL;
|
||||||
|
|
||||||
int whitespace = 0;
|
|
||||||
int preprocessor = 0;
|
|
||||||
int line_comment = 0;
|
|
||||||
int multiline_comment = 0;
|
|
||||||
int character = 0;
|
|
||||||
int string = 0;
|
|
||||||
int operator = 0;
|
|
||||||
int keyword = 0;
|
|
||||||
int digit = 0;
|
|
||||||
int uppercase = 0;
|
|
||||||
int lowercase = 0;
|
|
||||||
int underscore = 0;
|
|
||||||
|
|
||||||
char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
|
char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
|
||||||
|
|
||||||
char * c_keywords [32] = {
|
char * c_keywords [32] = {
|
||||||
@ -40,32 +27,32 @@ int main (void) {
|
|||||||
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
||||||
};
|
};
|
||||||
|
|
||||||
syntax_define (& whitespace, 1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
|
(void) syntax_define (1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
|
||||||
syntax_define (& preprocessor, 0, 0, "#", "\n", '\\', COLOUR_PINK, EFFECT_BOLD);
|
(void) syntax_define (0, 0, "#", "\n", '\\', COLOUR_PINK, EFFECT_BOLD);
|
||||||
syntax_define (& line_comment, 0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
(void) syntax_define (0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
syntax_define (& multiline_comment, 0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
(void) syntax_define (0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
syntax_define (& character, 0, 0, "'", "'", '\\', COLOUR_RED, EFFECT_NORMAL);
|
(void) syntax_define (0, 0, "'", "'", '\\', COLOUR_RED, EFFECT_NORMAL);
|
||||||
syntax_define (& string, 0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
|
(void) syntax_define (0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
|
||||||
syntax_define (& operator, 1, 0, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', COLOUR_CYAN, EFFECT_NORMAL);
|
(void) syntax_define (1, 0, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', COLOUR_CYAN, EFFECT_NORMAL);
|
||||||
|
|
||||||
for (word = 0; word != 32; ++word) {
|
for (word = 0; word != 32; ++word) {
|
||||||
syntax_define (& keyword, 0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
|
(void) syntax_define (0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
syntax_define (& digit, 1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
|
(void) syntax_define (1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
|
||||||
syntax_define (& uppercase, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
|
(void) syntax_define (1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
|
||||||
syntax_define (& lowercase, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
|
(void) syntax_define (1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
|
||||||
syntax_define (& underscore, 0, 1, "_", separator, '\0', COLOUR_PINK, EFFECT_BOLD);
|
(void) syntax_define (0, 1, "_", separator, '\0', COLOUR_PINK, EFFECT_BOLD);
|
||||||
|
|
||||||
buffer = record ();
|
buffer = record ();
|
||||||
|
|
||||||
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
||||||
syntax_select (& buffer [offset], & index, & length);
|
select = syntax_select (& buffer [offset], & length);
|
||||||
|
|
||||||
if (index >= syntax_count) {
|
if (select >= syntax_count) {
|
||||||
curses_style (EFFECT_NORMAL, COLOUR_WHITE);
|
curses_style (EFFECT_NORMAL, COLOUR_WHITE);
|
||||||
} else {
|
} else {
|
||||||
curses_style (syntax_effect [index], syntax_colour [index]);
|
curses_style (syntax_effect [select], syntax_colour [select]);
|
||||||
}
|
}
|
||||||
|
|
||||||
out (& buffer [offset], length);
|
out (& buffer [offset], length);
|
||||||
|
Loading…
Reference in New Issue
Block a user