Re: zend_highlight line number patch - hope it's okay

From: Date: Fri, 20 Sep 2002 00:44:56 +0000
Subject: Re: zend_highlight line number patch - hope it's okay
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-14107@lists.php.net to get a copy of this message
Yeah, I was kinda noticing that just now. The whole discussion was basically just to enable line numbering, and the query string was basically just to preserve bc issues. I'm not terribly familiar with all the Zend and PHP standards, this being the first time I've worked with the source of PHP; though I understand the logic behind keeping the two separated (which is why I wanted an ini entry in the first place, hehe). I guess the next best thing to do is patch the highlight_string functions and call zend_highlight with an additional parameter specifying the format. Is this acceptable? Sorry for the stupid mistake Devon Original Message: ----------------- From: Andi Gutmans andi@zend.com Date: Fri, 20 Sep 2002 02:57:59 +0300 To: devon@sitetronics.com, php-cvs@lists.php.net, derick@php.net Subject: Re: [PHP-CVS] zend_highlight line number patch - hope it's okay I haven't followed the whole discussion so I'm not quite sure what you want to do. In any case, you can't include files from PHP in Zend (i.e. #include "main/SAPI.h"). Zend should not be dependent on PHP. Andi At 07:09 PM 9/19/2002 -0400, devon@sitetronics.com wrote: >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("<"); >+ break; >+ case '>': >+ ZEND_PUTS(">"); >+ break; >+ case '&': >+ ZEND_PUTS("&"); >+ break; >+ case '\t': >+ ZEND_PUTS(" "); >+ 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/ . > > > >-- >PHP CVS Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ .

« previous php.cvs (#14107) next »