Source code for img2gb.c_export
_COMMENT = "// This file was generated by img2gb, DO NOT EDIT\n\n"
[docs]
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
[docs]
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