Changeset 14797
- Timestamp:
- 02/07/08 20:10:08 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.core/support/normalize_file_whitespace.php
r14796 r14797 3 3 error_reporting(E_ALL); 4 4 require_once('normalize_whitespace_normalizer.php'); 5 if ($argc < 4)5 if ($argc < 2) 6 6 { 7 7 $name = basename($argv[0]); 8 echo "\nUsage: {$name} < configfile> <username> <password>\n";8 echo "\nUsage: {$name} <files_list>\n"; 9 9 echo " For example:\n"; 10 echo " {$name} midgard 'sgadmin+sgname' 'adminpasswd'\n\n";10 echo " {$name} `find ~/svn/midcom/ -name '*.php'` \n\n"; 11 11 exit(1); 12 12 } 13 $conffile =& $argv[1]; 14 $username =& $argv[2]; 15 $password =& $argv[3]; 16 if (!mgd_config_init($conffile)) 13 $files = array_slice($argv, 1); 14 15 if (!function_exists('file_put_contents')) 17 16 { 18 echo "\nInitialization failed\n\n"; 19 exit(1); 20 } 21 mgd_auth_midgard($username, $password); 22 if (!$_MIDGARD['user']) 23 { 24 echo "\nAuthentication failed\n\n"; 25 exit(1); 26 } 27 if (!$_MIDGARD['sitegroup'] === 0) 28 { 29 echo "\nSG0 usage not supported\n\n"; 30 exit(1); 17 function file_put_contents($file, &$data) 18 { 19 $fp = fopen($file, 'w'); 20 if (!$fp) 21 { 22 return false; 23 } 24 $ret = fwrite($fp, $data); 25 fclose($fp); 26 return $ret; 27 } 31 28 } 32 29 33 34 35 30 $normalizer = new midcom_support_wsnormalizer(); 31 foreach ($files as $file) 32 { 33 $data = file_get_contents($file); 34 $normalized = $normalizer->normalize($data); 35 if ($data === $normalized) 36 { 37 unset($data, $normalized); 38 continue; 39 } 40 file_put_contents($file, $normalized); 41 unset($data, $normalized); 42 } 36 43 37 44 ?>
