Changeset 14797

Show
Ignore:
Timestamp:
02/07/08 20:10:08 (10 months ago)
Author:
rambo
Message:

one should check which file one is editing...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/support/normalize_file_whitespace.php

    r14796 r14797  
    33error_reporting(E_ALL); 
    44require_once('normalize_whitespace_normalizer.php'); 
    5 if ($argc < 4
     5if ($argc < 2
    66{ 
    77    $name = basename($argv[0]); 
    8     echo "\nUsage: {$name} <configfile> <username> <password>\n"; 
     8    echo "\nUsage: {$name} <files_list>\n"; 
    99    echo "  For example:\n"; 
    10     echo "  {$name} midgard 'sgadmin+sgname' 'adminpasswd' \n\n"; 
     10    echo "  {$name} `find ~/svn/midcom/ -name '*.php'` \n\n"; 
    1111    exit(1); 
    1212} 
    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 
     15if (!function_exists('file_put_contents')) 
    1716{ 
    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    } 
    3128} 
    3229 
    33  
    34  
    3530$normalizer = new midcom_support_wsnormalizer(); 
     31foreach ($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} 
    3643 
    3744?>