Changeset 1563 for FCKeditor/trunk


Ignore:
Timestamp:
02/19/08 13:41:58 (7 years ago)
Author:
wwalc
Message:

fixlineends now strips spaces and tabs from the end of line

Location:
FCKeditor/trunk/_dev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/_dev/fixlineends.bat

    r1562 r1563  
    2222:: 
    2323 
    24 php fixlineends.php --eofnewline --eofstripwhite --nohidden --nosystem ../ 
     24php fixlineends.php --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem ../ 
  • FCKeditor/trunk/_dev/fixlineends.php

    r1562 r1563  
    22<?php 
    33/* 
    4  * FCKreleaser - FCKeditor Releaser - http://www.fckeditor.net 
    5  * Copyright (C) 2003-2007 Frederico Caldeira Knabben 
    6  * 
    7  * == BEGIN LICENSE == 
    8  * 
    9  * Licensed under the terms of any of the following licenses at your 
    10  * choice: 
    11  * 
    12  *  - GNU General Public License Version 2 or later (the "GPL") 
    13  *    http://www.gnu.org/licenses/gpl.html 
    14  * 
    15  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
    16  *    http://www.gnu.org/licenses/lgpl.html 
    17  * 
    18  *  - Mozilla Public License Version 1.1 or later (the "MPL") 
    19  *    http://www.mozilla.org/MPL/MPL-1.1.html 
    20  * 
    21  * == END LICENSE == 
    22  * 
    23  * Script for automatic line-ending corrections. 
    24  * Requires PHP5 to run: http://www.gophp5.org/ ;) 
    25  */ 
     4* FCKreleaser - FCKeditor Releaser - http://www.fckeditor.net 
     5* Copyright (C) 2003-2007 Frederico Caldeira Knabben 
     6* 
     7* == BEGIN LICENSE == 
     8* 
     9* Licensed under the terms of any of the following licenses at your 
     10* choice: 
     11* 
     12*  - GNU General Public License Version 2 or later (the "GPL") 
     13*    http://www.gnu.org/licenses/gpl.html 
     14* 
     15*  - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
     16*    http://www.gnu.org/licenses/lgpl.html 
     17* 
     18*  - Mozilla Public License Version 1.1 or later (the "MPL") 
     19*    http://www.mozilla.org/MPL/MPL-1.1.html 
     20* 
     21* == END LICENSE == 
     22* 
     23* Script for automatic line-ending corrections. 
     24* Requires PHP5 to run: http://www.gophp5.org/ ;) 
     25*/ 
    2626 
    2727error_reporting(E_ALL); 
     
    9090$eofstripwhite = false; 
    9191/** 
     92 * Strip whitespace from the end of line 
     93 * @var boolean $eolstripwhite 
     94 */ 
     95$eolstripwhite = false; 
     96/** 
    9297 * Force new line character at the end of file 
    9398 * @var boolean $eofnewline 
     
    121126 * -1 to disable 
    122127 *  0 to fix only current directory 
    123  *  
     128 * 
    124129 * @var integer $maxdepth 
    125130 */ 
     
    130135 * example: 
    131136 * --excluderegex = "/(\.\w+)$/" 
    132  *  
     137 * 
    133138 * @var string $excluderegex 
    134139 */ 
     
    140145 */ 
    141146$windows = (strtolower(substr(PHP_OS, 0, 3)) == "win"); 
     147 
     148/** 
     149 * Count saved bytes 
     150 * @var integer $saved_bytes 
     151 */ 
     152$saved_bytes = 0; 
    142153 
    143154/** 
     
    201212 * @param string $path relative or absolute path name to file 
    202213 * @param string $nl name of a constant that holds new line character (CRLF|CR|LF) 
    203  * @return bool  
     214 * @return bool 
    204215 */ 
    205216function fixFile($path, $nl) { 
    206217 
    207218    $contents = file($path); 
     219    $size = filesize($path); 
    208220    if ($contents === false) { 
    209221        echo "\rERROR: couldn't read the " . $path . " file". "\n"; 
     
    312324                break; 
    313325        } 
     326        if ($GLOBALS['eolstripwhite']) { 
     327            $before = strlen($line); 
     328            $line = preg_replace("/(?:\x09|\x20)+((?:\r|\n)+)$/", "$1", $line); 
     329            if (strlen($line) != $before) { 
     330                $modified = true; 
     331            } 
     332        } 
    314333        $new_content .= $line; 
    315334    } 
     
    325344                fwrite($fp, $new_content); 
    326345                flock($fp, LOCK_UN); 
    327                 echo "\rMODIFIED to " . $nl . ": " . $path . "\n"; 
     346                echo "\rMODIFIED to " . $nl . ": " . $path ; 
     347                if ($GLOBALS['eolstripwhite']) { 
     348                    $saved = $size - strlen($new_content); 
     349                    $GLOBALS['saved_bytes'] += $saved; 
     350                    if ($saved>0) { 
     351                        echo " (saved " . $saved . "B)"; 
     352                    } 
     353                    else if ($saved<0) { 
     354                        echo " (" . abs($saved) . "B added)"; 
     355                    } 
     356                } 
     357                echo "\n"; 
    328358            } else { 
    329359                echo "\rERROR: couldn't lock the " . $path . " file". "\n"; 
     
    417447function printHelp() { 
    418448    $help = <<<HELP 
    419      
     449 
    420450SYNOPSIS 
    421451       php fixlineends.php [options] PATH [PATH2...] 
    422        grep [options] [-e PATTERN | -f FILE] [FILE...] 
    423452 
    424453DESCRIPTION 
    425        Traverse recursively all the paths given and fix line endings  
     454       Traverse recursively all the paths given and fix line endings 
    426455       in each file. 
    427456 
     
    429458       --eofnewline 
    430459            force new line character at the end of file 
    431         
     460 
    432461       --eofstripwhite 
    433462            strip whitespace from the end of file 
    434         
     463 
     464       --eolstripwhite 
     465            strip whitespace from the end of line (spaces, tabs) 
     466 
    435467       --excluderegex=regex 
    436468            use regex to exclude files, preg_match() format expected 
    437              
     469 
    438470       --help 
    439471            display this help and exit 
    440              
     472 
    441473       --noarchive 
    442474            if set to true, archive files are skipped (Windows only) 
    443         
     475 
    444476       --nodotfiles 
    445477            if set to true, dot files are skipped 
    446              
     478 
    447479       --nohidden 
    448480            if set to true, hidden files are skipped (Windows only) 
     
    450482       --nosystem 
    451483            if set to true, system files are skipped (Windows only) 
    452              
     484 
    453485       --maxdepth 
    454             fix line ends only if file is N or fewer levels below  
    455             the command line argument; Use --max-depth=0 to omit  
     486            fix line ends only if file is N or fewer levels below 
     487            the command line argument; Use --max-depth=0 to omit 
    456488            subdirectories 
    457              
     489 
    458490EXAMPLES 
    459             php fixlineends.php --eofstripwhite --eofnewline --maxdepth=1  
     491            php fixlineends.php --eofstripwhite --eofnewline --maxdepth=1 
    460492                --nodotfiles --excluderegex=/\_private/ . 
    461         
    462        This command fixes line endings in current directory and in  
     493 
     494       This command fixes line endings in current directory and in 
    463495       subdirectories placed one level below. Dot files are skipped. 
    464496       Paths that match "_private" are skipped. White chars are stripped 
    465497       at the end of file. New line character is added to the end of file 
    466498       (if required). 
    467         
    468         
     499 
     500 
    469501HELP; 
    470502    echo $help; 
     
    513545                $GLOBALS['excluderegex'] = $arg[1]; 
    514546                break; 
    515                  
     547 
    516548            case '--eofnewline': 
    517549                $GLOBALS['eofnewline'] = true; 
     
    520552            case '--eofstripwhite': 
    521553                $GLOBALS['eofstripwhite'] = true; 
     554                break; 
     555 
     556            case '--eolstripwhite': 
     557                $GLOBALS['eolstripwhite'] = true; 
    522558                break; 
    523559        } 
     
    554590 
    555591    if ($windows) { 
    556         $longoptions = array("eofstripwhite", "eofnewline", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex="); 
     592        $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex="); 
    557593    } 
    558594    else { 
    559         $longoptions = array("eofstripwhite", "eofnewline", "help", "nodotfiles", "maxdepth=", "excluderegex="); 
     595        $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex="); 
    560596    } 
    561597 
     
    579615 
    580616print "\rDone!".str_repeat(" ",40)."\n"; 
     617if ($saved_bytes>0) { 
     618    echo "saved " . $saved_bytes . "B"; 
     619} 
     620else if ($saved_bytes<0) { 
     621    echo abs($saved_bytes) . "B added"; 
     622} 
Note: See TracChangeset for help on using the changeset viewer.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy