root/branches/1.0.x/build/dos2unix.php

Revision 705, 2.5 kB (checked in by laurentj, 1 year ago)

replaced all CRLF by LF in files

Line 
1 <?php
2
3 /**
4 * @package     jBuildTools
5 * @author      Jouanneau Laurent
6 * @contributor
7 * @copyright   2006-2007 Jouanneau laurent
8 * @link        http://www.jelix.org
9 * @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html
10 */
11
12 require_once(dirname(__FILE__).'/lib/jCmdUtils.class.php');
13
14 // arguments :  repertoire
15 // repertoire : le chemin du repertoire où les fichiers seront convertis
16
17 try{
18     $sws = array('-n'=>false);
19     $params = array('dirpath'=>true);
20
21     list($switches, $parameters) = jCmdUtils::getOptionsAndParams($_SERVER['argv'], $sws, $params);
22
23 }catch(Exception $e){
24     echo "dos2unix error : " , $e->getMessage(),"\n";
25     echo "php dos2unix.php [-n] dir
26    -n: no modification, test mode\n";
27     exit(1);
28 }
29
30 $dirpath = $parameters['dirpath'];
31
32 if(substr($dirpath,-1) == '/'){
33    $dirpath=substr($dirpath,0,-1);
34 }
35
36 function parsePath($dir){
37     global $switches;
38     if ($dh = opendir($dir)) {
39         $dirlist=array();
40         $cdok=false;
41         while (($file = readdir($dh)) !== false) {
42             if($file == '.svn')
43                 continue;
44             $type= filetype($dir.'/'.$file);
45             if($type == 'dir'){
46                 if($file != '.' && $file !='..' ){
47                     $dirlist[]=$file;
48                 }
49             }else{
50                 if(preg_match("/\.(php|xml|rng|dist|tpl|properties)$/",$file)) {
51                     $content = file_get_contents($dir.'/'.$file);
52                     if(strpos($content,"\r") !== false) {
53                         if (isset($switches['-n'])) {
54                             echo $dir.'/'.$file." need to be converted\n";
55                         }
56                         else {
57                             echo " convert ".$dir.'/'.$file."\n";
58                             $content = str_replace("\r\n","\n", $content);
59                             file_put_contents($dir.'/'.$file,$content);
60                         }
61                     }
62                     else {
63                         //echo "  ".$dir.'/'.$file."\n";
64                     }
65                 } else {
66                     //echo "! no parsing $file\n";
67                 }
68             }
69         }
70         closedir($dh);
71         foreach($dirlist as $d){
72             parsePath( $dir.'/'.$d);
73         }
74     }else{
75         echo "!!! error when reading directory $dir !!!\n";
76         exit(1);
77     }
78 }
79
80
81
82 $output='';
83 if (is_dir($dirpath)) {
84     parsePath($dirpath);
85 }else{
86     echo "mauvais repertoire $dirpath\n";
87     exit(1);
88 }
89
90 echo "\n\nend\n";
91 exit(0);
92 ?>
Note: See TracBrowser for help on using the browser.
Download in other formats: Plain Text Original Format