diff options
Diffstat (limited to 'cfile.c')
-rw-r--r-- | cfile.c | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -0,0 +1,55 @@ +/* + Convert a binary file to a C u_long array +*/ +#include <stdio.h> +#include <errno.h> + +int main(int argc, char *argv[]) +{ + char *name="bfile"; + FILE *in,*out; + unsigned long num; + int col; + + in=stdin; + out=stdout; + + if (argc>1) + if (!(in=fopen(argv[1],"rb"))) + perror(argv[0]); + + if (argc>2) + if (!(out=fopen(argv[2],"w"))) + perror(argv[0]); + + 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; + + while(!feof(in)) + { + fread(&num,sizeof(unsigned long),1,in); + + if (col==0) + fprintf(out,"\n\t\t\t"); + + fprintf(out,"0x%.8x,",num); + + col=(col+1)%4; + num=0; + } + + fprintf(out,"\n\t\t\t};\n"); + + fclose(in); + fclose(out); +} |