/*
 * Copyright (c) 1999 Robert Woodcock <rcw@debian.org>
 * This code is hereby licensed for public consumption under either the
 * GNU GPL v2 or greater, or Larry Wall's Artistic license - your choice.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <stdio.h>
#include <cdaudio.h>

int main(int argc, char *argv[])
{
	int fd, i;
	unsigned long discid;
	struct disc_info disc;
	struct cddb_entry currentdisc;
	
	if (argc < 2) {
		fprintf(stderr, "Usage: %s <devicename>\n", argv[0]);
		exit(1);
	}

	fd = cd_init_device(argv[1]);
	if (fd < 0) {
		perror("cd-discid: cd_init_device");
		exit(1);
	}

	cd_stat(fd, &disc);
	if (!disc.disc_present) {
		fprintf(stderr, "cd-discid: No CD in drive %s\n", argv[1]);
		exit(1);
	}

	cddb_stat_disc_data(fd, &currentdisc);

	printf("%08lx", currentdisc.entry_id);

	printf(" %d", disc.disc_totaltracks);

	for (i=0;i<disc.disc_totaltracks;i++) {
		printf(" %d", disc.track[i].track_start);
	}
	
	printf(" %d\n", (disc.disc_length.minutes * 60) + disc.disc_length.seconds);

        return 0;
}
