Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Code Formatter for STYLE(9)?

68 views
Skip to first unread message

Sebastian Huber

unread,
Mar 24, 2016, 9:37:32 AM3/24/16
to
Hello,

is there a ready to use C code formatter available that honours
STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
Chromium, Mozilla by default. The GNU indent --original seems to produce
nothing usable. Same problem with astyle --style=bsd.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebasti...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

_______________________________________________
freebsd...@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hacke...@freebsd.org"

Matthew Seaman

unread,
Mar 24, 2016, 10:55:32 AM3/24/16
to
On 2016/03/24 13:29, Sebastian Huber wrote:
> Hello,
>
> is there a ready to use C code formatter available that honours
> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
> Chromium, Mozilla by default. The GNU indent --original seems to produce
> nothing usable. Same problem with astyle --style=bsd.
>

pkg uses uncrustify with this config file:

https://github.com/freebsd/pkg/blob/master/freebsd.cfg

It's approximately what style(9) describes but doesn't cover things like
sorting include files and I don't think it was updated in response to
the recent change allowing { brackets } around certain single-line
statements.

Cheers,

Matthew


signature.asc

Pietro Cerutti

unread,
Mar 24, 2016, 12:31:49 PM3/24/16
to
It looks like it does: https://github.com/freebsd/pkg/commit/1bc61a4

--
Pietro Cerutti
ga...@FreeBSD.org

PGP Public Key:
http://gahr.ch/pgp

Hans Petter Selasky

unread,
Mar 24, 2016, 4:22:36 PM3/24/16
to
On 03/24/16 14:29, Sebastian Huber wrote:
> Hello,
>
> is there a ready to use C code formatter available that honours
> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
> Chromium, Mozilla by default. The GNU indent --original seems to produce
> nothing usable. Same problem with astyle --style=bsd.
>

Hi,

Maybe you want to contribute to:

https://svnweb.freebsd.org/base/head/tools/tools/indent_wrapper

It also supports diffs.

--HPS

Bryan Drewery

unread,
Mar 24, 2016, 8:15:53 PM3/24/16
to
On 3/24/2016 9:24 AM, Pietro Cerutti wrote:
> On 2016-03-24 15:54, Matthew Seaman wrote:
>> On 2016/03/24 13:29, Sebastian Huber wrote:
>>> Hello,
>>>
>>> is there a ready to use C code formatter available that honours
>>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
>>> Chromium, Mozilla by default. The GNU indent --original seems to produce
>>> nothing usable. Same problem with astyle --style=bsd.
>>>
>>
>> pkg uses uncrustify with this config file:
>>
>> https://github.com/freebsd/pkg/blob/master/freebsd.cfg
>>
>> It's approximately what style(9) describes but doesn't cover things like
>> sorting include files and I don't think it was updated in response to
>> the recent change allowing { brackets } around certain single-line
>> statements.
>
> It looks like it does: https://github.com/freebsd/pkg/commit/1bc61a4
>

It's not quite right. It is adding {} to single-line if statements in
some code.

> static __inline struct filemon *
> filemon_acquire(struct filemon *filemon)
> {
> -
> - if (filemon != NULL)
> + if (filemon != NULL) {
> refcount_acquire(&filemon->refcnt);
> + }
> return (filemon);
> }

It's also not aware of our (silly?) blank line with no declarations rule:

> static __inline void
> filemon_drop(struct filemon *filemon)
> {
> -
> sx_xunlock(&filemon->lock);
> filemon_release(filemon);
> }

And wrapping multiple conditions:

> - if (p->p_filemon != NULL && p != curproc)
> + if ((p->p_filemon != NULL) && (p != curproc)) {
> return (EBUSY);
> + }

It's also not respecting the wrap rule of tabs + 4 spaces.

It's also adding random blank lines before functions and macros.

It found a useless 'return;' at least.

--
Regards,
Bryan Drewery

signature.asc

Jonathan Anderson

unread,
Mar 24, 2016, 8:28:34 PM3/24/16
to
On 24 Mar 2016, at 21:45, Bryan Drewery wrote:

> On 3/24/2016 9:24 AM, Pietro Cerutti wrote:
>> On 2016-03-24 15:54, Matthew Seaman wrote:
>>> On 2016/03/24 13:29, Sebastian Huber wrote:
>>>> Hello,
>>>>
>>>> is there a ready to use C code formatter available that honours
>>>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
>>>> Chromium, Mozilla by default. The GNU indent --original seems to produce
>>>> nothing usable. Same problem with astyle --style=bsd.
>>>>
>>>
>>> pkg uses uncrustify with this config file:
>>>
>>> https://github.com/freebsd/pkg/blob/master/freebsd.cfg
>>>
>>> It's approximately what style(9) describes but doesn't cover things like
>>> sorting include files and I don't think it was updated in response to
>>> the recent change allowing { brackets } around certain single-line
>>> statements.
>>
>> It looks like it does: https://github.com/freebsd/pkg/commit/1bc61a4
>>
>
> It's not quite right. It is adding {} to single-line if statements in
> some code.

