aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/MakeHeader.py.in
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-08-27 07:48:10 +0200
committerDaniel Lange <DLange@git.local>2020-08-27 07:48:10 +0200
commitf3147ea2d1598914c2db53e8cfb34c8ff81e2ff4 (patch)
tree3ee82b2af2ab3d38b6e4b07f3994516aac72f742 /scripts/MakeHeader.py.in
parentdf568a576f7b44ac5a2b9b7222c7f39d9932f626 (diff)
downloaddebian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.gz
debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.tar.bz2
debian_htop-f3147ea2d1598914c2db53e8cfb34c8ff81e2ff4.zip
New upstream version 3.0.0upstream/3.0.0
Diffstat (limited to 'scripts/MakeHeader.py.in')
-rw-r--r--scripts/MakeHeader.py.in104
1 files changed, 104 insertions, 0 deletions
diff --git a/scripts/MakeHeader.py.in b/scripts/MakeHeader.py.in
new file mode 100644
index 0000000..8a68877
--- /dev/null
+++ b/scripts/MakeHeader.py.in
@@ -0,0 +1,104 @@
+#!/usr/bin/env @PYTHON@
+import os, sys, io
+try:
+ from StringIO import StringIO
+except ImportError:
+ StringIO = io.StringIO
+
+ANY=1
+COPY=2
+SKIP=3
+SKIPONE=4
+
+state = ANY
+static = 0
+
+file = io.open(sys.argv[1], "r", encoding="utf-8")
+name = sys.argv[1][:-2]
+
+out = StringIO()
+
+selfheader = '#include "' + name + '.h"'
+
+out.write( "/* Do not edit this file. It was automatically generated. */\n" )
+out.write( "\n" )
+
+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]
+ if state == ANY:
+ if line == '/*{':
+ state = COPY
+ elif line == selfheader:
+ pass
+ elif line.find("#include") == 0:
+ pass
+ elif line.find("htop - ") == 0 and line[-2:] == ".c":
+ out.write(line[:-2] + ".h\n")
+ elif line.find("static ") != -1:
+ if line[-1] == "{":
+ state = SKIP
+ static = 1
+ else:
+ state = SKIPONE
+ elif len(line) > 1:
+ static = 0
+ equals = line.find(" = ")
+ if line[-3:] == "= {":
+ out.write( "extern " + line[:-4] + ";\n" )
+ state = SKIP
+ elif equals != -1:
+ out.write("extern " + line[:equals] + ";\n" )
+ elif line.startswith("typedef struct"):
+ state = SKIP
+ elif line[-1] == "{":
+ out.write("extern " + line[:-2].replace("inline ", "") + ";\n")
+ state = SKIP
+ elif line[-1] == ";":
+ out.write("extern " + line + "\n")
+ else:
+ out.write( line + "\n")
+ is_blank = False
+ elif line == "":
+ if not is_blank:
+ out.write( line + "\n")
+ is_blank = True
+ else:
+ out.write( line + "\n")
+ is_blank = False
+ elif state == COPY:
+ is_blank = False
+ if line == "}*/":
+ state = ANY
+ else:
+ out.write( line + "\n")
+ elif state == SKIP:
+ is_blank = False
+ if len(line) >= 1 and line[0] == "}":
+ if static == 1:
+ state = SKIPONE
+ else:
+ state = ANY
+ static = 0
+ elif state == SKIPONE:
+ is_blank = False
+ state = ANY
+
+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 io.open(name + ".h", "r", encoding="utf-8") as orig:
+ origcontents = orig.readlines()
+except:
+ origcontents = ""
+if origcontents != out.readlines():
+ with io.open(name + ".h", "w", encoding="utf-8") as new:
+ print("Writing "+name+".h")
+ new.write(out.getvalue())
+out.close()

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