Code beautifiers, anyone?

Matti J. Karki mjk at iki.fi
Thu Aug 24 19:10:02 UTC 2006


On 8/24/06, Kyrre Nygård <kyrreny at broadpark.no> wrote:
>
> Perhaps you could share with us whatever scripts you've written?
>
> Thanks!
>

Well, my scripts aren't magic. They are pretty simple. Here's few (not
scripts, these are valid Vim regexps):

:%s/).*\n.*{/) {/g

:%s/) *{/) {/g

:%s/\t/    /g

:%s/^ *$//g

:%s/ *$//g

1) Move curly brackets from the next line to the end of an expression.
2) Clean up some crazy bracket placements.
3) Remove tab characters and replace them with 4 spaces. This may mess
some multiline comments.
4) Clean all lines, which contain only spaces.
5) Almost same as above. Cleans up spaces at the end of the line.

If you run those one after another, the C source file should be much
nicer to read and manipulate. The idea should be quite clear and the
same regexp rules should be possible to be applied to other
regexp-savvy programs/interpreters, so it should be no problem to
create a set of scripts, which use those rules to modify a set of
files at one run. Some of those regexps are applicable (with minor
modifications) to other target languages also.



        -Matti


More information about the freebsd-questions mailing list