blob: 881eeba69ea0b6e7ce6e45175e58bcf4132414f6 [file] [log] [blame]
Martin Rothae39fc42016-07-29 14:20:55 -06001#!/bin/sh
2# This file is part of the coreboot project.
3#
4# Copyright (C) 2016 Google Inc.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; version 2 of the License.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# DESCR: Check for non-ASCII and unprintable characters
16
17LC_ALL=C export LC_ALL
18
19INCLUDED_FILES='\.[chsS]$\|\.asl$\|\.cb$\|\.inc$\|Kconfig\|\.ld$|\.txt\|\.hex'
20EXCLUDED_DIRS='^payloads/\|^src/vendorcode/\|^Documentation/\|^build/\|^3rdparty/\|^\.git/\|^coreboot-builds/\|^util/nvidia/cbootimage'
21EXCLUDED_FILES='to-wiki/towiki\.sh$\|vga/vga_font\|video/font\|PDCurses.*x11'
22EXCLUDED_PHRASES='Copyright\|Ported to\|Intel®\|°C\|°F\|Athlon™\|Copyright.*©\|A-Za-zÀ-ÿ'
23
24# Use git ls-files if the code is in a git repo, otherwise use find.
25if [ -n "$(command -v git)" ] && [ -d .git ]; then
26 FIND_FILES="git ls-files"
27else
28 FIND_FILES="find . "
29fi
30
31# 1. Get the list of files to parse and send them through grep
32# 2. Find any characters that aren't TAB, or space (0x20) to ~ (0x7F)
33# LF (0x10) isn't included, as it ends the grep line
34# 3. Remove common phrases and names that have been found
35# 4. Run the result through grep again to highlight the issues that were
36# found. Without this step, the characters can be difficult to see.
37grep -n "[^ -~]" \
38 $(${FIND_FILES} | sed 's|^\./||' | sort | \
39 grep "$INCLUDED_FILES" | \
40 grep -v "$EXCLUDED_DIRS" | \
41 grep -v "$EXCLUDED_FILES") | \
42 grep -iv "$EXCLUDED_PHRASES" | \
43 grep --color='auto' "[^ -~]"