[Midnightbsd-cvs] src [10859] trunk/usr.sbin/cdcontrol/cdcontrol.c: sync cdcontrol with freebsd 10 stable

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 13 18:21:18 EDT 2018


Revision: 10859
          http://svnweb.midnightbsd.org/src/?rev=10859
Author:   laffer1
Date:     2018-06-13 18:21:17 -0400 (Wed, 13 Jun 2018)
Log Message:
-----------
sync cdcontrol with freebsd 10 stable

Modified Paths:
--------------
    trunk/usr.sbin/cdcontrol/Makefile
    trunk/usr.sbin/cdcontrol/cdcontrol.1
    trunk/usr.sbin/cdcontrol/cdcontrol.c

Property Changed:
----------------
    trunk/usr.sbin/cdcontrol/cdcontrol.1

Modified: trunk/usr.sbin/cdcontrol/Makefile
===================================================================
--- trunk/usr.sbin/cdcontrol/Makefile	2018-06-13 19:18:25 UTC (rev 10858)
+++ trunk/usr.sbin/cdcontrol/Makefile	2018-06-13 22:21:17 UTC (rev 10859)
@@ -1,9 +1,8 @@
-# $FreeBSD: src/usr.sbin/cdcontrol/Makefile,v 1.10 2003/04/04 17:49:13 obrien Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/cdcontrol/Makefile 201724 2010-01-07 09:40:34Z dwmalone $
 
 PROG= cdcontrol
 
-WARNS?= 2
-
 DPADD=	${LIBEDIT} ${LIBTERMCAP}
 LDADD=	-ledit -ltermcap
 

Modified: trunk/usr.sbin/cdcontrol/cdcontrol.1
===================================================================
--- trunk/usr.sbin/cdcontrol/cdcontrol.1	2018-06-13 19:18:25 UTC (rev 10858)
+++ trunk/usr.sbin/cdcontrol/cdcontrol.1	2018-06-13 22:21:17 UTC (rev 10859)
@@ -1,6 +1,7 @@
-.\" $FreeBSD: src/usr.sbin/cdcontrol/cdcontrol.1,v 1.40 2005/01/18 20:02:32 ru Exp $
+.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/cdcontrol/cdcontrol.1 233648 2012-03-29 05:02:12Z eadler $
 .\"
-.Dd May 8, 2002
+.Dd June 27, 2008
 .Dt CDCONTROL 1
 .Os
 .Sh NAME
@@ -130,6 +131,14 @@
 Eject the disc.
 .It Ic close
 Inject the disc.
+.It Ic volume
+Same as
+.Em status volume
+command.
+.It Ic volume Ar level
+Set the volume of both channels to
+.Ar level .
+Allowed values are in the range 0-255.
 .It Ic volume Ar left_channel right_channel
 Set the volume of left channel to
 .Ar left_channel


Property changes on: trunk/usr.sbin/cdcontrol/cdcontrol.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/cdcontrol/cdcontrol.c
===================================================================
--- trunk/usr.sbin/cdcontrol/cdcontrol.c	2018-06-13 19:18:25 UTC (rev 10858)
+++ trunk/usr.sbin/cdcontrol/cdcontrol.c	2018-06-13 22:21:17 UTC (rev 10859)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Compact Disc Control Utility by Serge V. Vakulenko <vak at cronyx.ru>.
  * Based on the non-X based CD player by Jean-Marc Zucconi and
@@ -16,10 +17,23 @@
  * 11-Oct-1995: Serge V.Vakulenko <vak at cronyx.ru>
  *              New eject algorithm.
  *              Some code style reformatting.
+ * 
+ * 13-Dec-1999: Knut A. Syed <kas at kas.no>
+ * 		Volume-command modified.  If used with only one
+ * 		parameter it now sets both channels.  If used without
+ * 		parameters it will print volume-info.
+ * 		Version 2.0.1
+ *
+ * 27-Jun-2008  Pietro Cerutti <gahr at FreeBSD.org>
+ * 		Further enhancement to volume. Values not in range 0-255
+ * 		are now reduced to be in range. This prevents overflow in
+ * 		the uchar storing the volume (256 -> 0, -20 -> 236, ...).
+ * 		Version 2.0.2
+ *
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/cdcontrol/cdcontrol.c,v 1.49 2005/10/19 15:37:43 stefanf Exp $");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/cdcontrol/cdcontrol.c 227225 2011-11-06 16:52:26Z ed $");
 
 #include <sys/cdio.h>
 #include <sys/cdrio.h>
