Michael S. Tsirkin | 2597b75 | 2011-10-04 15:26:01 +0200 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (C) 2011 Red Hat, Inc., Michael S. Tsirkin <mst@redhat.com> |
| 3 | # |
| 4 | # This file may be distributed under the terms of the GNU GPLv3 license. |
| 5 | |
| 6 | # Read a preprocessed ASL listing and put each ACPI_EXTRACT |
| 7 | # directive in a comment, to make iasl skip it. |
| 8 | # We also put each directive on a new line, the machinery |
Kevin O'Connor | ffc0687 | 2014-06-11 15:40:04 -0400 | [diff] [blame^] | 9 | # in scripts/acpi_extract.py requires this. |
Michael S. Tsirkin | 2597b75 | 2011-10-04 15:26:01 +0200 | [diff] [blame] | 10 | |
Johannes Krampf | 24ef4fd | 2014-01-12 10:54:22 -0500 | [diff] [blame] | 11 | import re |
| 12 | import sys |
| 13 | import fileinput |
Michael S. Tsirkin | 2597b75 | 2011-10-04 15:26:01 +0200 | [diff] [blame] | 14 | |
| 15 | def die(diag): |
| 16 | sys.stderr.write("Error: %s\n" % (diag)) |
| 17 | sys.exit(1) |
| 18 | |
| 19 | # Note: () around pattern make split return matched string as part of list |
| 20 | psplit = re.compile(r''' ( |
| 21 | \b # At word boundary |
| 22 | ACPI_EXTRACT_\w+ # directive |
| 23 | \s+ # some whitespace |
| 24 | \w+ # array name |
Johannes Krampf | 24ef4fd | 2014-01-12 10:54:22 -0500 | [diff] [blame] | 25 | )''', re.VERBOSE) |
Michael S. Tsirkin | 2597b75 | 2011-10-04 15:26:01 +0200 | [diff] [blame] | 26 | |
| 27 | lineno = 0 |
| 28 | for line in fileinput.input(): |
| 29 | # line number and debug string to output in case of errors |
| 30 | lineno = lineno + 1 |
| 31 | debug = "input line %d: %s" % (lineno, line.rstrip()) |
| 32 | |
Johannes Krampf | 24ef4fd | 2014-01-12 10:54:22 -0500 | [diff] [blame] | 33 | s = psplit.split(line) |
Michael S. Tsirkin | 2597b75 | 2011-10-04 15:26:01 +0200 | [diff] [blame] | 34 | # The way split works, each odd item is the matching ACPI_EXTRACT directive. |
| 35 | # Put each in a comment, and on a line by itself. |
| 36 | for i in range(len(s)): |
| 37 | if (i % 2): |
| 38 | sys.stdout.write("\n/* %s */\n" % s[i]) |
| 39 | else: |
| 40 | sys.stdout.write(s[i]) |
| 41 | |