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.

168 lines
4.2 KiB

27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 0.91 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.zend.com/license/0_91.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@zend.com> |
  16. | Zeev Suraski <zeev@zend.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "zend.h"
  20. #include "zend-parser.h"
  21. #include "zend_compile.h"
  22. #include "zend_highlight.h"
  23. #include "zend_ptr_stack.h"
  24. #include "zend_globals.h"
  25. #ifndef ZTS
  26. extern char *zendtext;
  27. extern int zendleng;
  28. #else
  29. #define zendtext ((char *) zend_get_zendtext(CLS_C))
  30. #define zendleng zend_get_zendleng(CLS_C)
  31. #endif
  32. static void html_putc(char c)
  33. {
  34. switch (c) {
  35. case '\n':
  36. ZEND_PUTS("<br>");
  37. break;
  38. case '<':
  39. ZEND_PUTS("&lt;");
  40. break;
  41. case '>':
  42. ZEND_PUTS("&gt;");
  43. break;
  44. case '&':
  45. ZEND_PUTS("&amp;");
  46. break;
  47. case ' ':
  48. ZEND_PUTS("&nbsp;");
  49. break;
  50. case '\t':
  51. ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;");
  52. break;
  53. default:
  54. ZEND_PUTC(c);
  55. break;
  56. }
  57. }
  58. static void html_puts(char *s, uint len)
  59. {
  60. register char *ptr=s, *end=s+len;
  61. while (ptr<end) {
  62. html_putc(*ptr++);
  63. }
  64. }
  65. ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini)
  66. {
  67. zval token;
  68. int token_type;
  69. char *last_color = syntax_highlighter_ini->highlight_html;
  70. char *next_color;
  71. int in_string=0;
  72. CLS_FETCH();
  73. zend_printf("<font color=\"%s\">\n", last_color);
  74. /* highlight stuff coming back from zendlex() */
  75. token.type = 0;
  76. while ((token_type=lex_scan(&token CLS_CC))) {
  77. switch (token_type) {
  78. case T_INLINE_HTML:
  79. next_color = syntax_highlighter_ini->highlight_html;
  80. break;
  81. case T_COMMENT:
  82. next_color = syntax_highlighter_ini->highlight_comment;
  83. break;
  84. case T_OPEN_TAG:
  85. next_color = syntax_highlighter_ini->highlight_default;
  86. break;
  87. case T_CLOSE_TAG:
  88. next_color = syntax_highlighter_ini->highlight_default;
  89. break;
  90. case T_CONSTANT_ENCAPSED_STRING:
  91. next_color = syntax_highlighter_ini->highlight_string;
  92. break;
  93. case '"':
  94. next_color = syntax_highlighter_ini->highlight_string;
  95. in_string = !in_string;
  96. break;
  97. case T_WHITESPACE:
  98. html_puts(zendtext, zendleng); /* no color needed */
  99. token.type = 0;
  100. continue;
  101. break;
  102. default:
  103. if (token.type==0) {
  104. next_color = syntax_highlighter_ini->highlight_keyword;
  105. } else {
  106. if (in_string) {
  107. next_color = syntax_highlighter_ini->highlight_string;
  108. } else {
  109. next_color = syntax_highlighter_ini->highlight_default;
  110. }
  111. }
  112. break;
  113. }
  114. if (last_color != next_color) {
  115. if (last_color != syntax_highlighter_ini->highlight_html) {
  116. zend_printf("</font>");
  117. }
  118. last_color = next_color;
  119. if (last_color != syntax_highlighter_ini->highlight_html) {
  120. zend_printf("<font color=\"%s\">", last_color);
  121. }
  122. }
  123. switch (token_type) {
  124. case T_DOLLAR_OPEN_CURLY_BRACES:
  125. html_puts("{", 1);
  126. break;
  127. default:
  128. html_puts(zendtext, zendleng);
  129. break;
  130. }
  131. if (token.type == IS_STRING) {
  132. switch (token_type) {
  133. case T_OPEN_TAG:
  134. case T_CLOSE_TAG:
  135. case T_WHITESPACE:
  136. break;
  137. default:
  138. efree(token.value.str.val);
  139. break;
  140. }
  141. }
  142. token.type = 0;
  143. }
  144. if (last_color != syntax_highlighter_ini->highlight_html) {
  145. zend_printf("</font>\n");
  146. }
  147. zend_printf("</font>\n");
  148. }
  149. /*
  150. * Local variables:
  151. * tab-width: 4
  152. * c-basic-offset: 4
  153. * End:
  154. */