2019-09-11 11:47:16 -07:00
|
|
|
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)'
|
2019-09-17 08:26:44 -07:00
|
|
|
s = s.gsub /local /, ''
|
|
|
|
s = s.gsub /\n\n\n/, "\n\n"
|
2019-09-11 11:47:16 -07:00
|
|
|
s = IO.popen 'unexpand', mode: "r+" do |io| pipe_in_out io, s end
|
|
|
|
30.times do s = s.gsub(/ /, ' ') end
|
|
|
|
puts s
|