mirror of
https://github.com/mpv-player/mpv
synced 2025-02-18 05:37:04 +00:00
cosmetics: K&R coding style, indent with 4 spaces, no tabs
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30671 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
b1e549d7bc
commit
d393029ce2
@ -82,8 +82,8 @@ stream_t* open_cdda(char *dev, char *track);
|
||||
static cd_toc_t cdtoc[100];
|
||||
static int cdtoc_last_track;
|
||||
|
||||
int
|
||||
read_toc(const char *dev) {
|
||||
int read_toc(const char *dev)
|
||||
{
|
||||
int first = 0, last = -1;
|
||||
int i;
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
@ -93,9 +93,11 @@ read_toc(const char *dev) {
|
||||
char device[10];
|
||||
|
||||
sprintf(device, "\\\\.\\%s", dev);
|
||||
drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
||||
drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, 0, 0);
|
||||
|
||||
if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) {
|
||||
if (!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc,
|
||||
sizeof(CDROM_TOC), &r, 0)) {
|
||||
mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC);
|
||||
return 0;
|
||||
}
|
||||
@ -228,30 +230,30 @@ read_toc(const char *dev) {
|
||||
int cdd_identify(const char *dev)
|
||||
{
|
||||
cdtoc_last_track = 0;
|
||||
if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
|
||||
{
|
||||
if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) {
|
||||
int i, min, sec, frame;
|
||||
cdtoc_last_track = read_toc(dev);
|
||||
if (cdtoc_last_track < 0) {
|
||||
mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev);
|
||||
mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice,
|
||||
dev);
|
||||
return -1;
|
||||
}
|
||||
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track);
|
||||
for (i = 1; i <= cdtoc_last_track; i++)
|
||||
{
|
||||
for (i = 1; i <= cdtoc_last_track; i++) {
|
||||
frame = cdtoc[i].frame - cdtoc[i-1].frame;
|
||||
sec = frame / 75;
|
||||
frame -= sec * 75;
|
||||
min = sec / 60;
|
||||
sec -= min * 60;
|
||||
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame);
|
||||
mp_msg(MSGT_IDENTIFY, MSGL_INFO,
|
||||
"ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame);
|
||||
}
|
||||
}
|
||||
return cdtoc_last_track;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
cddb_sum(int n) {
|
||||
unsigned int cddb_sum(int n)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
ret = 0;
|
||||
@ -262,8 +264,8 @@ cddb_sum(int n) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
cddb_discid(int tot_trks) {
|
||||
unsigned long cddb_discid(int tot_trks)
|
||||
{
|
||||
unsigned int i, t = 0, n = 0;
|
||||
|
||||
i = 0;
|
||||
@ -278,16 +280,21 @@ cddb_discid(int tot_trks) {
|
||||
|
||||
|
||||
|
||||
int
|
||||
cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) {
|
||||
int cddb_http_request(char *command,
|
||||
int (*reply_parser)(HTTP_header_t*, cddb_data_t*),
|
||||
cddb_data_t *cddb_data)
|
||||
{
|
||||
char request[4096];
|
||||
int fd, ret = 0;
|
||||
URL_t *url;
|
||||
HTTP_header_t *http_hdr;
|
||||
|
||||
if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1;
|
||||
if (reply_parser == NULL || command == NULL || cddb_data == NULL)
|
||||
return -1;
|
||||
|
||||
sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello, cddb_data->freedb_proto_level );
|
||||
sprintf(request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d",
|
||||
cddb_data->freedb_server, command, cddb_data->cddb_hello,
|
||||
cddb_data->freedb_proto_level);
|
||||
mp_msg(MSGT_OPEN, MSGL_INFO,"Request[%s]\n", request);
|
||||
|
||||
url = url_new(request);
|
||||
@ -298,13 +305,15 @@ cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*
|
||||
|
||||
fd = http_send_request(url,0);
|
||||
if (fd < 0) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest);
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR,
|
||||
MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
http_hdr = http_read_response(fd);
|
||||
if (http_hdr == NULL) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse);
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR,
|
||||
MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -328,14 +337,15 @@ cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_read_cache(cddb_data_t *cddb_data) {
|
||||
int cddb_read_cache(cddb_data_t *cddb_data)
|
||||
{
|
||||
char file_name[100];
|
||||
struct stat stats;
|
||||
int file_fd, ret;
|
||||
size_t file_size;
|
||||
|
||||
if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
|
||||
if (cddb_data == NULL || cddb_data->cache_dir == NULL)
|
||||
return -1;
|
||||
|
||||
sprintf(file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
|
||||
|
||||
@ -365,7 +375,8 @@ cddb_read_cache(cddb_data_t *cddb_data) {
|
||||
}
|
||||
cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size);
|
||||
if (cddb_data->xmcd_file_size != file_size) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead);
|
||||
mp_msg(MSGT_DEMUX, MSGL_WARN,
|
||||
MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead);
|
||||
close(file_fd);
|
||||
return -1;
|
||||
}
|
||||
@ -376,15 +387,16 @@ cddb_read_cache(cddb_data_t *cddb_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_write_cache(cddb_data_t *cddb_data) {
|
||||
int cddb_write_cache(cddb_data_t *cddb_data)
|
||||
{
|
||||
// We have the file, save it for cache.
|
||||
struct stat file_stat;
|
||||
char file_name[100];
|
||||
int file_fd, ret;
|
||||
int wrote = 0;
|
||||
|
||||
if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
|
||||
if (cddb_data == NULL || cddb_data->cache_dir == NULL)
|
||||
return -1;
|
||||
|
||||
// Check if the CDDB cache dir exist
|
||||
ret = stat(cddb_data->cache_dir, &file_stat);
|
||||
@ -397,7 +409,9 @@ cddb_write_cache(cddb_data_t *cddb_data) {
|
||||
if (ret < 0) {
|
||||
#endif
|
||||
perror("mkdir");
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory, cddb_data->cache_dir);
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR,
|
||||
MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory,
|
||||
cddb_data->cache_dir);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -427,14 +441,15 @@ cddb_write_cache(cddb_data_t *cddb_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
int cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
|
||||
{
|
||||
unsigned long disc_id;
|
||||
char category[100];
|
||||
char *ptr = NULL, *ptr2 = NULL;
|
||||
int ret, status;
|
||||
|
||||
if( http_hdr==NULL || cddb_data==NULL ) return -1;
|
||||
if (http_hdr == NULL || cddb_data == NULL)
|
||||
return -1;
|
||||
|
||||
ret = sscanf(http_hdr->body, "%d ", &status);
|
||||
if (ret != 1) {
|
||||
@ -444,7 +459,8 @@ cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
|
||||
switch (status) {
|
||||
case 210:
|
||||
ret = sscanf( http_hdr->body, "%d %99s %08lx", &status, category, &disc_id);
|
||||
ret = sscanf(http_hdr->body, "%d %99s %08lx", &status,
|
||||
category, &disc_id);
|
||||
if (ret != 3) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
|
||||
return -1;
|
||||
@ -452,7 +468,8 @@ cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
// Check if it's a xmcd database file
|
||||
ptr = strstr(http_hdr->body, "# xmcd");
|
||||
if (ptr == NULL) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned);
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR,
|
||||
MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned);
|
||||
return -1;
|
||||
}
|
||||
ptr = strdup(ptr);
|
||||
@ -461,8 +478,9 @@ cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
ptr2 = strstr(ptr, "\n.\r\n");
|
||||
if (!ptr2)
|
||||
ptr2 = strstr(ptr, "\n.\n");
|
||||
if (ptr2) ptr2++;
|
||||
else {
|
||||
if (ptr2) {
|
||||
ptr2++;
|
||||
} else {
|
||||
mp_msg(MSGT_DEMUX, MSGL_FIXME, "Unable to find '.'\n");
|
||||
ptr2 = ptr + strlen(ptr); //return -1;
|
||||
}
|
||||
@ -482,15 +500,16 @@ cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_request_titles(cddb_data_t *cddb_data) {
|
||||
int cddb_request_titles(cddb_data_t *cddb_data)
|
||||
{
|
||||
char command[1024];
|
||||
sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id);
|
||||
sprintf(command, "cddb+read+%s+%08lx",
|
||||
cddb_data->category, cddb_data->disc_id);
|
||||
return cddb_http_request(command, cddb_read_parse, cddb_data);
|
||||
}
|
||||
|
||||
int
|
||||
cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
int cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
|
||||
{
|
||||
char album_title[100];
|
||||
char *ptr = NULL;
|
||||
int ret;
|
||||
@ -503,7 +522,8 @@ cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
ptr++;
|
||||
// We have a list of exact/inexact matches, so which one do we use?
|
||||
// So let's take the first one.
|
||||
ret = sscanf(ptr, "%99s %08lx %99s", cddb_data->category, &(cddb_data->disc_id), album_title);
|
||||
ret = sscanf(ptr, "%99s %08lx %99s", cddb_data->category,
|
||||
&(cddb_data->disc_id), album_title);
|
||||
if (ret != 3) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
|
||||
return -1;
|
||||
@ -522,12 +542,13 @@ cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
strncpy(album_title, ptr, len);
|
||||
album_title[len]='\0';
|
||||
}
|
||||
mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
|
||||
mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle,
|
||||
album_title);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
int cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
|
||||
{
|
||||
char album_title[100];
|
||||
char *ptr = NULL;
|
||||
int ret, status;
|
||||
@ -541,7 +562,8 @@ cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
switch (status) {
|
||||
case 200:
|
||||
// Found exact match
|
||||
ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status, cddb_data->category, &(cddb_data->disc_id), album_title);
|
||||
ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status,
|
||||
cddb_data->category, &(cddb_data->disc_id), album_title);
|
||||
if (ret != 4) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
|
||||
return -1;
|
||||
@ -560,7 +582,8 @@ cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
strncpy(album_title, ptr, len);
|
||||
album_title[len]='\0';
|
||||
}
|
||||
mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
|
||||
mp_msg(MSGT_DEMUX, MSGL_STATUS,
|
||||
MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
|
||||
return cddb_request_titles(cddb_data);
|
||||
case 202:
|
||||
// No match found
|
||||
@ -582,7 +605,8 @@ blues c711930d Santana / Supernatural
|
||||
cddb_parse_matches_list(http_hdr, cddb_data);
|
||||
return cddb_request_titles(cddb_data);
|
||||
case 500:
|
||||
mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr);
|
||||
mp_msg(MSGT_DEMUX, MSGL_FIXME,
|
||||
MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr);
|
||||
break;
|
||||
default:
|
||||
mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
|
||||
@ -590,8 +614,8 @@ blues c711930d Santana / Supernatural
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
int cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
|
||||
{
|
||||
int max;
|
||||
int ret, status;
|
||||
char *ptr;
|
||||
@ -622,13 +646,13 @@ cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_get_proto_level(cddb_data_t *cddb_data) {
|
||||
int cddb_get_proto_level(cddb_data_t *cddb_data)
|
||||
{
|
||||
return cddb_http_request("stat", cddb_proto_level_parse, cddb_data);
|
||||
}
|
||||
|
||||
int
|
||||
cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
int cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
|
||||
{
|
||||
int ret, status;
|
||||
|
||||
ret = sscanf(http_hdr->body, "%d ", &status);
|
||||
@ -651,13 +675,13 @@ cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_get_freedb_sites(cddb_data_t *cddb_data) {
|
||||
int cddb_get_freedb_sites(cddb_data_t *cddb_data)
|
||||
{
|
||||
return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data);
|
||||
}
|
||||
|
||||
void
|
||||
cddb_create_hello(cddb_data_t *cddb_data) {
|
||||
void cddb_create_hello(cddb_data_t *cddb_data)
|
||||
{
|
||||
char host_name[51];
|
||||
char *user_name;
|
||||
|
||||
@ -675,11 +699,12 @@ cddb_create_hello(cddb_data_t *cddb_data) {
|
||||
}
|
||||
user_name = getenv("LOGNAME");
|
||||
}
|
||||
sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayer", VERSION );
|
||||
sprintf(cddb_data->cddb_hello, "&hello=%s+%s+%s+%s",
|
||||
user_name, host_name, "MPlayer", VERSION);
|
||||
}
|
||||
|
||||
int
|
||||
cddb_retrieve(cddb_data_t *cddb_data) {
|
||||
int cddb_retrieve(cddb_data_t *cddb_data)
|
||||
{
|
||||
char offsets[1024], command[1024];
|
||||
char *ptr;
|
||||
unsigned int i, time_len;
|
||||
@ -699,15 +724,18 @@ cddb_retrieve(cddb_data_t *cddb_data) {
|
||||
|
||||
cddb_create_hello(cddb_data);
|
||||
if (cddb_get_proto_level(cddb_data) < 0) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel);
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR,
|
||||
MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//cddb_get_freedb_sites(&cddb_data);
|
||||
|
||||
sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, cddb_data->tracks, offsets, time_len );
|
||||
sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id,
|
||||
cddb_data->tracks, offsets, time_len);
|
||||
ret = cddb_http_request(command, cddb_query_parse, cddb_data);
|
||||
if( ret<0 ) return -1;
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (cddb_data->cache_dir != NULL) {
|
||||
free(cddb_data->cache_dir);
|
||||
@ -715,17 +743,17 @@ cddb_retrieve(cddb_data_t *cddb_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cddb_resolve(const char *dev, char **xmcd_file) {
|
||||
int cddb_resolve(const char *dev, char **xmcd_file)
|
||||
{
|
||||
char cddb_cache_dir[] = DEFAULT_CACHE_DIR;
|
||||
char *home_dir = NULL;
|
||||
cddb_data_t cddb_data;
|
||||
|
||||
if (cdtoc_last_track <= 0)
|
||||
{
|
||||
if (cdtoc_last_track <= 0) {
|
||||
cdtoc_last_track = read_toc(dev);
|
||||
if (cdtoc_last_track < 0) {
|
||||
mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev);
|
||||
mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice,
|
||||
dev);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -733,7 +761,8 @@ cddb_resolve(const char *dev, char **xmcd_file) {
|
||||
cddb_data.disc_id = cddb_discid(cddb_data.tracks);
|
||||
cddb_data.anonymous = 1; // Don't send user info by default
|
||||
|
||||
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_DISCID=%08lx\n", cddb_data.disc_id);
|
||||
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_DISCID=%08lx\n",
|
||||
cddb_data.disc_id);
|
||||
|
||||
// Check if there is a CD in the drive
|
||||
// FIXME: That's not really a good way to check
|
||||
@ -744,15 +773,19 @@ cddb_resolve(const char *dev, char **xmcd_file) {
|
||||
|
||||
home_dir = getenv("HOME");
|
||||
#ifdef __MINGW32__
|
||||
if( home_dir==NULL ) home_dir = getenv("USERPROFILE");
|
||||
if( home_dir==NULL ) home_dir = getenv("HOMEPATH");
|
||||
if (home_dir == NULL)
|
||||
home_dir = getenv("USERPROFILE");
|
||||
if (home_dir == NULL)
|
||||
home_dir = getenv("HOMEPATH");
|
||||
// Last resort, store the cddb cache in the mplayer directory
|
||||
if( home_dir==NULL ) home_dir = (char *)get_path("");
|
||||
if (home_dir == NULL)
|
||||
home_dir = (char *)get_path("");
|
||||
#endif
|
||||
if (home_dir == NULL) {
|
||||
cddb_data.cache_dir = NULL;
|
||||
} else {
|
||||
cddb_data.cache_dir = malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1);
|
||||
cddb_data.cache_dir = malloc(strlen(home_dir)
|
||||
+ strlen(cddb_cache_dir) + 1);
|
||||
if (cddb_data.cache_dir == NULL) {
|
||||
mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
|
||||
return -1;
|
||||
@ -777,19 +810,18 @@ cddb_resolve(const char *dev, char **xmcd_file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*******************************************************************************************************************
|
||||
*
|
||||
* xmcd parser
|
||||
*
|
||||
*******************************************************************************************************************/
|
||||
char*
|
||||
xmcd_parse_dtitle(cd_info_t *cd_info, char *line) {
|
||||
/***************
|
||||
* xmcd parser *
|
||||
***************/
|
||||
char *xmcd_parse_dtitle(cd_info_t *cd_info, char *line)
|
||||
{
|
||||
char *ptr, *album;
|
||||
ptr = strstr(line, "DTITLE=");
|
||||
if (ptr != NULL) {
|
||||
ptr += 7;
|
||||
album = strstr(ptr, "/");
|
||||
if( album==NULL ) return NULL;
|
||||
if (album == NULL)
|
||||
return NULL;
|
||||
cd_info->album = malloc(strlen(album + 2) + 1);
|
||||
if (cd_info->album == NULL) {
|
||||
return NULL;
|
||||
@ -806,8 +838,8 @@ xmcd_parse_dtitle(cd_info_t *cd_info, char *line) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char*
|
||||
xmcd_parse_dgenre(cd_info_t *cd_info, char *line) {
|
||||
char *xmcd_parse_dgenre(cd_info_t *cd_info, char *line)
|
||||
{
|
||||
char *ptr;
|
||||
ptr = strstr(line, "DGENRE=");
|
||||
if (ptr != NULL) {
|
||||
@ -821,8 +853,8 @@ xmcd_parse_dgenre(cd_info_t *cd_info, char *line) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char*
|
||||
xmcd_parse_ttitle(cd_info_t *cd_info, char *line) {
|
||||
char *xmcd_parse_ttitle(cd_info_t *cd_info, char *line)
|
||||
{
|
||||
unsigned int track_nb;
|
||||
unsigned long sec, off;
|
||||
char *ptr;
|
||||
@ -832,24 +864,30 @@ xmcd_parse_ttitle(cd_info_t *cd_info, char *line) {
|
||||
// Here we point to the track number
|
||||
track_nb = atoi(ptr);
|
||||
ptr = strstr(ptr, "=");
|
||||
if( ptr==NULL ) return NULL;
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
ptr++;
|
||||
|
||||
sec = cdtoc[track_nb].frame;
|
||||
off = cdtoc[track_nb + 1].frame - sec + 1;
|
||||
|
||||
cd_info_add_track( cd_info, ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off );
|
||||
cd_info_add_track(cd_info, ptr, track_nb + 1,
|
||||
(unsigned int) (off / (60 * 75)),
|
||||
(unsigned int) ((off / 75) % 60),
|
||||
(unsigned int) (off % 75),
|
||||
sec, off);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
cd_info_t*
|
||||
cddb_parse_xmcd(char *xmcd_file) {
|
||||
cd_info_t *cddb_parse_xmcd(char *xmcd_file)
|
||||
{
|
||||
cd_info_t *cd_info = NULL;
|
||||
int length, pos = 0;
|
||||
char *ptr, *ptr2;
|
||||
unsigned int audiolen;
|
||||
if( xmcd_file==NULL ) return NULL;
|
||||
if (xmcd_file == NULL)
|
||||
return NULL;
|
||||
|
||||
cd_info = cd_info_new();
|
||||
if (cd_info == NULL) {
|
||||
@ -861,7 +899,8 @@ cddb_parse_xmcd(char *xmcd_file) {
|
||||
while (ptr != NULL && pos < length) {
|
||||
// Read a line
|
||||
ptr2 = ptr;
|
||||
while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++;
|
||||
while(ptr2[0] != '\0' && ptr2[0] != '\r' && ptr2[0] != '\n')
|
||||
ptr2++;
|
||||
if (ptr2[0] == '\0') {
|
||||
break;
|
||||
}
|
||||
@ -869,13 +908,17 @@ cddb_parse_xmcd(char *xmcd_file) {
|
||||
// Ignore comments
|
||||
if (ptr[0] != '#') {
|
||||
// Search for the album title
|
||||
if( xmcd_parse_dtitle(cd_info, ptr) );
|
||||
if (xmcd_parse_dtitle(cd_info, ptr))
|
||||
;
|
||||
// Search for the genre
|
||||
else if( xmcd_parse_dgenre(cd_info, ptr) );
|
||||
else if (xmcd_parse_dgenre(cd_info, ptr))
|
||||
;
|
||||
// Search for a track title
|
||||
else if( xmcd_parse_ttitle(cd_info, ptr) ) audiolen++; // <-- audiolen++ to shut up gcc warning
|
||||
else if (xmcd_parse_ttitle(cd_info, ptr))
|
||||
audiolen++; // <-- audiolen++ to shut up gcc warning
|
||||
}
|
||||
if( ptr2[1]=='\n' ) ptr2++;
|
||||
if (ptr2[1] == '\n')
|
||||
ptr2++;
|
||||
pos = (ptr2 + 1) - ptr;
|
||||
ptr = ptr2 + 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user