summaryrefslogtreecommitdiff
path: root/usr.bin/cdio
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2002-04-18 20:18:32 +0000
committerMarc Espie <espie@cvs.openbsd.org>2002-04-18 20:18:32 +0000
commit76d219f65638843ff161b03f55f0f64a65b1fbda (patch)
treeeb87dd023c9bbf85ff56e1b3e5752f3b0a995c6e /usr.bin/cdio
parent8541d4cea4eb18bff6178b24db7e8107d3c8b7a5 (diff)
Add cddb support.
Diffstat (limited to 'usr.bin/cdio')
-rw-r--r--usr.bin/cdio/Makefile4
-rw-r--r--usr.bin/cdio/cddb.c372
-rw-r--r--usr.bin/cdio/cdio.112
-rw-r--r--usr.bin/cdio/cdio.c238
-rw-r--r--usr.bin/cdio/extern.h34
5 files changed, 571 insertions, 89 deletions
diff --git a/usr.bin/cdio/Makefile b/usr.bin/cdio/Makefile
index d185d9c4c9c..24effdf9d96 100644
--- a/usr.bin/cdio/Makefile
+++ b/usr.bin/cdio/Makefile
@@ -1,7 +1,9 @@
-# $OpenBSD: Makefile,v 1.1 1996/08/23 23:42:28 downsj Exp $
+# $OpenBSD: Makefile,v 1.2 2002/04/18 20:18:31 espie Exp $
PROG= cdio
DPADD= ${LIBUTIL}
LDADD= -lutil
+SRCS= cdio.c cddb.c
+CDIAGFLAGS=-Wall -W -Wmissing-prototypes -pedantic
.include <bsd.prog.mk>
diff --git a/usr.bin/cdio/cddb.c b/usr.bin/cdio/cddb.c
new file mode 100644
index 00000000000..01d2025f720
--- /dev/null
+++ b/usr.bin/cdio/cddb.c
@@ -0,0 +1,372 @@
+/* $OpenBSD $*/
+/*
+ * Copyright (c) 2002 Marc Espie.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
+ * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/cdio.h>
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <vis.h>
+#include "extern.h"
+
+unsigned long cddb_discid(int, struct cd_toc_entry *);
+unsigned long cddb_sum(unsigned long);
+void send_hello(FILE *);
+void send_query(FILE *, int, struct cd_toc_entry *);
+int further_query(FILE *, char *);
+int connect_to(const char *, const char *);
+int parse_connect_to(const char *, const char *);
+char * get_line(FILE *);
+char * get_answer(FILE *);
+void verify_track_names(char **, int, struct cd_toc_entry *);
+char * safe_copy(const char *);
+
+unsigned long
+cddb_sum(unsigned long v)
+{
+ unsigned long sum = 0;
+
+ while (v > 0) {
+ sum += v % 10;
+ v /= 10;
+ }
+ return (sum);
+}
+
+unsigned long
+cddb_discid(int n, struct cd_toc_entry *e)
+{
+ unsigned long sum;
+ int i;
+
+ sum = 0;
+ for (i =0; i < n; i++)
+ sum += cddb_sum(entry2time(e+i));
+ return (((sum % 0xff) << 24) |
+ ((entry2time(e+n) - entry2time(e)) << 8) | n);
+}
+
+void
+send_hello(FILE *cout)
+{
+ char hostname[MAXHOSTNAMELEN];
+
+ if (gethostname(hostname, sizeof(hostname)) == -1)
+ strcpy(hostname, "unknown");
+ fprintf(cout, "CDDB HELLO %s %s cdio " VERSION "\r\n",
+ getlogin(), hostname);
+ fflush(cout);
+}
+
+void
+send_query(FILE *f, int n, struct cd_toc_entry *e)
+{
+ int i;
+
+ fprintf(f, "cddb query %8lx %d", cddb_discid(n, e), n);
+ for (i = 0; i < n; i++)
+ fprintf(f, " %lu", entry2frames(e+i));
+ fprintf(f, " %lu\r\n", (entry2frames(e+n)-entry2frames(e)) /75);
+}
+
+#define MAXSIZE 256
+char copy_buffer[MAXSIZE];
+
+char *
+safe_copy(const char *title)
+{
+ strnvis(copy_buffer, title, MAXSIZE-1, VIS_TAB|VIS_NL);
+ return strdup(copy_buffer);
+}
+
+int
+further_query(FILE *cout, char *line)
+{
+ char *key;
+ char *title;
+
+ key = strchr(line, ' ');
+ if (!key)
+ return 0;
+ *key++ = 0;
+ title = strchr(key, ' ');
+ if (!title)
+ return 0;
+ *title++ = 0;
+ strnvis(copy_buffer, title, MAXSIZE-1, VIS_TAB|VIS_NL);
+ printf("%s", copy_buffer);
+ strnvis(copy_buffer, line, MAXSIZE-1, VIS_TAB|VIS_NL);
+ printf("(%s)\n", copy_buffer);
+ fprintf(cout, "CDDB READ %s %s\r\n", line, key);
+ fflush(cout);
+ return 1;
+}
+
+
+int
+connect_to(const char *host, const char *serv)
+{
+ int s = -1;
+ struct addrinfo hints, *res0 = NULL, *res;
+ int error;
+
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
+ error = getaddrinfo(host, serv, &hints, &res0);
+ if (error) {
+ warnx("%s", gai_strerror(error));
+ return -1;
+ }
+
+ for (res = res0; res; res = res->ai_next) {
+ s = socket(res->ai_family, res->ai_socktype,
+ res->ai_protocol);
+ if (s == -1)
+ continue;
+ if (connect(s, res->ai_addr, res->ai_addrlen) == -1) {
+ close(s);
+ s = -1;
+ continue;
+ }
+ break;
+ }
+ if (s == -1)
+ warn("cddb");
+ freeaddrinfo(res0);
+ return s;
+}
+
+int
+parse_connect_to(const char *host_port, const char *port)
+{
+ int s;
+ char *last, *host;
+
+ host = (char *)host_port;
+
+ last = strrchr(host_port, ':');
+ if (last != 0 && !(last != host && last[-1] == ':')) {
+ port = last + 1;
+ host = malloc(last - host_port + 1);
+ if (!host)
+ return -1;
+ memcpy(host, host_port, last-host_port);
+ host[last-host_port] = 0;
+ }
+ s = connect_to(host, port);
+ if (host != host_port)
+ free(host);
+ return s;
+}
+
+char *
+get_line(FILE *cin)
+{
+ char *line;
+ size_t len;
+
+ line = fgetln(cin, &len);
+ if (!line)
+ return NULL;
+ if (len == 0)
+ return NULL;
+ if (line[len-1] == '\n')
+ line[--len] = 0;
+ if (len != 0 && line[len-1] == '\r')
+ line[--len] = 0;
+ return line;
+}
+
+char *
+get_answer(FILE *cin)
+{
+ char *line;
+
+ line = get_line(cin);
+ if (*line != '2')
+ return NULL;
+ else
+ return line;
+}
+
+void
+verify_track_names(char **names, int n, struct cd_toc_entry *e)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (names[i] == 0)
+ names[i] = strdup(e->control & 4 ? "data" : "audio");
+ }
+}
+
+char **
+cddb(const char *host_port, int n, struct cd_toc_entry *e, char *arg)
+{
+ int s = -1;
+ FILE *cin = NULL;
+ FILE *cout = NULL;
+ char *type;
+ char *line;
+ char **result = NULL;
+ int i;
+
+ s = parse_connect_to(host_port, "cddb");
+ if (s == -1)
+ goto end;
+ cin = fdopen(s, "r");
+ if (!cin) {
+ warn("cddb: fdopen");
+ goto end;
+ }
+ cout = fdopen(s, "w");
+ s = -1;
+ if (!cout) {
+ warn("cddb: fdopen");
+ goto end;
+ }
+ line = get_answer(cin);
+ if (!line) {
+ warnx("cddb: won't talk to us");
+ goto end;
+ }
+
+ send_hello(cout);
+ line = get_answer(cin);
+ if (!line) {
+ warnx("cddb: problem in hello");
+ goto end;
+ }
+
+ send_query(cout, n, e);
+ fflush(cout);
+ line = get_answer(cin);
+ if (!line) {
+ warnx("cddb: problem in query");
+ goto end;
+ }
+ type = strchr(line, ' ');
+ if (!type)
+ goto end;
+ *type++ = 0;
+ /* no match or other issue */
+ if (strcmp(line, "202") == 0) {
+ printf("cddb: No match in database\n");
+ goto end;
+ }
+ if (strcmp(line, "211") == 0 || strcmp(line, "212") == 0) {
+ int number = atoi(arg);
+ if (number == 0) {
+ if (strcmp(line, "211") == 0)
+ printf("cddb: multiple matches\n");
+ else {
+ printf("cddb: inexact match\n");
+ number = 1;
+ }
+ }
+ if (number == 0) {
+ for (i = 1;; i++) {
+ line = get_line(cin);
+ if (strcmp(line, ".") == 0)
+ goto end;
+ printf("%d: %s\n", i, line);
+ }
+ } else {
+ int ok = 0;
+
+ for (i = 1;; i++) {
+ line = get_line(cin);
+ if (!line)
+ break;
+ if (strcmp(line, ".") == 0)
+ break;
+ if (i == number)
+ ok = further_query(cout, line);
+ }
+ if (!ok)
+ goto end;
+ }
+ } else if (strcmp(line, "200") != 0 || !further_query(cout, type))
+ goto end;
+ result = malloc(sizeof(char *) * n+1);
+ if (!result)
+ goto end;
+ for (i = 0; i <= n; i++)
+ result[i] = NULL;
+ line = get_answer(cin);
+ if (!line)
+ goto end2;
+ for (;;) {
+ long k;
+ char *end;
+
+ line = get_line(cin);
+ if (!line)
+ goto end2;
+ if (strcmp(line, ".") == 0)
+ goto end;
+ if (strncmp(line, "TTITLE", 6) != 0)
+ continue;
+ line += 6;
+ k = strtol(line, &end, 10);
+ if (*end++ != '=')
+ continue;
+ if (k >= n)
+ continue;
+ result[k] = safe_copy(end);
+ }
+ fprintf(cout, "QUIT\r\n");
+ verify_track_names(result, n, e);
+ goto end;
+end2:
+ free(result);
+ result = NULL;
+end:
+ if (cout)
+ fclose(cout);
+ if (cin)
+ fclose(cin);
+ if (s != -1)
+ close(s);
+ return result;
+}
+
+void
+free_names(char **names)
+{
+ int i;
+
+ for (i = 0; names[i]; i++)
+ free(names[i]);
+ free(names);
+}
diff --git a/usr.bin/cdio/cdio.1 b/usr.bin/cdio/cdio.1
index 65ad3ccfeaa..3b0eabd0ffd 100644
--- a/usr.bin/cdio/cdio.1
+++ b/usr.bin/cdio/cdio.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cdio.1,v 1.22 2001/08/17 11:13:58 mpech Exp $
+.\" $OpenBSD: cdio.1,v 1.23 2002/04/18 20:18:31 espie Exp $
.\"
.Dd July 3, 1995
.Dt CDIO 1
@@ -9,6 +9,7 @@
.Sh SYNOPSIS
.Nm cdio
.Op Fl sv
+.Op Fl d Ar host:port
.Op Fl f Ar device
.Op Ar command args ...
.Sh DESCRIPTION
@@ -41,6 +42,8 @@ Do not print table headers or human-readable comments.
.It Fl v
Verbose mode.
Print as much information as possible.
+.It Fl d Ar host:port
+Specifies cddb host.
.It Fl f Ar device
Specifies a device name such as
.Pa /dev/rcd0d
@@ -129,6 +132,10 @@ Play the left subtrack on both left and right channels.
Play the right subtrack on both left and right channels.
.It Ic info
Print the table of contents.
+.It Ic cddb Op Ar n
+Print the table of contents after matching the disc with the cddb.
+In case of multiple matches, reissue the command with
+.Ar n
.It Ic status
Print information about the disc:
the current playing status and position,
@@ -164,7 +171,8 @@ Quit the program.
.Sh AUTHORS
Jean-Marc Zucconi,
Andrey A.\ Chernov,
-Serge V.\ Vakulenko
+Serge V.\ Vakulenko,
+Marc Espie
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c
index ed77d9b4592..82454ddc13b 100644
--- a/usr.bin/cdio/cdio.c
+++ b/usr.bin/cdio/cdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cdio.c,v 1.23 2002/03/22 03:43:37 espie Exp $ */
+/* $OpenBSD: cdio.c,v 1.24 2002/04/18 20:18:31 espie Exp $ */
/*
* Compact Disc Control Utility by Serge V. Vakulenko <vak@cronyx.ru>.
* Based on the non-X based CD player by Jean-Marc Zucconi and
@@ -34,8 +34,8 @@
#include <sys/file.h>
#include <sys/cdio.h>
#include <sys/ioctl.h>
+#include "extern.h"
-#define VERSION "2.0"
#define ASTS_INVALID 0x00 /* Audio status byte not valid */
#define ASTS_PLAYING 0x11 /* Audio play operation in progress */
@@ -66,11 +66,12 @@
#define CMD_NEXT 16
#define CMD_PREV 17
#define CMD_REPLAY 18
+#define CMD_CDDB 19
struct cmdtab {
int command;
char *name;
- unsigned min;
+ unsigned int min;
char *args;
} cmdtab[] = {
{ CMD_CLOSE, "close", 1, "" },
@@ -95,7 +96,8 @@ struct cmdtab {
{ CMD_STATUS, "status", 1, "" },
{ CMD_STOP, "stop", 3, "" },
{ CMD_VOLUME, "volume", 1, "<l> <r> | left | right | mute | mono | stereo" },
-{ 0, }
+{ CMD_CDDB, "cddbinfo", 2, "[n]" },
+{ 0, 0, 0, 0}
};
struct cd_toc_entry *toc_buffer;
@@ -104,6 +106,8 @@ char *cdname;
int fd = -1;
int verbose = 1;
int msf = 1;
+const char *cddb_host;
+char **track_names;
extern char *__progname;
@@ -116,12 +120,13 @@ int status(int *, int *, int *, int *);
int open_cd(char *);
int play(char *arg);
int info(char *arg);
+int cddbinfo(char *arg);
int pstatus(char *arg);
int play_next(char *arg);
int play_prev(char *arg);
int play_same(char *arg);
char *input(int *);
-void prtrack(struct cd_toc_entry *e, int lastflag);
+void prtrack(struct cd_toc_entry *e, int lastflag, char *name);
void lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f);
unsigned int msf2lba(u_char m, u_char s, u_char f);
int play_blocks(int blk, int len);
@@ -166,9 +171,7 @@ usage()
}
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int cmd;
char *arg;
@@ -177,8 +180,12 @@ main(argc, argv)
if (! cdname)
cdname = getenv("CDROM");
+ cddb_host = getenv("CDDB");
+ if (!cddb_host)
+ cddb_host = "freedb.freedb.org";
+
for (;;) {
- switch (getopt(argc, argv, "svf:")) {
+ switch (getopt(argc, argv, "svd:f:")) {
case -1:
break;
case 's':
@@ -190,6 +197,9 @@ main(argc, argv)
case 'f':
cdname = optarg;
continue;
+ case 'd':
+ cddb_host = optarg;
+ continue;
default:
usage();
}
@@ -249,9 +259,7 @@ main(argc, argv)
}
int
-run(cmd, arg)
- int cmd;
- char *arg;
+run(int cmd, char *arg)
{
int l, r, rc;
static char newcdname[MAXPATHLEN];
@@ -267,6 +275,12 @@ run(cmd, arg)
return info(arg);
+ case CMD_CDDB:
+ if (fd < 0 && ! open_cd(cdname))
+ return (0);
+
+ return cddbinfo(arg);
+
case CMD_STATUS:
if (fd < 0 && ! open_cd(cdname))
return (0);
@@ -347,6 +361,9 @@ run(cmd, arg)
close(fd);
fd = -1;
#endif
+ if (track_names)
+ free_names(track_names);
+ track_names = NULL;
return (0);
case CMD_CLOSE:
@@ -436,8 +453,7 @@ run(cmd, arg)
}
int
-play(arg)
- char *arg;
+play(char *arg)
{
struct ioc_toc_header h;
int rc, n, start, end = 0, istart = 1, iend = 1;
@@ -488,8 +504,8 @@ play(arg)
*
* tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]
*/
- unsigned tr1, tr2;
- unsigned m1, m2, s1, s2, f1, f2;
+ int tr1, tr2;
+ unsigned int m1, m2, s1, s2, f1, f2;
unsigned char tm, ts, tf;
tr2 = m2 = s2 = f2 = f1 = 0;
@@ -557,7 +573,7 @@ play(arg)
goto Try_Absolute_Timed_Addresses;
Play_Relative_Addresses:
- if (! tr1)
+ if (tr1 <= 0)
tr1 = 1;
else if (tr1 > n)
tr1 = n;
@@ -594,7 +610,7 @@ Play_Relative_Addresses:
m1 += tm;
- if (! tr2) {
+ if (tr2 <= 0) {
if (m2 || s2 || f2) {
tr2 = tr1;
f2 += f1;
@@ -717,8 +733,7 @@ Clean_up:
}
int
-play_prev(arg)
- char *arg;
+play_prev(char *arg)
{
int trk, min, sec, frm, rc;
struct ioc_toc_header h;
@@ -742,8 +757,7 @@ play_prev(arg)
}
int
-play_same(arg)
- char *arg;
+play_same(char *arg)
{
int trk, min, sec, frm, rc;
struct ioc_toc_header h;
@@ -762,8 +776,7 @@ play_same(arg)
}
int
-play_next(arg)
- char *arg;
+play_next(char *arg)
{
int trk, min, sec, frm, rc;
struct ioc_toc_header h;
@@ -793,8 +806,7 @@ play_next(arg)
}
char *
-strstatus(sts)
- int sts;
+strstatus(int sts)
{
switch (sts) {
case ASTS_INVALID:
@@ -815,8 +827,7 @@ strstatus(sts)
}
int
-pstatus(arg)
- char *arg;
+pstatus(char *arg)
{
struct ioc_vol v;
struct ioc_read_subchannel ss;
@@ -826,10 +837,19 @@ pstatus(arg)
rc = status(&trk, &m, &s, &f);
if (rc >= 0) {
- if (verbose)
- printf("Audio status = %d<%s>, current track = %d, current position = %d:%02d.%02d\n",
- rc, strstatus(rc), trk, m, s, f);
- else
+ if (verbose) {
+ if (track_names)
+ printf("Audio status = %d<%s>, "
+ "current track = %d (%s)\n"
+ "\tcurrent position = %d:%02d.%02d\n",
+ rc, strstatus(rc), trk,
+ trk ? track_names[trk-1] : "", m, s, f);
+ else
+ printf("Audio status = %d<%s>, "
+ "current track = %d, "
+ "current position = %d:%02d.%02d\n",
+ rc, strstatus(rc), trk, m, s, f);
+ } else
printf("%d %d %d:%02d.%02d\n", rc, trk, m, s, f);
} else
printf("No current status info available\n");
@@ -867,8 +887,7 @@ pstatus(arg)
}
int
-info(arg)
- char *arg;
+info(char *arg)
{
struct ioc_toc_header h;
int rc, i, n;
@@ -898,19 +917,51 @@ info(arg)
for (i = 0; i < n; i++) {
printf("%5d ", toc_buffer[i].track);
- prtrack(toc_buffer + i, 0);
+ prtrack(toc_buffer + i, 0, NULL);
}
printf("%5d ", toc_buffer[n].track);
- prtrack(toc_buffer + n, 1);
+ prtrack(toc_buffer + n, 1, NULL);
+ return (0);
+}
+
+int
+cddbinfo(char *arg)
+{
+ struct ioc_toc_header h;
+ int rc, i, n;
+
+ rc = ioctl(fd, CDIOREADTOCHEADER, &h);
+ if (rc == -1) {
+ warn("getting toc header");
+ return (rc);
+ }
+
+ n = h.ending_track - h.starting_track + 1;
+ rc = read_toc_entrys((n + 1) * sizeof (struct cd_toc_entry));
+ if (rc < 0)
+ return (rc);
+
+ if (track_names)
+ free_names(track_names);
+ track_names = NULL;
+
+ track_names = cddb(cddb_host, n, toc_buffer, arg);
+ if (!track_names)
+ return(0);
+
+ printf("-------------------------------------------------\n");
+
+ for (i = 0; i < n; i++) {
+ printf("%5d ", toc_buffer[i].track);
+ prtrack(toc_buffer + i, 0, track_names[i]);
+ }
+ printf("%5d ", toc_buffer[n].track);
+ prtrack(toc_buffer + n, 1, "");
return (0);
}
void
-lba2msf(lba, m, s, f)
- unsigned long lba;
- u_char *m;
- u_char *s;
- u_char *f;
+lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f)
{
lba += 150; /* block start offset */
lba &= 0xffffff; /* negative lbas use only 24 bits */
@@ -926,30 +977,65 @@ msf2lba(u_char m, u_char s, u_char f)
return (((m * 60) + s) * 75 + f) - 150;
}
+unsigned long
+entry2time(struct cd_toc_entry *e)
+{
+ int block;
+ u_char m, s, f;
+
+ if (msf) {
+ return (e->addr.msf.minute * 60 + e->addr.msf.second);
+ } else {
+ block = ntohl(e->addr.lba);
+ lba2msf(block, &m, &s, &f);
+ return (m*60+s);
+ }
+}
+
+unsigned long
+entry2frames(struct cd_toc_entry *e)
+{
+ int block;
+ unsigned char m, s, f;
+
+ if (msf) {
+ return e->addr.msf.frame + e->addr.msf.second * 75 +
+ e->addr.msf.minute * 60 * 75;
+ } else {
+ block = ntohl(e->addr.lba);
+ lba2msf(block, &m, &s, &f);
+ return f + s * 75 + m * 60 * 75;
+ }
+}
+
void
-prtrack(e, lastflag)
- struct cd_toc_entry *e;
- int lastflag;
+prtrack(struct cd_toc_entry *e, int lastflag, char *name)
{
int block, next, len;
u_char m, s, f;
if (msf) {
- /* Print track start */
- printf("%2d:%02d.%02d ", e->addr.msf.minute,
- e->addr.msf.second, e->addr.msf.frame);
+ if (!name || lastflag)
+ /* Print track start */
+ printf("%2d:%02d.%02d ", e->addr.msf.minute,
+ e->addr.msf.second, e->addr.msf.frame);
block = msf2lba(e->addr.msf.minute, e->addr.msf.second,
e->addr.msf.frame);
} else {
block = ntohl(e->addr.lba);
- lba2msf(block, &m, &s, &f);
- /* Print track start */
- printf("%2d:%02d.%02d ", m, s, f);
+ if (!name || lastflag) {
+ lba2msf(block, &m, &s, &f);
+ /* Print track start */
+ printf("%2d:%02d.%02d ", m, s, f);
+ }
}
if (lastflag) {
- /* Last track -- print block */
- printf(" - %6d - -\n", block);
+ if (!name)
+ /* Last track -- print block */
+ printf(" - %6d - -\n", block);
+ else
+ printf("\n");
return;
}
@@ -961,17 +1047,16 @@ prtrack(e, lastflag)
len = next - block;
lba2msf(len, &m, &s, &f);
+ if (name)
+ printf("%2d:%02d.%02d %s\n", m, s, f, name);
/* Print duration, block, length, type */
- printf("%2d:%02d.%02d %6d %6d %5s\n", m, s, f, block, len,
- (e->control & 4) ? "data" : "audio");
+ else
+ printf("%2d:%02d.%02d %6d %6d %5s\n", m, s, f, block, len,
+ (e->control & 4) ? "data" : "audio");
}
int
-play_track(tstart, istart, tend, iend)
- int tstart;
- int istart;
- int tend;
- int iend;
+play_track(int tstart, int istart, int tend, int iend)
{
struct ioc_play_track t;
@@ -984,9 +1069,7 @@ play_track(tstart, istart, tend, iend)
}
int
-play_blocks(blk, len)
- int blk;
- int len;
+play_blocks(int blk, int len)
{
struct ioc_play_blocks t;
@@ -997,9 +1080,7 @@ play_blocks(blk, len)
}
int
-setvol(left, right)
- int left;
- int right;
+setvol(int left, int right)
{
struct ioc_vol v;
@@ -1012,8 +1093,7 @@ setvol(left, right)
}
int
-read_toc_entrys(len)
- int len;
+read_toc_entrys(int len)
{
struct ioc_read_toc_entry t;
@@ -1038,13 +1118,7 @@ read_toc_entrys(len)
}
int
-play_msf(start_m, start_s, start_f, end_m, end_s, end_f)
- int start_m;
- int start_s;
- int start_f;
- int end_m;
- int end_s;
- int end_f;
+play_msf(int start_m, int start_s, int start_f, int end_m, int end_s, int end_f)
{
struct ioc_play_msf a;
@@ -1059,11 +1133,7 @@ play_msf(start_m, start_s, start_f, end_m, end_s, end_f)
}
int
-status(trk, min, sec, frame)
- int *trk;
- int *min;
- int *sec;
- int *frame;
+status(int *trk, int *min, int *sec, int *frame)
{
struct ioc_read_subchannel s;
struct cd_sub_channel_info data;
@@ -1095,8 +1165,7 @@ status(trk, min, sec, frame)
}
char *
-input(cmd)
- int *cmd;
+input(int *cmd)
{
static char buf[80];
char *p;
@@ -1115,9 +1184,7 @@ input(cmd)
}
char *
-parse(buf, cmd)
- char *buf;
- int *cmd;
+parse(char *buf, int *cmd)
{
struct cmdtab *c;
char *p;
@@ -1177,8 +1244,7 @@ parse(buf, cmd)
}
int
-open_cd(dev)
- char *dev;
+open_cd(char *dev)
{
char *realdev;
int tries;
diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h
new file mode 100644
index 00000000000..da36276f2b2
--- /dev/null
+++ b/usr.bin/cdio/extern.h
@@ -0,0 +1,34 @@
+/* $OpenBSD $*/
+/*
+ * Copyright (c) 2002 Marc Espie.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
+ * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+struct cd_toc_entry;
+
+extern unsigned long entry2time(struct cd_toc_entry *);
+extern unsigned long entry2frames(struct cd_toc_entry *);
+extern char ** cddb(const char *, int, struct cd_toc_entry *, char *);
+extern void free_names(char **);
+
+#define VERSION "2.1"