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 - sapi/phpdbg - phpdbg_eol.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 10 78 12.8 %
Date: 2018-09-22 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2018 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP 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.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Anatol Belski <ab@php.net>                                  |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : #ifdef HAVE_CONFIG_H
      20             : #       include "config.h"
      21             : #endif
      22             : 
      23             : #include "phpdbg.h"
      24             : #include "phpdbg_eol.h"
      25             : 
      26             : ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
      27             : 
      28             : #define EOL_LIST_LEN 4
      29             : struct phpdbg_eol_rep phpdbg_eol_list[EOL_LIST_LEN] = {
      30             :         {"CRLF", "\r\n", PHPDBG_EOL_CRLF},
      31             : /*      {"LFCR", "\n\r", PHPDBG_EOL_LFCR},*/
      32             :         {"LF", "\n", PHPDBG_EOL_LF},
      33             :         {"CR", "\r", PHPDBG_EOL_CR},
      34             : };
      35             : 
      36          80 : int phpdbg_eol_global_update(char *name)
      37             : {
      38             : 
      39          80 :         if (0 == memcmp(name, "CRLF", 4) || 0 == memcmp(name, "crlf", 4) || 0 == memcmp(name, "DOS", 3) || 0 == memcmp(name, "dos", 3)) {
      40           0 :                 PHPDBG_G(eol) = PHPDBG_EOL_CRLF;
      41          80 :         } else if (0 == memcmp(name, "LF", 2) || 0 == memcmp(name, "lf", 2) || 0 == memcmp(name, "UNIX", 4) || 0 == memcmp(name, "unix", 4)) {
      42           0 :                 PHPDBG_G(eol) = PHPDBG_EOL_LF;
      43          80 :         } else if (0 == memcmp(name, "CR", 2) || 0 == memcmp(name, "cr", 2) || 0 == memcmp(name, "MAC", 3) || 0 == memcmp(name, "mac", 3)) {
      44           0 :                 PHPDBG_G(eol) = PHPDBG_EOL_CR;
      45             :         } else {
      46          80 :                 return FAILURE;
      47             :         }
      48             : 
      49           0 :         return SUCCESS;
      50             : }
      51             : 
      52           0 : char *phpdbg_eol_name(int id)
      53             : {
      54           0 :         size_t i = 0;
      55             : 
      56           0 :         while (i < EOL_LIST_LEN) {
      57             : 
      58           0 :                 if (id == phpdbg_eol_list[i].id) {
      59           0 :                         return phpdbg_eol_list[i].name;
      60             :                 }
      61             : 
      62           0 :                 i++;
      63             :         }
      64             : 
      65           0 :         return NULL;
      66             : }
      67             : 
      68           0 : char *phpdbg_eol_rep(int id)
      69             : {
      70           0 :         size_t i = 0;
      71             : 
      72           0 :         while (i < EOL_LIST_LEN) {
      73             : 
      74           0 :                 if (id == phpdbg_eol_list[i].id) {
      75           0 :                         return phpdbg_eol_list[i].rep;
      76             :                 }
      77             : 
      78           0 :                 i++;
      79             :         }
      80             : 
      81           0 :         return NULL;
      82             : }
      83             : 
      84             : 
      85             : /* Inspired by https://ccrma.stanford.edu/~craig/utility/flip/flip.cpp */
      86         824 : void phpdbg_eol_convert(char **str, int *len)
      87             : {
      88         824 :         char *in = *str, *out ;
      89         824 :         int in_len = *len, out_len, cursor, i;
      90             :         char last, cur;
      91             : 
      92         824 :         if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) != PHPDBG_IS_REMOTE) {
      93         824 :                 return;
      94             :         }
      95             : 
      96           0 :         out_len = *len;
      97           0 :         if (PHPDBG_EOL_CRLF == PHPDBG_G(eol)) { /* XXX add LFCR case if it's gonna be needed */
      98             :                 /* depending on the source EOL the out str will have all CR/LF duplicated */
      99           0 :                 for (i = 0; i < in_len; i++) {
     100           0 :                         if (0x0a == in[i] || 0x0d == in[i]) {
     101           0 :                                 out_len++;
     102             :                         }
     103             :                 }
     104           0 :                 out = (char *)emalloc(out_len);
     105             : 
     106           0 :                 last = cur = in[0];
     107           0 :                 i = cursor = 0;
     108           0 :                 for (; i < in_len;) {
     109           0 :                         if (0x0a == cur && last != 0x0d) {
     110           0 :                                 out[cursor] = 0x0d;
     111           0 :                                 cursor++;
     112           0 :                                 out[cursor] = cur;
     113           0 :                         } else if(0x0d == cur) {
     114           0 :                                 if (i + 1 < in_len && 0x0a != in[i+1]) {
     115           0 :                                         out[cursor] = cur;
     116           0 :                                         cursor++;
     117           0 :                                         out[cursor] = 0x0a;
     118           0 :                                         last = 0x0a;
     119             :                                 } else {
     120           0 :                                         out[cursor] = 0x0d;
     121           0 :                                         last = 0x0d;
     122             :                                 }
     123             :                         } else {
     124           0 :                                 out[cursor] = cur;
     125           0 :                                 last = cur;
     126             :                         }
     127             : 
     128           0 :                         i++;
     129           0 :                         cursor++;
     130           0 :                         cur = in[i];
     131             :                 }
     132             : 
     133           0 :         } else if (PHPDBG_EOL_LF == PHPDBG_G(eol) || PHPDBG_EOL_CR == PHPDBG_G(eol)) {
     134             :                 char want, kick;
     135             : 
     136           0 :                 if (PHPDBG_EOL_LF == PHPDBG_G(eol)) {
     137           0 :                         want = 0x0a;
     138           0 :                         kick = 0x0d;
     139             :                 } else {
     140           0 :                         want = 0x0d;
     141           0 :                         kick = 0x0a;
     142             :                 }
     143             : 
     144             :                 /* We gonna have a smaller or equally long string, estimation is almost neglecting */
     145           0 :                 out = (char *)emalloc(out_len);
     146             : 
     147           0 :                 last = cur = in[0];
     148           0 :                 i = cursor = 0;
     149           0 :                 for (; cursor < in_len;) {
     150           0 :                         if (kick == cur) {
     151           0 :                                 out[cursor] = want;
     152           0 :                         } else if (want == cur) {
     153           0 :                                 if (kick != last) {
     154           0 :                                         out[cursor] = want;
     155             :                                 }
     156             :                         } else {
     157           0 :                                 out[cursor] = cur;
     158             :                         }
     159             : 
     160           0 :                         last = cur;
     161           0 :                         cursor++;
     162           0 :                         cur = in[cursor];
     163             :                 }
     164             :         } else {
     165           0 :                 return;
     166             :         }
     167             : 
     168           0 :         efree(*str);
     169           0 :         *str = erealloc(out, cursor);
     170           0 :         *len = cursor;
     171           0 :         in = NULL;
     172             : }

Generated by: LCOV version 1.10

Generated at Sat, 22 Sep 2018 10:27:04 +0000 (8 hours ago)

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