Perhaps some of the `full_brace` cases should use `ignore` rather than `add` or `remove`, since the new rule is "you may put braces around single lines" rather than "you may not" (as in the old style(9)) or "you must" (as in this uncrustify config).


Jon
--
Jonathan Anderson
jona...@FreeBSD.org
signature.asc

Baptiste Daroussin

unread,
Mar 25, 2016, 3:48:05 AM3/25/16
to
On Thu, Mar 24, 2016 at 05:15:30PM -0700, Bryan Drewery wrote:
> On 3/24/2016 9:24 AM, Pietro Cerutti wrote:
> > On 2016-03-24 15:54, Matthew Seaman wrote:
> >> On 2016/03/24 13:29, Sebastian Huber wrote:
> >>> Hello,
> >>>
> >>> is there a ready to use C code formatter available that honours
> >>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
> >>> Chromium, Mozilla by default. The GNU indent --original seems to produce
> >>> nothing usable. Same problem with astyle --style=bsd.
> >>>
> >>
> >> pkg uses uncrustify with this config file:
> >>
> >> https://github.com/freebsd/pkg/blob/master/freebsd.cfg
> >>
> >> It's approximately what style(9) describes but doesn't cover things like
> >> sorting include files and I don't think it was updated in response to
> >> the recent change allowing { brackets } around certain single-line
> >> statements.
> >
> > It looks like it does: https://github.com/freebsd/pkg/commit/1bc61a4
> >
>
> It's not quite right. It is adding {} to single-line if statements in
> some code.

Yes this is un purpose for pkg
>
> > static __inline struct filemon *
> > filemon_acquire(struct filemon *filemon)
> > {
> > -
> > - if (filemon != NULL)
> > + if (filemon != NULL) {
> > refcount_acquire(&filemon->refcnt);
> > + }
> > return (filemon);
> > }
>
> It's also not aware of our (silly?) blank line with no declarations rule:

I couldn't find how to make that
>
> > static __inline void
> > filemon_drop(struct filemon *filemon)
> > {
> > -
> > sx_xunlock(&filemon->lock);
> > filemon_release(filemon);
> > }
>
> And wrapping multiple conditions:
>
> > - if (p->p_filemon != NULL && p != curproc)
> > + if ((p->p_filemon != NULL) && (p != curproc)) {
> > return (EBUSY);
> > + }

Same I couldn't find how to make that better
>
> It's also not respecting the wrap rule of tabs + 4 spaces.

same
>
> It's also adding random blank lines before functions and macros.

yup

The above reasons are why it has not been automatically used in pkg.
It is the closer I could get, I would be happy to get patches to improve

Best regards,
Bapt
signature.asc

Julian Elischer

unread,
Mar 25, 2016, 5:37:07 AM3/25/16
to
On 25/03/2016 8:15 AM, Bryan Drewery wrote:
> On 3/24/2016 9:24 AM, Pietro Cerutti wrote:
>> On 2016-03-24 15:54, Matthew Seaman wrote:
>>> On 2016/03/24 13:29, Sebastian Huber wrote:
>>>> Hello,
>>>>
>>>> is there a ready to use C code formatter available that honours
>>>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
>>>> Chromium, Mozilla by default. The GNU indent --original seems to produce
>>>> nothing usable. Same problem with astyle --style=bsd.

there was an indent() config that was quite close.

Julian Elischer

unread,
Mar 25, 2016, 5:39:26 AM3/25/16
to
On 25/03/2016 5:36 PM, Julian Elischer wrote:
> On 25/03/2016 8:15 AM, Bryan Drewery wrote:
>> On 3/24/2016 9:24 AM, Pietro Cerutti wrote:
>>> On 2016-03-24 15:54, Matthew Seaman wrote:
>>>> On 2016/03/24 13:29, Sebastian Huber wrote:
>>>>> Hello,
>>>>>
>>>>> is there a ready to use C code formatter available that honours
>>>>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
>>>>> Chromium, Mozilla by default. The GNU indent --original seems to
>>>>> produce
>>>>> nothing usable. Same problem with astyle --style=bsd.
>
> there was an indent() config that was quite close.

I'm talking abut hte indnet in freebsd /usr/bin

Sebastian Huber

unread,
Mar 29, 2016, 8:45:32 AM3/29/16
to
On 24/03/16 21:25, Hans Petter Selasky wrote:
> On 03/24/16 14:29, Sebastian Huber wrote:
>> Hello,
>>
>> is there a ready to use C code formatter available that honours
>> STYLE(9)? I tried clang-format, but it knows only LLVM, Google,
>> Chromium, Mozilla by default. The GNU indent --original seems to produce
>> nothing usable. Same problem with astyle --style=bsd.
>>
>
> Hi,
>
> Maybe you want to contribute to:
>
> https://svnweb.freebsd.org/base/head/tools/tools/indent_wrapper
>
> It also supports diffs.

I tried to use the FreeBSD indent with your configuration on a pretty
badly formatted file, but it didn't work well. My hope was that someone
has a configuration for the clang-format.

The uncrustify program seems to be quite capable, but would require
additional support to cope with STYLE(9). At least using

https://github.com/freebsd/pkg/blob/master/freebsd.cfg


didn't yield a good result.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebasti...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

0 new messages