1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Alexandre Bourget
12 * Plugin to transform a Rockbox produced m3u playlist into something
13 * understandable by the picky original iRiver firmware.
15 * Based on sort.c by the Rockbox team.
17 * All files in this archive are subject to the GNU General Public License.
18 * See the file COPYING in the source tree root for full license agreement.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
28 static struct plugin_api
* rb
;
31 static char *filename
;
33 static char *stringbuffer
;
34 static char crlf
[2] = "\r\n";
36 int read_buffer(int offset
)
40 fd
= rb
->open(filename
, O_RDONLY
);
44 /* Fill the buffer from the file */
45 rb
->lseek(fd
, offset
, SEEK_SET
);
46 readsize
= rb
->read(fd
, stringbuffer
, buf_size
);
50 return readsize
* 10 - 2;
52 if(readsize
== buf_size
)
53 return buf_size
; /* File too big */
58 static int write_file(void)
60 char tmpfilename
[MAX_PATH
+1];
66 /* Create a temporary file */
68 rb
->snprintf(tmpfilename
, MAX_PATH
+1, "%s.tmp", filename
);
70 fd
= rb
->creat(tmpfilename
);
74 /* Let's make sure it always writes CR/LF and not only LF */
75 buf_ptr
= stringbuffer
;
76 str_begin
= stringbuffer
;
78 /* Transform slashes into backslashes */
82 if((*buf_ptr
== '\r') || (*buf_ptr
== '\n')) {
83 /* We have no complete string ? It's only a leading \n or \r ? */
87 /* Terminate string */
90 /* Write our new string */
91 rc
= rb
->write(fd
, str_begin
, rb
->strlen(str_begin
));
97 rc
= rb
->write(fd
, crlf
, 2);
103 /* Reset until we get a new line */
108 /* We start a new line here */
113 /* Next char, until ... */
114 } while(buf_ptr
++ < stringbuffer
+ readsize
);
118 /* Remove the original file */
119 rc
= rb
->remove(filename
);
124 /* Replace the old file with the new */
125 rc
= rb
->rename(tmpfilename
, filename
);
133 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
138 filename
= (char *)parameter
;
142 buf
= rb
->plugin_get_audio_buffer((size_t *)&buf_size
); /* start munching memory */
147 rb
->screens
[i
]->clear_display();
148 rb
->splash(0, "Converting...");
152 rb
->screens
[i
]->clear_display();
154 rb
->splash(0, "Writing...");
158 rb
->screens
[i
]->clear_display();
160 rb
->splash(HZ
, "Can't write file: %d", rc
);
162 rb
->splash(HZ
, "Done");
166 rb
->splash(HZ
, "Can't read file: %d", rc
);
168 rb
->splash(HZ
, "The file is too big");