home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <sys/types.h>
- #include <cdaudio.h>
-
- #define DB_ID_NTRACKS 5
- #define DB_ID_MAXLEN 20
-
- #define DBID_MAP_SIZE 66
-
- static char dbid_int_map[DBID_MAP_SIZE] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
- 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V', 'W', 'X', 'Y', 'Z', '@', '_', '=', '+',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
- 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
- 'u', 'v', 'w', 'x', 'y', 'z',
- };
-
- #define DBID_MAP(b,val) {\
- register int v = (val);\
- if (v>=DBID_MAP_SIZE) {\
- sprintf(b, "%02d", v);\
- b+= 2;\
- }\
- else *b++ = dbid_int_map[v];\
- }
-
- const char *
- db_get_id( CDPLAYER *cdplayer, CDSTATUS *status )
- {
- char db_rtrn_buf[1024];
- CDTRACKINFO info;
- int min, sec, i;
- char *bufp = db_rtrn_buf, *tmp;
- int nCDTracks, nIDTracks;
-
- if (status->state == CD_NODISC || status->state == CD_ERROR)
- return (NULL);
-
- nCDTracks = status->last - status->first + 1;
- DBID_MAP( bufp, ((nCDTracks>>4)&0xf) );
- DBID_MAP( bufp, (nCDTracks&0xf) );
-
- if ( nCDTracks < DB_ID_NTRACKS ) nIDTracks = nCDTracks;
- else if (nCDTracks == DB_ID_NTRACKS ) nIDTracks = DB_ID_NTRACKS;
- else {
- nIDTracks = DB_ID_NTRACKS - 1;
- for (min= 0, sec= 0,i = status->first ; i <= status->last ; i++ ) {
- CDgettrackinfo( cdplayer, i, &info );
- min+= info.total_min;
- sec+= info.total_sec;
- }
- min+= sec/60;
- sec = sec % 60;
- DBID_MAP( bufp, min );
- DBID_MAP( bufp, sec );
- }
-
- for (i = 0; i < nIDTracks; i++) {
- if (status->first+i <= status->last) {
- CDgettrackinfo( cdplayer, status->first+i, &info );
- DBID_MAP( bufp, info.total_min );
- DBID_MAP( bufp, info.total_sec );
- }
- }
- *bufp++ = '\0';
- return (strdup( db_rtrn_buf ));
- }
-