@@ -39,7 +53,7 @@
 #include <unistd.h>
 #include <vis.h>
 
-#define VERSION "2.0"
+#define VERSION "2.0.2"
 
 #define ASTS_INVALID	0x00  /* Audio status byte not valid */
 #define ASTS_PLAYING	0x11  /* Audio play operation in progress */
@@ -74,7 +88,7 @@
 #define STATUS_MEDIA	0x2
 #define STATUS_VOLUME	0x4
 
-struct cmdtab {
+static struct cmdtab {
 	int command;
 	const char *name;
 	unsigned min;
@@ -100,46 +114,46 @@
 { CMD_STATUS,	"status",	1, "[audio | media | volume]" },
 { CMD_STOP,	"stop",		3, "" },
 { CMD_VOLUME,	"volume",	1,
-      "<l> <r> | left | right | mute | mono | stereo" },
+      "<l&r> <l> <r> | left | right | mute | mono | stereo" },
 { CMD_CDID,	"cdid",		2, "" },
 { CMD_SPEED,	"speed",	2, "speed" },
 { 0,		NULL,		0, NULL }
 };
 
-struct cd_toc_entry	toc_buffer[100];
+static struct cd_toc_entry toc_buffer[100];
 
-const char	*cdname;
-int		fd = -1;
-int		verbose = 1;
-int		msf = 1;
+static const char *cdname;
+static int	fd = -1;
+static int	verbose = 1;
+static int	msf = 1;
 
-int		 setvol(int, int);
-int		 read_toc_entrys(int);
-int		 play_msf(int, int, int, int, int, int);
-int		 play_track(int, int, int, int);
-int		 get_vol(int *, int *);
-int		 status(int *, int *, int *, int *);
-int		 open_cd(void);
-int		 next_prev(char *arg, int);
-int		 play(char *arg);
-int		 info(char *arg);
-int		 cdid(void);
-int		 pstatus(char *arg);
-char		*input(int *);
-void		 prtrack(struct cd_toc_entry *e, int lastflag);
-void		 lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f);
-unsigned int	 msf2lba(u_char m, u_char s, u_char f);
-int		 play_blocks(int blk, int len);
-int		 run(int cmd, char *arg);
-char		*parse(char *buf, int *cmd);
-void		 help(void);
-void		 usage(void);
-char		*use_cdrom_instead(const char *);
-__const char	*strstatus(int);
+static int	 setvol(int, int);
+static int	 read_toc_entrys(int);
+static int	 play_msf(int, int, int, int, int, int);
+static int	 play_track(int, int, int, int);
+static int	 status(int *, int *, int *, int *);
+static int	 open_cd(void);
+static int	 next_prev(char *arg, int);
+static int	 play(char *arg);
+static int	 info(char *arg);
+static int	 cdid(void);
+static int	 pstatus(char *arg);
+static char	*input(int *);
+static void	 prtrack(struct cd_toc_entry *e, int lastflag);
+static void	 lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f);
+static unsigned int msf2lba(u_char m, u_char s, u_char f);
+static int	 play_blocks(int blk, int len);
+static int	 run(int cmd, char *arg);
+static char	*parse(char *buf, int *cmd);
+static void	 help(void);
+static void	 usage(void);
+static char	*use_cdrom_instead(const char *);
+static const char *strstatus(int);
 static u_int	 dbprog_discid(void);
-__const char	*cdcontrol_prompt(void);
+static const char *cdcontrol_prompt(void);
 
-void help ()
+static void
+help(void)
 {
 	struct cmdtab *c;
 	const char *s;
@@ -165,13 +179,15 @@
 	printf ("\tThe plain target address is taken as a synonym for play.\n");
 }
 
