1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: ipodio-win32.c 12205 2007-02-05 01:20:20Z dave $
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
)
80 snprintf(filename
,256,"%s.h",cname
);
81 fp
= fopen(filename
,"w+");
83 fprintf(stderr
,"Couldn't open %s\n",filename
);
87 fprintf(fp
,"/* Generated by ipod2c */\n\n");
88 fprintf(fp
,"#define LEN_%s %d\n",cname
,(int)len
);
89 fprintf(fp
,"extern unsigned char %s[];\n",cname
);
94 int main (int argc
, char* argv
[])
104 fprintf(stderr
,"Usage: ipod2c file.ipod cname\n");
111 fd
= open(infile
,O_RDONLY
|O_BINARY
);
113 fprintf(stderr
,"Can not open %s\n",infile
);
117 len
= filesize(fd
) - 8;
119 n
= lseek(fd
,8,SEEK_SET
);
121 fprintf(stderr
,"Seek failed\n");
126 n
= read(fd
,buf
,len
);
128 fprintf(stderr
,"Short read, aborting\n");
133 if (write_cfile(buf
,len
,cname
) < 0) {
136 if (write_hfile(buf
,len
,cname
) < 0) {