31 lines
619 B
Ruby
31 lines
619 B
Ruby
FNAME = ARGV.shift
|
|
|
|
def pipe_in_out io, s
|
|
io << s
|
|
io.close_write
|
|
io.read
|
|
end
|
|
|
|
style_args = %w(
|
|
astyle
|
|
--style=java
|
|
--indent=tab=8
|
|
--add-braces
|
|
--pad-oper
|
|
--pad-comma
|
|
--unpad-paren
|
|
--delete-empty-lines
|
|
--indent-col1-comments
|
|
)
|
|
|
|
s = File.read FNAME
|
|
s = IO.popen 'expand', mode: "r+" do |io| pipe_in_out io, s end
|
|
s = IO.popen style_args, mode: "r+" do |io| pipe_in_out io, s end
|
|
s = s.gsub /\b(\w+) \(/, '\1('
|
|
s = s.gsub /\(\s*(.*)\s*\)/, '(\1)'
|
|
s = s.gsub /local /, ''
|
|
s = s.gsub /\n\n\n/, "\n\n"
|
|
s = IO.popen 'unexpand', mode: "r+" do |io| pipe_in_out io, s end
|
|
30.times do s = s.gsub(/ /, ' ') end
|
|
puts s
|