Comment out the correct #endif directive.
[mplayer/greg.git] / stream / cdinfo.c
blob7a44dc2576706dd39d2848c180f5a4f0aab2111c
1 /*
2 * CD Info
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
4 * (C) 2002, MPlayer team.
5 */
7 #include "config.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "mp_msg.h"
13 #include "help_mp.h"
14 #include "cdd.h"
16 /*******************************************************************************************************************
18 * xmcd parser, cd info list
20 *******************************************************************************************************************/
22 cd_info_t*
23 cd_info_new() {
24 cd_info_t *cd_info = NULL;
26 cd_info = malloc(sizeof(cd_info_t));
27 if( cd_info==NULL ) {
28 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
29 return NULL;
32 memset(cd_info, 0, sizeof(cd_info_t));
34 return cd_info;
37 void
38 cd_info_free(cd_info_t *cd_info) {
39 cd_track_t *cd_track, *cd_track_next;
40 if( cd_info==NULL ) return;
41 if( cd_info->artist!=NULL ) free(cd_info->artist);
42 if( cd_info->album!=NULL ) free(cd_info->album);
43 if( cd_info->genre!=NULL ) free(cd_info->genre);
45 cd_track_next = cd_info->first;
46 while( cd_track_next!=NULL ) {
47 cd_track = cd_track_next;
48 cd_track_next = cd_track->next;
49 if( cd_track->name!=NULL ) free(cd_track->name);
50 free(cd_track);
54 cd_track_t*
55 cd_info_add_track(cd_info_t *cd_info, char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length) {
56 cd_track_t *cd_track;
58 if( cd_info==NULL || track_name==NULL ) return NULL;
60 cd_track = malloc(sizeof(cd_track_t));
61 if( cd_track==NULL ) {
62 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
63 return NULL;
65 memset(cd_track, 0, sizeof(cd_track_t));
67 cd_track->name = malloc(strlen(track_name)+1);
68 if( cd_track->name==NULL ) {
69 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
70 free(cd_track);
71 return NULL;
73 strcpy(cd_track->name, track_name);
74 cd_track->track_nb = track_nb;
75 cd_track->min = min;
76 cd_track->sec = sec;
77 cd_track->msec = msec;
78 cd_track->frame_begin = frame_begin;
79 cd_track->frame_length = frame_length;
81 if( cd_info->first==NULL ) {
82 cd_info->first = cd_track;
84 if( cd_info->last!=NULL ) {
85 cd_info->last->next = cd_track;
88 cd_track->prev = cd_info->last;
90 cd_info->last = cd_track;
91 cd_info->current = cd_track;
93 cd_info->nb_tracks++;
95 return cd_track;
98 cd_track_t*
99 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) {
100 cd_track_t *cd_track=NULL;
102 if( cd_info==NULL ) return NULL;
104 cd_track = cd_info->first;
105 while( cd_track!=NULL ) {
106 if( cd_track->track_nb==track_nb ) {
107 return cd_track;
109 cd_track = cd_track->next;
111 return NULL;
114 void
115 cd_info_debug(cd_info_t *cd_info) {
116 cd_track_t *current_track;
117 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === start =========\n");
118 if( cd_info==NULL ) {
119 mp_msg(MSGT_DEMUX, MSGL_INFO, "cd_info is NULL\n");
120 return;
122 mp_msg(MSGT_DEMUX, MSGL_INFO, " artist=[%s]\n", cd_info->artist);
123 mp_msg(MSGT_DEMUX, MSGL_INFO, " album=[%s]\n", cd_info->album);
124 mp_msg(MSGT_DEMUX, MSGL_INFO, " genre=[%s]\n", cd_info->genre);
125 mp_msg(MSGT_DEMUX, MSGL_INFO, " nb_tracks=%d\n", cd_info->nb_tracks);
126 mp_msg(MSGT_DEMUX, MSGL_INFO, " length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
127 current_track = cd_info->first;
128 while( current_track!=NULL ) {
129 mp_msg(MSGT_DEMUX, MSGL_INFO, " #%2d %2d:%02d.%02d @ %7ld\t[%s] \n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec, current_track->frame_begin, current_track->name);
130 current_track = current_track->next;
132 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === end =========\n");