From owner-freebsd-hackers@freebsd.org Fri Mar 25 09:36:51 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CC5E6ADC84A for ; Fri, 25 Mar 2016 09:36:51 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 84317119F for ; Fri, 25 Mar 2016 09:36:51 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from Julian-MBP3.local (ppp121-45-238-157.lns20.per1.internode.on.net [121.45.238.157]) (authenticated bits=0) by vps1.elischer.org (8.15.2/8.15.2) with ESMTPSA id u2P9aeuN093811 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Fri, 25 Mar 2016 02:36:43 -0700 (PDT) (envelope-from julian@freebsd.org) Subject: Re: Code Formatter for STYLE(9)? To: freebsd-hackers@freebsd.org References: <56F3EBB1.1060603@embedded-brains.de> <56F3FFB3.6070801@FreeBSD.org> <1fc0f5efcc94822f7f5ca9bbcb850faf@gahr.ch> <56F48322.9030208@FreeBSD.org> From: Julian Elischer Message-ID: <56F506A3.80203@freebsd.org> Date: Fri, 25 Mar 2016 17:36:35 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <56F48322.9030208@FreeBSD.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2016 09:36:51 -0000 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. >>> 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. >