bin2h.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2008,2010 Free Software Foundation, Inc.
  3. *
  4. * GRUB is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * GRUB is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. int
  20. main (int argc, char *argv[])
  21. {
  22. int b, i;
  23. char *sym;
  24. if (2 != argc)
  25. return 1;
  26. sym = argv[1];
  27. b = getchar ();
  28. if (b == EOF)
  29. goto abort;
  30. printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n"
  31. "unsigned char %s[] =\n{\n", sym);
  32. while (1)
  33. {
  34. printf ("0x%02x", b);
  35. b = getchar ();
  36. if (b == EOF)
  37. goto end;
  38. for (i = 0; i < 16 - 1; i++)
  39. {
  40. printf (", 0x%02x", b);
  41. b = getchar ();
  42. if (b == EOF)
  43. goto end;
  44. }
  45. printf (",\n");
  46. }
  47. end:
  48. printf ("\n};\n");
  49. abort:
  50. exit (0);
  51. }