_COMMENT = "// This file was generated by img2gb, DO NOT EDIT\n\n"


def generate_c_file(code):
    """Generate the content of a C file that contains the given code.

    :param str code: The C code to embed in the C file.

    :rtype: str
    """
    c = _COMMENT
    c += "#include <types.h>\n\n"
    c += code
    c += "\n"
    return c


def generate_c_header_file(code, filename="header.h"):
    """Generate the content of a C header file that contains the given code.

    :param str code: The C code to embed in the C header file.
    :param str filename: The header file name (default = ``"header.h"``)

    :rtype: str
    """
    name = filename.replace(".", "_").upper()
    h = _COMMENT
    h += "#ifndef _%s\n" % name
    h += "#define _%s\n\n" % name
    h += code
    h += "\n\n"
    h += "\n#endif\n"
    return h
