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.

54 lines
1.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # DISTRHO Plugin Framework (DPF)
  4. # Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # Permission to use, copy, modify, and/or distribute this software for any purpose with
  7. # or without fee is hereby granted, provided that the above copyright notice and this
  8. # permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  11. # TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  12. # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  14. # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. import os
  17. import sys
  18. # -----------------------------------------------------
  19. def res2c(filename):
  20. resname = "src_" + os.path.basename(filename.replace(".","_"))
  21. fhandle = open(filename, 'rb')
  22. resdata = fhandle.read()
  23. print("const unsigned char %s[] = {\n" % resname)
  24. for data in resdata:
  25. print(" %3u," % data)
  26. print("};\n")
  27. print("const unsigned int %s_len = %d;\n" % (resname, fhandle.tell()))
  28. if sys.platform != "darwin":
  29. print("const unsigned char* _binary_%s_start = %s;\n" % (resname, resname))
  30. print("const unsigned char* _binary_%s_end = %s + %d;\n" % (resname, resname, fhandle.tell()))
  31. # -----------------------------------------------------
  32. if __name__ == '__main__':
  33. if len(sys.argv) != 2:
  34. print("Usage: %s <filename>" % sys.argv[0])
  35. quit()
  36. filename = sys.argv[1]
  37. if not os.path.exists(filename):
  38. print("Folder '%s' does not exist" % filename)
  39. quit()
  40. # dump code now
  41. res2c(filename)