zend_highlight line number patch - hope it's okay

From: Date: Thu, 19 Sep 2002 23:09:20 +0000
Subject: zend_highlight line number patch - hope it's okay
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-14105@lists.php.net to get a copy of this message
diff -u ../../php4cvs/Zend/zend_highlight.c ./zend_highlight.c --- ../../php4cvs/Zend/zend_highlight.c Sun Sep 15 23:56:30 2002 +++ ./zend_highlight.c Fri Sep 20 00:07:11 2002 @@ -24,6 +24,7 @@ #include "zend_highlight.h" #include "zend_ptr_stack.h" #include "zend_globals.h" +#include "main/SAPI.h" ZEND_API void zend_html_putc(char c) { @@ -52,7 +53,6 @@ } } - ZEND_API void zend_html_puts(const char *s, uint len) { const char *ptr=s, *end=s+len; @@ -76,18 +76,33 @@ } } - - ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC) { zval token; int token_type; char *last_color = syntax_highlighter_ini->highlight_html; char *next_color; - int in_string=0; + int in_string = 0, lineno = 0, highlight_format = 0; + char *strtok_buf = NULL, *strtoken, *val; + + if (SG(request_info).query_string) { + strtoken = strtok_r(SG(request_info).query_string, "&", &strtok_buf); + while (strtoken) { + val = strchr(strtoken, '='); + if (val && strncmp(strtoken, "HIGHLIGHT_FORMAT", 16) == 0 && strncmp(val, "=lineno", 7) == 0) { + highlight_format = 1; + } else if (val && strncmp(strtoken, "HIGHLIGHT_FORMAT", 16) == 0 && strncmp(val, "=default", 8) == 0) { + highlight_format = 0; + } + strtoken = strtok_r(NULL, ".", &strtok_buf); + } + } + + zend_printf("<pre>"); + if (highlight_format == HL_FORMAT_LINENO) { + zend_highlight_puts("\n", 1, highlight_format, &lineno, last_color); + } - zend_printf("<code>"); - zend_printf("<font color=\"%s\">\n", last_color); /* highlight stuff coming back from zendlex() */ token.type = 0; while ((token_type=lex_scan(&token TSRMLS_CC))) { @@ -113,7 +128,7 @@ in_string = !in_string; break; case T_WHITESPACE: - zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng)); /* no color needed */ + zend_highlight_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng), highlight_format, &lineno, last_color); /* no color needed */ token.type = 0; continue; break; @@ -141,10 +156,10 @@ } switch (token_type) { case T_END_HEREDOC: - zend_html_puts(token.value.str.val, token.value.str.len); + zend_highlight_puts(token.value.str.val, token.value.str.len, highlight_format, &lineno, last_color); break; default: - zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng)); + zend_highlight_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng), highlight_format, &lineno, last_color); break; } @@ -172,14 +187,11 @@ token.type = 0; } if (last_color != syntax_highlighter_ini->highlight_html) { - zend_printf("</font>\n"); + zend_printf("</font>"); } - zend_printf("</font>\n"); - zend_printf("</code>"); + zend_printf("</font>\n</pre>"); } - - ZEND_API void zend_strip(TSRMLS_D) { zval token; @@ -191,7 +203,7 @@ case T_COMMENT: token.type = 0; continue; - + case T_WHITESPACE: if (token.type) { putchar(' '); @@ -237,6 +249,45 @@ } } token.type = 0; + } +} + +ZEND_API void zend_highlight_putc(char c, int highlight_format, int *lineno, char *color) +{ + switch (c) { + case '\n': + if (highlight_format == HL_FORMAT_LINENO) { + ++(*lineno); + zend_printf("</font>\n<a name=\"%d\">% 4d</a>: <font color=\"%s\">", *lineno, *lineno, color); + } else { + zend_printf("\n"); + } + break; + case '<': + ZEND_PUTS("&lt;"); + break; + case '>': + ZEND_PUTS("&gt;"); + break; + case '&': + ZEND_PUTS("&amp;"); + break; + case '\t': + ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;"); + break; + default: + ZEND_PUTC(c); + break; + } +} + + +ZEND_API void zend_highlight_puts(const char *s, uint len, int highlight_format, int *lineno, char *color) +{ + const char *ptr = s, *end = s + len; + + while (ptr < end) { + zend_highlight_putc(*ptr++, highlight_format, lineno, color); } } /* diff -u ../../php4cvs/Zend/zend_highlight.h ./zend_highlight.h --- ../../php4cvs/Zend/zend_highlight.h Sat May 11 13:35:52 2002 +++ ./zend_highlight.h Fri Sep 20 00:07:13 2002 @@ -27,7 +27,8 @@ #define HL_STRING_COLOR "#DD0000" /* red */ #define HL_BG_COLOR "#FFFFFF" /* white */ #define HL_KEYWORD_COLOR "#007700" /* green */ - +#define HL_FORMAT_DEFAULT 0 +#define HL_FORMAT_LINENO 1 typedef struct _zend_syntax_highlighter_ini { char *highlight_html; @@ -45,6 +46,8 @@ ZEND_API int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name TSRMLS_DC); ZEND_API void zend_html_putc(char c); ZEND_API void zend_html_puts(const char *s, uint len); +ZEND_API void zend_highlight_putc(char c, int highlight_format, int *lineno, char *color); +ZEND_API void zend_highlight_puts(const char *s, uint len, int highlight_format, int *lineno, char *color); END_EXTERN_C() extern zend_syntax_highlighter_ini syntax_highlighter_ini; -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ .

« previous php.cvs (#14105) next »