diff options
author | Noe Rubinstein <nrubinstein@avencall.com> | 2012-01-04 11:05:51 +0100 |
---|---|---|
committer | Noe Rubinstein <nrubinstein@avencall.com> | 2012-01-04 11:05:51 +0100 |
commit | 5c7d677e73bab98741b48940f1e1ec7bbd662c5d (patch) | |
tree | 6877177a1f465d2bfde30e74253afaa9c2f51542 /fix_linux_indent.rb | |
parent | 64998e378294bf28e512386c602c1a8e3ca8214b (diff) |
script to fix indent
Diffstat (limited to 'fix_linux_indent.rb')
-rwxr-xr-x | fix_linux_indent.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/fix_linux_indent.rb b/fix_linux_indent.rb new file mode 100755 index 0000000..8d2da60 --- /dev/null +++ b/fix_linux_indent.rb @@ -0,0 +1,20 @@ +#!/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 +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 |