bin2c.c 702 B

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