Changeset 1563 for FCKeditor/trunk
- Timestamp:
- 02/19/08 13:41:58 (5 years ago)
- Location:
- FCKeditor/trunk/_dev
- Files:
-
- 2 edited
-
fixlineends.bat (modified) (1 diff)
-
fixlineends.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
FCKeditor/trunk/_dev/fixlineends.bat
r1562 r1563 22 22 :: 23 23 24 php fixlineends.php --eo fnewline --eofstripwhite --nohidden --nosystem ../24 php fixlineends.php --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem ../ -
FCKeditor/trunk/_dev/fixlineends.php
r1562 r1563 2 2 <?php 3 3 /* 4 * FCKreleaser - FCKeditor Releaser - http://www.fckeditor.net5 * Copyright (C) 2003-2007 Frederico Caldeira Knabben6 *7 * == BEGIN LICENSE ==8 *9 * Licensed under the terms of any of the following licenses at your10 * choice:11 *12 * - GNU General Public License Version 2 or later (the "GPL")13 * http://www.gnu.org/licenses/gpl.html14 *15 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")16 * http://www.gnu.org/licenses/lgpl.html17 *18 * - Mozilla Public License Version 1.1 or later (the "MPL")19 * http://www.mozilla.org/MPL/MPL-1.1.html20 *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 */ 26 26 27 27 error_reporting(E_ALL); … … 90 90 $eofstripwhite = false; 91 91 /** 92 * Strip whitespace from the end of line 93 * @var boolean $eolstripwhite 94 */ 95 $eolstripwhite = false; 96 /** 92 97 * Force new line character at the end of file 93 98 * @var boolean $eofnewline … … 121 126 * -1 to disable 122 127 * 0 to fix only current directory 123 * 128 * 124 129 * @var integer $maxdepth 125 130 */ … … 130 135 * example: 131 136 * --excluderegex = "/(\.\w+)$/" 132 * 137 * 133 138 * @var string $excluderegex 134 139 */ … … 140 145 */ 141 146 $windows = (strtolower(substr(PHP_OS, 0, 3)) == "win"); 147 148 /** 149 * Count saved bytes 150 * @var integer $saved_bytes 151 */ 152 $saved_bytes = 0; 142 153 143 154 /** … … 201 212 * @param string $path relative or absolute path name to file 202 213 * @param string $nl name of a constant that holds new line character (CRLF|CR|LF) 203 * @return bool 214 * @return bool 204 215 */ 205 216 function fixFile($path, $nl) { 206 217 207 218 $contents = file($path); 219 $size = filesize($path); 208 220 if ($contents === false) { 209 221 echo "\rERROR: couldn't read the " . $path . " file". "\n"; … … 312 324 break; 313 325 } 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 } 314 333 $new_content .= $line; 315 334 } … … 325 344 fwrite($fp, $new_content); 326 345 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"; 328 358 } else { 329 359 echo "\rERROR: couldn't lock the " . $path . " file". "\n"; … … 417 447 function printHelp() { 418 448 $help = <<<HELP 419 449 420 450 SYNOPSIS 421 451 php fixlineends.php [options] PATH [PATH2...] 422 grep [options] [-e PATTERN | -f FILE] [FILE...]423 452 424 453 DESCRIPTION 425 Traverse recursively all the paths given and fix line endings 454 Traverse recursively all the paths given and fix line endings 426 455 in each file. 427 456 … … 429 458 --eofnewline 430 459 force new line character at the end of file 431 460 432 461 --eofstripwhite 433 462 strip whitespace from the end of file 434 463 464 --eolstripwhite 465 strip whitespace from the end of line (spaces, tabs) 466 435 467 --excluderegex=regex 436 468 use regex to exclude files, preg_match() format expected 437 469 438 470 --help 439 471 display this help and exit 440 472 441 473 --noarchive 442 474 if set to true, archive files are skipped (Windows only) 443 475 444 476 --nodotfiles 445 477 if set to true, dot files are skipped 446 478 447 479 --nohidden 448 480 if set to true, hidden files are skipped (Windows only) … … 450 482 --nosystem 451 483 if set to true, system files are skipped (Windows only) 452 484 453 485 --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 456 488 subdirectories 457 489 458 490 EXAMPLES 459 php fixlineends.php --eofstripwhite --eofnewline --maxdepth=1 491 php fixlineends.php --eofstripwhite --eofnewline --maxdepth=1 460 492 --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 463 495 subdirectories placed one level below. Dot files are skipped. 464 496 Paths that match "_private" are skipped. White chars are stripped 465 497 at the end of file. New line character is added to the end of file 466 498 (if required). 467 468 499 500 469 501 HELP; 470 502 echo $help; … … 513 545 $GLOBALS['excluderegex'] = $arg[1]; 514 546 break; 515 547 516 548 case '--eofnewline': 517 549 $GLOBALS['eofnewline'] = true; … … 520 552 case '--eofstripwhite': 521 553 $GLOBALS['eofstripwhite'] = true; 554 break; 555 556 case '--eolstripwhite': 557 $GLOBALS['eolstripwhite'] = true; 522 558 break; 523 559 } … … 554 590 555 591 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="); 557 593 } 558 594 else { 559 $longoptions = array("eofstripwhite", "eofnewline", " help", "nodotfiles", "maxdepth=", "excluderegex=");595 $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex="); 560 596 } 561 597 … … 579 615 580 616 print "\rDone!".str_repeat(" ",40)."\n"; 617 if ($saved_bytes>0) { 618 echo "saved " . $saved_bytes . "B"; 619 } 620 else if ($saved_bytes<0) { 621 echo abs($saved_bytes) . "B added"; 622 }
Note: See TracChangeset
for help on using the changeset viewer.
