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.

50 lines
1.6KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # DISTRHO Plugin Framework (DPF)
  4. # Copyright (C) 2012-2022 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. # -----------------------------------------------------
  29. if __name__ == '__main__':
  30. if len(sys.argv) != 2:
  31. print("Usage: %s <filename>" % sys.argv[0])
  32. quit()
  33. filename = sys.argv[1]
  34. if not os.path.exists(filename):
  35. print("File '%s' does not exist" % filename)
  36. quit()
  37. # dump code now
  38. res2c(filename)