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: 91 95 95.8 %
Date: 2014-04-16 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        4414 : ZEND_API void zend_html_putc(char c)
      30             : {
      31        4414 :         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        3875 :                         ZEND_PUTC(c);
      52             :                         break;
      53             :         }
      54        4414 : }
      55             : 
      56             : 
      57         873 : ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
      58             : {
      59         873 :         const unsigned char *ptr = (const unsigned char*)s, *end = ptr + len;
      60         873 :         unsigned char *filtered = NULL;
      61             :         size_t filtered_len;
      62             : 
      63         873 :         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        6131 :         while (ptr<end) {
      70        4385 :                 if (*ptr==' ') {
      71             :                         do {
      72         316 :                                 zend_html_putc(*ptr);
      73         316 :                         } while ((++ptr < end) && (*ptr==' '));
      74             :                 } else {
      75        4098 :                         zend_html_putc(*ptr++);
      76             :                 }
      77             :         }
      78             : 
      79         873 :         if (LANG_SCNG(output_filter)) {
      80           0 :                 efree(filtered);
      81             :         }
      82         873 : }
      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 :         token.type = 0;
      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          32 :                                 next_color = syntax_highlighter_ini->highlight_default;
     108          32 :                                 break;
     109             :                         case T_CLOSE_TAG:
     110          15 :                                 next_color = syntax_highlighter_ini->highlight_default;
     111          15 :                                 break;
     112             :                         case '"':
     113             :                         case T_ENCAPSED_AND_WHITESPACE:
     114             :                         case T_CONSTANT_ENCAPSED_STRING:
     115          38 :                                 next_color = syntax_highlighter_ini->highlight_string;
     116          38 :                                 break;
     117             :                         case T_WHITESPACE:
     118         199 :                                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);  /* no color needed */
     119         199 :                                 token.type = 0;
     120         199 :                                 continue;
     121             :                                 break;
     122             :                         default:
     123         328 :                                 if (token.type == 0) {
     124         247 :                                         next_color = syntax_highlighter_ini->highlight_keyword;
     125             :                                 } else {
     126          81 :                                         next_color = syntax_highlighter_ini->highlight_default;
     127             :                                 }
     128             :                                 break;
     129             :                 }
     130             : 
     131         437 :                 if (last_color != next_color) {
     132         305 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     133         273 :                                 zend_printf("</span>");
     134             :                         }
     135         305 :                         last_color = next_color;
     136         305 :                         if (last_color != syntax_highlighter_ini->highlight_html) {
     137         302 :                                 zend_printf("<span style=\"color: %s\">", last_color);
     138             :                         }
     139             :                 }
     140             : 
     141         437 :                 zend_html_puts((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);
     142             : 
     143         437 :                 if (token.type == IS_STRING) {
     144         171 :                         switch (token_type) {
     145             :                                 case T_OPEN_TAG:
     146             :                                 case T_OPEN_TAG_WITH_ECHO:
     147             :                                 case T_CLOSE_TAG:
     148             :                                 case T_WHITESPACE:
     149             :                                 case T_COMMENT:
     150             :                                 case T_DOC_COMMENT:
     151          47 :                                         break;
     152             :                                 default:
     153         124 :                                         efree(token.value.str.val);
     154             :                                         break;
     155             :                         }
     156             :                 }
     157         437 :                 token.type = 0;
     158             :         }
     159             : 
     160          34 :         if (last_color != syntax_highlighter_ini->highlight_html) {
     161          29 :                 zend_printf("</span>\n");
     162             :         }
     163          34 :         zend_printf("</span>\n");
     164          34 :         zend_printf("</code>");
     165          34 : }
     166             : 
     167           9 : ZEND_API void zend_strip(TSRMLS_D)
     168             : {
     169             :         zval token;
     170             :         int token_type;
     171           9 :         int prev_space = 0;
     172             : 
     173           9 :         token.type = 0;
     174         219 :         while ((token_type=lex_scan(&token TSRMLS_CC))) {
     175         201 :                 switch (token_type) {
     176             :                         case T_WHITESPACE:
     177          78 :                                 if (!prev_space) {
     178          63 :                                         zend_write(" ", sizeof(" ") - 1);
     179          63 :                                         prev_space = 1;
     180             :                                 }
     181             :                                                 /* lack of break; is intentional */
     182             :                         case T_COMMENT:
     183             :                         case T_DOC_COMMENT:
     184         102 :                                 token.type = 0;
     185         102 :                                 continue;
     186             :                         
     187             :                         case T_END_HEREDOC:
     188           1 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     189             :                                 /* read the following character, either newline or ; */
     190           1 :                                 if (lex_scan(&token TSRMLS_CC) != T_WHITESPACE) {
     191           1 :                                         zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     192             :                                 }
     193           1 :                                 zend_write("\n", sizeof("\n") - 1);
     194           1 :                                 prev_space = 1;
     195           1 :                                 token.type = 0;
     196           1 :                                 continue;
     197             : 
     198             :                         default:
     199          98 :                                 zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
     200             :                                 break;
     201             :                 }
     202             : 
     203          98 :                 if (token.type == IS_STRING) {
     204          40 :                         switch (token_type) {
     205             :                                 case T_OPEN_TAG:
     206             :                                 case T_OPEN_TAG_WITH_ECHO:
     207             :                                 case T_CLOSE_TAG:
     208             :                                 case T_WHITESPACE:
     209             :                                 case T_COMMENT:
     210             :                                 case T_DOC_COMMENT:
     211          16 :                                         break;
     212             : 
     213             :                                 default:
     214          24 :                                         STR_FREE(token.value.str.val);
     215             :                                         break;
     216             :                         }
     217             :                 }
     218          98 :                 prev_space = token.type = 0;
     219             :         }
     220           9 : }
     221             : 
     222             : /*
     223             :  * Local variables:
     224             :  * tab-width: 4
     225             :  * c-basic-offset: 4
     226             :  * indent-tabs-mode: t
     227             :  * End:
     228             :  */
     229             : 

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:43 +0000 (4 days ago)

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