#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# DISTRHO Plugin Framework (DPF)
# Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with
# or without fee is hereby granted, provided that the above copyright notice and this
# permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
# TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
# NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import os
import sys

# -----------------------------------------------------

def res2c(filename):
    resname = "src_" + os.path.basename(filename.replace(".","_"))
    fhandle = open(filename, 'rb')
    resdata = fhandle.read()

    print("const unsigned char %s[] = {\n" % resname)
    for data in resdata:
        print(" %3u," % data)
    print("};\n")

    print("const unsigned int %s_len = %d;\n" % (resname, fhandle.tell()))

# -----------------------------------------------------

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("Usage: %s <filename>" % sys.argv[0])
        quit()

    filename = sys.argv[1]

    if not os.path.exists(filename):
        print("File '%s' does not exist" % filename)
        quit()

    # dump code now
    res2c(filename)
