summaryrefslogtreecommitdiff
path: root/fix_linux_indent.rb
blob: 01dc12c2a958f29bb280dc74de87e6461529b0e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env ruby1.9.1

str = $stdin.read
spaces = str[/[ \t]*/]
spl = spaces.scan(/\t/).length + (spaces.scan(/ /).length + 7) / 8
start = rand(0xFFFFFFFFFFFFFFFFFFFF).to_s(36)
stop = rand(0xFFFFFFFFFFFFFFFFFFFF).to_s(36)
input = '{' * spl + '//' + start + "\n" + str + "\n//" + stop + "\n}" * spl
indent = 'scripts/Lindent'
indent = 'indent' unless File.exist? indent
io = IO.popen("indent -linux", "r+")
io.print input
io.close_write
next until io.gets[start]

unless io.gets[stop]
  loop do
    print $_.chomp
    break if io.gets[stop]
    print "\n"
  end
end