REBOL [
    Title: "Indent {}"
    Date: 24-Jan-2003
    Version: 2.0.0
    File: %indent.r
    Author: "Gregory Pecheret"
    Usage: "rebol -s indent.r CATx.cpp Cfgx.java "
    Purpose: {This utility is to indent programs using {} as blocks like CPP or Java.  Almost a one-liner !!}
    Email: gregory.pecheret@free.fr
    Web: http://reviewer.free.fr
    Category: [util text 3]
]

indent: func [f [file!]][
        t: 0
        code: detab read f
        code: next code
        while [not tail? code][
                if newline = first code [loop t [insert next code tab]]
                if #"{" = first code [t: t + 1]
                if #"}" = first code [t: t - 1]
                either all [#" " = first back code #" " = first code]
                [remove back code]
                [code: next code]
        ]
        code: head code
        code: next code
        while [not tail? code][
                either all [tab = first back code #" " = first code]
                [remove code]
                [code: next code]
        ]
        code: head code
        code: next code
        while [not tail? code][
                either all [tab = first back code #"}" = first code]
                [remove back code]
                [code: next code]
        ]

        code: head code
        write f code
        print rejoin [f " done"]
]


args: copy system/options/args
while [not tail? args] [
  indent to-file first args
  args: next args
]