Develop and Download Open Source Software

Browse Subversion Repository

Contents of /script/replaceTab.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 279 - (show annotations) (download)
Wed Mar 12 05:28:19 2008 UTC (16 years, 2 months ago) by satofumi
File size: 721 byte(s)
adjust tab index
1 #!/usr/bin/ruby
2 # ソースコード中の TAB を8文字の空白に置換するスクリプト
3 # $Id$
4
5 require 'find'
6 require 'fileutils.rb'
7
8 $replaced = false
9
10 # TAB の置換操作
11 def replaceTab(fname)
12
13 # ファイルの読み出し
14 lines = File.readlines(fname).join
15
16 if lines.match("\t") == nil
17 # 置換処理は不要
18 return
19 end
20
21 # 置換処理
22 lines.gsub!("\t", ' ')
23
24 # オリジナルファイルの退避
25 FileUtils.copy(fname, fname + '.orig')
26 File.open(fname, 'w') { |io|
27 io.write(lines)
28 }
29 print fname + ' '
30 $replaced = true
31 end
32
33 # .cpp, .c .h の探索
34 Find.find('./') { |fname|
35 ext = File.extname(fname)
36 if ! (ext == '.h' || ext == '.cpp' || ext == '.c')
37 next
38 end
39 replaceTab(fname)
40 }
41
42 if $replaced
43 print "\n"
44 end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26