From 954af9179665457b40453a0417ddf5b3949a0449 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 4 Mar 2007 18:35:36 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- cfile8.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 cfile8.c (limited to 'cfile8.c') diff --git a/cfile8.c b/cfile8.c new file mode 100644 index 0000000..702da6f --- /dev/null +++ b/cfile8.c @@ -0,0 +1,55 @@ +/* + Convert a binary file to a C unsigned char array +*/ +#include +#include + +int main(int argc, char *argv[]) +{ + char *name="bfile"; + FILE *in,*out; + unsigned char 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{",name); + + col=0; + num=0; + + while(!feof(in)) + { + fread(&num,sizeof num,1,in); + + if (col==0) + fprintf(out,"\n"); + + fprintf(out,"0x%.2x,",num); + + col=(col+1)%16; + num=0; + } + + fprintf(out,"\n};\n"); + + fclose(in); + fclose(out); +} -- cgit v1.2.3