[libvirt] [PATCH 2/2] maint: tighten curly brace syntax checking
Eric Blake
eblake at redhat.com
Thu Sep 4 21:40:08 UTC 2014
On 09/04/2014 03:39 AM, Peter Krempa wrote:
> On 09/04/14 01:17, Eric Blake wrote:
>> Now that hanging brace offenders have been fixed, we can automate
>> the check, and document our style. Done as a separate commit from
>> code changes, to make it easier to just backport code changes, if
>> that is ever needed.
>>
>>
>> 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; } || :
>> + @files=$$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); \
>> + if $(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; then \
>> + echo '$(ME): Non-K&R style used for curly braces around' \
>> + 'function body, see HACKING' 1>&2; exit 1; \
>> + fi; \
This half was just whitespace changes and reformatting into an explicit
shell if instead of implicit &&...
>> + if $(GREP) -A1 -En ' ((if|for|while|switch) \(|(else|do)\b)[^{]*$$'\
>> + $$files | grep '^[^ ]*- *{'; then \
Oops, I need to use $(GREP) here, for consistency.
>> + echo '$(ME): Use hanging braces for compound statements,' \
>> + 'see HACKING' 1>&2; exit 1; \
>> + fi
...while this added if is the real addition.
>>
>> sc_prohibit_windows_special_chars_in_filename:
>> @files=$$($(VC_LIST_EXCEPT) | grep '[:*?"<>|]'); \
>
> My brain isn't that good in parsing regexes, but they look good to me
> and the test passed.
The first grep half is basically saying: find all compound commands,
then show that line and the subsequent line, as in:
--
src/qemu/qemu_process.c:4997: if (qemuDomainObjBeginJob(driver, dom,
src/qemu/qemu_process.c-4998-
QEMU_JOB_DESTROY) < 0)
The second grep then focuses on the second line (those with
filename:-line-) - if any of them is a lone {, then the first line
probably needs tweaking to use a hanging brace.
>
> ACK.
Pushed with that minor tweak.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140904/3bf22561/attachment-0001.sig>
More information about the libvir-list
mailing list