#!/usr/bin/env python ## Copyright (C) 2011 Gary Benson ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. # See http://gbenson.net/?p=292 for details... import re import sys hunks = [] for line in sys.stdin.xreadlines(): line = line.rstrip() if line.startswith("@@"): hunks.append([line]) elif line[:3] not in ("---", "+++"): hunks[-1].append(line) IGNORE = map(re.compile, ( r"^$", r"^ ", r"^[+-]make(\[\d+\])?: (Entering|Leaving) directory `.*'$", r"^[+-]gcc -DHAVE_CONFIG_H", r"^[+-].*/libiberty.a", r"^[+-]Making a new config file\.\.\.", r"^[+-]Test Run By .* on ... ... [ \d]\d \d\d:\d\d:\d\d \d{4}$", r"^[+-].*/gdb/gdb version .* -nw -nx -data-directory .*/data-directory$")) def is_expected(line): for expr in IGNORE: if expr.match(line): return True return False for hunk in hunks: hunk = [(line, is_expected(line)) for line in hunk] for line, expected in hunk[1:]: if not expected: for line, expected in hunk: if line.startswith("@@"): colour = 33 else: colour = expected and 32 or 31 print "\x1B[%dm%s\x1B[0m" % (colour, line) break