File: check_mixed_eol.sh

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (82 lines) | stat: -rwxr-xr-x 2,726 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash

cd $(dirname "$0")/../..

find . \(                         \
    -path './.git'      -prune -o \
    -path './3rdparty'  -prune -o \
    -path './src/expat' -prune -o \
    -path './src/jpeg'  -prune -o \
    -path './src/png'   -prune -o \
    -path './src/tiff'  -prune -o \
    -path './src/zlib'  -prune \) \
    -o -type f -print0 |
(
while IFS= read -r -d '' file; do

    # skip binary files
    case "$file" in
    *.ani | *.bmp | *.chm | *.cur | *.dia | *.gif | *.gz | *.hlp | *.icns | *.ico | *.jpg | *.mo | *.mpg | *.pcx | *.pdf | *.png | *.pnm | *.pyc | *.tga | *.tif | *.ttf | *.wav | *.zip )
        continue
        ;;
    esac

    # get used EOL
    read dos unix mac <<< $(dos2unix --info=dum "$file" | awk '{print $1, $2, $3}')
    if [[ "$dos" -eq 0 ]] && [[ "$unix" -eq 0 ]]; then
        :
    elif [[ "$dos" -eq 0 ]] && [[ "$mac" -eq 0 ]]; then
        :
    elif [[ "$unix" -eq 0 ]] && [[ "$mac" -eq 0 ]]; then
        :
    else
        echo "ERROR - mixed EOL: $file"
        rc=$((rc+1))
        continue
    fi

    # empty file
    if [[ "$dos" -eq 0 ]] && [[ "$unix" -eq 0 ]] && [[ "$mac" -eq 0 ]]; then
        continue;
    fi

    # determine expected EOL
    warn_expected_eol_unknown=0
    case "$file" in
    *.applescript | *.apspec | *.bkgen | *.bkl | *.c | *.C | *.cmake | *.cpp | *.css | *.cxx | *.guess | *.h | *.htm | *.html | *.iface | *.in | *.js | *.json | *.log | *.lua | *.m4 | *.mm | *.manifest | *.md | *.mk | *.mms | *.opt | *.patch | *.pbxproj | *.pl | *.plist | *.po | *.py | *.sh | *.sub | *.svg | *.tex | *.txt | *.TXT | *.unx | *.vms | *.xcconfig | *.xcscheme | *.xcworkspacedata | *.xbm | *.xml | *.xpm | *.xrc | *.yml )
        expected_eoltype=unix
        ;;
    *.bat | *.bcc | *.gcc | *.iss | *.props | *.rc | *.sln | *.vc | *.vcproj | *.vcxproj | *.vcxproj.filters )
        expected_eoltype=dos
        ;;
    * )
        # warn_expected_eol_unknown=1
        expected_eoltype=
        ;;
    esac

    # check for filename without extension
    if [[ "$expected_eoltype" = "" ]]; then
        fullfile=$(basename -- "$file")
        if [[ "${fullfile:1}" != *"."* ]]; then
            warn_expected_eol_unknown=0
            expected_eoltype=unix
        fi
    fi

    if [[ "$warn_expected_eol_unknown" -eq 1 ]]; then
        echo "WARNING - no expected EOL specified: $file"
    fi

    # check if expected EOL matches used EOL
    if [[ "$expected_eoltype" = "unix" ]] && [[ "$unix" -eq 0 ]]; then
        echo "ERROR - wrong EOL, expected unix: $file"
        rc=$((rc+1))
    elif [[ "$expected_eoltype" = "dos" ]] && [[ "$dos" -eq 0 ]]; then
        echo "ERROR - wrong EOL, expected dos: $file"
        rc=$((rc+1))
    fi

done
exit $rc
)