📄 lyric_parse.c
字号:
/*
* lyric_parse.c
*
* Lyrics parse program
*
* Copyright (c) FARADAY, All Right Reserved 2007
*
* Created by: K.J. Lin <kjlin@faraday-tech.com>
*
*/
#include <string.h>
#include "api.h"
#include "lrc_parser.h"
UINT8 lyric[MAX_LYRIC_WORD];
UINT8 *seg2lrc[MAX_LYRIC_SEGMENT];
UINT8 time2seg[MAX_MUSIC_LENGTH];
UINT8 remains;
BOOLEAN eof;
UINT8 line_buf[128];
UINT8 tmp[16], tmp_pos;
UINT16 time[10];
UINT8 time_count;
FILE_t *fp;
static UINT16 parse_time(UINT8 xdata *buf)
{
return ((buf[0]-'0')*10 + (buf[1]-'0'))*60 + (buf[3]-'0')*10 + (buf[4]-'0');
}
static BOOLEAN get_line(UINT8 xdata *buf)
{
UINT8 data tok;
while(!eof) {
if(remains == 0) {
remains = api_u16FileRead(tmp, sizeof(tmp), fp);
tmp_pos = 0;
if(remains != sizeof(tmp))
eof = true;
}
while(remains) {
remains--;
tok = tmp[tmp_pos++];
if(tok == 0x0D)
continue;
else if(tok == 0x0A) {
*buf = '\0';
return true;
}
else
*buf++ = tok;
}
}
return FALSE;
}
static BOOLEAN get_time(UINT8 xdata * xdata *buf)
{
UINT8 tok, n;
UINT8 timetok[9];
BOOLEAN find = false;
n = 0;
while((tok = *((*buf)++)) != '\0') {
if(tok == '[') {
find = true;
}
else if(tok == ']') {
if(!find)
return false;
timetok[n++] = '\0';
if(timetok[0]>='0' && timetok[0]<='9'&&timetok[1]>='0' && timetok[1]<='9'&&timetok[3]>='0' && timetok[3]<='9'&&timetok[4]>='0' && timetok[4]<='9')
{
time[time_count++] = parse_time(timetok);
if(**buf != '[')
return true;
n = 0;
find = false;
}
else
{
return false;
}
}
else {
timetok[n++] = tok;
}
}
return false;
}
BOOLEAN lyric_parse(UINT8 *filename)
{
UINT8 tok, i;
UINT8 data segment;
UINT8 xdata *buf,*buf1;
UINT8 xdata *plyric;
memset(time2seg, 0xFF, MAX_MUSIC_LENGTH);
fp = NULL;
if((fp = api_pFileOpen(filename)) == NULL)
return false;
remains = 0;
segment = 0;
tmp_pos = 0;
eof = false;
plyric = lyric;
while(get_line(line_buf)) {
time_count = 0;
buf = line_buf;
//Print(line_buf);
if(get_time(&buf) == true) {
for(i = 0; i < time_count; i++)
time2seg[time[i]] = segment;
buf1 = plyric;
//seg2lrc[segment] = (UINT16)plyric;
//Print(buf);
while((tok = *buf++) != '\0')
*plyric++ = tok;
*plyric++ = '\0';
seg2lrc[segment] = buf1;
//Print(buf1);
Print(seg2lrc[segment]);
if(++segment >= MAX_LYRIC_SEGMENT || ((UINT16)plyric - (UINT16)lyric) >= MAX_LYRIC_WORD)
break;
}
}
api_vFileClose(fp);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -