home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / utils / bin2h.c next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  756 b   |  37 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <sys/stat.h>
  5. #include <unistd.h>
  6.  
  7. int
  8. main(int argc, char **argv)
  9. {
  10.   int f = open(argv[1], O_RDONLY|O_BINARY);
  11.   FILE *of = fopen(argv[3], "w");
  12.   unsigned char buf[4096];
  13.   int rbytes;
  14.   int col=0, i;
  15.   if (argc < 4)
  16.   {
  17.     printf("usage: bin2byte infile symname outfile\n");
  18.     exit(1);
  19.   }
  20.   fprintf(of, "unsigned char %s[] = {\n", argv[2]);
  21.   while ((rbytes = read(f, buf, 4096)) > 0)
  22.   {
  23.     for (i=0; i<rbytes; i++)
  24.     {
  25.       fprintf(of, "%d,", buf[i]);
  26.       if (col++ == 32)
  27.       {
  28.         fprintf(of, "\n");
  29.         col = 0;
  30.       }
  31.     }
  32.   }
  33.   fprintf(of, "};\n");
  34.   fclose(of);
  35.   return 0;
  36. }
  37.