Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Nov 2000 15:53:02 -0800 (PST)
From:      sethk@osd.bsdi.com
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/22672: [PATCH] Add "next" and "prev" commands to cdcontrol(1).
Message-ID:  <200011072353.eA7Nr2A69987@pike.osd.bsdi.com>

next in thread | raw e-mail | index | archive | help

>Number:         22672
>Category:       bin
>Synopsis:       Add "next" and "prev" commands to cdcontrol(1).
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 07 16:00:02 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Seth Kingsley
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
BSDi / Open Source Division
>Environment:

FreeBSD veritech.osd.bsdi.com 5.0-CURRENT
FreeBSD 5.0-CURRENT #6: Sat Nov  4 16:05:30 PST 2000
root@veritech.osd.bsdi.com:/usr/src/sys/compile/VERITECH  i386

>Description:

I often find myself using the "status audio" command, looking at the
track number and then typing the number of the next track. This patch
also filters the media catalog ID through vis() since in some cases it
contains control characters.

>How-To-Repeat:

N/A

>Fix:

Index: cdcontrol.1
===================================================================
RCS file: /ncvs/src/usr.sbin/cdcontrol/cdcontrol.1,v
retrieving revision 1.23
diff -u -r1.23 cdcontrol.1
--- cdcontrol.1	2000/07/13 22:56:43	1.23
+++ cdcontrol.1	2000/10/25 06:14:02
@@ -52,9 +52,13 @@
 The available commands are listed below.  Only as many
 characters as are required to uniquely identify a command
 need be specified.
-Word
+The word
 .Em play
-can be omitted.
+can be omitted or the characters ``+'' and ``-'' can be used in the
+place of
+.Em next
+and
+.Em prev .
 .Bl -tag -width Cm
 
 .It Cm play Ar first_track Op Ar last_track
@@ -89,6 +93,12 @@
 using
 .Ar length
 logical blocks.
+
+.It Cm next Op Ar tracks
+Skip forward a number of tracks (default 1).
+
+.It Cm prev Op Ar tracks
+Skip back a number of tracks (default 1).
 
 .It Cm pause
 Stop playing.
Index: cdcontrol.c
===================================================================
RCS file: /ncvs/src/usr.sbin/cdcontrol/cdcontrol.c,v
retrieving revision 1.27
diff -u -r1.27 cdcontrol.c
--- cdcontrol.c	2000/07/13 22:56:43	1.27
+++ cdcontrol.c	2000/11/07 23:38:10
@@ -25,6 +25,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <vis.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -59,15 +60,17 @@
 #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_CDID        15
+#define CMD_NEXT        7
+#define CMD_PREV        8
+#define CMD_QUIT        9
+#define CMD_RESUME      10
+#define CMD_STOP        11
+#define CMD_VOLUME      12
+#define CMD_CLOSE       13
+#define CMD_RESET       14
+#define CMD_SET         15
+#define CMD_STATUS      16
+#define CMD_CDID        17
 #define STATUS_AUDIO    0x1
 #define STATUS_MEDIA    0x2
 #define STATUS_VOLUME   0x4
@@ -89,6 +92,8 @@
 { CMD_PLAY,     "play",         1, "track1[.index1] [track2[.index2]]" },
 { CMD_PLAY,     "play",         1, "tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]" },
 { CMD_PLAY,     "play",         1, "[#block [len]]" },
+{ CMD_NEXT,     "next",         1, "[tracks]"},
+{ CMD_PREV,     "prev",         2, "[tracks]"},
 { CMD_QUIT,     "quit",         1, "" },
 { CMD_RESET,    "reset",        4, "" },
 { CMD_RESUME,   "resume",       1, "" },
@@ -115,6 +120,7 @@
 int             status __P((int *, int *, int *, int *));
 int             open_cd __P((void));
 int             play __P((char *arg));
+int		next_prev __P((char *arg, int));
 int             info __P((char *arg));
 int             cdid __P((void));
 int             pstatus __P((char *arg));
@@ -347,6 +353,16 @@
 
 		return play (arg);
 
+	case CMD_NEXT:
+	case CMD_PREV:
+		if (fd < 0 && ! open_cd ())
+			return (0);
+
+		while (isspace (*arg))
+			arg++;
+
+		return next_prev (arg, cmd);
+
 	case CMD_SET:
 		if (! strcasecmp (arg, "msf"))
 			msf = 1;
@@ -672,6 +688,42 @@
 	return (0);
 }
 
+int next_prev (char *arg, int cmd)
+{
+	struct ioc_toc_header h;
+	int rc, n, trk, off, jnk;
+	int dir = (cmd == CMD_NEXT) ? 1 : -1;
+
+	rc = ioctl (fd, CDIOREADTOCHEADER, &h);
+
+	if (rc < 0)
+		return (rc);
+
+	n = h.ending_track - h.starting_track + 1;
+	rc = status (&trk, &jnk, &jnk, &jnk);
+
+	if (rc < 1)
+		trk = 1;
+
+	if (arg && *arg)
+	{
+		if (1 != sscanf (arg, "%u", &off)) 
+		{
+			warnx("invalid command argument");
+			return (0);
+		}
+		else
+			trk += off * dir;
+	}
+	else
+		trk+= dir;
+
+	trk %= (n + 1);
+	trk = (trk < 1) ? 1 : trk;
+
+	return (play_track (trk, 1, n, 1));
+}
+
 char *strstatus (int sts)
 {
 	switch (sts) {
@@ -692,7 +744,7 @@
 	struct cd_sub_channel_info data;
 	int rc, trk, m, s, f;
 	int what = 0;
-	char *p;
+	char *p, vmcn[(4 * 15) + 1];
 
 	while ((p = strtok(arg, " \t"))) {
 	    arg = 0;
@@ -732,8 +784,11 @@
 		       ss.data->what.media_catalog.mc_valid ? "": "in");
 		if (ss.data->what.media_catalog.mc_valid &&
 		    ss.data->what.media_catalog.mc_number[0])
-		    printf(", number \"%.15s\"",
-			   ss.data->what.media_catalog.mc_number);
+		{
+		    strvisx (vmcn, ss.data->what.media_catalog.mc_number,
+			    15, VIS_OCTAL | VIS_NL);
+		    printf(", number \"%.61s\"", vmcn);
+		}
 		putchar('\n');
 	    } else
 		printf("No media catalog info available\n");
@@ -1086,7 +1141,17 @@
 		*cmd = CMD_PLAY;
 		return (p);
 	}
-
+	else if (*p == '+')
+	{
+		*cmd = CMD_NEXT;
+		return (p + 1);
+	}
+	else if (*p == '-')
+	{
+		*cmd = CMD_PREV;
+		return (p + 1);
+	}
+	    
 	for (buf = p; *p && ! isspace (*p); p++)
 		continue;
   

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011072353.eA7Nr2A69987>