Never use GNU Indent

I thought that since I had changed my coding style (4 space indents instead of 8-space tab indents), I'd cheat and have Indent update all my code automatically instead of doing it all myself (it's like 7,000 LOC). Never again. I made sure not to use it's retarded built-in settings, but it just ignored them. I said unto Indent "Do not use tabs in your indentation, but use spaces instead, for my name is the USER." But lo and behold, tabs. And spaces. 4 spaces for 1 level of indentation, 1 (8-space) tab for two levels of indentation, 1 tab and 4 spaces for 3 and so on. I even tested it beforehand on a single file, thinking "If it doesn't work, I can just manually fix this one file". It worked. It was fine. It was only when I applied it to my entire project directory thinking "this is surely a good idea" that it decided to break everything. In some files, it just deleted all the indentation and added a bunch of random blank lines. Because Indent is evil. It doesn't like K&R style, you see. It resents me for not using GNU style, the brace style of the devil, by whom Indent was sent to fulfil evil prophecies.

So, lesson learned, never use GNU Indent. I was hoping A-Style would be able to fix everything but it throws a std::bad_alloc exception for some reason.
closed account (o1vk4iN6)
Surely you have a back up or use source control with 7000 lines of code.
I do for some of the projects, but even if I restore them, I'll have to re-format all the code anyway. If I could get A-Style to do it, it would be better.
Ouch. May I ask why a Ctrl+H is not applicable?
Because I'd have to do it to about 300 files. Also, with some of them, it actually completely removed the indentation and just added blank lines in between every line of code. It also changed the pointers so that the asterisk is with the variable name instead of the type (minor annoyance), indented conditional extern "C" blocks, broke up all the lines above 80 chars (which I do manually, but it did it in a completely retarded way), broke some comments, and I'm pretty sure it even broke some code so that it doesn't compile any more.

Also my whole projects directory is actually about 11,000 LOC, about 8,000 lines of comments, (and 1500 blank lines).
Last edited on
You could still use sed.
True, but I want A-Style to fix everything. I figured out the right command-line options, but there are some errors when I run it:
$ astyle --style=1tbs -s4 --indent-namespaces --indent-labels --indent-preprocessor -H -xd -k1 -R "Projects/*"
directory Projects/*
errno message: No such file or directory
Error getting file status in directory Projects/Libraries/WIP/SGE/lib

Artistic Style has terminated!

I can't remember how to reproduce the std::bad_alloc exception.

Another problem is that A-Style also seems to want to indent my comments with tabs. Why can't it just not use tabs at all?
I meant why did you not use Ctrl+H before?

For me, VC++ can import multiple files at once and perform find & replace on all files in a solution; I sometimes use it as a utility.
Well, gedit doesn't have a "find and replace in all documents" function and I didn't think to use sed, so I used indent, and now I regret it.
directory Projects/*
errno message: No such file or directory
Simple enough. It doesn't support wildcards. You have to issue one command per file. I recommend generating a listing and then processing it with a regex.
I only used the wildcard because it told me to! I already have a file listing (from when I counted the LOC) so I'll do what you said.
Topic archived. No new replies allowed.