Re: spaghetti-code indent program

From: Alfie Costa (
Date: Tue Jul 11 2000 - 04:36:42 CEST

On 10 Jul 2000, at 20:35, Mark Roberts <> wrote:

> There has been an 'indent' for C-programs for decades, and there's a
> GNU-version of it, of course. But even the GNU-version is only useful
> for C.

Coincidentally, I have one version of it, and that's probably what inspired the
question. Also, Midnight Commander's Cooledit has a built-in C indenter.

> It could prove fairly easy to create an indent-program for scripts, using
> lex and yacc to create a scanner and simple parser. The parser would only
> have to recognise a few things, like 'if', 'while' and function calls.

Mustn't forget quotes, brackets, 'here' files, etc. Shell script indenting may
be even worse than C code.

> And if it's so easy, probably someone's done it.

It would be interesting to hear about anything like this. (Provided I don't
have to learn 'emacs'...)

> Are you sure you need it, anyway?

No, it's very uncertain. On the one hand, it's nice to have code that's easier
to read, or in the style that a particular person is most comfortable with.
But the command line syntax of the 'indent' program I've seen is quite
complicated**, so that it's easier to stick with the default indents that come
with the program. Unfortunately, these aren't always one's favorite indents.
Cooledit's indenter is the same way, only you can't configure that.

(** Here's an example of the complexity a 1993 'indent' offers...
     indent [filename[s...]] [@listfile]

     [-+|-n+] [-bacc|-nbacc] [-bad|-nbad] [-badp|-nbadp] [-bap|-nbap]
     [-bbb|-nbbb] [-bc|-nbc] [-br|-nbr] [-brr|-nbrr] [-bs|-nbs] [-cdb|-ncdb]
     [-ce|-nce] [-dj|-ndj] [-eei|-neei] [-ei|-nei] [-fc1|-nfc1] [-ip|-nip]
     [-ldefs|-nldefs] [-lp|-nlp] [-pcs|-npcs] [-pro|-npro] [-prs|-nprs]
     [-ps|-nps] [-psl|-npsl] [-sc|-nsc] [-sob|-nsob] [-st|-nst] [-tabu|-ntabu]
     [-troff|-ntroff] [-v|-nv]

     [-c:n] [-cci:n] [-cd:n] [-ci:n] [-cli:n] [-cp:n] [-d:n] [-di:n] [-i:n]
     [-l:n] [-lc:n] [-tabs:n]

     [-fb:...] [-fbc:...] [-fbx:...] [-fc:...] [-fk:...] [-fs:...] [-T:...]
<snip>'s impressive, but when all you want to do is save labor, it is also a
little frustrating. )

To unsubscribe, e-mail:
For additional commands, e-mail:

This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:15 CET