-void usage ()
+static void
+usage(void)
 {
 	fprintf (stderr, "usage: cdcontrol [-sv] [-f device] [command ...]\n");
 	exit (1);
 }
 
-char *use_cdrom_instead(const char *old_envvar)
+static char *
+use_cdrom_instead(const char *old_envvar)
 {
 	char *device;
 
@@ -183,7 +199,8 @@
 }
 
 
-int main (int argc, char **argv)
+int
+main(int argc, char **argv)
 {
 	int cmd;
 	char *arg;
@@ -190,7 +207,7 @@
 
 	for (;;) {
 		switch (getopt (argc, argv, "svhf:")) {
-		case EOF:
+		case -1:
 			break;
 		case 's':
 			verbose = 0;
@@ -228,7 +245,7 @@
 
 	if (argc > 0) {
 		char buf[80], *p;
-		int len;
+		int len, rc;
 
 		for (p=buf; argc-->0; ++argv) {
 			len = strlen (*argv);
@@ -244,7 +261,11 @@
 		}
 		*p = 0;
 		arg = parse (buf, &cmd);
-		return (run (cmd, arg));
+		rc = run (cmd, arg);
+		if (rc < 0 && verbose)
+			warn(NULL);
+
+		return (rc);
 	}
 
 	if (verbose == 1)
@@ -267,10 +288,11 @@
 	}
 }
 
-int run (int cmd, char *arg)
+static int
+run(int cmd, char *arg)
 {
 	long speed;
-	int l, r, rc;
+	int l, r, rc, count;
 
 	switch (cmd) {
 
@@ -396,6 +418,12 @@
 		if (fd < 0 && !open_cd ())
 			return (0);
 
+		if (! strlen (arg)) {
+			char volume[] = "volume";
+
+		    	return pstatus (volume);
+		}
+
 		if (! strncasecmp (arg, "left", strlen(arg)))
 			return ioctl (fd, CDIOCSETLEFT);
 
@@ -411,13 +439,14 @@
 		if (! strncasecmp (arg, "mute", strlen(arg)))
 			return ioctl (fd, CDIOCSETMUTE);
 
-		if (2 != sscanf (arg, "%d %d", &l, &r)) {
-			warnx("invalid command arguments");
-			return (0);
-		}
+		count = sscanf (arg, "%d %d", &l, &r);
+		if (count == 1)
+		    return setvol (l, l);
+		if (count == 2)
+		    return setvol (l, r);
+		warnx("invalid command arguments");
+		return (0);
 
-		return setvol (l, r);
-
 	case CMD_SPEED:
 		if (fd < 0 && ! open_cd ())
 			return (0);
@@ -441,7 +470,8 @@
 	}
 }
 
-int play (char *arg)
+static int
+play(char *arg)
 {
 	struct ioc_toc_header h;
 	unsigned int n;
@@ -724,7 +754,8 @@
 	return (0);
 }
 
-int next_prev (char *arg, int cmd)
+static int
+next_prev(char *arg, int cmd)
 {
 	struct ioc_toc_header h;
 	int dir, junk, n, off, rc, trk;
@@ -754,7 +785,8 @@
 	return (play_track (trk, 1, n, 1));
 }
 
-const char *strstatus (int sts)
+static const char *
+strstatus(int sts)
 {
 	switch (sts) {
 	case ASTS_INVALID:	return ("invalid");
@@ -767,7 +799,8 @@
 	}
 }
 
-int pstatus (char *arg)
+static int
+pstatus(char *arg)
 {
 	struct ioc_vol v;
 	struct ioc_read_subchannel ss;
@@ -878,7 +911,7 @@
  *	The integer disc ID.
  */
 static u_int
-dbprog_discid()
+dbprog_discid(void)
 {
 	struct	ioc_toc_header h;
 	int	rc;
@@ -909,7 +942,8 @@
 	return((n % 0xff) << 24 | t << 8 | ntr);
 }
 
-int cdid ()
+static int
+cdid(void)
 {
 	u_int	id;
 
@@ -923,7 +957,8 @@
 	return id ? 0 : 1;
 }
 
-int info (char *arg __unused)
+static int
+info(char *arg __unused)
 {
 	struct ioc_toc_header h;
 	int rc, i, n;
@@ -960,7 +995,8 @@
 	return (0);
 }
 
-void lba2msf (unsigned long lba, u_char *m, u_char *s, u_char *f)
+static void
+lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f)
 {
 	lba += 150;			/* block start offset */
 	lba &= 0xffffff;		/* negative lbas use only 24 bits */
@@ -970,12 +1006,14 @@
 	*f = lba % 75;
 }
 
-unsigned int msf2lba (u_char m, u_char s, u_char f)
+static unsigned int
+msf2lba(u_char m, u_char s, u_char f)
 {
 	return (((m * 60) + s) * 75 + f) - 150;
 }
 
-void prtrack (struct cd_toc_entry *e, int lastflag)
+static void
+prtrack(struct cd_toc_entry *e, int lastflag)
 {
 	int block, next, len;
 	u_char m, s, f;
@@ -1013,7 +1051,8 @@
 		(e->control & 4) ? "data" : "audio");
 }
 
