=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/cdio/cdio.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/cdio/cdio.c 1997/05/01 12:40:28 1.8 --- src/usr.bin/cdio/cdio.c 1998/04/25 04:41:29 1.9 *************** *** 1,4 **** ! /* $OpenBSD: cdio.c,v 1.8 1997/05/01 12:40:28 downsj Exp $ */ /* * Compact Disc Control Utility by Serge V. Vakulenko . * Based on the non-X based CD player by Jean-Marc Zucconi and --- 1,4 ---- ! /* $OpenBSD: cdio.c,v 1.9 1998/04/25 04:41:29 millert Exp $ */ /* * Compact Disc Control Utility by Serge V. Vakulenko . * Based on the non-X based CD player by Jean-Marc Zucconi and *************** *** 27,33 **** --- 27,35 ---- #include #include #include + #include #include + #include #include #include #include *************** *** 46,67 **** #endif #define CMD_DEBUG 1 ! #define CMD_EJECT 2 ! #define CMD_HELP 3 ! #define CMD_INFO 4 ! #define CMD_PAUSE 5 ! #define CMD_PLAY 6 ! #define CMD_QUIT 7 ! #define CMD_RESUME 8 ! #define CMD_STOP 9 ! #define CMD_VOLUME 10 ! #define CMD_CLOSE 11 ! #define CMD_RESET 12 ! #define CMD_SET 13 ! #define CMD_STATUS 14 ! #define CMD_NEXT 15 ! #define CMD_PREV 16 ! #define CMD_REPLAY 17 struct cmdtab { int command; --- 48,70 ---- #endif #define CMD_DEBUG 1 ! #define CMD_DEVICE 2 ! #define CMD_EJECT 3 ! #define CMD_HELP 4 ! #define CMD_INFO 5 ! #define CMD_PAUSE 6 ! #define CMD_PLAY 7 ! #define CMD_QUIT 8 ! #define CMD_RESUME 9 ! #define CMD_STOP 10 ! #define CMD_VOLUME 11 ! #define CMD_CLOSE 12 ! #define CMD_RESET 13 ! #define CMD_SET 14 ! #define CMD_STATUS 15 ! #define CMD_NEXT 16 ! #define CMD_PREV 17 ! #define CMD_REPLAY 18 struct cmdtab { int command; *************** *** 71,76 **** --- 74,80 ---- } cmdtab[] = { { CMD_CLOSE, "close", 1, "" }, { CMD_DEBUG, "debug", 1, "on | off" }, + { CMD_DEVICE, "device", 1, "devname" }, { CMD_EJECT, "eject", 1, "" }, { CMD_HELP, "?", 1, 0 }, { CMD_HELP, "help", 1, "" }, *************** *** 108,114 **** int play_track __P((int, int, int, int)); int get_vol __P((int *, int *)); int status __P((int *, int *, int *, int *)); ! int open_cd __P((void)); int play __P((char *arg)); int info __P((char *arg)); int pstatus __P((char *arg)); --- 112,118 ---- int play_track __P((int, int, int, int)); int get_vol __P((int *, int *)); int status __P((int *, int *, int *, int *)); ! int open_cd __P((char *)); int play __P((char *arg)); int info __P((char *arg)); int pstatus __P((char *arg)); *************** *** 237,243 **** arg = input (&cmd); if (run (cmd, arg) < 0) { if (verbose) ! perror (__progname); close (fd); fd = -1; } --- 241,247 ---- arg = input (&cmd); if (run (cmd, arg) < 0) { if (verbose) ! warn (NULL); close (fd); fd = -1; } *************** *** 250,255 **** --- 254,260 ---- char *arg; { int l, r, rc; + static char newcdname[MAXPATHLEN]; switch (cmd) { *************** *** 257,287 **** exit (0); case CMD_INFO: ! if (fd < 0 && ! open_cd ()) return (0); return info (arg); case CMD_STATUS: ! if (fd < 0 && ! open_cd ()) return (0); return pstatus (arg); case CMD_PAUSE: ! if (fd < 0 && ! open_cd ()) return (0); return ioctl (fd, CDIOCPAUSE); case CMD_RESUME: ! if (fd < 0 && ! open_cd ()) return (0); return ioctl (fd, CDIOCRESUME); case CMD_STOP: ! if (fd < 0 && ! open_cd ()) return (0); rc = ioctl (fd, CDIOCSTOP); --- 262,292 ---- exit (0); case CMD_INFO: ! if (fd < 0 && ! open_cd (cdname)) return (0); return info (arg); case CMD_STATUS: ! if (fd < 0 && ! open_cd (cdname)) return (0); return pstatus (arg); case CMD_PAUSE: ! if (fd < 0 && ! open_cd (cdname)) return (0); return ioctl (fd, CDIOCPAUSE); case CMD_RESUME: ! if (fd < 0 && ! open_cd (cdname)) return (0); return ioctl (fd, CDIOCRESUME); case CMD_STOP: ! if (fd < 0 && ! open_cd (cdname)) return (0); rc = ioctl (fd, CDIOCSTOP); *************** *** 291,297 **** return (rc); case CMD_RESET: ! if (fd < 0 && ! open_cd ()) return (0); rc = ioctl (fd, CDIOCRESET); --- 296,302 ---- return (rc); case CMD_RESET: ! if (fd < 0 && ! open_cd (cdname)) return (0); rc = ioctl (fd, CDIOCRESET); *************** *** 302,308 **** return (0); case CMD_DEBUG: ! if (fd < 0 && ! open_cd ()) return (0); if (! strcasecmp (arg, "on")) --- 307,313 ---- return (0); case CMD_DEBUG: ! if (fd < 0 && ! open_cd (cdname)) return (0); if (! strcasecmp (arg, "on")) *************** *** 315,322 **** return (0); case CMD_EJECT: ! if (fd < 0 && ! open_cd ()) return (0); (void) ioctl (fd, CDIOCALLOW); --- 320,343 ---- return (0); + case CMD_DEVICE: + /* close old device */ + if (fd > -1) { + (void) ioctl (fd, CDIOCALLOW); + close(fd); + fd = -1; + } + + /* open new device */ + if (!open_cd (arg)) + return (0); + (void) strncpy(newcdname, arg, sizeof(newcdname) - 1); + newcdname[sizeof(newcdname) - 1] = '\0'; + cdname = newcdname; + return (1); + case CMD_EJECT: ! if (fd < 0 && ! open_cd (cdname)) return (0); (void) ioctl (fd, CDIOCALLOW); *************** *** 331,337 **** case CMD_CLOSE: #if defined(CDIOCCLOSE) ! if (fd < 0 && ! open_cd ()) return (0); (void) ioctl (fd, CDIOCALLOW); --- 352,358 ---- case CMD_CLOSE: #if defined(CDIOCCLOSE) ! if (fd < 0 && ! open_cd (cdname)) return (0); (void) ioctl (fd, CDIOCALLOW); *************** *** 347,353 **** #endif case CMD_PLAY: ! if (fd < 0 && ! open_cd ()) return (0); while (isspace (*arg)) --- 368,374 ---- #endif case CMD_PLAY: ! if (fd < 0 && ! open_cd (cdname)) return (0); while (isspace (*arg)) *************** *** 365,371 **** return (0); case CMD_VOLUME: ! if (fd < 0 && !open_cd ()) return (0); if (! strncasecmp (arg, "left", strlen(arg))) --- 386,392 ---- return (0); case CMD_VOLUME: ! if (fd < 0 && !open_cd (cdname)) return (0); if (! strncasecmp (arg, "left", strlen(arg))) *************** *** 391,409 **** return setvol (l, r); case CMD_NEXT: ! if (fd < 0 && ! open_cd ()) return (0); return play_next (arg); case CMD_PREV: ! if (fd < 0 && ! open_cd ()) return (0); return play_prev (arg); case CMD_REPLAY: ! if (fd < 0 && ! open_cd ()) return 0; return play_same (arg); --- 412,430 ---- return setvol (l, r); case CMD_NEXT: ! if (fd < 0 && ! open_cd (cdname)) return (0); return play_next (arg); case CMD_PREV: ! if (fd < 0 && ! open_cd (cdname)) return (0); return play_prev (arg); case CMD_REPLAY: ! if (fd < 0 && ! open_cd (cdname)) return 0; return play_same (arg); *************** *** 716,722 **** rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! perror ("getting toc header"); return (rc); } --- 737,743 ---- rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! warn ("getting toc header"); return (rc); } *************** *** 741,747 **** rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! perror ("getting toc header"); return (rc); } --- 762,768 ---- rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! warn ("getting toc header"); return (rc); } *************** *** 763,769 **** rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! perror ("getting toc header"); return (rc); } --- 784,790 ---- rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) { ! warn ("getting toc header"); return (rc); } *************** *** 807,819 **** int rc, trk, m, s, f; 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 printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f); ! else printf ("No current status info available\n"); bzero (&ss, sizeof (ss)); --- 828,840 ---- int rc, trk, m, s, f; 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 printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f); ! } else printf ("No current status info available\n"); bzero (&ss, sizeof (ss)); *************** *** 834,846 **** printf("No media catalog info available\n"); rc = ioctl (fd, CDIOCGETVOL, &v); ! if (rc >= 0) if (verbose) printf ("Left volume = %d, right volume = %d\n", v.vol[0], v.vol[1]); else printf ("%d %d\n", v.vol[0], v.vol[1]); ! else printf ("No volume level info available\n"); return(0); } --- 855,867 ---- printf("No media catalog info available\n"); rc = ioctl (fd, CDIOCGETVOL, &v); ! if (rc >= 0) { if (verbose) printf ("Left volume = %d, right volume = %d\n", v.vol[0], v.vol[1]); else printf ("%d %d\n", v.vol[0], v.vol[1]); ! } else printf ("No volume level info available\n"); return(0); } *************** *** 860,866 **** printf ("%d %d %d\n", h.starting_track, h.ending_track, h.len); } else { ! perror ("getting toc header"); return (rc); } --- 881,887 ---- printf ("%d %d %d\n", h.starting_track, h.ending_track, h.len); } else { ! warn ("getting toc header"); return (rc); } *************** *** 1134,1157 **** return p; } ! int open_cd () ! { char *dev; if (fd > -1) return (1); ! fd = opendev(cdname, O_RDONLY, OPENDEV_PART, &dev); if (fd < 0) { if ((errno == ENXIO) || (errno == EIO)) { /* ENXIO has an overloaded meaning here. * The original "Device not configured" should * be interpreted as "No disc in drive %s". */ ! fprintf (stderr, "%s: No disc in drive %s.\n", __progname, dev); return (0); } ! perror (dev); ! exit (1); } return (1); } --- 1155,1179 ---- return p; } ! int open_cd (dev) char *dev; + { + char *realdev; if (fd > -1) return (1); ! fd = opendev(dev, O_RDONLY, OPENDEV_PART, &realdev); if (fd < 0) { if ((errno == ENXIO) || (errno == EIO)) { /* ENXIO has an overloaded meaning here. * The original "Device not configured" should * be interpreted as "No disc in drive %s". */ ! warnx ("No disc in drive %s.", realdev); return (0); } ! warn ("Can't open %s", realdev); ! return (0); } return (1); }