mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
Fix a few minor bogons in the docs, also make it possible to execute cmds
from args, e.g. cdplay cd0 "play 1 99" if you just want to feed the CD a command and exit the cdplay utility. Note that if you want to use post-play commands like `pause' and `resume', you should still use cdplay interactively.
This commit is contained in:
parent
9bf204a77e
commit
158a4a24fa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=13461
@ -7,10 +7,16 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm cdplay
|
||||
.Op Ar device
|
||||
.Op Ar cmd
|
||||
.Sh DESCRIPTION
|
||||
.Nm cdplay
|
||||
is a program to control an audio CD player. The device is a name such
|
||||
as cd0 or mcd0.
|
||||
is a program to control an audio CD player. The
|
||||
.Ar device
|
||||
is a name such as cd0 or mcd0 and the optional
|
||||
.Ar cmd
|
||||
is one of the commands (and any arguments) from the
|
||||
.Nm
|
||||
command set. The \fBhelp\fR command will give a complete listing.
|
||||
.Pp
|
||||
If the device not specified, the environment variable
|
||||
.Ev CDPLAY
|
||||
@ -20,7 +26,8 @@ Currently supported commands are as follows:
|
||||
.Bl -tag -width Cm
|
||||
.It Cm play first_track last_track
|
||||
Play from track
|
||||
.Nm first_track to track
|
||||
.Nm first_track
|
||||
to track
|
||||
.Nm last_track.
|
||||
The first track has number 1
|
||||
.Xr play 1
|
||||
|
@ -1,14 +1,15 @@
|
||||
/* Non-X based CD player by Jean-Marc Zucconi */
|
||||
/* Modifications by Andrew A. Chernov */
|
||||
/* More modifications by Jordan Hubbard */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/cdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define command(s) strncmp(cmd,s,strlen(s))==0
|
||||
#include <unistd.h>
|
||||
|
||||
struct cd_toc_entry toc_buffer[100];
|
||||
|
||||
@ -17,32 +18,77 @@ int standalone;
|
||||
|
||||
char *cmd, *cdname;
|
||||
|
||||
int pause (), resume (), stop (), eject (), setvol (int, int),
|
||||
read_toc_header (struct ioc_toc_header *), read_toc_entry (int),
|
||||
play_msf (int, int, int, int, int, int), play_track (int, int),
|
||||
get_vol (int *, int *), status (int *, int *, int *, int *);
|
||||
void open_cd ();
|
||||
int input ();
|
||||
int cdpause (void);
|
||||
int resume (void);
|
||||
int stop (void);
|
||||
int eject (void);
|
||||
int reset (void);
|
||||
int setdebug (void);
|
||||
int clrdebug (void);
|
||||
int getvol (int *l, int *r);
|
||||
int input (void);
|
||||
int setvol (int, int);
|
||||
int read_toc_header (struct ioc_toc_header *);
|
||||
int read_toc_entrys (int);
|
||||
int play_msf (int, int, int, int, int, int);
|
||||
int play_track (int, int);
|
||||
int get_vol (int *, int *);
|
||||
int status (int *, int *, int *, int *);
|
||||
int runcmd(char *cmd);
|
||||
void open_cd (void);
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
switch (argc) {
|
||||
case 3:
|
||||
standalone = -1;
|
||||
cdname = argv[1];
|
||||
return runcmd(argv[2]);
|
||||
|
||||
case 2:
|
||||
cdname = argv[1];
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if ((cdname = getenv("CDPLAY")) != NULL)
|
||||
/* Break if CDPLAY is set */
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"Usage: cdplay <cd> [cmd]\n"
|
||||
"Where <cd> is device name such as cd0 or mcd0 and [cmd] is an\n"
|
||||
"optional command from the cdplay command set. Use `help' for a list\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
standalone = isatty (0);
|
||||
while (input()) {
|
||||
if (runcmd(cmd) == -127)
|
||||
break;
|
||||
fflush (stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define command(s) strncmp(cmd,s,strlen(s))==0
|
||||
|
||||
int
|
||||
runcmd(char *cmd)
|
||||
{
|
||||
int rc;
|
||||
|
||||
switch (argc) {
|
||||
case 2: cdname = argv[1];
|
||||
break;
|
||||
case 1: if(cdname = getenv("CDPLAY"))
|
||||
/* Break if CDPLAY is set */
|
||||
break;
|
||||
default: fprintf(stderr, "Usage: cdplay <cd>\n<cd> is device name such as cd0 or mcd0\n");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
standalone = isatty (0);
|
||||
while (input ()) {
|
||||
rc = 0;
|
||||
if (!command ("quit") && !command ("help"))
|
||||
open_cd ();
|
||||
if (command ("quit"))
|
||||
rc = -127;
|
||||
else if (command ("help")) {
|
||||
printf("play <start_trk> <end_trk>, reset, pause, resume, stop, setdebug, clrdebug\n"
|
||||
"eject, setvol <l> <r>, getvol, tochdr, msfplay <m1> <s1> <f1> <m2> <s2> <f2>,\n"
|
||||
"tocentry, status, quit, help\n");
|
||||
rc = 1;
|
||||
}
|
||||
else {
|
||||
open_cd ();
|
||||
if (command ("play")) {
|
||||
int start, end;
|
||||
sscanf (cmd+4, "%d%d", &start, &end);
|
||||
@ -62,28 +108,33 @@ main (int argc, char **argv)
|
||||
rc = clrdebug ();
|
||||
else if (command ("eject")) {
|
||||
rc = eject ();
|
||||
} else if (command ("setvol")) {
|
||||
}
|
||||
else if (command ("setvol")) {
|
||||
int l, r;
|
||||
sscanf (cmd+6, "%d %d", &l, &r);
|
||||
rc = setvol (l, r);
|
||||
} else if (command ("getvol")) {
|
||||
}
|
||||
else if (command ("getvol")) {
|
||||
int r, l;
|
||||
rc = getvol (&l, &r);
|
||||
if (rc > -1)
|
||||
printf ("%d %d\n", l, r);
|
||||
} else if (command ("tochdr")) {
|
||||
}
|
||||
else if (command ("tochdr")) {
|
||||
struct ioc_toc_header h;
|
||||
rc = read_toc_header (&h);
|
||||
if (rc > -1) {
|
||||
if (standalone)
|
||||
printf("start end length\n");
|
||||
printf("start end length\n");
|
||||
printf ("%d %d %d\n", h.starting_track, h.ending_track, h.len);
|
||||
}
|
||||
} else if (command ("msfplay")) {
|
||||
}
|
||||
else if (command ("msfplay")) {
|
||||
int m1, m2, s1, s2, f1, f2;
|
||||
sscanf(cmd+7, "%d%d%d%d%d%d", &m1, &s1, &f1, &m2, &s2, &f2);
|
||||
rc = play_msf (m1, s1, f1, m2, s2, f2);
|
||||
} else if (command ("tocentry")) {
|
||||
}
|
||||
else if (command ("tocentry")) {
|
||||
struct ioc_toc_header h;
|
||||
int i, n;
|
||||
rc = read_toc_header (&h);
|
||||
@ -96,32 +147,31 @@ main (int argc, char **argv)
|
||||
for (i = 0; i <= n; i++)
|
||||
printf ("%5d %6d %6d %5d\n", toc_buffer[i].track, toc_buffer[i].addr.msf.minute,
|
||||
toc_buffer[i].addr.msf.second, toc_buffer[i].addr.msf.frame);
|
||||
}
|
||||
} else if (command ("status")) {
|
||||
}
|
||||
}
|
||||
else if (command ("status")) {
|
||||
int trk, m, s, f;
|
||||
rc = status (&trk, &m, &s, &f);
|
||||
if (standalone)
|
||||
printf("status track minute second frame\n");
|
||||
printf ("%d %02d %d %d %d\n", rc, trk, m, s, f);
|
||||
} else if (command("quit"))
|
||||
break;
|
||||
else if (command("help"))
|
||||
printf(
|
||||
"play <start_trk> <end_trk>, reset, pause, resume, stop, setdebug, clrdebug,\n\
|
||||
eject, setvol <l> <r>, getvol, tochdr, msfplay <m1> <s1> <f1> <m2> <s2> <f2>,\n\
|
||||
tocentry, status, quit, help\n");
|
||||
else
|
||||
printf("No such command, enter 'help' for commands list\n");
|
||||
fflush (stdout);
|
||||
}
|
||||
else {
|
||||
printf("No such command, enter 'help' for command list\n");
|
||||
rc = 1;
|
||||
}
|
||||
if (rc < 0) {
|
||||
if (standalone)
|
||||
perror("cdplay");
|
||||
}
|
||||
if (standalone < 0 || rc < 0) {
|
||||
close (cd_fd);
|
||||
cd_fd = -1;
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
play_track (int start, int end)
|
||||
{
|
||||
@ -133,42 +183,50 @@ play_track (int start, int end)
|
||||
t.end_index = 1;
|
||||
return ioctl (cd_fd, CDIOCPLAYTRACKS, &t);
|
||||
}
|
||||
|
||||
int
|
||||
reset ()
|
||||
{
|
||||
return ioctl (cd_fd, CDIOCRESET);
|
||||
}
|
||||
|
||||
int
|
||||
cdpause ()
|
||||
{
|
||||
return ioctl (cd_fd, CDIOCPAUSE);
|
||||
}
|
||||
|
||||
int
|
||||
setdebug ()
|
||||
{
|
||||
return (ioctl (cd_fd, CDIOCSETDEBUG));
|
||||
}
|
||||
|
||||
int
|
||||
clrdebug ()
|
||||
{
|
||||
return (ioctl (cd_fd, CDIOCCLRDEBUG));
|
||||
}
|
||||
|
||||
int
|
||||
resume ()
|
||||
{
|
||||
return (ioctl (cd_fd, CDIOCRESUME));
|
||||
}
|
||||
|
||||
int
|
||||
stop ()
|
||||
{
|
||||
return ioctl (cd_fd, CDIOCSTOP);
|
||||
}
|
||||
|
||||
int
|
||||
eject ()
|
||||
{
|
||||
(void) ioctl (cd_fd, CDIOCALLOW);
|
||||
return ioctl (cd_fd, CDIOCEJECT);
|
||||
}
|
||||
|
||||
int
|
||||
setvol (int l, int r)
|
||||
{
|
||||
@ -180,6 +238,7 @@ setvol (int l, int r)
|
||||
v.vol[3] = 0;
|
||||
return ioctl (cd_fd, CDIOCSETVOL, &v);
|
||||
}
|
||||
|
||||
int
|
||||
getvol (int *l, int *r)
|
||||
{
|
||||
@ -190,11 +249,13 @@ getvol (int *l, int *r)
|
||||
*r = v.vol[1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
read_toc_header (struct ioc_toc_header *h)
|
||||
{
|
||||
return ioctl (cd_fd, CDIOREADTOCHEADER, (char *) h);
|
||||
}
|
||||
|
||||
int
|
||||
read_toc_entrys (int len)
|
||||
{
|
||||
@ -206,6 +267,7 @@ read_toc_entrys (int len)
|
||||
t.data = toc_buffer;
|
||||
return ioctl (cd_fd, CDIOREADTOCENTRYS, (char *) &t);
|
||||
}
|
||||
|
||||
int
|
||||
play_msf (int start_m, int start_s, int start_f,
|
||||
int end_m, int end_s, int end_f)
|
||||
@ -220,6 +282,7 @@ play_msf (int start_m, int start_s, int start_f,
|
||||
a.end_f = end_f;
|
||||
return ioctl (cd_fd, CDIOCPLAYMSF, (char *) &a);
|
||||
}
|
||||
|
||||
int
|
||||
status (int *trk, int *min, int *sec, int *frame)
|
||||
{
|
||||
@ -256,6 +319,7 @@ input ()
|
||||
cmd[l-1] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
open_cd ()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user