News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

AStyle formatting help needed

Started by Jewest, March 08, 2018, 10:28:00 AM

Previous topic - Next topic

Jewest

Dear All,

I have found the astyle formatter and I love it.
There is only on thing that I can not make the formatter do in version 17.12, what I have made working in version 12.11.

What I want:

Quoteif(statment1 == 1) statment1++;
or
Quote
if(statment1 == 1)
statment1++;
transform in:
Quote
if(statment1 == 1)
{
  statment1++;
}
What do I have so far?
Quote
if(statment1 == 1)
{statment1++;}
But I want the break in to new lines in one single step.

Anyone got a suggestion?

thank you in advance,

Jewest

oBFusCATed

Can you setup the command line version to do it?
Astyle is not a project we develop, it is an external tool we just integrate in the IDE.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Jewest

I understand, I had version 12.11 doing what is doing what is supposed todo.
is there are way to debug this? can I see the output to the astyle formatter?
I have a feeling that its the parameter sequence that C::B is sending to aStyle.

oBFusCATed

As far as I know you can install a command line astyle. You need to use the same version.
Otherwise debugging could be done by building cb with debug symbols/no optimizations and using gdb to step through the code...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Jewest

I did some digging around.

Source file:
void main()
{
    if(def ==1) def=3;
    else def=12;

while(def<12) def--;
}



int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}


switch (foo)
{
case 1:
    a += 1;
    break;

case 2:
{
    a += 2;
    break;
}
}


command with aStyle 3.1  command used:  astyle -A1 --indent=spaces=2 -f -j < benchmark.cpp > test.cpp

results in:
void main()
{
  if(def ==1)
  {
    def=3;
  }
  else
  {
    def=12;
  }

  while(def<12)
  {
    def--;
  }
}



int Foo(bool isBar)
{
  if (isBar)
  {
    bar();
    return 1;
  }
  else
  {
    return 0;
  }
}


switch (foo)
{
case 1:
  a += 1;
  break;

case 2:
{
  a += 2;
  break;
}
}



I see "--add-one-line-braces / -J"  in the option window of C::B but apparently I am overlooking the "--add-braces / -j" that I need.
Any suggestions which option to enable on the screen?

Jewest

At the moment I have created the following workaround:

Add a new tool in the tools menu
With the following settings:
astyle
-A1 --indent=spaces=2 -f -j $(ACTIVE_EDITOR_FILENAME)

This does the job for me at the moment.
(Detecting the change on disk is slow, but acceptable)

BlueHazzard

Ticket on SF would be nice so this won't get lost...