TQt conversion of scintilla for Qt3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HFacer.py 2.3KB

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