Mercurial > molko
changeset 171:d841cff1017c
molko-bcc: allow -0 to NULL-terminate arrays
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 21 Oct 2020 11:47:18 +0200 |
parents | e60a13969acb |
children | 6250883b81f0 |
files | cmake/MolkoBuildAssets.cmake tools/bcc/bcc.c |
diffstat | 2 files changed, 23 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cmake/MolkoBuildAssets.cmake Wed Oct 21 10:07:53 2020 +0200 +++ b/cmake/MolkoBuildAssets.cmake Wed Oct 21 11:47:18 2020 +0200 @@ -26,11 +26,19 @@ get_filename_component(outputdir ${output} DIRECTORY) get_filename_component(name ${basename} NAME_WE) get_filename_component(category ${outputdir} NAME) + get_filename_Component(extension ${a} EXT) file(MAKE_DIRECTORY ${outputdir}) + # For "text" files, we create a C array null-terminated. + if (${extension} MATCHES "\\.(txt|sql)") + set(arg0 -0) + else () + unset(arg0) + endif () + add_custom_command( OUTPUT ${output} - COMMAND $<TARGET_FILE:bcc> -s ${a} ${category}-${name} > ${output} + COMMAND $<TARGET_FILE:bcc> ${arg0} -s ${a} ${category}-${name} > ${output} DEPENDS ${a} $<TARGET_FILE:bcc>
--- a/tools/bcc/bcc.c Wed Oct 21 10:07:53 2020 +0200 +++ b/tools/bcc/bcc.c Wed Oct 21 11:47:18 2020 +0200 @@ -27,6 +27,7 @@ static const char *charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; static bool fstatic; +static bool nullterm; noreturn static void usage(void) @@ -84,10 +85,7 @@ if (idx == 0) putchar('\t'); - printf("0x%02x", (unsigned char)ch); - - if (!feof(fp)) - printf(", "); + printf("0x%02x, ", (unsigned char)ch); if (++idx == 4) { idx = 0; @@ -95,6 +93,14 @@ } } + /* Add final '\0' if requested. */ + if (nullterm) { + if (idx++ == 0) + putchar('\t'); + + printf("0x00"); + } + if (idx != 0) printf("\n"); @@ -107,8 +113,11 @@ { int ch; - while ((ch = getopt(argc, argv, "s")) != -1) { + while ((ch = getopt(argc, argv, "0s")) != -1) { switch (ch) { + case '0': + nullterm = true; + break; case 's': fstatic = true; break;