bin2hex.c 755 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. int main( int argc, const char * argv [] )
  5. {
  6. const char * varname;
  7. int i = 0;
  8. int c;
  9. int id = 0;
  10. if(argv[1] && strcmp(argv[1],"-i")==0)
  11. {
  12. argv++;
  13. argc--;
  14. id=1;
  15. }
  16. if(argc==1)
  17. {
  18. fprintf(stderr, "bin2hex: [-i] firmware\n");
  19. exit(1);
  20. }
  21. varname = argv[1];
  22. printf( "/* automatically generated by bin2hex */\n" );
  23. printf( "static unsigned char %s [] %s =\n{\n", varname , id?"__initdata":"");
  24. while ( ( c = getchar( ) ) != EOF )
  25. {
  26. if ( i != 0 && i % 10 == 0 )
  27. printf( "\n" );
  28. printf( "0x%02lx,", c & 0xFFl );
  29. i++;
  30. }
  31. printf( "};\nstatic int %sLen = %d;\n", varname, i );
  32. return 0;
  33. }