2 * Compact Disc Control Utility by Serge V. Vakulenko <vak@cronyx.ru>.
3 * Based on the non-X based CD player by Jean-Marc Zucconi and
6 * Fixed and further modified on 5-Sep-1995 by Jukka Ukkonen <jau@funet.fi>.
8 * 11-Sep-1995: Jukka A. Ukkonen <jau@funet.fi>
9 * A couple of further fixes to my own earlier "fixes".
11 * 18-Sep-1995: Jukka A. Ukkonen <jau@funet.fi>
12 * Added an ability to specify addresses relative to the
13 * beginning of a track. This is in fact a variation of
14 * doing the simple play_msf() call.
16 * 11-Oct-1995: Serge V.Vakulenko <vak@cronyx.ru>
17 * New eject algorithm.
18 * Some code style reformatting.
22 static const char rcsid[] =
28 #include <sys/ioctl.h>
29 #include <sys/param.h>
43 #define ASTS_INVALID 0x00 /* Audio status byte not valid */
44 #define ASTS_PLAYING 0x11 /* Audio play operation in progress */
45 #define ASTS_PAUSED 0x12 /* Audio play operation paused */
46 #define ASTS_COMPLETED 0x13 /* Audio play operation successfully completed */
47 #define ASTS_ERROR 0x14 /* Audio play operation stopped due to error */
48 #define ASTS_VOID 0x15 /* No current audio status to return */
50 #ifndef DEFAULT_CD_DRIVE
51 # define DEFAULT_CD_DRIVE "/dev/cd0c"
54 #ifndef DEFAULT_CD_PARTITION
55 # define DEFAULT_CD_PARTITION "c"
74 #define CMD_PREVIOUS 17
75 #define STATUS_AUDIO 0x1
76 #define STATUS_MEDIA 0x2
77 #define STATUS_VOLUME 0x4
85 { CMD_CLOSE, "close", 1, "" },
86 { CMD_DEBUG, "debug", 1, "on | off" },
87 { CMD_EJECT, "eject", 1, "" },
88 { CMD_HELP, "?", 1, 0 },
89 { CMD_HELP, "help", 1, "" },
90 { CMD_INFO, "info", 1, "" },
91 { CMD_NEXT, "next", 1, "" },
92 { CMD_PAUSE, "pause", 2, "" },
93 { CMD_PLAY, "play", 1, "min1:sec1[.fram1] [min2:sec2[.fram2]]" },
94 { CMD_PLAY, "play", 1, "track1[.index1] [track2[.index2]]" },
95 { CMD_PLAY, "play", 1, "tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]" },
96 { CMD_PLAY, "play", 1, "[#block [len]]" },
97 { CMD_PREVIOUS, "previous", 2, "" },
98 { CMD_QUIT, "quit", 1, "" },
99 { CMD_RESET, "reset", 4, "" },
100 { CMD_RESUME, "resume", 1, "" },
101 { CMD_SET, "set", 2, "msf | lba" },
102 { CMD_STATUS, "status", 1, "[audio | media | volume]" },
103 { CMD_STOP, "stop", 3, "" },
104 { CMD_VOLUME, "volume", 1, "<l> <r> | left | right | mute | mono | stereo" },
105 { CMD_CDID, "cdid", 2, "" },
109 struct cd_toc_entry toc_buffer[100];
116 int setvol __P((int, int));
117 int read_toc_entrys __P((int));
118 int play_msf __P((int, int, int, int, int, int));
119 int play_track __P((int, int, int, int));
120 int get_vol __P((int *, int *));
121 int status __P((int *, int *, int *, int *));
122 int open_cd __P((void));
123 int next_prev __P((char *arg, int));
124 int play __P((char *arg));
125 int info __P((char *arg));
126 int cdid __P((void));
127 int pstatus __P((char *arg));
128 char *input __P((int *));
129 void prtrack __P((struct cd_toc_entry *e, int lastflag));
130 void lba2msf __P((unsigned long lba,
131 u_char *m, u_char *s, u_char *f));
132 unsigned int msf2lba __P((u_char m, u_char s, u_char f));
133 int play_blocks __P((int blk, int len));
134 int run __P((int cmd, char *arg));
135 char *parse __P((char *buf, int *cmd));
136 void help __P((void));
137 void usage __P((void));
138 char *use_cdrom_instead __P((const char *));
139 __const char *strstatus __P((int));
140 static u_int dbprog_discid __P((void));
141 __const char *cdcontrol_prompt __P((void));
150 for (c=cmdtab; c->name; ++c) {
154 for (i = c->min, s = c->name; *s; s++, i--) {
162 printf (" %s", c->args);
165 printf ("\n\tThe word \"play\" is not required for the play commands.\n");
166 printf ("\tThe plain target address is taken as a synonym for play.\n");
171 fprintf (stderr, "usage: cdcontrol [-sv] [-f device] [command ...]\n");
175 char *use_cdrom_instead(const char *old_envvar)
179 device = getenv(old_envvar);
181 warnx("%s environment variable deprecated, "
182 "please use CDROM in the future.", old_envvar);
187 int main (int argc, char **argv)
193 switch (getopt (argc, argv, "svhf:")) {
214 if (argc > 0 && ! strcasecmp (*argv, "help"))
218 cdname = getenv("CDROM");
222 cdname = use_cdrom_instead("MUSIC_CD");
224 cdname = use_cdrom_instead("CD_DRIVE");
226 cdname = use_cdrom_instead("DISC");
228 cdname = use_cdrom_instead("CDPLAY");
231 cdname = DEFAULT_CD_DRIVE;
232 warnx("no CD device name specified, defaulting to %s", cdname);
239 for (p=buf; argc-->0; ++argv) {
240 len = strlen (*argv);
242 if (p + len >= buf + sizeof (buf) - 1)
252 arg = parse (buf, &cmd);
253 return (run (cmd, arg));
257 verbose = isatty (0);
260 printf ("Compact Disc Control utility, version %s\n", VERSION);
261 printf ("Type `?' for command list\n\n");
266 if (run (cmd, arg) < 0) {
276 int run (int cmd, char *arg)
286 if (fd < 0 && ! open_cd ())
292 if (fd < 0 && ! open_cd ())
298 if (fd < 0 && ! open_cd ())
301 return pstatus (arg);
305 if (fd < 0 && ! open_cd ())
308 while (isspace (*arg))
311 return next_prev (arg, cmd);
314 if (fd < 0 && ! open_cd ())
317 return ioctl (fd, CDIOCPAUSE);
320 if (fd < 0 && ! open_cd ())
323 return ioctl (fd, CDIOCRESUME);
326 if (fd < 0 && ! open_cd ())
329 rc = ioctl (fd, CDIOCSTOP);
331 (void) ioctl (fd, CDIOCALLOW);
336 if (fd < 0 && ! open_cd ())
339 rc = ioctl (fd, CDIOCRESET);
347 if (fd < 0 && ! open_cd ())
350 if (! strcasecmp (arg, "on"))
351 return ioctl (fd, CDIOCSETDEBUG);
353 if (! strcasecmp (arg, "off"))
354 return ioctl (fd, CDIOCCLRDEBUG);
356 warnx("invalid command arguments");
361 if (fd < 0 && ! open_cd ())
364 (void) ioctl (fd, CDIOCALLOW);
365 rc = ioctl (fd, CDIOCEJECT);
371 if (fd < 0 && ! open_cd ())
374 (void) ioctl (fd, CDIOCALLOW);
375 rc = ioctl (fd, CDIOCCLOSE);
383 if (fd < 0 && ! open_cd ())
386 while (isspace (*arg))
392 if (! strcasecmp (arg, "msf"))
394 else if (! strcasecmp (arg, "lba"))
397 warnx("invalid command arguments");
401 if (fd < 0 && !open_cd ())
404 if (! strncasecmp (arg, "left", strlen(arg)))
405 return ioctl (fd, CDIOCSETLEFT);
407 if (! strncasecmp (arg, "right", strlen(arg)))
408 return ioctl (fd, CDIOCSETRIGHT);
410 if (! strncasecmp (arg, "mono", strlen(arg)))
411 return ioctl (fd, CDIOCSETMONO);
413 if (! strncasecmp (arg, "stereo", strlen(arg)))
414 return ioctl (fd, CDIOCSETSTERIO);
416 if (! strncasecmp (arg, "mute", strlen(arg)))
417 return ioctl (fd, CDIOCSETMUTE);
419 if (2 != sscanf (arg, "%d %d", &l, &r)) {
420 warnx("invalid command arguments");
424 return setvol (l, r);
436 struct ioc_toc_header h;
438 int rc, start, end = 0, istart = 1, iend = 1;
440 rc = ioctl (fd, CDIOREADTOCHEADER, &h);
445 n = h.ending_track - h.starting_track + 1;
446 rc = read_toc_entrys ((n + 1) * sizeof (struct cd_toc_entry));
451 if (! arg || ! *arg) {
452 /* Play the whole disc */
454 return play_blocks (0, msf2lba (toc_buffer[n].addr.msf.minute,
455 toc_buffer[n].addr.msf.second,
456 toc_buffer[n].addr.msf.frame));
458 return play_blocks (0, ntohl(toc_buffer[n].addr.lba));
461 if (strchr (arg, '#')) {
462 /* Play block #blk [ len ] */
465 if (2 != sscanf (arg, "#%d%d", &blk, &len) &&
466 1 != sscanf (arg, "#%d", &blk))
471 len = msf2lba (toc_buffer[n].addr.msf.minute,
472 toc_buffer[n].addr.msf.second,
473 toc_buffer[n].addr.msf.frame) - blk;
475 len = ntohl(toc_buffer[n].addr.lba) - blk;
477 return play_blocks (blk, len);
480 if (strchr (arg, ':')) {
482 * Play MSF m1:s1 [ .f1 ] [ m2:s2 [ .f2 ] ]
484 * Will now also undestand timed addresses relative
485 * to the beginning of a track in the form...
487 * tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]
490 unsigned m1, m2, s1, s2, f1, f2;
491 unsigned char tm, ts, tf;
493 tr2 = m2 = s2 = f2 = f1 = 0;
494 if (8 == sscanf (arg, "%d %d:%d.%d %d %d:%d.%d",
495 &tr1, &m1, &s1, &f1, &tr2, &m2, &s2, &f2))
496 goto Play_Relative_Addresses;
498 tr2 = m2 = s2 = f2 = f1 = 0;
499 if (7 == sscanf (arg, "%d %d:%d %d %d:%d.%d",
500 &tr1, &m1, &s1, &tr2, &m2, &s2, &f2))
501 goto Play_Relative_Addresses;
503 tr2 = m2 = s2 = f2 = f1 = 0;
504 if (7 == sscanf (arg, "%d %d:%d.%d %d %d:%d",
505 &tr1, &m1, &s1, &f1, &tr2, &m2, &s2))
506 goto Play_Relative_Addresses;
508 tr2 = m2 = s2 = f2 = f1 = 0;
509 if (7 == sscanf (arg, "%d %d:%d.%d %d:%d.%d",
510 &tr1, &m1, &s1, &f1, &m2, &s2, &f2))
511 goto Play_Relative_Addresses;
513 tr2 = m2 = s2 = f2 = f1 = 0;
514 if (6 == sscanf (arg, "%d %d:%d.%d %d:%d",
515 &tr1, &m1, &s1, &f1, &m2, &s2))
516 goto Play_Relative_Addresses;
518 tr2 = m2 = s2 = f2 = f1 = 0;
519 if (6 == sscanf (arg, "%d %d:%d %d:%d.%d",
520 &tr1, &m1, &s1, &m2, &s2, &f2))
521 goto Play_Relative_Addresses;
523 tr2 = m2 = s2 = f2 = f1 = 0;
524 if (6 == sscanf (arg, "%d %d:%d.%d %d %d",
525 &tr1, &m1, &s1, &f1, &tr2, &m2))
526 goto Play_Relative_Addresses;
528 tr2 = m2 = s2 = f2 = f1 = 0;
529 if (5 == sscanf (arg, "%d %d:%d %d:%d", &tr1, &m1, &s1, &m2, &s2))
530 goto Play_Relative_Addresses;
532 tr2 = m2 = s2 = f2 = f1 = 0;
533 if (5 == sscanf (arg, "%d %d:%d %d %d",
534 &tr1, &m1, &s1, &tr2, &m2))
535 goto Play_Relative_Addresses;
537 tr2 = m2 = s2 = f2 = f1 = 0;
538 if (5 == sscanf (arg, "%d %d:%d.%d %d",
539 &tr1, &m1, &s1, &f1, &tr2))
540 goto Play_Relative_Addresses;
542 tr2 = m2 = s2 = f2 = f1 = 0;
543 if (4 == sscanf (arg, "%d %d:%d %d", &tr1, &m1, &s1, &tr2))
544 goto Play_Relative_Addresses;
546 tr2 = m2 = s2 = f2 = f1 = 0;
547 if (4 == sscanf (arg, "%d %d:%d.%d", &tr1, &m1, &s1, &f1))
548 goto Play_Relative_Addresses;
550 tr2 = m2 = s2 = f2 = f1 = 0;
551 if (3 == sscanf (arg, "%d %d:%d", &tr1, &m1, &s1))
552 goto Play_Relative_Addresses;
554 tr2 = m2 = s2 = f2 = f1 = 0;
555 goto Try_Absolute_Timed_Addresses;
557 Play_Relative_Addresses:
564 tm = toc_buffer[tr1].addr.msf.minute;
565 ts = toc_buffer[tr1].addr.msf.second;
566 tf = toc_buffer[tr1].addr.msf.frame;
568 lba2msf(ntohl(toc_buffer[tr1].addr.lba),
575 printf ("Track %d is not that long.\n", tr1);
596 if (m2 || s2 || f2) {
614 m2 = toc_buffer[n].addr.msf.minute;
615 s2 = toc_buffer[n].addr.msf.second;
616 f2 = toc_buffer[n].addr.msf.frame;
618 lba2msf(ntohl(toc_buffer[n].addr.lba),
625 } else if (tr2 > n) {
632 tm = toc_buffer[tr2].addr.msf.minute;
633 ts = toc_buffer[tr2].addr.msf.second;
634 tf = toc_buffer[tr2].addr.msf.frame;
636 lba2msf(ntohl(toc_buffer[tr2].addr.lba),
654 tm = toc_buffer[n].addr.msf.minute;
655 ts = toc_buffer[n].addr.msf.second;
656 tf = toc_buffer[n].addr.msf.frame;
658 lba2msf(ntohl(toc_buffer[n].addr.lba),
666 printf ("The playing time of the disc is not that long.\n");
669 return (play_msf (m1, s1, f1, m2, s2, f2));
671 Try_Absolute_Timed_Addresses:
672 if (6 != sscanf (arg, "%d:%d.%d%d:%d.%d",
673 &m1, &s1, &f1, &m2, &s2, &f2) &&
674 5 != sscanf (arg, "%d:%d.%d%d:%d", &m1, &s1, &f1, &m2, &s2) &&
675 5 != sscanf (arg, "%d:%d%d:%d.%d", &m1, &s1, &m2, &s2, &f2) &&
676 3 != sscanf (arg, "%d:%d.%d", &m1, &s1, &f1) &&
677 4 != sscanf (arg, "%d:%d%d:%d", &m1, &s1, &m2, &s2) &&
678 2 != sscanf (arg, "%d:%d", &m1, &s1))
683 m2 = toc_buffer[n].addr.msf.minute;
684 s2 = toc_buffer[n].addr.msf.second;
685 f2 = toc_buffer[n].addr.msf.frame;
687 lba2msf(ntohl(toc_buffer[n].addr.lba),
694 return play_msf (m1, s1, f1, m2, s2, f2);
698 * Play track trk1 [ .idx1 ] [ trk2 [ .idx2 ] ]
700 if (4 != sscanf (arg, "%d.%d%d.%d", &start, &istart, &end, &iend) &&
701 3 != sscanf (arg, "%d.%d%d", &start, &istart, &end) &&
702 3 != sscanf (arg, "%d%d.%d", &start, &end, &iend) &&
703 2 != sscanf (arg, "%d.%d", &start, &istart) &&
704 2 != sscanf (arg, "%d%d", &start, &end) &&
705 1 != sscanf (arg, "%d", &start))
710 return (play_track (start, istart, end, iend));
713 warnx("invalid command arguments");
717 int next_prev (char *arg, int cmd)
719 struct ioc_toc_header h;
720 int dir, junk, n, off, rc, trk;
722 dir = (cmd == CMD_NEXT) ? 1 : -1;
723 rc = ioctl (fd, CDIOREADTOCHEADER, &h);
727 n = h.ending_track - h.starting_track + 1;
728 rc = status (&trk, &junk, &junk, &junk);
733 if (sscanf (arg, "%u", &off) != 1) {
734 warnx("invalid command argument");
741 if (trk > h.ending_track)
744 return (play_track (trk, 1, n, 1));
747 const char *strstatus (int sts)
750 case ASTS_INVALID: return ("invalid");
751 case ASTS_PLAYING: return ("playing");
752 case ASTS_PAUSED: return ("paused");
753 case ASTS_COMPLETED: return ("completed");
754 case ASTS_ERROR: return ("error");
755 case ASTS_VOID: return ("void");
756 default: return ("??");
760 int pstatus (char *arg)
763 struct ioc_read_subchannel ss;
764 struct cd_sub_channel_info data;
765 int rc, trk, m, s, f;
767 char *p, vmcn[(4 * 15) + 1];
769 while ((p = strtok(arg, " \t"))) {
771 if (!strncasecmp(p, "audio", strlen(p)))
772 what |= STATUS_AUDIO;
773 else if (!strncasecmp(p, "media", strlen(p)))
774 what |= STATUS_MEDIA;
775 else if (!strncasecmp(p, "volume", strlen(p)))
776 what |= STATUS_VOLUME;
778 warnx("invalid command arguments");
783 what = STATUS_AUDIO|STATUS_MEDIA|STATUS_VOLUME;
784 if (what & STATUS_AUDIO) {
785 rc = status (&trk, &m, &s, &f);
788 printf ("Audio status = %d<%s>, current track = %d, current position = %d:%02d.%02d\n",
789 rc, strstatus (rc), trk, m, s, f);
791 printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f);
793 printf ("No current status info available\n");
795 if (what & STATUS_MEDIA) {
796 bzero (&ss, sizeof (ss));
798 ss.data_len = sizeof (data);
799 ss.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
800 ss.data_format = CD_MEDIA_CATALOG;
801 rc = ioctl (fd, CDIOCREADSUBCHANNEL, (char *) &ss);
803 printf("Media catalog is %sactive",
804 ss.data->what.media_catalog.mc_valid ? "": "in");
805 if (ss.data->what.media_catalog.mc_valid &&
806 ss.data->what.media_catalog.mc_number[0])
808 strvisx (vmcn, ss.data->what.media_catalog.mc_number,
809 (sizeof (vmcn) - 1) / 4, VIS_OCTAL | VIS_NL);
810 printf(", number \"%.*s\"", (int)sizeof (vmcn), vmcn);
814 printf("No media catalog info available\n");
816 if (what & STATUS_VOLUME) {
817 rc = ioctl (fd, CDIOCGETVOL, &v);
820 printf ("Left volume = %d, right volume = %d\n",
823 printf ("%d %d\n", v.vol[0], v.vol[1]);
825 printf ("No volume level info available\n");
832 * Convert an integer to its text string representation, and
833 * compute its checksum. Used by dbprog_discid to derive the
837 * n - The integer value.
840 * The integer checksum.
849 /* For backward compatibility this algorithm must not change */
850 sprintf(buf, "%u", n);
851 for (p = buf; *p != '\0'; p++)
860 * Compute a magic disc ID based on the number of tracks,
861 * the length of each track, and a checksum of the string
862 * that represents the offset of each track.
865 * s - Pointer to the curstat_t structure.
868 * The integer disc ID.
873 struct ioc_toc_header h;
879 rc = ioctl (fd, CDIOREADTOCHEADER, &h);
882 ntr = h.ending_track - h.starting_track + 1;
885 rc = read_toc_entrys ((ntr + 1) * sizeof (struct cd_toc_entry));
889 /* For backward compatibility this algorithm must not change */
890 for (i = 0; i < ntr; i++) {
891 #define TC_MM(a) toc_buffer[a].addr.msf.minute
892 #define TC_SS(a) toc_buffer[a].addr.msf.second
893 n += dbprog_sum((TC_MM(i) * 60) + TC_SS(i));
895 t += ((TC_MM(i+1) * 60) + TC_SS(i+1)) -
896 ((TC_MM(i) * 60) + TC_SS(i));
899 return((n % 0xff) << 24 | t << 8 | ntr);
906 id = dbprog_discid();
911 printf ("%08x\n",id);
916 int info (char *arg __unused)
918 struct ioc_toc_header h;
921 rc = ioctl (fd, CDIOREADTOCHEADER, &h);
924 printf ("Starting track = %d, ending track = %d, TOC size = %d bytes\n",
925 h.starting_track, h.ending_track, h.len);
927 printf ("%d %d %d\n", h.starting_track,
928 h.ending_track, h.len);
930 warn("getting toc header");
934 n = h.ending_track - h.starting_track + 1;
935 rc = read_toc_entrys ((n + 1) * sizeof (struct cd_toc_entry));
940 printf ("track start duration block length type\n");
941 printf ("-------------------------------------------------\n");
944 for (i = 0; i < n; i++) {
945 printf ("%5d ", toc_buffer[i].track);
946 prtrack (toc_buffer + i, 0);
948 printf ("%5d ", toc_buffer[n].track);
949 prtrack (toc_buffer + n, 1);
953 void lba2msf (unsigned long lba, u_char *m, u_char *s, u_char *f)
955 lba += 150; /* block start offset */
956 lba &= 0xffffff; /* negative lbas use only 24 bits */
957 *m = lba / (60 * 75);
963 unsigned int msf2lba (u_char m, u_char s, u_char f)
965 return (((m * 60) + s) * 75 + f) - 150;
968 void prtrack (struct cd_toc_entry *e, int lastflag)
970 int block, next, len;
974 /* Print track start */
975 printf ("%2d:%02d.%02d ", e->addr.msf.minute,
976 e->addr.msf.second, e->addr.msf.frame);
978 block = msf2lba (e->addr.msf.minute, e->addr.msf.second,
981 block = ntohl(e->addr.lba);
982 lba2msf(block, &m, &s, &f);
983 /* Print track start */
984 printf ("%2d:%02d.%02d ", m, s, f);
987 /* Last track -- print block */
988 printf (" - %6d - -\n", block);
993 next = msf2lba (e[1].addr.msf.minute, e[1].addr.msf.second,
994 e[1].addr.msf.frame);
996 next = ntohl(e[1].addr.lba);
998 lba2msf (len, &m, &s, &f);
1000 /* Print duration, block, length, type */
1001 printf ("%2d:%02d.%02d %6d %6d %5s\n", m, s, f, block, len,
1002 (e->control & 4) ? "data" : "audio");
1005 int play_track (int tstart, int istart, int tend, int iend)
1007 struct ioc_play_track t;
1009 t.start_track = tstart;
1010 t.start_index = istart;
1014 return ioctl (fd, CDIOCPLAYTRACKS, &t);
1017 int play_blocks (int blk, int len)
1019 struct ioc_play_blocks t;
1024 return ioctl (fd, CDIOCPLAYBLOCKS, &t);
1027 int setvol (int left, int right)
1036 return ioctl (fd, CDIOCSETVOL, &v);
1039 int read_toc_entrys (int len)
1041 struct ioc_read_toc_entry t;
1043 t.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
1044 t.starting_track = 0;
1046 t.data = toc_buffer;
1048 return (ioctl (fd, CDIOREADTOCENTRYS, (char *) &t));
1051 int play_msf (int start_m, int start_s, int start_f,
1052 int end_m, int end_s, int end_f)
1054 struct ioc_play_msf a;
1056 a.start_m = start_m;
1057 a.start_s = start_s;
1058 a.start_f = start_f;
1063 return ioctl (fd, CDIOCPLAYMSF, (char *) &a);
1066 int status (int *trk, int *min, int *sec, int *frame)
1068 struct ioc_read_subchannel s;
1069 struct cd_sub_channel_info data;
1072 bzero (&s, sizeof (s));
1074 s.data_len = sizeof (data);
1075 s.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
1076 s.data_format = CD_CURRENT_POSITION;
1078 if (ioctl (fd, CDIOCREADSUBCHANNEL, (char *) &s) < 0)
1081 *trk = s.data->what.position.track_number;
1083 *min = s.data->what.position.reladdr.msf.minute;
1084 *sec = s.data->what.position.reladdr.msf.second;
1085 *frame = s.data->what.position.reladdr.msf.frame;
1087 lba2msf(ntohl(s.data->what.position.reladdr.lba),
1094 return s.data->header.audio_status;
1100 return ("cdcontrol> ");
1107 static EditLine *el = NULL;
1108 static History *hist = NULL;
1110 static char buf[MAXLINE];
1113 const char *bp = NULL;
1119 el = el_init("cdcontrol", stdin, stdout,
1121 hist = history_init();
1122 history(hist, &he, H_EVENT, 100);
1123 el_set(el, EL_HIST, history, hist);
1124 el_set(el, EL_EDITOR, "emacs");
1125 el_set(el, EL_PROMPT, cdcontrol_prompt);
1126 el_set(el, EL_SIGNAL, 1);
1127 el_source(el, NULL);
1129 if ((bp = el_gets(el, &num)) == NULL || num == 0) {
1131 fprintf (stderr, "\r\n");
1135 len = (num > MAXLINE) ? MAXLINE : num;
1136 memcpy(buf, bp, len);
1138 history(hist, &he, H_ENTER, bp);
1142 if (! fgets (buf, sizeof (buf), stdin)) {
1144 fprintf (stderr, "\r\n");
1148 p = parse (buf, cmd);
1153 char *parse (char *buf, int *cmd)
1159 for (p=buf; isspace (*p); p++)
1162 if (isdigit (*p) || (p[0] == '#' && isdigit (p[1]))) {
1165 } else if (*p == '+') {
1168 } else if (*p == '-') {
1169 *cmd = CMD_PREVIOUS;
1173 for (buf = p; *p && ! isspace (*p); p++)
1180 if (*p) { /* It must be a spacing character! */
1184 for (q=p; *q && *q != '\n' && *q != '\r'; q++)
1190 for (c=cmdtab; c->name; ++c) {
1191 /* Is it an exact match? */
1192 if (! strcasecmp (buf, c->name)) {
1197 /* Try short hand forms then... */
1198 if (len >= c->min && ! strncasecmp (buf, c->name, len)) {
1199 if (*cmd != -1 && *cmd != c->command) {
1200 warnx("ambiguous command");
1208 warnx("invalid command, enter ``help'' for commands");
1212 while (isspace (*p))
1219 char devbuf[MAXPATHLEN];
1224 if (*cdname == '/') {
1225 snprintf (devbuf, MAXPATHLEN, "%s", cdname);
1227 snprintf (devbuf, MAXPATHLEN, "%s%s", _PATH_DEV, cdname);
1230 fd = open (devbuf, O_RDONLY);
1232 if (fd < 0 && errno == ENOENT) {
1233 strcat (devbuf, DEFAULT_CD_PARTITION);
1234 fd = open (devbuf, O_RDONLY);
1238 if (errno == ENXIO) {
1239 /* ENXIO has an overloaded meaning here.
1240 * The original "Device not configured" should
1241 * be interpreted as "No disc in drive %s". */
1242 warnx("no disc in drive %s", devbuf);
1245 err(1, "%s", devbuf);