Page 1 of 1

Source code formatter for BricxCC / NXC

Posted: 05 Aug 2012, 14:23
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.

Re: Source code formatter for BricxCC / NXC

Posted: 05 Aug 2012, 23:49
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.

Re: Source code formatter for BricxCC / NXC

Posted: 06 Aug 2012, 21:22
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...

Re: Source code formatter for BricxCC / NXC

Posted: 07 Aug 2012, 02:43
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.

Re: Source code formatter for BricxCC / NXC

Posted: 08 Aug 2012, 15:43
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

Re: Source code formatter for BricxCC / NXC

Posted: 09 Aug 2012, 16:24
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.

Re: Source code formatter for BricxCC / NXC

Posted: 09 Aug 2012, 16:54
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 :))) )