Re: [PATCH 2/2] maint: tighten curly brace syntax checking

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

 



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

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]