Index: trunk/tools/code-utils/stylize.php |
— | — | @@ -43,23 +43,24 @@ |
44 | 44 | |
45 | 45 | function stylize_file( $filename, $backup = true ) { |
46 | 46 | echo "Stylizing file $filename\n"; |
| 47 | + |
| 48 | + $s = ( $filename == '-' ) |
| 49 | + ? file_get_contents( '/dev/stdin' ) |
| 50 | + : file_get_contents( $filename ); |
| 51 | + |
| 52 | + if ( $s === false ) { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + $stylizer = new Stylizer( $s ); |
| 57 | + $s = $stylizer->stylize(); |
| 58 | + |
47 | 59 | if ( $filename == '-' ) { |
48 | | - $s = file_get_contents( '/dev/stdin' ); |
49 | | - if ( $s === false ) { |
50 | | - return; |
51 | | - } |
52 | | - $stylizer = new Stylizer( $s ); |
53 | | - $s = $stylizer->stylize(); |
54 | 60 | echo $s; |
55 | 61 | } else { |
56 | | - $s = file_get_contents( $filename ); |
57 | | - if ( $s === false ) { |
58 | | - return; |
59 | | - } |
60 | | - $stylizer = new Stylizer( $s ); |
61 | | - $s = $stylizer->stylize(); |
62 | | - if ( $backup ) |
| 62 | + if ( $backup ) { |
63 | 63 | rename( $filename, "$filename~" ); |
| 64 | + } |
64 | 65 | file_put_contents( $filename, $s ); |
65 | 66 | } |
66 | 67 | } |
— | — | @@ -152,7 +153,6 @@ |
153 | 154 | var $endl = " |
154 | 155 | "; |
155 | 156 | |
156 | | - |
157 | 157 | function __construct( $s ) { |
158 | 158 | $s = str_replace( "\r\n", "\n", $s ); |
159 | 159 | $this->tokens = token_get_all( $s ); |
— | — | @@ -299,5 +299,4 @@ |
300 | 300 | // Fix whitespace at the line end |
301 | 301 | return preg_replace( '!^([\t ]+)(\n.*)$!s', '\2', $s, 1 ); |
302 | 302 | } |
303 | | - |
304 | 303 | } |