updated Scintilla to 2.29
[TortoiseGit.git] / ext / scintilla / include / HFacer.py
blob1dc25beda27c1ac74372c019bc25f613ff9ba376
1 #!/usr/bin/env python
2 # HFacer.py - regenerate the Scintilla.h and SciLexer.h files from the Scintilla.iface interface
3 # definition file.
4 # The header files are copied to a temporary file apart from the section between a /* ++Autogenerated*/
5 # comment and a /* --Autogenerated*/ comment which is generated by the printHFile and printLexHFile
6 # functions. After the temporary file is created, it is copied back to the original file name.
8 import sys
9 import os
10 import Face
12 def Contains(s,sub):
13 return s.find(sub) != -1
15 def printLexHFile(f,out):
16 for name in f.order:
17 v = f.features[name]
18 if v["FeatureType"] in ["val"]:
19 if Contains(name, "SCE_") or Contains(name, "SCLEX_"):
20 out.write("#define " + name + " " + v["Value"] + "\n")
22 def printHFile(f,out):
23 for name in f.order:
24 v = f.features[name]
25 if v["Category"] != "Deprecated":
26 if v["FeatureType"] in ["fun", "get", "set"]:
27 featureDefineName = "SCI_" + name.upper()
28 out.write("#define " + featureDefineName + " " + v["Value"] + "\n")
29 elif v["FeatureType"] in ["evt"]:
30 featureDefineName = "SCN_" + name.upper()
31 out.write("#define " + featureDefineName + " " + v["Value"] + "\n")
32 elif v["FeatureType"] in ["val"]:
33 if not (Contains(name, "SCE_") or Contains(name, "SCLEX_")):
34 out.write("#define " + name + " " + v["Value"] + "\n")
36 def CopyWithInsertion(input, output, genfn, definition):
37 copying = 1
38 for line in input.readlines():
39 if copying:
40 output.write(line)
41 if Contains(line, "/* ++Autogenerated"):
42 copying = 0
43 genfn(definition, output)
44 if Contains(line, "/* --Autogenerated"):
45 copying = 1
46 output.write(line)
48 def contents(filename):
49 f = open(filename)
50 t = f.read()
51 f.close()
52 return t
54 def Regenerate(filename, genfn, definition):
55 inText = contents(filename)
56 tempname = "HFacer.tmp"
57 out = open(tempname,"w")
58 hfile = open(filename)
59 CopyWithInsertion(hfile, out, genfn, definition)
60 out.close()
61 hfile.close()
62 outText = contents(tempname)
63 if inText == outText:
64 os.unlink(tempname)
65 else:
66 os.unlink(filename)
67 os.rename(tempname, filename)
69 f = Face.Face()
70 try:
71 f.ReadFromFile("Scintilla.iface")
72 Regenerate("Scintilla.h", printHFile, f)
73 Regenerate("SciLexer.h", printLexHFile, f)
74 print("Maximum ID is %s" % max([x for x in f.values if int(x) < 3000]))
75 except:
76 raise