[BACK]Return to cdio.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cdio

Diff for /src/usr.bin/cdio/cdio.c between version 1.8 and 1.9

version 1.8, 1997/05/01 12:40:28 version 1.9, 1998/04/25 04:41:29
Line 27 
Line 27 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
 #include <util.h>  #include <util.h>
   #include <err.h>
 #include <errno.h>  #include <errno.h>
   #include <sys/param.h>
 #include <sys/file.h>  #include <sys/file.h>
 #include <sys/cdio.h>  #include <sys/cdio.h>
 #include <sys/ioctl.h>  #include <sys/ioctl.h>
Line 46 
Line 48 
 #endif  #endif
   
 #define CMD_DEBUG       1  #define CMD_DEBUG       1
 #define CMD_EJECT       2  #define CMD_DEVICE      2
 #define CMD_HELP        3  #define CMD_EJECT       3
 #define CMD_INFO        4  #define CMD_HELP        4
 #define CMD_PAUSE       5  #define CMD_INFO        5
 #define CMD_PLAY        6  #define CMD_PAUSE       6
 #define CMD_QUIT        7  #define CMD_PLAY        7
 #define CMD_RESUME      8  #define CMD_QUIT        8
 #define CMD_STOP        9  #define CMD_RESUME      9
 #define CMD_VOLUME      10  #define CMD_STOP        10
 #define CMD_CLOSE       11  #define CMD_VOLUME      11
 #define CMD_RESET       12  #define CMD_CLOSE       12
 #define CMD_SET         13  #define CMD_RESET       13
 #define CMD_STATUS      14  #define CMD_SET         14
 #define CMD_NEXT        15  #define CMD_STATUS      15
 #define CMD_PREV        16  #define CMD_NEXT        16
 #define CMD_REPLAY      17  #define CMD_PREV        17
   #define CMD_REPLAY      18
   
 struct cmdtab {  struct cmdtab {
         int command;          int command;
Line 71 
Line 74 
 } cmdtab[] = {  } cmdtab[] = {
 { CMD_CLOSE,    "close",        1, "" },  { CMD_CLOSE,    "close",        1, "" },
 { CMD_DEBUG,    "debug",        1, "on | off" },  { CMD_DEBUG,    "debug",        1, "on | off" },
   { CMD_DEVICE,   "device",       1, "devname" },
 { CMD_EJECT,    "eject",        1, "" },  { CMD_EJECT,    "eject",        1, "" },
 { CMD_HELP,     "?",            1, 0 },  { CMD_HELP,     "?",            1, 0 },
 { CMD_HELP,     "help",         1, "" },  { CMD_HELP,     "help",         1, "" },
Line 108 
Line 112 
 int             play_track __P((int, int, int, int));  int             play_track __P((int, int, int, int));
 int             get_vol __P((int *, int *));  int             get_vol __P((int *, int *));
 int             status __P((int *, int *, int *, int *));  int             status __P((int *, int *, int *, int *));
 int             open_cd __P((void));  int             open_cd __P((char *));
 int             play __P((char *arg));  int             play __P((char *arg));
 int             info __P((char *arg));  int             info __P((char *arg));
 int             pstatus __P((char *arg));  int             pstatus __P((char *arg));
Line 237 
Line 241 
                 arg = input (&cmd);                  arg = input (&cmd);
                 if (run (cmd, arg) < 0) {                  if (run (cmd, arg) < 0) {
                         if (verbose)                          if (verbose)
                                 perror (__progname);                                  warn (NULL);
                         close (fd);                          close (fd);
                         fd = -1;                          fd = -1;
                 }                  }
Line 250 
Line 254 
         char *arg;          char *arg;
 {  {
         int l, r, rc;          int l, r, rc;
           static char newcdname[MAXPATHLEN];
   
         switch (cmd) {          switch (cmd) {
   
Line 257 
Line 262 
                 exit (0);                  exit (0);
   
         case CMD_INFO:          case CMD_INFO:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return info (arg);                  return info (arg);
   
         case CMD_STATUS:          case CMD_STATUS:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return pstatus (arg);                  return pstatus (arg);
   
         case CMD_PAUSE:          case CMD_PAUSE:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return ioctl (fd, CDIOCPAUSE);                  return ioctl (fd, CDIOCPAUSE);
   
         case CMD_RESUME:          case CMD_RESUME:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return ioctl (fd, CDIOCRESUME);                  return ioctl (fd, CDIOCRESUME);
   
         case CMD_STOP:          case CMD_STOP:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 rc = ioctl (fd, CDIOCSTOP);                  rc = ioctl (fd, CDIOCSTOP);
Line 291 
Line 296 
                 return (rc);                  return (rc);
   
         case CMD_RESET:          case CMD_RESET:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 rc = ioctl (fd, CDIOCRESET);                  rc = ioctl (fd, CDIOCRESET);
Line 302 
Line 307 
                 return (0);                  return (0);
   
         case CMD_DEBUG:          case CMD_DEBUG:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 if (! strcasecmp (arg, "on"))                  if (! strcasecmp (arg, "on"))
Line 315 
Line 320 
   
                 return (0);                  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:          case CMD_EJECT:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 (void) ioctl (fd, CDIOCALLOW);                  (void) ioctl (fd, CDIOCALLOW);
Line 331 
Line 352 
   
         case CMD_CLOSE:          case CMD_CLOSE:
 #if defined(CDIOCCLOSE)  #if defined(CDIOCCLOSE)
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 (void) ioctl (fd, CDIOCALLOW);                  (void) ioctl (fd, CDIOCALLOW);
Line 347 
Line 368 
 #endif  #endif
   
         case CMD_PLAY:          case CMD_PLAY:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 while (isspace (*arg))                  while (isspace (*arg))
Line 365 
Line 386 
                 return (0);                  return (0);
   
         case CMD_VOLUME:          case CMD_VOLUME:
                 if (fd < 0 && !open_cd ())                  if (fd < 0 && !open_cd (cdname))
                         return (0);                          return (0);
   
                 if (! strncasecmp (arg, "left", strlen(arg)))                  if (! strncasecmp (arg, "left", strlen(arg)))
Line 391 
Line 412 
                 return setvol (l, r);                  return setvol (l, r);
   
         case CMD_NEXT:          case CMD_NEXT:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return play_next (arg);                  return play_next (arg);
   
         case CMD_PREV:          case CMD_PREV:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return (0);                          return (0);
   
                 return play_prev (arg);                  return play_prev (arg);
   
         case CMD_REPLAY:          case CMD_REPLAY:
                 if (fd < 0 && ! open_cd ())                  if (fd < 0 && ! open_cd (cdname))
                         return 0;                          return 0;
   
                 return play_same (arg);                  return play_same (arg);
Line 716 
Line 737 
                 rc = ioctl (fd, CDIOREADTOCHEADER, &h);                  rc = ioctl (fd, CDIOREADTOCHEADER, &h);
                 if (rc < 0)                  if (rc < 0)
                 {                  {
                         perror ("getting toc header");                          warn ("getting toc header");
                         return (rc);                          return (rc);
                 }                  }
   
Line 741 
Line 762 
                 rc = ioctl (fd, CDIOREADTOCHEADER, &h);                  rc = ioctl (fd, CDIOREADTOCHEADER, &h);
                 if (rc < 0)                  if (rc < 0)
                 {                  {
                         perror ("getting toc header");                          warn ("getting toc header");
                         return (rc);                          return (rc);
                 }                  }
   
Line 763 
Line 784 
                 rc = ioctl (fd, CDIOREADTOCHEADER, &h);                  rc = ioctl (fd, CDIOREADTOCHEADER, &h);
                 if (rc < 0)                  if (rc < 0)
                 {                  {
                         perror ("getting toc header");                          warn ("getting toc header");
                         return (rc);                          return (rc);
                 }                  }
   
Line 807 
Line 828 
         int rc, trk, m, s, f;          int rc, trk, m, s, f;
   
         rc = status (&trk, &m, &s, &f);          rc = status (&trk, &m, &s, &f);
         if (rc >= 0)          if (rc >= 0) {
                 if (verbose)                  if (verbose)
                         printf ("Audio status = %d<%s>, current track = %d, current position = %d:%02d.%02d\n",                          printf ("Audio status = %d<%s>, current track = %d, current position = %d:%02d.%02d\n",
                                 rc, strstatus (rc), trk, m, s, f);                                  rc, strstatus (rc), trk, m, s, f);
                 else                  else
                         printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f);                          printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f);
         else          } else
                 printf ("No current status info available\n");                  printf ("No current status info available\n");
   
         bzero (&ss, sizeof (ss));          bzero (&ss, sizeof (ss));
Line 834 
Line 855 
                 printf("No media catalog info available\n");                  printf("No media catalog info available\n");
   
         rc = ioctl (fd, CDIOCGETVOL, &v);          rc = ioctl (fd, CDIOCGETVOL, &v);
         if (rc >= 0)          if (rc >= 0) {
                 if (verbose)                  if (verbose)
                         printf ("Left volume = %d, right volume = %d\n",                          printf ("Left volume = %d, right volume = %d\n",
                                 v.vol[0], v.vol[1]);                                  v.vol[0], v.vol[1]);
                 else                  else
                         printf ("%d %d\n", v.vol[0], v.vol[1]);                          printf ("%d %d\n", v.vol[0], v.vol[1]);
         else          } else
                 printf ("No volume level info available\n");                  printf ("No volume level info available\n");
         return(0);          return(0);
 }  }
Line 860 
Line 881 
                         printf ("%d %d %d\n", h.starting_track,                          printf ("%d %d %d\n", h.starting_track,
                                 h.ending_track, h.len);                                  h.ending_track, h.len);
         } else {          } else {
                 perror ("getting toc header");                  warn ("getting toc header");
                 return (rc);                  return (rc);
         }          }
   
Line 1134 
Line 1155 
         return p;          return p;
 }  }
   
 int open_cd ()  int open_cd (dev)
 {  
         char *dev;          char *dev;
   {
           char *realdev;
   
         if (fd > -1)          if (fd > -1)
                 return (1);                  return (1);
   
         fd = opendev(cdname, O_RDONLY, OPENDEV_PART, &dev);          fd = opendev(dev, O_RDONLY, OPENDEV_PART, &realdev);
         if (fd < 0) {          if (fd < 0) {
                 if ((errno == ENXIO) || (errno == EIO)) {                  if ((errno == ENXIO) || (errno == EIO)) {
                         /*  ENXIO has an overloaded meaning here.                          /*  ENXIO has an overloaded meaning here.
                          *  The original "Device not configured" should                           *  The original "Device not configured" should
                          *  be interpreted as "No disc in drive %s". */                           *  be interpreted as "No disc in drive %s". */
                         fprintf (stderr, "%s: No disc in drive %s.\n", __progname, dev);                          warnx ("No disc in drive %s.", realdev);
                         return (0);                          return (0);
                 }                  }
                 perror (dev);                  warn ("Can't open %s", realdev);
                 exit (1);                  return (0);
         }          }
         return (1);          return (1);
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9