Author Topic: AStyle formatting help needed  (Read 601 times)

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 22
AStyle formatting help needed
« on: March 08, 2018, 10:28:00 am »
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:

Quote
if(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
« Last Edit: March 08, 2018, 10:34:17 am by Jewest »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11036
    • Travis build status
Re: AStyle formatting help needed
« Reply #1 on: March 08, 2018, 07:56:16 pm »
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!]

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: AStyle formatting help needed
« Reply #2 on: March 09, 2018, 09:20:03 am »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11036
    • Travis build status
Re: AStyle formatting help needed
« Reply #3 on: March 09, 2018, 10:16:35 am »
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!]

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: AStyle formatting help needed
« Reply #4 on: March 09, 2018, 03:28:36 pm »
I did some digging around.

Source file:
Code: [Select]
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:
 
Code: [Select]
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?

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: AStyle formatting help needed
« Reply #5 on: May 02, 2018, 10:32:59 am »
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)

Online BlueHazzard

  • Lives here!
  • ****
  • Posts: 1966
Re: AStyle formatting help needed
« Reply #6 on: May 02, 2018, 07:55:10 pm »
Ticket on SF would be nice so this won't get lost...