#!/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