Mirror of CollapseOS
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

51 rinda
1.4KB

  1. /*
  2. * Copyright (c) 2020 Byron Grobe
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <stdint.h>
  19. #define BUFSZ 32
  20. static const char intro[] = "static const unsigned char %s[] = {\n ";
  21. int main(int argc, char **argv) {
  22. int n;
  23. int col = 0;
  24. uint8_t buf[BUFSZ];
  25. if (argc < 2) {
  26. fprintf(stderr, "Specify a name for the data structure...\n");
  27. return 1;
  28. }
  29. printf(intro, argv[1]);
  30. while(!feof(stdin)) {
  31. n = fread(buf, 1, BUFSZ, stdin);
  32. for(int i = 0; i < n; ++i) {
  33. if (col+4 >= 76) {
  34. printf("\n ");
  35. col = 0;
  36. }
  37. printf("0x%.2x, ", buf[i]);
  38. col += 6;
  39. }
  40. }
  41. printf("};\n");
  42. }