1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include <sys/types.h>
34 static off_t
filesize(int fd
)
42 static int write_cfile(unsigned char* buf
, off_t len
, char* cname
)
48 snprintf(filename
,256,"%s.c",cname
);
50 fp
= fopen(filename
,"w+");
52 fprintf(stderr
,"Couldn't open %s\n",filename
);
56 fprintf(fp
,"/* Generated by ipod2c */\n\n");
57 fprintf(fp
,"unsigned char %s[] = {",cname
);
64 fprintf(fp
,"0x%02x",buf
[i
]);
66 fprintf(fp
,"0x%02x, ",buf
[i
]);
75 static int write_hfile(unsigned char* buf
, off_t len
, char* cname
)
81 snprintf(filename
,256,"%s.h",cname
);
82 fp
= fopen(filename
,"w+");
84 fprintf(stderr
,"Couldn't open %s\n",filename
);
88 fprintf(fp
,"/* Generated by ipod2c */\n\n");
89 fprintf(fp
,"#define LEN_%s %d\n",cname
,(int)len
);
90 fprintf(fp
,"extern unsigned char %s[];\n",cname
);
95 int main (int argc
, char* argv
[])
105 fprintf(stderr
,"Usage: ipod2c file.ipod cname\n");
112 fd
= open(infile
,O_RDONLY
|O_BINARY
);
114 fprintf(stderr
,"Can not open %s\n",infile
);
118 len
= filesize(fd
) - 8;
120 n
= lseek(fd
,8,SEEK_SET
);
122 fprintf(stderr
,"Seek failed\n");
127 n
= read(fd
,buf
,len
);
129 fprintf(stderr
,"Short read, aborting\n");
134 if (write_cfile(buf
,len
,cname
) < 0) {
137 if (write_hfile(buf
,len
,cname
) < 0) {