Added file types, Ada and C++ highlighting modes...
This commit is contained in:
parent
98aaf77c38
commit
e8e1121f5c
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
gcc -ansi -Wall -Wextra -Wpedantic -Werror -o xighlight xighlight.c
|
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -o xighlight xighlight.c
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
87
xighlight.c
87
xighlight.c
@ -19,6 +19,8 @@ static void highlight_c (void) {
|
|||||||
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
program_mode = "C highlighting mode\n";
|
||||||
|
|
||||||
syntax_define_separators (separators);
|
syntax_define_separators (separators);
|
||||||
|
|
||||||
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
@ -45,10 +47,12 @@ static void highlight_ada (void) {
|
|||||||
"type", "case", "in", "constant", "until", "is", "raise", "use",
|
"type", "case", "in", "constant", "until", "is", "raise", "use",
|
||||||
"if", "declare", "range", "delay", "limited", "record", "when", "delta",
|
"if", "declare", "range", "delay", "limited", "record", "when", "delta",
|
||||||
"loop", "rem", "while", "digits", "renames", "with", "do", "mod",
|
"loop", "rem", "while", "digits", "renames", "with", "do", "mod",
|
||||||
"requeue", "xor", "procedure", "protected", "interface",
|
"requeue", "xor", "procedure", "protected", "interface", "synchronized", "exception", "overriding",
|
||||||
"synchronized", "exception", "overriding", "terminate"
|
"terminate"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
program_mode = "Ada highlighting mode\n";
|
||||||
|
|
||||||
syntax_define_separators (separators);
|
syntax_define_separators (separators);
|
||||||
|
|
||||||
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
@ -61,25 +65,94 @@ static void highlight_ada (void) {
|
|||||||
syntax_define_words (keywords, 73, COLOUR_BLUE, EFFECT_NORMAL);
|
syntax_define_words (keywords, 73, COLOUR_BLUE, EFFECT_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void highlight_cpp (void) {
|
||||||
|
char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
|
||||||
|
|
||||||
|
char * keywords [102] = {
|
||||||
|
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept",
|
||||||
|
"auto", "bitand", "bitor", "bool", "break", "case", "catch", "char",
|
||||||
|
"char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval",
|
||||||
|
"constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype",
|
||||||
|
"default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit",
|
||||||
|
"export", "extern", "false", "float", "for", "friend", "goto", "if",
|
||||||
|
"inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not",
|
||||||
|
"not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public",
|
||||||
|
"reflexpr", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof",
|
||||||
|
"static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this",
|
||||||
|
"thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
|
||||||
|
"unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor",
|
||||||
|
"xor_eq", "final", "override", "import", "module", "transaction_safe"
|
||||||
|
};
|
||||||
|
|
||||||
|
program_mode = "C++ highlighting mode\n";
|
||||||
|
|
||||||
|
syntax_define_separators (separators);
|
||||||
|
|
||||||
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_range ("/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("#", "\n", '\\', COLOUR_PINK, EFFECT_NORMAL);
|
||||||
|
syntax_define_range ("'", "'", '\\', COLOUR_PINK, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_operators (".,:;<=>+*-/%!&~^?|()[]{}", COLOUR_BLUE, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_words (keywords, 102, COLOUR_BLUE, EFFECT_NORMAL);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
static void highlight_ (void) {
|
||||||
|
char * separators = ".,:;<=>+*-/&|()\" \t\r\n";
|
||||||
|
|
||||||
|
char * keywords [73] = {
|
||||||
|
};
|
||||||
|
|
||||||
|
syntax_define_separators (separators);
|
||||||
|
|
||||||
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_range ("--", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("'", "'", '\0', COLOUR_PINK, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_operators (".,:;<=>+*-/&|()'", COLOUR_BLUE, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_words (keywords, 73, COLOUR_BLUE, EFFECT_NORMAL);
|
||||||
|
}
|
||||||
|
*/
|
||||||
int main (int argc, char * * argv) {
|
int main (int argc, char * * argv) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int select = 0;
|
int select = 0;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
char * buffer = NULL;
|
char * buffer = NULL;
|
||||||
|
|
||||||
if (argc != 1) {
|
program_name = "Xighlight -- Syntax highlighting program\n";
|
||||||
if (string_compare (argv [1], "c") != 0) {
|
program_license = "GNU/GPLv3 -- GNU General Public License (version 3)\n";
|
||||||
|
|
||||||
|
if (argc == 2) {
|
||||||
|
int type = file_type (argv [1]);
|
||||||
|
|
||||||
|
fatal_failure (type == -1, "xighlight: Unknown file type.");
|
||||||
|
|
||||||
|
buffer = file_import (argv [1]);
|
||||||
|
|
||||||
|
if ((type == FILE_TYPE_C_SOURCE) || (type == FILE_TYPE_C_HEADER)) {
|
||||||
highlight_c ();
|
highlight_c ();
|
||||||
} else if (string_compare (argv [1], "ada") != 0) {
|
} else if ((type == FILE_TYPE_ADA_BODY) || (type == FILE_TYPE_ADA_SPECIFICATION)) {
|
||||||
highlight_ada ();
|
highlight_ada ();
|
||||||
|
} else if ((type == FILE_TYPE_CPP_SOURCE) || (type == FILE_TYPE_CPP_HEADER)) {
|
||||||
|
highlight_cpp ();
|
||||||
} else {
|
} else {
|
||||||
highlight_c ();
|
echo ("0123456789" + type);
|
||||||
|
fatal_failure (1, "Unknown highlighting mode:");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
buffer = record ();
|
||||||
|
|
||||||
highlight_c ();
|
highlight_c ();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = record ();
|
echo (program_name);
|
||||||
|
echo (program_license);
|
||||||
|
echo (program_mode);
|
||||||
|
|
||||||
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
||||||
select = syntax_select (& buffer [offset], & length);
|
select = syntax_select (& buffer [offset], & length);
|
||||||
|
Loading…
Reference in New Issue
Block a user