[PATCH v2 16/16] Require K&R styled curly braces around function bodies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Although not explicitly requested, we are using K&R (or Kernel)
indentation for curly braces around functions in HACKING file and most
of the code.  Using grep -P, this patch add the syntax-check rule for
it (while skipping all the false positives with foreach constructs).

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---

Notes:
    Unfortunately, the regexp is meant to catch as much as possible and
    thus one line functions must occupy two lines, e.g.:
    
    static inline int getuid(void) { return 0; }
    
    is not valid.  This can be changed by appending $$ to the end of the
    regexp which I didn't want to do since it might not catch something
    else I haven't thought of.
    
    Anyway, feel free to request such change and I'll push it changed
    without any modifications to such one-liners.

 cfg.mk | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/cfg.mk b/cfg.mk
index 7a65d1e..559f719 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -898,6 +898,13 @@ sc_prohibit_virConnectOpen_in_virsh:
 	halt='Use vshConnect() in virsh instead of virConnectOpen*'    \
 	  $(_sc_search_regexp)

+sc_curly_braces_style:
+	@files=$$($(VC_LIST_EXCEPT) | grep '\.[ch]$$');                \
+	$(GREP) -nHP                                                   \
+'^\s*(?!([a-zA-Z_]*for_?each[a-zA-Z_]*) ?\()([_a-zA-Z0-9]+( [_a-zA-Z0-9]+)* ?\()?(\*?[_a-zA-Z0-9]+(,? \*?[_a-zA-Z0-9\[\]]+)+|void)\) ?\{' \
+	$$files && { echo '$(ME): Non-K&R style used for curly'        \
+			  'braces around function body, see'           \
+			  'HACKING' 1>&2; exit 1; } || :

 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]