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: 90 96 93.8 %
Date: 2016-07-26 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 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             : #include "zend_exceptions.h"
      29             : 
      30        4363 : ZEND_API void zend_html_putc(char c)
      31             : {
      32        4363 :         switch (c) {
      33             :                 case '\n':
      34         123 :                         ZEND_PUTS("<br />");
      35         123 :                         break;
      36             :                 case '<':
      37          58 :                         ZEND_PUTS("&lt;");
      38          58 :                         break;
      39             :                 case '>':
      40          23 :                         ZEND_PUTS("&gt;");
      41          23 :                         break;
      42             :                 case '&':
      43           4 :                         ZEND_PUTS("&amp;");
      44           4 :                         break;
      45             :                 case ' ':
      46         318 :                         ZEND_PUTS("&nbsp;");
      47         318 :                         break;
      48             :                 case '\t':
      49          17 :                         ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;");
      50          17 :                         break;
      51             :                 default:
      52        3820 :                         ZEND_PUTC(c);
      53             :                         break;
      54             :         }
      55        4363 : }
      56             : 
      57             : 
      58         881 : ZEND_API void zend_html_puts(const char *s, size_t len)
      59             : {
      60         881 :         const unsigned char *ptr = (const unsigned char*)s, *end = ptr + len;
      61         881 :         unsigned char *filtered = NULL;
      62             :         size_t filtered_len;
      63             : 
      64         881 :         if (LANG_SCNG(output_filter)) {
      65           0 :                 LANG_SCNG(output_filter)(&filtered, &filtered_len, ptr, len);
      66           0 :                 ptr = filtered;
      67           0 :                 end = filtered + filtered_len;
      68             :         }
      69             : 
      70        6096 :         while (ptr<end) {
      71        4334 :                 if (*ptr==' ') {
      72             :                         do {
      73         318 :                                 zend_html_putc(*ptr);
      74         318 :                         } while ((++ptr < end) && (*ptr==' '));
      75             :                 } else {
      76        4045 :                         zend_html_putc(*ptr++);
      77             :                 }
      78             :         }
      79             : 
      80         881 :         if (LANG_SCNG(output_filter)) {
      81           0 :                 efree(filtered);
      82             :         }
      83         881 : }
      84             : 
      85             : 
      86          35 : ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini)
      87             : {
      88             :         zval token;
      89             :         int token_type;
      90          35 :         char *last_color = syntax_highlighter_ini->highlight_html;
      91             :         char *next_color;
      92             : 
      93          35 :         zend_printf("<code>");
      94          35 :         zend_printf("<span style=\"color: %s\">\n", last_color);
      95             :         /* highlight stuff coming back from zendlex() */
      96          35 :         ZVAL_UNDEF(&token);
      97         714 :         while ((token_type=lex_scan(&token))) {
      98         644 :                 switch (token_type) {
      99             :                         case T_INLINE_HTML:
     100          13 :                                 next_color = syntax_highlighter_ini->highlight_html;
     101          13 :                                 break;
     102             :                         case T_COMMENT:
     103             :                         case T_DOC_COMMENT:
     104          11 :                                 next_color = syntax_highlighter_ini->highlight_comment;
     105          11 :                                 break;
     106             :                         case T_OPEN_TAG:
     107             :                         case T_OPEN_TAG_WITH_ECHO:
     108             :                         case T_CLOSE_TAG:
     109             :                         case T_LINE:
     110             :                         case T_FILE:
     111             :                         case T_DIR:
     112             :                         case T_TRAIT_C:
     113             :                         case T_METHOD_C:
     114             :                         case T_FUNC_C:
     115             :                         case T_NS_C:
     116             :                         case T_CLASS_C:
     117          51 :                                 next_color = syntax_highlighter_ini->highlight_default;
     118          51 :                                 break;
     119             :                         case '"':
     120             :                         case T_ENCAPSED_AND_WHITESPACE:
     121             :                         case T_CONSTANT_ENCAPSED_STRING:
     122          38 :                                 next_color = syntax_highlighter_ini->highlight_string;
     123          38 :                                 break;
     124             :                         case T_WHITESPACE:
     125         202 :                                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));  /* no color needed */
     126         202 :                                 ZVAL_UNDEF(&token);
     127         202 :                                 continue;
     128             :                                 break;
     129             :                         default:
     130         329 :                                 if (Z_TYPE(token) == IS_UNDEF) {
     131         251 :                                         next_color = syntax_highlighter_ini->highlight_keyword;
     132             :                                 } else {
     133          78 :                                         next_color = syntax_highlighter_ini->highlight_default;
     134             :                                 }
     135             :                                 break;
     136             :                 }
     137             : 
     138         442 :                 if (last_color != next_color) {
     139         307 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     140         274 :                                 zend_printf("</span>");
     141             :                         }
     142         307 :                         last_color = next_color;
     143         307 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     144         304 :                                 zend_printf("<span style=\"color: %s\">", last_color);
     145             :                         }
     146             :                 }
     147             : 
     148         442 :                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     149             : 
     150         442 :                 if (Z_TYPE(token) == IS_STRING) {
     151         121 :                         switch (token_type) {
     152             :                                 case T_OPEN_TAG:
     153             :                                 case T_OPEN_TAG_WITH_ECHO:
     154             :                                 case T_CLOSE_TAG:
     155             :                                 case T_WHITESPACE:
     156             :                                 case T_COMMENT:
     157             :                                 case T_DOC_COMMENT:
     158           0 :                                         break;
     159             :                                 default:
     160         121 :                                         zend_string_release(Z_STR(token));
     161             :                                         break;
     162             :                         }
     163             :                 }
     164         442 :                 ZVAL_UNDEF(&token);
     165             :         }
     166             : 
     167          35 :         if (last_color != syntax_highlighter_ini->highlight_html) {
     168          30 :                 zend_printf("</span>\n");
     169             :         }
     170          35 :         zend_printf("</span>\n");
     171          35 :         zend_printf("</code>");
     172             : 
     173             :         /* Discard parse errors thrown during tokenization */
     174          35 :         zend_clear_exception();
     175          35 : }
     176             : 
     177          10 : ZEND_API void zend_strip(void)
     178             : {
     179             :         zval token;
     180             :         int token_type;
     181          10 :         int prev_space = 0;
     182             : 
     183          10 :         ZVAL_UNDEF(&token);
     184         230 :         while ((token_type=lex_scan(&token))) {
     185         210 :                 switch (token_type) {
     186             :                         case T_WHITESPACE:
     187          82 :                                 if (!prev_space) {
     188          67 :                                         zend_write(" ", sizeof(" ") - 1);
     189          67 :                                         prev_space = 1;
     190             :                                 }
     191             :                                                 /* lack of break; is intentional */
     192             :                         case T_COMMENT:
     193             :                         case T_DOC_COMMENT:
     194         107 :                                 ZVAL_UNDEF(&token);
     195         107 :                                 continue;
     196             : 
     197             :                         case T_END_HEREDOC:
     198           1 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     199             :                                 /* read the following character, either newline or ; */
     200           1 :                                 if (lex_scan(&token) != T_WHITESPACE) {
     201           1 :                                         zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     202             :                                 }
     203           1 :                                 zend_write("\n", sizeof("\n") - 1);
     204           1 :                                 prev_space = 1;
     205           1 :                                 ZVAL_UNDEF(&token);
     206           1 :                                 continue;
     207             : 
     208             :                         default:
     209         102 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     210             :                                 break;
     211             :                 }
     212             : 
     213         102 :                 if (Z_TYPE(token) == IS_STRING) {
     214          22 :                         switch (token_type) {
     215             :                                 case T_OPEN_TAG:
     216             :                                 case T_OPEN_TAG_WITH_ECHO:
     217             :                                 case T_CLOSE_TAG:
     218             :                                 case T_WHITESPACE:
     219             :                                 case T_COMMENT:
     220             :                                 case T_DOC_COMMENT:
     221           0 :                                         break;
     222             : 
     223             :                                 default:
     224          22 :                                         zend_string_release(Z_STR(token));
     225             :                                         break;
     226             :                         }
     227             :                 }
     228         102 :                 prev_space = 0;
     229         102 :                 ZVAL_UNDEF(&token);
     230             :         }
     231             : 
     232             :         /* Discard parse errors thrown during tokenization */
     233          10 :         zend_clear_exception();
     234          10 : }
     235             : 
     236             : /*
     237             :  * Local variables:
     238             :  * tab-width: 4
     239             :  * c-basic-offset: 4
     240             :  * indent-tabs-mode: t
     241             :  * End:
     242             :  */
     243             : 

Generated by: LCOV version 1.10

Generated at Tue, 26 Jul 2016 17:07:30 +0000 (2 days ago)

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