996
|
1 /*****************************************************************************
|
|
2
|
|
3 NAME
|
|
4 bin2c.c -- convert a binary data file to a C source file
|
|
5
|
|
6 LICENSE TERMS
|
|
7 Copyright (C) 2007 Alex Smith
|
|
8
|
|
9 This program is free software; you can redistribute it and/or modify
|
|
10 it under the terms of the GNU General Public License as published by
|
|
11 the Free Software Foundation; either version 2 of the License, or
|
|
12 (at your option) any later version.
|
|
13
|
|
14 This program is distributed in the hope that it will be useful,
|
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 GNU General Public License for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with this program; if not, write to the Free Software
|
|
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
22
|
|
23 ***************************************************************************/
|
|
24
|
|
25 #include <stdio.h>
|
|
26
|
|
27 int main(int argc, char** argv)
|
|
28 {
|
|
29 int c,colno;
|
|
30 if(argc!=2)
|
|
31 {
|
|
32 fprintf(stderr,"Usage: bin2c varname < infile > outfile\n");
|
|
33 return 0;
|
|
34 }
|
|
35 (void) puts("/* This file is automatically generated; to modify it,");
|
|
36 (void) puts(" modify the source file, not this file. */");
|
|
37 (void) puts("#include \"config.h\"");
|
|
38 printf("const char* %s=\"\\\n",argv[1]);
|
|
39 colno=0;
|
|
40 while((c=getchar())!=EOF)
|
|
41 {
|
|
42 printf("\\x%02x",(unsigned)c);
|
|
43 colno+=4;
|
|
44 if(colno>70) {(void) puts("\\"); colno=0;}
|
|
45 }
|
|
46 (void) puts("\";");
|
|
47 return 0;
|
|
48 }
|