Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
603B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define BUFSZ 32
  4. static const char intro[] = "static const unsigned char %s[] = {\n ";
  5. int main(int argc, char **argv) {
  6. int n;
  7. int col = 0;
  8. uint8_t buf[BUFSZ];
  9. if (argc < 2) {
  10. fprintf(stderr, "Specify a name for the data structure...\n");
  11. return 1;
  12. }
  13. printf(intro, argv[1]);
  14. while(!feof(stdin)) {
  15. n = fread(buf, 1, BUFSZ, stdin);
  16. for(int i = 0; i < n; ++i) {
  17. if (col+4 >= 76) {
  18. printf("\n ");
  19. col = 0;
  20. }
  21. printf("0x%.2x, ", buf[i]);
  22. col += 6;
  23. }
  24. }
  25. printf("};\n");
  26. }