#include int main(int argc,char **argv) { FILE *fin, *fout; int c1=0, c2=0; long iFileLen, l, i; char temp[10], *c; if (argc!=3) { printf("Usage : bin2h infile.bin outfile.h\n"); return -1; } fin = fopen(argv[1], "r"); if (fin<=0) { printf("Error could not open file %s\n", argv[1]); return -2; } // Get length of file fseek(fin, 0, SEEK_END); iFileLen = ftell(fin); if (iFileLen %2!=0) { printf("Error, input file must have even length."); return -3; } // Return to begining fseek(fin, 0, SEEK_SET); fout = fopen(argv[2], "w"); if (fout<=0) { printf("Error could not open file %s\n", argv[2]); return -2; } printf("Processing %s (length %d)...\n", argv[1], iFileLen); fprintf(fout, "unsigned short fontdata[] = {"); for (i=0; i> 4) | ((c1 & 0xf) << 4); c2 = getc(fin); c2 = ((c2 & 0xF0) >> 4) | ((c2 & 0xf) << 4); l = (c1 << 8) + c2; if (c1 & 0xF0) { fprintf(fout, "0x7FFF,"); } else { fprintf(fout, "0x0000,"); } if (c1 & 0x0F) { fprintf(fout, "0x7FFF,"); } else { fprintf(fout, "0x0000,"); } if (c2 & 0xF0) { fprintf(fout, "0x7FFF,"); } else { fprintf(fout, "0x0000,"); } if (c2 & 0x0F) { fprintf(fout, "0x7FFF,"); } else { fprintf(fout, "0x0000,"); } /* sprintf(temp, "0x%4X,", l); for (c=temp; *c; c++) { if (*c==' ') *c = '0'; } fprintf(fout, temp);*/ } fprintf(fout, "\n};\n"); fclose(fin); fclose(fout); return 0; }