blob: fbb830d3be3fa0cbc243b0b841bf00a88b269968 [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'
Martin Roth3748aae2018-09-02 18:49:12 -060020EXCLUDED_DIRS='^payloads/external/\|^src/vendorcode/\|^Documentation/'
Martin Rothae39fc42016-07-29 14:20:55 -060021EXCLUDED_FILES='to-wiki/towiki\.sh$\|vga/vga_font\|video/font\|PDCurses.*x11'
Martin Roth3748aae2018-09-02 18:49:12 -060022EXCLUDED_PHRASES='Copyright\|Ported to\|Intel®\|°C\|°F\|Athlon™\|Copyright.*©'
Martin Rothae39fc42016-07-29 14:20:55 -060023
Martin Roth300b25a2018-09-02 18:45:43 -060024# Exit if git isn't present or the code isn't in a git repo
25if [ -z "$(command -v git)" ] || \
26 [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ]
Alex Thiessen73f19dc2018-01-16 23:05:48 +000027then
Martin Roth300b25a2018-09-02 18:45:43 -060028 exit
Martin Rothae39fc42016-07-29 14:20:55 -060029fi
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.
Martin Roth300b25a2018-09-02 18:45:43 -060037# shellcheck disable=SC2046
38git grep -lP "[^\t-~]" | \
39 grep "$INCLUDED_FILES" | \
40 grep -v "$EXCLUDED_DIRS" | \
41 grep -v "$EXCLUDED_FILES" | \
42 xargs -I % \
43 grep -n "[^ -~]" % | \
44 grep -iv "$EXCLUDED_PHRASES" | \
45 grep --color='auto' "[^ -~]"