LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-21-2014, 06:34 AM   #1
dougy83
LQ Newbie
 
Registered: Feb 2008
Posts: 1

Rep: Reputation: 0
astyle adding braces to single-statement blocks


Hi,

I've been trying to get asyle to reformat C++ code such that every statement in a for() loop body gets brackets placed around it (while, if, etc. also desirable).

e.g. the code
Code:
for(int i = 0; i < 10; i++) 
    for(int j = 0; j < 10; j++)
        arr[i][j] = i*j;
would be converted to
Code:
for(int i = 0; i < 10; i++) 
{
    for(int j = 0; j < 10; j++)
    {
        arr[i][j] = i*j;
    }
}
The asyle -j option only does this for the second loop, which gives the following. I'm using -A1 style btw.
Code:
for(int i = 0; i < 10; i++) 
    for(int j = 0; j < 10; j++)
    {
        arr[i][j] = i*j;
    }
Any help would be appreciated. If it's not possible with the current astyle, how hard is it to modify the astyle code for such functionality?


EDIT:
I may be mistaken, but from the source code it appears that this functionality has been explicitly disabled, which is a shame (as I don't know how to fix it quickly without destroying everything). Lines 5286 of ASFormatter.cpp have the telltale code (a 'header' is defined as a for/while/if/etc. keyword):
Code:
	// do not add if a header follows
	if (isCharPotentialHeader(currentLine, charNum))
		if (findHeader(headers) != NULL)
			return false;
This can't simply be removed, as the next lines find the first ';' character to put a bracket after (this will screw up a for loop, for example - actually it will screw up an already-bracketed block too). Any help fixing the code still appreciated

Last edited by dougy83; 01-21-2014 at 07:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SCP "Username and Password in single statement" ajpnaveen Linux - Newbie 4 09-13-2010 08:24 PM
[SOLVED] Shell script for adding a statement in a file after a particular statement TheIndependentAquarius Programming 4 06-28-2010 04:07 AM
How Can I Use An "if" statement on a Single Command Line? jagooch Linux - General 4 02-11-2009 12:32 AM
Adding directories to the PATH statement kaplan71 Slackware 2 09-02-2004 04:57 PM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 03:03 PM


All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration