home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.73.zip / src / bme / dat2inc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2014-07-23  |  980 b   |  52 lines

  1. //
  2. // Datafile -> C include file
  3. //
  4.  
  5. #include <stdio.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     FILE *in;
  10.     FILE *out;
  11.     int length;
  12.     int c;
  13.  
  14.     if (argc < 3)
  15.     {
  16.         printf("Usage: dat2inc <datafile> <includefile>\n\n");
  17.         return 1;
  18.     }
  19.     in = fopen(argv[1], "rb");
  20.     if (!in)
  21.     {
  22.         printf("Datafile open error!\n");
  23.         return 1;
  24.     }
  25.     out = fopen(argv[2], "wt");
  26.     if (!out)
  27.     {
  28.         printf("Includefile open error!\n");
  29.         fclose(in);
  30.         return 1;
  31.     }
  32.     fseek(in, 0, SEEK_END);
  33.     length = ftell(in);
  34.     fseek(in, 0, SEEK_SET);
  35.  
  36.     fprintf(out, "unsigned char datafile[] = {\n");
  37.     for (c = 0; c < length; c++)
  38.     {
  39.         if (c)
  40.         { 
  41.             fprintf(out, ", ");
  42.             if (!(c % 10)) fprintf(out, "\n");
  43.         }
  44.         fprintf(out, "0x%02x", fgetc(in));
  45.     }
  46.     fprintf(out, "};\n");
  47.     fclose(in);
  48.     fclose(out);
  49.     return 0;
  50. }
  51.  
  52.