Ticket #5188: 5188.patch
File 5188.patch, 4.1 KB (added by , 15 years ago) |
---|
-
fixlineends.bat
4 4 :: For licensing, see LICENSE.html or http://ckeditor.com/license 5 5 :: 6 6 7 php fixlineends.php --excluderegex=/(?:_dev[\\\/]_thirdparty)/ --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem ../../7 php fixlineends.php --excluderegex=/(?:_dev[\\\/]_thirdparty)/ --eolstripwhite --eofnewline --eofstripwhite --nohidden --nosystem --fixbom ../../ -
fixlineends.php
63 63 $list["txt"] = CRLF; 64 64 $list["xml"] = CRLF; 65 65 66 $bom = array(); 67 $bom['asp'] = true; 68 $bom['js'] = true; 69 66 70 /** 67 71 * Do not modify anything below 68 72 * use command line arguments to modify script's behaviour … … 107 111 */ 108 112 $nodotfiles = false; 109 113 /** 114 * If set to true, BOM characters are fixed 115 * @var boolean $fixbom 116 */ 117 $fixbom = false; 118 /** 110 119 * How deep to recurse into subdirectories 111 120 * -1 to disable 112 121 * 0 to fix only current directory … … 318 327 $new_content .= $line; 319 328 } 320 329 330 if ($GLOBALS['fixbom']) { 331 $before_fixing = $new_content; 332 $ext = strtolower(substr($path, strrpos($path, ".") + 1)); 333 $new_content = stripUtf8Bom( $new_content ); 334 if (!empty($GLOBALS['bom'][$ext])) { 335 $new_content = "\xEF\xBB\xBF" . $new_content; // BOM 336 } 337 if ($new_content != $before_fixing) 338 $modified = true; 339 } 340 321 341 if ($modified) { 322 342 $fp = fopen($path, "wb"); 323 343 if (!$fp) { … … 352 372 } 353 373 354 374 /** 375 * Strip BOM from a string 376 * @param string $data 377 */ 378 function stripUtf8Bom( $data ) 379 { 380 if ( substr( $data, 0, 3 ) == "\xEF\xBB\xBF" ) 381 return stripUtf8Bom(substr_replace( $data, '', 0, 3 )) ; 382 383 return $data ; 384 } 385 386 /** 355 387 * Fix ending lines in all files at given path 356 388 * 357 389 * @param string $path … … 452 484 --excluderegex=regex 453 485 use regex to exclude files, preg_match() format expected 454 486 487 --fixbom 488 fix BOM characters 489 455 490 --help 456 491 display this help and exit 457 492 458 493 --noarchive 459 if set to true, archive files are skipped(Windows only)494 skip archive files (Windows only) 460 495 461 496 --nodotfiles 462 if set to true, dot files are skipped497 skip dot files 463 498 464 499 --nohidden 465 if set to true, hidden files are skipped(Windows only)500 skip hidden files (Windows only) 466 501 467 502 --nosystem 468 if set to true, system files are skipped(Windows only)503 skip system files (Windows only) 469 504 470 505 --maxdepth 471 506 fix line ends only if file is N or fewer levels below … … 526 561 $GLOBALS['nodotfiles'] = true; 527 562 break; 528 563 564 case '--fixbom': 565 $GLOBALS['fixbom'] = true; 566 break; 567 529 568 case '--excluderegex': 530 569 $GLOBALS['excluderegex'] = $arg[1]; 531 570 break; … … 571 610 } 572 611 573 612 if ($_SERVER['argc']>1) { 574 613 include "../_thirdparty/console_getopt/Getopt.php"; 575 614 576 615 if ($windows) { 577 $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex=" );616 $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "noarchive", "nohidden", "nosystem", "nodotfiles", "maxdepth=", "excluderegex=", "fixbom"); 578 617 } 579 618 else { 580 $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex=" );619 $longoptions = array("eofstripwhite", "eofnewline", "eolstripwhite", "help", "nodotfiles", "maxdepth=", "excluderegex=", "fixbom"); 581 620 } 582 621 583 622 $con = new Console_Getopt;