Martin Roth | ae39fc4 | 2016-07-29 14:20:55 -0600 | [diff] [blame] | 1 | #!/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 | |
| 17 | LC_ALL=C export LC_ALL |
| 18 | |
| 19 | INCLUDED_FILES='\.[chsS]$\|\.asl$\|\.cb$\|\.inc$\|Kconfig\|\.ld$|\.txt\|\.hex' |
Martin Roth | 3748aae | 2018-09-02 18:49:12 -0600 | [diff] [blame] | 20 | EXCLUDED_DIRS='^payloads/external/\|^src/vendorcode/\|^Documentation/' |
Martin Roth | ae39fc4 | 2016-07-29 14:20:55 -0600 | [diff] [blame] | 21 | EXCLUDED_FILES='to-wiki/towiki\.sh$\|vga/vga_font\|video/font\|PDCurses.*x11' |
Martin Roth | 3748aae | 2018-09-02 18:49:12 -0600 | [diff] [blame] | 22 | EXCLUDED_PHRASES='Copyright\|Ported to\|Intel®\|°C\|°F\|Athlon™\|Copyright.*©' |
Martin Roth | ae39fc4 | 2016-07-29 14:20:55 -0600 | [diff] [blame] | 23 | |
Martin Roth | 300b25a | 2018-09-02 18:45:43 -0600 | [diff] [blame] | 24 | # Exit if git isn't present or the code isn't in a git repo |
| 25 | if [ -z "$(command -v git)" ] || \ |
| 26 | [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] |
Alex Thiessen | 73f19dc | 2018-01-16 23:05:48 +0000 | [diff] [blame] | 27 | then |
Martin Roth | 300b25a | 2018-09-02 18:45:43 -0600 | [diff] [blame] | 28 | exit |
Martin Roth | ae39fc4 | 2016-07-29 14:20:55 -0600 | [diff] [blame] | 29 | fi |
| 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 Roth | 300b25a | 2018-09-02 18:45:43 -0600 | [diff] [blame] | 37 | # shellcheck disable=SC2046 |
| 38 | git 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' "[^ -~]" |