Xighlight C source code...
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

82 Zeilen
3.3KB

  1. /*
  2. * Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
  3. *
  4. * Xighlight is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
  5. * 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.
  6. * 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.
  7. */
  8. #include <xolatile/xyntax.h>
  9. #include <xolatile/xyntax.c>
  10. #include <xolatile/xurses.h>
  11. #include <xolatile/xurses.c>
  12. int main (void) {
  13. int offset = 0;
  14. int word = 0;
  15. int index = 0;
  16. int length = 0;
  17. char * buffer = NULL;
  18. int whitespace = 0;
  19. int preprocessor = 0;
  20. int line_comment = 0;
  21. int multiline_comment = 0;
  22. int character = 0;
  23. int string = 0;
  24. int operator = 0;
  25. int keyword = 0;
  26. int digit = 0;
  27. int uppercase = 0;
  28. int lowercase = 0;
  29. int underscore = 0;
  30. char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
  31. char * c_keywords [32] = {
  32. "register", "volatile", "auto", "const", "static", "extern", "if", "else",
  33. "do", "while", "for", "continue", "switch", "case", "default", "break",
  34. "enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
  35. "char", "short", "int", "long", "signed", "unsigned", "float", "double"
  36. };
  37. syntax_define (& whitespace, 1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
  38. syntax_define (& preprocessor, 0, 0, "#", "\n", '\\', COLOUR_PINK, EFFECT_BOLD);
  39. syntax_define (& line_comment, 0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
  40. syntax_define (& multiline_comment, 0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
  41. syntax_define (& character, 0, 0, "'", "'", '\\', COLOUR_RED, EFFECT_NORMAL);
  42. syntax_define (& string, 0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
  43. syntax_define (& operator, 1, 0, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', COLOUR_CYAN, EFFECT_NORMAL);
  44. for (word = 0; word != 32; ++word) {
  45. syntax_define (& keyword, 0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
  46. }
  47. syntax_define (& digit, 1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
  48. syntax_define (& uppercase, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
  49. syntax_define (& lowercase, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
  50. syntax_define (& underscore, 0, 1, "_", separator, '\0', COLOUR_PINK, EFFECT_BOLD);
  51. buffer = record ();
  52. for (offset = 0; buffer [offset] != '\0'; offset += length) {
  53. syntax_select (& buffer [offset], & index, & length);
  54. if (index >= syntax_count) {
  55. curses_style (EFFECT_NORMAL, COLOUR_WHITE);
  56. } else {
  57. curses_style (syntax_effect [index], syntax_colour [index]);
  58. }
  59. out (& buffer [offset], length);
  60. curses_style (-1, -1);
  61. }
  62. buffer = deallocate (buffer);
  63. syntax_delete ();
  64. return (EXIT_SUCCESS);
  65. }