Source code formatter for BricxCC / NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
surfi-nxt
Posts: 3
Joined: 05 Aug 2012, 14:07

Source code formatter for BricxCC / NXC

Post by surfi-nxt »

Hello All,

for some days I have started to program under BricxCC / NXC for my Lego Mindstorms NXT.

Is there any option to auto formatting of the existed (already entered) source code, like for example in Eclipse?

Thanks and regards.
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: Source code formatter for BricxCC / NXC

Post by tcwan »

surfi-nxt wrote:Hello All,

for some days I have started to program under BricxCC / NXC for my Lego Mindstorms NXT.

Is there any option to auto formatting of the existed (already entered) source code, like for example in Eclipse?

Thanks and regards.
A quick way to do this in Eclipse, is to go to Preferences->General->Editors->File Associations and define an association for *.nxc (which I presume is the default extension for NXC files), and map it to the CDT editor.

Not all keywords will be highlighted, but most of the standard C keywords would be recognized.
surfi-nxt
Posts: 3
Joined: 05 Aug 2012, 14:07

Re: Source code formatter for BricxCC / NXC

Post by surfi-nxt »

tcwan, do you mean, I should copy the source code to Eclipse, reformat it, and then copy back to BricxCC?

Not so comfortable as I expected :)

The source code formatter is almost the only thing is missing for me in BricxCC...
tcwan
Posts: 186
Joined: 30 Sep 2010, 07:39

Re: Source code formatter for BricxCC / NXC

Post by tcwan »

surfi-nxt wrote:tcwan, do you mean, I should copy the source code to Eclipse, reformat it, and then copy back to BricxCC?

Not so comfortable as I expected :)

The source code formatter is almost the only thing is missing for me in BricxCC...
Well, I'm not aware of any source formatter for BrcixCC itself.

I misunderstood your question earlier, Eclipse does have a source formatter, it can be enabled via Preferences->C/C++->Code Style->Formatter.
You'll need to select the code block to reformat, and select Source->Format (Ctrl-Shift-F).

I suppose you don't really need to copy it back to BricxCC, just open the files in one IDE, modify, save it, and reopen it in the other.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Source code formatter for BricxCC / NXC

Post by afanofosc »

BricxCC does not come with a code beautifier/formatter. Until that changes, which might be a very long while, you will need to use other standalone tools for this. If I can find some cross-platform pascal code that would make it easy to add this feature to BricxCC I will certainly consider doing so.

John
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
surfi-nxt
Posts: 3
Joined: 05 Aug 2012, 14:07

Re: Source code formatter for BricxCC / NXC

Post by surfi-nxt »

Hello John,

would you consider some other approach for the source code formatter? I think it would be very easy to add this feature to BricxCC in this way.

You could make a menu command (better with a hot-key) to call some external source code formatter via command line. After the call of the formatter you could just reload the nxc-file in the BricxCC. For the user it would be transparent and working fine!

You could put an option in BricxCC to configure the command line of the formatter call like:

“formatter.exe –c %srcfile”

or something like that, or the fix coded command line call for the test purposes.

I would be the first tester for the feature :)

BTW, I have found and tested this formatter:

http://uncrustify.sourceforge.net/

Just called:

“uncrustify.exe -c d.cfg test.nxc” - it works very fine!

“uncrustify.exe -c ben.cfg test.nxc” - is also good!

I am looking forward to hear from you.

Thanks and regards.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Source code formatter for BricxCC / NXC

Post by HaWe »

I personally didn't use such a beautifier ever - and never wished to have one. I'm just typing my spaces and tabs in the moment I'm writing code.

For John's development time to invest I surely would have more and better proposals for the top of his to-do-list (e.g., ANSI C compa.........) :P

But I must admit, that auto-indent of 2x white space after, e.g., "{" + [ENTER] for line feed sometimes would be nice to have ;)
(thank God that this is not the wish list thread :))) )
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 15 guests