PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_highlight.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 88 94 93.6 %
Date: 2014-11-22 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        | 
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.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             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include <zend_language_parser.h>
      24             : #include "zend_compile.h"
      25             : #include "zend_highlight.h"
      26             : #include "zend_ptr_stack.h"
      27             : #include "zend_globals.h"
      28             : 
      29        4382 : ZEND_API void zend_html_putc(char c)
      30             : {
      31        4382 :         switch (c) {
      32             :                 case '\n':
      33         122 :                         ZEND_PUTS("<br />");
      34         122 :                         break;
      35             :                 case '<':
      36          57 :                         ZEND_PUTS("&lt;");
      37          57 :                         break;
      38             :                 case '>':
      39          23 :                         ZEND_PUTS("&gt;");
      40          23 :                         break;
      41             :                 case '&':
      42           4 :                         ZEND_PUTS("&amp;");
      43           4 :                         break;
      44             :                 case ' ':
      45         316 :                         ZEND_PUTS("&nbsp;");
      46         316 :                         break;
      47             :                 case '\t':
      48          17 :                         ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;");
      49          17 :                         break;
      50             :                 default:
      51        3843 :                         ZEND_PUTC(c);
      52             :                         break;
      53             :         }
      54        4382 : }
      55             : 
      56             : 
      57         859 : ZEND_API void zend_html_puts(const char *s, size_t len TSRMLS_DC)
      58             : {
      59         859 :         const unsigned char *ptr = (const unsigned char*)s, *end = ptr + len;
      60         859 :         unsigned char *filtered = NULL;
      61             :         size_t filtered_len;
      62             : 
      63         859 :         if (LANG_SCNG(output_filter)) {
      64           0 :                 LANG_SCNG(output_filter)(&filtered, &filtered_len, ptr, len TSRMLS_CC);
      65           0 :                 ptr = filtered;
      66           0 :                 end = filtered + filtered_len;
      67             :         }
      68             : 
      69        6071 :         while (ptr<end) {
      70        4353 :                 if (*ptr==' ') {
      71             :                         do {
      72         316 :                                 zend_html_putc(*ptr);
      73         316 :                         } while ((++ptr < end) && (*ptr==' '));
      74             :                 } else {
      75        4066 :                         zend_html_putc(*ptr++);
      76             :                 }
      77             :         }
      78             : 
      79         859 :         if (LANG_SCNG(output_filter)) {
      80           0 :                 efree(filtered);
      81             :         }
      82         859 : }
      83             : 
      84             : 
      85          34 : ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini TSRMLS_DC)
      86             : {
      87             :         zval token;
      88             :         int token_type;
      89          34 :         char *last_color = syntax_highlighter_ini->highlight_html;
      90             :         char *next_color;
      91             : 
      92          34 :         zend_printf("<code>");
      93          34 :         zend_printf("<span style=\"color: %s\">\n", last_color);
      94             :         /* highlight stuff coming back from zendlex() */
      95          34 :         ZVAL_UNDEF(&token);
      96         704 :         while ((token_type=lex_scan(&token TSRMLS_CC))) {
      97         636 :                 switch (token_type) {
      98             :                         case T_INLINE_HTML:
      99          13 :                                 next_color = syntax_highlighter_ini->highlight_html;
     100          13 :                                 break;
     101             :                         case T_COMMENT:
     102             :                         case T_DOC_COMMENT:
     103          11 :                                 next_color = syntax_highlighter_ini->highlight_comment;
     104          11 :                                 break;
     105             :                         case T_OPEN_TAG:
     106             :                         case T_OPEN_TAG_WITH_ECHO:
     107             :                         case T_CLOSE_TAG:
     108             :                         case T_LINE:
     109             :                         case T_FILE:
     110             :                         case T_DIR:
     111             :                         case T_TRAIT_C:
     112             :                         case T_METHOD_C:
     113             :                         case T_FUNC_C:
     114             :                         case T_NS_C:
     115             :                         case T_CLASS_C:
     116          50 :                                 next_color = syntax_highlighter_ini->highlight_default;
     117          50 :                                 break;
     118             :                         case '"':
     119             :                         case T_ENCAPSED_AND_WHITESPACE:
     120             :                         case T_CONSTANT_ENCAPSED_STRING:
     121          38 :                                 next_color = syntax_highlighter_ini->highlight_string;
     122          38 :                                 break;
     123             :                         case T_WHITESPACE:
     124         199 :                                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);  /* no color needed */
     125         199 :                                 ZVAL_UNDEF(&token);
     126         199 :                                 continue;
     127             :                                 break;
     128             :                         default:
     129         325 :                                 if (Z_TYPE(token) == IS_UNDEF) {
     130         247 :                                         next_color = syntax_highlighter_ini->highlight_keyword;
     131             :                                 } else {
     132          78 :                                         next_color = syntax_highlighter_ini->highlight_default;
     133             :                                 }
     134             :                                 break;
     135             :                 }
     136             : 
     137         437 :                 if (last_color != next_color) {
     138         305 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     139         273 :                                 zend_printf("</span>");
     140             :                         }
     141         305 :                         last_color = next_color;
     142         305 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     143         302 :                                 zend_printf("<span style=\"color: %s\">", last_color);
     144             :                         }
     145             :                 }
     146             : 
     147         437 :                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);
     148             : 
     149         437 :                 if (Z_TYPE(token) == IS_STRING) {
     150         121 :                         switch (token_type) {
     151             :                                 case T_OPEN_TAG:
     152             :                                 case T_OPEN_TAG_WITH_ECHO:
     153             :                                 case T_CLOSE_TAG:
     154             :                                 case T_WHITESPACE:
     155             :                                 case T_COMMENT:
     156             :                                 case T_DOC_COMMENT:
     157           0 :                                         break;
     158             :                                 default:
     159         121 :                                         zend_string_release(Z_STR(token));
     160             :                                         break;
     161             :                         }
     162             :                 }
     163         437 :                 ZVAL_UNDEF(&token);
     164             :         }
     165             : 
     166          34 :         if (last_color != syntax_highlighter_ini->highlight_html) {
     167          29 :                 zend_printf("</span>\n");
     168             :         }
     169          34 :         zend_printf("</span>\n");
     170          34 :         zend_printf("</code>");
     171          34 : }
     172             : 
     173           9 : ZEND_API void zend_strip(TSRMLS_D)
     174             : {
     175             :         zval token;
     176             :         int token_type;
     177           9 :         int prev_space = 0;
     178             : 
     179           9 :         ZVAL_UNDEF(&token);
     180         219 :         while ((token_type=lex_scan(&token TSRMLS_CC))) {
     181         201 :                 switch (token_type) {
     182             :                         case T_WHITESPACE:
     183          78 :                                 if (!prev_space) {
     184          63 :                                         zend_write(" ", sizeof(" ") - 1);
     185          63 :                                         prev_space = 1;
     186             :                                 }
     187             :                                                 /* lack of break; is intentional */
     188             :                         case T_COMMENT:
     189             :                         case T_DOC_COMMENT:
     190         102 :                                 ZVAL_UNDEF(&token);
     191         102 :                                 continue;
     192             :                         
     193             :                         case T_END_HEREDOC:
     194           1 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     195             :                                 /* read the following character, either newline or ; */
     196           1 :                                 if (lex_scan(&token TSRMLS_CC) != T_WHITESPACE) {
     197           1 :                                         zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     198             :                                 }
     199           1 :                                 zend_write("\n", sizeof("\n") - 1);
     200           1 :                                 prev_space = 1;
     201           1 :                                 ZVAL_UNDEF(&token);
     202           1 :                                 continue;
     203             : 
     204             :                         default:
     205          98 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     206             :                                 break;
     207             :                 }
     208             : 
     209          98 :                 if (Z_TYPE(token) == IS_STRING) {
     210          22 :                         switch (token_type) {
     211             :                                 case T_OPEN_TAG:
     212             :                                 case T_OPEN_TAG_WITH_ECHO:
     213             :                                 case T_CLOSE_TAG:
     214             :                                 case T_WHITESPACE:
     215             :                                 case T_COMMENT:
     216             :                                 case T_DOC_COMMENT:
     217           0 :                                         break;
     218             : 
     219             :                                 default:
     220          22 :                                         zend_string_release(Z_STR(token));
     221             :                                         break;
     222             :                         }
     223             :                 }
     224          98 :                 prev_space = 0;
     225          98 :                 ZVAL_UNDEF(&token);
     226             :         }
     227           9 : }
     228             : 
     229             : /*
     230             :  * Local variables:
     231             :  * tab-width: 4
     232             :  * c-basic-offset: 4
     233             :  * indent-tabs-mode: t
     234             :  * End:
     235             :  */
     236             : 

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:11 +0000 (45 minutes ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.