aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGraham Inggs <ginggs@debian.org>2018-02-05 14:48:51 +0200
committerGraham Inggs <ginggs@debian.org>2018-02-05 14:48:51 +0200
commit2ee50d030178cede83eb9d0005fbc19f819d30fe (patch)
tree67d75c0a7c47e15bed9d0735ecf12abec4f8157b /scripts
parent31b71b67011fa52f091df6fe536a11d6d0bfb256 (diff)
downloaddebian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.gz
debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.bz2
debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.zip
Imported Upstream version 2.1.0upstream/2.1.0
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/MakeHeader.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/scripts/MakeHeader.py b/scripts/MakeHeader.py
index bcf1005..4841bda 100755
--- a/scripts/MakeHeader.py
+++ b/scripts/MakeHeader.py
@@ -1,6 +1,12 @@
#!/usr/bin/env python
-
import os, sys, string
+try:
+ from cStringIO import StringIO
+except ImportError:
+ try:
+ from StringIO import StringIO
+ except ImportError:
+ from io import StringIO
ANY=1
COPY=2
@@ -13,23 +19,15 @@ static = 0
file = open(sys.argv[1])
name = sys.argv[1][:-2]
-out = open(name + ".h", "w")
-class writer:
- def __init__(self, file):
- self.file = file
- def write(self, text):
- self.file.write(text + "\n")
-out = writer(out)
-
-print("Generating "+name+".h")
+out = StringIO()
selfheader = '#include "' + name + '.h"'
-out.write( "/* Do not edit this file. It was automatically generated. */" )
-out.write( "" )
+out.write( "/* Do not edit this file. It was automatically generated. */\n" )
+out.write( "\n" )
-out.write( "#ifndef HEADER_" + os.path.basename(name) )
-out.write( "#define HEADER_" + os.path.basename(name) )
+out.write( "#ifndef HEADER_" + os.path.basename(name) + "\n")
+out.write( "#define HEADER_" + os.path.basename(name) + "\n")
is_blank = False
for line in file.readlines():
line = line[:-1]
@@ -41,7 +39,7 @@ for line in file.readlines():
elif line.find("#include") == 0:
pass
elif line.find("htop - ") == 0 and line[-2:] == ".c":
- out.write(line[:-2] + ".h")
+ out.write(line[:-2] + ".h\n")
elif line.find("static ") != -1:
if line[-1] == "{":
state = SKIP
@@ -52,31 +50,31 @@ for line in file.readlines():
static = 0
equals = line.find(" = ")
if line[-3:] == "= {":
- out.write( "extern " + line[:-4] + ";" )
+ out.write( "extern " + line[:-4] + ";\n" )
state = SKIP
elif equals != -1:
- out.write("extern " + line[:equals] + ";" )
+ out.write("extern " + line[:equals] + ";\n" )
elif line.startswith("typedef struct"):
state = SKIP
elif line[-1] == "{":
- out.write( line[:-2].replace("inline", "extern") + ";" )
+ out.write( line[:-2].replace("inline", "extern") + ";\n" )
state = SKIP
else:
- out.write( line )
+ out.write( line + "\n")
is_blank = False
elif line == "":
if not is_blank:
- out.write( line )
+ out.write( line + "\n")
is_blank = True
else:
- out.write( line )
+ out.write( line + "\n")
is_blank = False
elif state == COPY:
is_blank = False
if line == "}*/":
state = ANY
else:
- out.write( line )
+ out.write( line + "\n")
elif state == SKIP:
is_blank = False
if len(line) >= 1 and line[0] == "}":
@@ -89,5 +87,19 @@ for line in file.readlines():
is_blank = False
state = ANY
-out.write( "" )
-out.write( "#endif" )
+out.write( "\n" )
+out.write( "#endif\n" )
+
+# only write a new .h file if something changed.
+# This prevents a lot of recompilation during development
+out.seek(0)
+try:
+ with open(name + ".h", "r") as orig:
+ origcontents = orig.readlines()
+except:
+ origcontents = ""
+if origcontents != out.readlines():
+ with open(name + ".h", "w") as new:
+ print("Writing "+name+".h")
+ new.write(out.getvalue())
+out.close()

© 2014-2024 Faster IT GmbH | imprint | privacy policy