-int play_track (int tstart, int istart, int tend, int iend)
+static int
+play_track(int tstart, int istart, int tend, int iend)
 {
 	struct ioc_play_track t;
 
@@ -1025,7 +1064,8 @@
 	return ioctl (fd, CDIOCPLAYTRACKS, &t);
 }
 
-int play_blocks (int blk, int len)
+static int
+play_blocks(int blk, int len)
 {
 	struct ioc_play_blocks  t;
 
@@ -1035,10 +1075,14 @@
 	return ioctl (fd, CDIOCPLAYBLOCKS, &t);
 }
 
-int setvol (int left, int right)
+static int
+setvol(int left, int right)
 {
 	struct ioc_vol  v;
 
+	left  = left  < 0 ? 0 : left  > 255 ? 255 : left;
+	right = right < 0 ? 0 : right > 255 ? 255 : right;
+
 	v.vol[0] = left;
 	v.vol[1] = right;
 	v.vol[2] = 0;
@@ -1047,7 +1091,8 @@
 	return ioctl (fd, CDIOCSETVOL, &v);
 }
 
-int read_toc_entrys (int len)
+static int
+read_toc_entrys(int len)
 {
 	struct ioc_read_toc_entry t;
 
@@ -1059,7 +1104,8 @@
 	return (ioctl (fd, CDIOREADTOCENTRYS, (char *) &t));
 }
 
-int play_msf (int start_m, int start_s, int start_f,
+static int
+play_msf(int start_m, int start_s, int start_f,
 	int end_m, int end_s, int end_f)
 {
 	struct ioc_play_msf a;
@@ -1074,7 +1120,8 @@
 	return ioctl (fd, CDIOCPLAYMSF, (char *) &a);
 }
 
-int status (int *trk, int *min, int *sec, int *frame)
+static int
+status(int *trk, int *min, int *sec, int *frame)
 {
 	struct ioc_read_subchannel s;
 	struct cd_sub_channel_info data;
@@ -1105,14 +1152,14 @@
 	return s.data->header.audio_status;
 }
 
-const char *
-cdcontrol_prompt()
+static const char *
+cdcontrol_prompt(void)
 {
 	return ("cdcontrol> ");
 }
 
-char *
-input (int *cmd)
+static char *
+input(int *cmd)
 {
 #define MAXLINE 80
 	static EditLine *el = NULL;
@@ -1161,7 +1208,8 @@
 	return (p);
 }
 
-char *parse (char *buf, int *cmd)
+static char *
+parse(char *buf, int *cmd)
 {
 	struct cmdtab *c;
 	char *p;
@@ -1225,7 +1273,8 @@
 	return p;
 }
 
-int open_cd ()
+static int
+open_cd(void)
 {
 	char devbuf[MAXPATHLEN];
 	const char *dev;



More information about the Midnightbsd-cvs mailing list