^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Unloved program to convert a binary on stdin to a C include on stdout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Jan 1999 Matt Mackall <mpm@selenic.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This software may be used and distributed according to the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * of the GNU General Public License, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) int main(int argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) int ch, total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) if (argc > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) printf("const char %s[] %s=\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) argv[1], argc > 2 ? argv[2] : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) printf("\t\"");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) while ((ch = getchar()) != EOF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) total++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) printf("\\x%02x", ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (total % 16 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) printf("\"\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) } while (ch != EOF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (argc > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) argv[1], total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }