]> granicus.if.org Git - php/commitdiff
MFZE1 (added zend_strip mode in the highliter)
authorSebastian Bergmann <sebastian@php.net>
Tue, 11 Dec 2001 06:30:30 +0000 (06:30 +0000)
committerSebastian Bergmann <sebastian@php.net>
Tue, 11 Dec 2001 06:30:30 +0000 (06:30 +0000)
Zend/zend_highlight.c
Zend/zend_highlight.h

index ec1417532071d097afea3c62a777d8b48eb7a4d8..3d2482c734e5cf87ae9075556c374f277269af8f 100644 (file)
@@ -173,6 +173,67 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
        zend_printf("</code>");
 }
 
+
+
+ZEND_API void zend_strip(TSRMLS_D)
+{
+       zval token;
+       int token_type;
+
+       token.type = 0;
+       while ((token_type=lex_scan(&token TSRMLS_CC))) {
+               switch (token_type) {
+                       case T_COMMENT:
+                               token.type = 0;
+                               break;
+
+                       case T_WHITESPACE:
+                               if (token.type) {
+                                       putchar(' ');
+                                       token.type = 0;
+                               }
+                               continue;
+               }
+
+               switch (token_type) {
+                       case 349:
+                               break;
+
+                       default: {
+                                       char c, *ptr=LANG_SCNG(yy_text), *end=LANG_SCNG(yy_text)+LANG_SCNG(yy_leng);
+                                       while (ptr<end) {
+                                               c = *ptr++;
+                                               putchar(c);
+                                       }
+                               }
+                               break;
+               }
+
+               if (token.type == IS_STRING) {
+                       switch (token_type) {
+                               case T_OPEN_TAG:
+                               case T_OPEN_TAG_WITH_ECHO:
+                               case T_CLOSE_TAG:
+                               case T_WHITESPACE:
+                               case T_COMMENT:
+                                       break;
+
+                               default:
+                                       efree(token.value.str.val);
+                                       break;
+                       }
+               } else if (token_type == T_END_HEREDOC) {
+                       zend_bool has_semicolon=(strchr(token.value.str.val, ';')?1:0);
+
+                       efree(token.value.str.val);
+                       if (has_semicolon) {
+                               /* the following semicolon was unput(), ignore it */
+                               lex_scan(&token TSRMLS_CC);
+                       }
+               }
+               token.type = 0;
+       }
+}
 /*
  * Local variables:
  * tab-width: 4
index 75ce879fc0dd8f824fb6ef17d054593c232a06ca..d8cba4a9c617425d8978ab7de9ac1cb97f784fe7 100644 (file)
@@ -40,6 +40,7 @@ typedef struct _zend_syntax_highlighter_ini {
 
 BEGIN_EXTERN_C()
 ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC);
+ZEND_API void zend_strip(TSRMLS_D);
 ZEND_API int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC);
 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);