Xighlight C source code...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

455 lines
30KB

  1. #include <xolatile/xtandard.c>
  2. #include <xolatile/xyntax.c>
  3. static void highlight_common (void) {
  4. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\"@#$` \t\r\n";
  5. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  6. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  7. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  8. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|@#$`", "", '\0', colour_cyan, effect_normal);
  9. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  10. }
  11. static void highlight_c (void) {
  12. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
  13. char * keywords [] = {
  14. "register", "volatile", "auto", "const", "static", "extern", "if", "else",
  15. "do", "while", "for", "continue", "switch", "case", "default", "break",
  16. "enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
  17. "char", "short", "int", "long", "signed", "unsigned", "float", "double"
  18. };
  19. int word;
  20. syntax_define (false, false, "/*", "*/", '\0', colour_grey, effect_bold);
  21. syntax_define (false, false, "//", "\n", '\0', colour_grey, effect_bold);
  22. syntax_define (false, false, "#", "\n", '\\', colour_yellow, effect_italic);
  23. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  24. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  25. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  26. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  27. }
  28. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  29. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', colour_cyan, effect_normal);
  30. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  31. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  32. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  33. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  34. }
  35. static void highlight_ada (void) {
  36. char * separators = ".,:;<=>+-*/&|()\" \t\r\n";
  37. char * keywords [] = {
  38. "abort", "else", "new", "return", "abs", "elsif", "not", "reverse",
  39. "abstract", "end", "null", "accept", "entry", "select", "access", "of",
  40. "separate", "aliased", "exit", "or", "some", "all", "others", "subtype",
  41. "and", "for", "out", "array", "function", "at", "tagged", "generic",
  42. "package", "task", "begin", "goto", "pragma", "body", "private", "then",
  43. "type", "case", "in", "constant", "until", "is", "raise", "use",
  44. "if", "declare", "range", "delay", "limited", "record", "when", "delta",
  45. "loop", "rem", "while", "digits", "renames", "with", "do", "mod",
  46. "requeue", "xor", "procedure", "protected", "interface", "synchronized", "exception", "overriding",
  47. "terminate"
  48. };
  49. int word;
  50. syntax_define (false, false, "--", "\n", '\0', colour_grey, effect_bold);
  51. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  52. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  53. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  54. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  55. }
  56. syntax_define (true, false, "()", "", '\0', colour_blue, effect_normal);
  57. syntax_define (true, false, ".,:;<=>+-*/&|'", "", '\0', colour_cyan, effect_normal);
  58. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  59. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  60. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  61. }
  62. static void highlight_cpp (void) {
  63. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
  64. char * keywords [] = {
  65. "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept",
  66. "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char",
  67. "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval",
  68. "constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype",
  69. "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit",
  70. "export", "extern", "false", "float", "for", "friend", "goto", "if",
  71. "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not",
  72. "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public",
  73. "reflexpr", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof",
  74. "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this",
  75. "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
  76. "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor",
  77. "xor_eq", "final", "override", "import", "module", "transaction_safe"
  78. };
  79. int word;
  80. syntax_define (false, false, "/*", "*/", '\0', colour_grey, effect_bold);
  81. syntax_define (false, false, "//", "\n", '\0', colour_grey, effect_bold);
  82. syntax_define (false, false, "#", "\n", '\\', colour_yellow, effect_italic);
  83. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  84. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  85. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  86. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  87. }
  88. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  89. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', colour_cyan, effect_normal);
  90. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  91. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  92. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  93. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  94. }
  95. static void highlight_common_assembly (void) {
  96. char * separators = ".,+-[]<> \t\r\n";
  97. char * instructions [] = {
  98. "mov", "movabs", "movapd", "movaps", "movebe", "movsd", "movsx", "movzx",
  99. "movsxd", "movd", "movq", "movs", "movsb", "movsw", "movsd", "movsq",
  100. "cmovmp", "cmovrcxz", "cmovc", "cmovnc", "cmove", "cmovne", "cmovz", "cmovnz",
  101. "cmovg", "cmovng", "cmovge", "cmovnge", "cmovl", "cmovnl", "cmovle", "cmovnle",
  102. "cmova", "cmovna", "cmovae", "cmovnae", "cmovb", "cmovnb", "cmovbe", "cmovnbe",
  103. "cmovs", "cmovns", "cmovo", "cmovno", "cmovp", "cmovnp", "cmovpo", "cmovpe",
  104. "cmp", "cmps", "cmpsb", "cmpsw", "cmpsd", "cmpsq", "cmpxchg", "lea",
  105. "monitor", "cpuid", "in", "out", "syscall", "sysenter", "sysret", "sysexit",
  106. "swap", "bswap", "pop", "push", "call", "ret", "enter", "leave",
  107. "and", "or", "not", "neg", "sal", "sar", "shl", "shr",
  108. "inc", "dec", "add", "sub", "mul", "div", "imul", "idiv",
  109. "nop", "fnop", "adc", "sbb", "aaa", "aas", "aam", "aad",
  110. "jmp", "jrcxz", "jc", "jnc", "je", "jne", "jz", "jnz",
  111. "jg", "jng", "jge", "jnge", "jl", "jnl", "jle", "jnle",
  112. "ja", "jna", "jae", "jnae", "jb", "jnb", "jbe", "jnbe",
  113. "js", "jns", "jo", "jno", "jp", "jnp", "jpo", "jpe",
  114. "rep", "repe", "repz", "repne", "repnz", "loop", "loope", "loopne"
  115. };
  116. char * registers [] = {
  117. "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
  118. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  119. "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  120. "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
  121. "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
  122. "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
  123. "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
  124. "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b",
  125. "ah", "ch", "dh", "bh"
  126. };
  127. int word;
  128. syntax_define (false, false, ";", "\n", '\0', colour_grey, effect_bold);
  129. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  130. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  131. for (word = 0; word != (int) (sizeof (instructions) / sizeof (instructions [0])); ++word) {
  132. syntax_define (false, true, instructions [word], separators, '\0', colour_yellow, effect_bold);
  133. }
  134. for (word = 0; word != (int) (sizeof (registers) / sizeof (registers [0])); ++word) {
  135. syntax_define (false, true, registers [word], separators, '\0', colour_cyan, effect_bold);
  136. }
  137. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  138. syntax_define (true, false, ".,+*-/%$<>", "", '\0', colour_cyan, effect_normal);
  139. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  140. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  141. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  142. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  143. }
  144. static void highlight_flat_assembly (void) {
  145. char * separators = ".,+-=:;(){}[]%$<> \t\r\n";
  146. char * instructions [] = {
  147. "mov", "movabs", "movapd", "movaps", "movebe", "movsd", "movsx", "movzx",
  148. "movsxd", "movd", "movq", "movs", "movsb", "movsw", "movsd", "movsq",
  149. "cmovmp", "cmovrcxz", "cmovc", "cmovnc", "cmove", "cmovne", "cmovz", "cmovnz",
  150. "cmovg", "cmovng", "cmovge", "cmovnge", "cmovl", "cmovnl", "cmovle", "cmovnle",
  151. "cmova", "cmovna", "cmovae", "cmovnae", "cmovb", "cmovnb", "cmovbe", "cmovnbe",
  152. "cmovs", "cmovns", "cmovo", "cmovno", "cmovp", "cmovnp", "cmovpo", "cmovpe",
  153. "cmp", "cmps", "cmpsb", "cmpsw", "cmpsd", "cmpsq", "cmpxchg", "lea",
  154. "monitor", "cpuid", "in", "out", "syscall", "sysenter", "sysret", "sysexit",
  155. "swap", "bswap", "pop", "push", "call", "ret", "enter", "leave",
  156. "and", "or", "not", "neg", "sal", "sar", "shl", "shr",
  157. "inc", "dec", "add", "sub", "mul", "div", "imul", "idiv",
  158. "nop", "fnop", "adc", "sbb", "aaa", "aas", "aam", "aad",
  159. "jmp", "jrcxz", "jc", "jnc", "je", "jne", "jz", "jnz",
  160. "jg", "jng", "jge", "jnge", "jl", "jnl", "jle", "jnle",
  161. "ja", "jna", "jae", "jnae", "jb", "jnb", "jbe", "jnbe",
  162. "js", "jns", "jo", "jno", "jp", "jnp", "jpo", "jpe",
  163. "rep", "repe", "repz", "repne", "repnz", "loop", "loope", "loopne"
  164. };
  165. char * registers [] = {
  166. "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
  167. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  168. "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  169. "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
  170. "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
  171. "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
  172. "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
  173. "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b",
  174. "ah", "ch", "dh", "bh"
  175. };
  176. char * keywords [] = {
  177. "format", "executable", "readable", "writable", "segment", "sector", "entry", "macro",
  178. "db", "dw", "dd", "dq", "rb", "rw", "rd", "rq"
  179. };
  180. int word;
  181. syntax_define (false, false, ";", "\n", '\0', colour_grey, effect_bold);
  182. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  183. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  184. for (word = 0; word != (int) (sizeof (instructions) / sizeof (instructions [0])); ++word) {
  185. syntax_define (false, true, instructions [word], separators, '\0', colour_yellow, effect_bold);
  186. }
  187. for (word = 0; word != (int) (sizeof (registers) / sizeof (registers [0])); ++word) {
  188. syntax_define (false, true, registers [word], separators, '\0', colour_cyan, effect_bold);
  189. }
  190. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  191. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_italic);
  192. }
  193. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  194. syntax_define (true, false, ".,+-=:;%$<>", "", '\0', colour_cyan, effect_normal);
  195. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  196. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  197. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  198. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  199. }
  200. static void highlight_fortran (void) {
  201. char * separators = ",:<=>+-*/&()[]\"\' \t\r\n";
  202. char * keywords [] = {
  203. "allocatable", "allocate", "associate", "backspace", "block", "call", "case", "common",
  204. "contains", "cycle", "data", "deallocate", "d0", "do", "else", "elseif",
  205. "end", "enddo", "endfile", "endif", "entry", "equivalence", "exit", "external",
  206. "forall", "format", "function", "goto", "if", "implicit", "inquire", "intent",
  207. "intrinsic", "module", "namelist", "none", "nullify", "only", "open", "optional",
  208. "parameter", "pointer", "print", "private", "program", "public", "read", "recursive",
  209. "return", "rewind", "save", "select", "sequence", "stop", "subroutine", "target",
  210. "then", "to", "type", "use", "where", "write"
  211. };
  212. char * constants [] = {
  213. ".and.", ".or.", ".not.", ".true.", ".false.", "in", "out", "character",
  214. "integer", "logical", "real", "complex", "dimension", "modulo", "len", "advance"
  215. };
  216. int word;
  217. syntax_define (false, false, "!", "\n", '\0', colour_grey, effect_bold);
  218. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  219. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  220. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  221. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  222. }
  223. for (word = 0; word != (int) (sizeof (constants) / sizeof (constants [0])); ++word) {
  224. syntax_define (false, true, constants [word], separators, '\0', colour_yellow, effect_italic);
  225. }
  226. syntax_define (true, false, "()[]", "", '\0', colour_blue, effect_normal);
  227. syntax_define (true, false, ",:<=>+-*/&", "", '\0', colour_cyan, effect_normal);
  228. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  229. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  230. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  231. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  232. }
  233. static void highlight_shell (void) {
  234. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}@#$`'\" \t\r\n";
  235. char * keywords [] = {
  236. "if", "then", "else", "elif", "fi", "do", "done", "case",
  237. "esac", "while", "until", "for", "function", "declare", "let", "local",
  238. "alias", "shopt", "export", "in", "return", "echo", "set", "alias",
  239. "exit", "source", "shift", "cd"
  240. };
  241. int word;
  242. syntax_define (false, false, "#", "\n", '\0', colour_grey, effect_bold);
  243. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  244. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  245. syntax_define (false, true, "$#", " ", '\0', colour_pink, effect_italic);
  246. syntax_define (false, false, "$((", "))", '\0', colour_blue, effect_italic);
  247. syntax_define (false, false, "${", "}", '\0', colour_yellow, effect_italic);
  248. syntax_define (false, false, "$(", ")", '\0', colour_cyan, effect_italic);
  249. syntax_define (false, true, "&&", " ", '\0', colour_yellow, effect_italic);
  250. syntax_define (false, true, "||", " ", '\0', colour_yellow, effect_italic);
  251. syntax_define (false, true, ";;", " ", '\0', colour_yellow, effect_italic);
  252. syntax_define (false, true, "<<", " ", '\0', colour_yellow, effect_italic);
  253. syntax_define (false, true, ">>", " ", '\0', colour_yellow, effect_italic);
  254. syntax_define (false, true, "<>", " ", '\0', colour_yellow, effect_italic);
  255. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  256. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  257. }
  258. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  259. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|@#$`", "", '\0', colour_cyan, effect_normal);
  260. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  261. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  262. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  263. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  264. }
  265. static void highlight_xofya (void) {
  266. char * separators = ".,:;<=>+-*/%!&~^?|(){}'\" \t\r\n";
  267. char * keywords [] = {
  268. "character", "natural", "integer", "logical", "address", "pointer", "union", "enter",
  269. "array", "iterate", "enumerate", "include", "exclude", "execute", "if", "else",
  270. "match", "for", "break", "cycle", "and", "or", "not", "true",
  271. "false", "nil", "range", "then", "terminate", "procedure", "program", "package"
  272. };
  273. int word;
  274. syntax_define (false, false, "!", "\n", '\0', colour_red, effect_bold);
  275. syntax_define (false, false, "---", "\n", '\0', colour_grey, effect_bold);
  276. syntax_define (false, false, "--!", "!--", '\0', colour_grey, effect_bold);
  277. syntax_define (false, false, "@", "\n", '\0', colour_red, effect_italic);
  278. syntax_define (false, false, "<!>", "\n", '\0', colour_red, effect_normal);
  279. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  280. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  281. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  282. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  283. }
  284. syntax_define (true, false, "(){}", "", '\0', colour_blue, effect_normal);
  285. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', colour_cyan, effect_normal);
  286. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  287. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  288. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  289. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  290. }
  291. int main (int argc, char * * argv) {
  292. int offset = 0;
  293. int select = 0;
  294. int length = 0;
  295. char * buffer = null;
  296. if (argc != 1) {
  297. if (string_compare (argv [1], "-v") || string_compare (argv [1], "--version")) {
  298. echo ("xighlight: Terminal syntax highlighter (version 144)\n");
  299. exit (log_success);
  300. } else if (string_compare (argv [1], "-l") || string_compare (argv [1], "--license")) {
  301. echo ("xighlight: Terminal syntax highlighter (GNU/GPLv3)\n");
  302. exit (log_success);
  303. } else if (string_compare (argv [1], "-a") || string_compare (argv [1], "--author")) {
  304. echo ("xighlight: Terminal syntax highlighter (Ognjen 'xolatile' Milan Robovic)\n");
  305. exit (log_success);
  306. } else if (string_compare (argv [1], "-h") || string_compare (argv [1], "--help")) {
  307. echo ("xighlight: Terminal syntax highlighter:\n");
  308. echo ("Example usage:\n");
  309. echo ("\t$ cat file.ext | xighlight [flag] -- You need to pass language flag in this case.\n");
  310. echo ("\t$ xighlight [flag] < file.ext -- You need to pass language flag in this case.\n");
  311. echo ("\t$ xighlight file.ext -- Language is automatically detected in this case.\n");
  312. echo ("Supported languages:\n");
  313. echo ("\t -C --c -- C syntax\n");
  314. echo ("\t -A --ada -- Ada syntax\n");
  315. echo ("\t -P --cpp -- C++ syntax \n");
  316. echo ("\t -S --assembly -- General assembly syntax\n");
  317. echo ("\t -T --flat -- Flat assembly syntax\n");
  318. echo ("\t -F --fortran -- Fortran syntax\n");
  319. echo ("\t -H --shell -- Shell syntax\n");
  320. echo ("\t -X --xofya -- Xofya\n");
  321. exit (log_success);
  322. } else if (string_compare (argv [1], "-C") || string_compare (argv [1], "--c")) {
  323. highlight_c ();
  324. } else if (string_compare (argv [1], "-A") || string_compare (argv [1], "--ada")) {
  325. highlight_ada ();
  326. } else if (string_compare (argv [1], "-P") || string_compare (argv [1], "--cpp")) {
  327. highlight_cpp ();
  328. } else if (string_compare (argv [1], "-S") || string_compare (argv [1], "--assembly")) {
  329. highlight_common_assembly ();
  330. } else if (string_compare (argv [1], "-T") || string_compare (argv [1], "--flat")) {
  331. highlight_flat_assembly ();
  332. } else if (string_compare (argv [1], "-F") || string_compare (argv [1], "--fortran")) {
  333. highlight_fortran ();
  334. } else if (string_compare (argv [1], "-H") || string_compare (argv [1], "--shell")) {
  335. highlight_shell ();
  336. } else if (string_compare (argv [1], "-X") || string_compare (argv [1], "--xofya")) {
  337. highlight_xofya ();
  338. } else {
  339. select = file_type (argv [1]);
  340. buffer = file_import (argv [1]);
  341. }
  342. }
  343. if (buffer == null) {
  344. buffer = record ();
  345. }
  346. if (syntax_active == false) {
  347. if ((select == file_type_c_source) || (select == file_type_c_header)) {
  348. highlight_c ();
  349. } else if ((select == file_type_ada_body) || (select == file_type_ada_specification)) {
  350. highlight_ada ();
  351. } else if ((select == file_type_cpp_source) || (select == file_type_cpp_header)) {
  352. highlight_cpp ();
  353. } else if (select == file_type_common_assembly) {
  354. highlight_common_assembly ();
  355. } else if (select == file_type_flat_assembly) {
  356. highlight_flat_assembly ();
  357. } else if (select == file_type_fortran_90) {
  358. highlight_fortran ();
  359. /*} else if (select == file_type_xofya) {
  360. highlight_xofya ();*/
  361. } else {
  362. highlight_common ();
  363. }
  364. }
  365. for (offset = 0; buffer [offset] != '\0'; offset += length) {
  366. select = syntax_select (& buffer [offset], & length);
  367. if (select >= syntax_count) {
  368. terminal_colour (colour_white, effect_normal);
  369. } else {
  370. terminal_colour (syntax_colour [select], syntax_effect [select]);
  371. }
  372. out (& buffer [offset], length);
  373. terminal_cancel ();
  374. }
  375. buffer = deallocate (buffer);
  376. return (log_success);
  377. }