summaryrefslogtreecommitdiff
path: root/scripts/maint/add_c_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/maint/add_c_file.py')
-rwxr-xr-xscripts/maint/add_c_file.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/maint/add_c_file.py b/scripts/maint/add_c_file.py
index 9ec182efcc..6656d0d422 100755
--- a/scripts/maint/add_c_file.py
+++ b/scripts/maint/add_c_file.py
@@ -99,10 +99,14 @@ class AutomakeChunk:
def __init__(self):
self.lines = []
self.kind = ""
+ self.hasBlank = False # true if we end with a blank line.
def addLine(self, line):
"""
Insert a line into this chunk while parsing the automake file.
+
+ Return True if we have just read the last line in the chunk, and
+ False otherwise.
"""
m = self.pat.match(line)
if m:
@@ -110,10 +114,12 @@ class AutomakeChunk:
raise ValueError("control line not preceded by a blank line")
self.kind = m.group(1)
- self.lines.append(line)
if line.strip() == "":
+ self.hasBlank = True
return True
+ self.lines.append(line)
+
return False
def insertMember(self, member):
@@ -145,8 +151,8 @@ class AutomakeChunk:
"{}{}{}\\\n".format(prespace, member, postspace))
def insert_at_end(self, member, prespace, postspace):
- lastline = self.lines[-1]
- self.lines[-1] += '{}\\\n'.format(postspace)
+ lastline = self.lines[-1].strip()
+ self.lines[-1] = '{}{}{}\\\n'.format(prespace, lastline, postspace)
self.lines.append("{}{}\n".format(prespace, member))
def dump(self, f):
@@ -156,6 +162,9 @@ class AutomakeChunk:
if not line.endswith("\n"):
f.write("\n")
+ if self.hasBlank:
+ f.write("\n")
+
class ParsedAutomake:
"""A sort-of-parsed automake file, with identified chunks into which
headers and c files can be inserted.