blob: 2698118406d97c164783335c7fb6cbfa6239183b [file] [log] [blame]
Michael S. Tsirkin2597b752011-10-04 15:26:01 +02001#!/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'Connorffc06872014-06-11 15:40:04 -04009# in scripts/acpi_extract.py requires this.
Michael S. Tsirkin2597b752011-10-04 15:26:01 +020010
Johannes Krampf24ef4fd2014-01-12 10:54:22 -050011import re
12import sys
13import fileinput
Michael S. Tsirkin2597b752011-10-04 15:26:01 +020014
15def 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
20psplit = re.compile(r''' (
21 \b # At word boundary
22 ACPI_EXTRACT_\w+ # directive
23 \s+ # some whitespace
24 \w+ # array name
Johannes Krampf24ef4fd2014-01-12 10:54:22 -050025 )''', re.VERBOSE)
Michael S. Tsirkin2597b752011-10-04 15:26:01 +020026
27lineno = 0
28for 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 Krampf24ef4fd2014-01-12 10:54:22 -050033 s = psplit.split(line)
Michael S. Tsirkin2597b752011-10-04 15:26:01 +020034 # 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