make_header.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. import os
  3. import glob
  4. import string
  5. # Generate include files
  6. f = open("theme_data.h", "wb")
  7. f.write("// THIS FILE HAS BEEN AUTOGENERATED, DON'T EDIT!!\n")
  8. # Generate png image block
  9. f.write("\n// png image block\n");
  10. pixmaps = glob.glob("*.png")
  11. pixmaps.sort()
  12. for x in pixmaps:
  13. var_str = x[:-4] + "_png"
  14. f.write("\nstatic const unsigned char " + var_str + "[] = {\n\t")
  15. pngf = open(x, "rb")
  16. b = pngf.read(1)
  17. while(len(b) == 1):
  18. f.write(hex(ord(b)))
  19. b = pngf.read(1)
  20. if (len(b) == 1):
  21. f.write(", ")
  22. f.write("\n};\n")
  23. pngf.close()
  24. # Generate shaders block
  25. f.write("\n// shaders block\n");
  26. shaders = glob.glob("*.gsl")
  27. shaders.sort()
  28. for x in shaders:
  29. var_str = x[:-4] + "_shader_code"
  30. f.write("\nstatic const char *" + var_str + " = \n")
  31. sf = open(x, "rb")
  32. b = sf.readline()
  33. while(b != ""):
  34. if (b.endswith("\r\n")):
  35. b = b[:-2]
  36. if (b.endswith("\n")):
  37. b = b[:-1]
  38. f.write(" \"" + b)
  39. b = sf.readline()
  40. if (b != ""):
  41. f.write("\"\n")
  42. f.write("\";\n")
  43. sf.close()
  44. f.close()