Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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


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
for(int i = 0; i < 10; i++) 
    for(int j = 0; j < 10; j++)
        arr[i][j] = i*j;
would be converted to
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.
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?

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):
	// 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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:38 AM.

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