Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:58

0001 #!/bin/bash
0002 #
0003 # Script to check include/test code for common pybind11 code style errors.
0004 #
0005 # This script currently checks for
0006 #
0007 # 1. missing space between keyword and parenthesis, e.g.: for(, if(, while(
0008 # 2. Missing space between right parenthesis and brace, e.g. 'for (...){'
0009 # 3. opening brace on its own line. It should always be on the same line as the
0010 #    if/while/for/do statement.
0011 #
0012 # Invoke as: tools/check-style.sh <filenames>
0013 #
0014 
0015 check_style_errors=0
0016 IFS=$'\n'
0017 
0018 
0019 found="$(grep '\<\(if\|for\|while\|catch\)(\|){' "$@" -rn --color=always)"
0020 if [ -n "$found" ]; then
0021     echo -e '\033[31;01mError: found the following coding style problems:\033[0m'
0022     check_style_errors=1
0023     echo "${found//^/    /}"
0024 fi
0025 
0026 found="$(awk '
0027 function prefix(filename, lineno) {
0028     return "    \033[35m" filename "\033[36m:\033[32m" lineno "\033[36m:\033[0m"
0029 }
0030 function mark(pattern, string) { sub(pattern, "\033[01;31m&\033[0m", string); return string }
0031 last && /^\s*{/ {
0032     print prefix(FILENAME, FNR-1) mark("\\)\\s*$", last)
0033     print prefix(FILENAME, FNR)   mark("^\\s*{", $0)
0034     last=""
0035 }
0036 { last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" }
0037 ' "$(find include -type f)" "$@")"
0038 if [ -n "$found" ]; then
0039     check_style_errors=1
0040     echo -e '\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m'
0041     echo "$found"
0042 fi
0043 
0044 exit $check_style_errors