# HG changeset patch # User David Demelier # Date 1603273638 -7200 # Node ID d841cff1017c6898eece9149e249882ba49796ba # Parent e60a13969acbaec7f36d5e312513e65e733685b7 molko-bcc: allow -0 to NULL-terminate arrays diff -r e60a13969acb -r d841cff1017c cmake/MolkoBuildAssets.cmake --- 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 $ -s ${a} ${category}-${name} > ${output} + COMMAND $ ${arg0} -s ${a} ${category}-${name} > ${output} DEPENDS ${a} $ diff -r e60a13969acb -r d841cff1017c tools/bcc/bcc.c --- 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;