Re: a simple formatter

From: Amos Jeffries <squid3@dont-contact.us>
Date: Thu, 7 Feb 2008 12:21:18 +1300 (NZDT)

> Hi all,
>
> I wrote a small perl script which fixes (some of) the astyle problems.
>
> Before use it, you must adjust the $ASTYLE_BIN variable at the beggining
> of the formatter.pl file.
>
> I am running it using the following command:
> # find . -name "*.cc" -exec formater.pl \{\} \;
> but it can take multiple files as arguments.
>
> I used it with astyle versions 1.18 and 1.21. I did not do extensive
> tests, so I am sure it contains bugs :-). Please use it with caution.
>
> I tried to implement Alex suggestions. For the problem discussion look
> at the thread:
> http://www.squid-cache.org/mail-archive/squid-dev/200801/0019.html
>
> This script starts the astyle and attach one filter in its input and one
> in its output, using pipes.
>
> The input filter search for "unsigned int XXXXX:1;" cases and convert
> them to "unsigned int XXXXX__FORASTYLE__1;".
>
> The output filter search for "unsigned int XXXXX__FORASTYLE__1;"
> patterns and convert them back to the original text.
> Also it search for the cases "#preprocessor directive {" or "{
> #preprocessor_directive" and fix them.
>
>
> Do we need something like that? Any comments/suggestions? Any testers?
>
> Regards,
> Christos
>

Tested.

I have made a (small) file of the structures I've noticed past formatting
errors on. With a manual fix-up to what I think it should look like in
readable C++ under the published squid formatting description.

The output of your script does this:
--- astyle-test-cases.cc-original 2008-02-07 12:13:07.000000000 +1300
+++ astyle-test-cases.cc 2008-02-07 12:19:14.000000000 +1300
@@ -9,10 +9,11 @@
 */

 /// structures with bit-fields
+
 struct t1 {
- unsigned int a:1;
- unsigned int b:1;
- unsigned int c:1;
+ unsigned int a:1;
+ unsigned int b:1;
+ unsigned int c:1;
 };

 /// code-blocks inside definition protection
@@ -20,6 +21,7 @@
 {
     ;
 }
+
 #endif

 /// regular function declarations
@@ -30,6 +32,7 @@
 }

 /// template class explicit Instantiation for some compilers
+
 template class ACLStrategised<HttpHeader*>;

 /// global template Instances with macro definition

NP: breaking the auto-docs away from the documented object is not that
good a thing to do.

Amos
Received on Wed Feb 06 2008 - 16:21:24 MST

This archive was generated by hypermail pre-2.1.9 : Sat Mar 01 2008 - 12:00:09 MST