/* Convert a binary file to a C u_long array */ #include #include #include int main(int argc, char *argv[]) { const char *name="bfile"; FILE *in,*out; unsigned long num; int col; int first; int len; in=stdin; out=stdout; if (argc>1) { if (!(in=fopen(argv[1],"rb"))) { perror(argv[1]); } } if (argc>2) { if (!(out=fopen(argv[2],"w"))) { perror(argv[2]); } } if (argc>3) { name=argv[3]; } if (argc>1) { fprintf(out,"/* Auto-generated binary of %s */\n\n",argv[1]); } else { fprintf(out,"/* Auto-generated binary */\n\n"); } fprintf(out,"unsigned long %s[]=\n\t\t\t{",name); col=0; num=0; first=1; len=0; fread(&num,sizeof(unsigned long),1,in); while(!feof(in)) { if (col==0) { if (first) { fprintf(out,"\n\t\t\t"); first=0; } else { fprintf(out,",\n\t\t\t"); } } else { fprintf(out,","); } fprintf(out,"0x%.8lx",num); col=(col+1)%4; num=0; len++; fread(&num,sizeof(unsigned long),1,in); } fprintf(out,"\n\t\t\t};\n#define %s_LEN %d\n", name, len); fclose(in); fclose(out); return 0; }