[Pkg-wmaker-commits] [wmrack] 24/97: rewrite the mixer-settings-file parser

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Aug 22 02:42:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmrack.

commit 91dc0028ec9f5af7bf8982ab096e23ea7f559da9
Author: Chris Waters <xtifr.w at gmail.com>
Date:   Thu Mar 8 17:37:34 2012 -0800

    rewrite the mixer-settings-file parser
---
 CHANGES  |  8 ++++++
 README   |  4 +--
 wmrack.1 |  2 +-
 wmrack.c | 90 +++++++++++++++++++++++++++++++++++++---------------------------
 4 files changed, 63 insertions(+), 41 deletions(-)

diff --git a/CHANGES b/CHANGES
index 82a36aa..43faf2b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+1.2 -> 1.3
+- rewrote the mixer settings file parsing logic almost completely to
+  be more robust, and to fix the bug (reported by Knut Anders Hatlen)
+  where WMRack would get confused about which mixer device to use when
+  two such devices had similar names (e.g. "pcm" and "pcm2").
+- changed "<linux/soundcard.h>" to "<sys/soundcard.h>", which should
+  be more portable.
+
 1.1 -> 1.2
 - removed some ugly macros that were causing some compilers to complain
   (mostly cosmetic changes, but extensive, and critical in a couple of cases)
diff --git a/README b/README
index 744d082..7264e66 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-wmrack 1.1
+wmrack 1.3
 
 The WindowMaker Sound Control Panel by Oliver Graf
 Currently maintained by Chris Waters <xtifr at users.sourceforge.net>
@@ -74,4 +74,4 @@ the progress of work, almost any part that was stolen, has been rewritten,
 restructured, and overworked.
 
 -----
-$Id: README,v 1.2 2001/02/14 10:19:19 xtifr Exp $
+$Id: README,v 1.3 2006/04/22 06:33:45 xtifr Exp $
diff --git a/wmrack.1 b/wmrack.1
index 93533ee..a27ce43 100644
--- a/wmrack.1
+++ b/wmrack.1
@@ -235,7 +235,7 @@ toggle record source button
 .B button-2
 set as record source and clear all other
 .SH COPYRIGHTS
-Copyright 1997, Oliver Graf <ograf at fga.de>.
+Copyright 1997, Oliver Graf <ograf at fga.de>.  2003-2006, Chris Waters
 Most styles copyright 1997, Heiko Wagner <hwagner at fga.de>.
 .Sp
 No guarantees or warranties or anything are provided or implied in any way
diff --git a/wmrack.c b/wmrack.c
index 2f0a86b..540975a 100644
--- a/wmrack.c
+++ b/wmrack.c
@@ -1,21 +1,21 @@
 /*
- * $Id: wmrack.c,v 1.3 2003/10/01 22:44:19 xtifr Exp $
+ * $Id: wmrack.c,v 1.4 2006/04/22 06:33:45 xtifr Exp $
  *
  * WMRack - WindowMaker Sound Control Panel
  *
- * Copyright (c) 1997 by Oliver Graf  <ograf at fga.de>   http://www.fga.de/~ograf/
- * Portions copyright (c) 2003 by Chris Waters <xtifr at users.sourceforge.net>>
+ * Copyright (c) 1997 by Oliver Graf  <ograf at fga.de>
+ * copyright 2003-2006 by Chris Waters <xtifr at users.sourceforge.net>
  *
- * ascd originally by Rob Malda <malda at cs.hope.edu>   http://www.cs.hope.edu/~malda/
+ * ascd originally by Rob Malda <malda at cs.hope.edu>
+ *   http://www.cs.hope.edu/~malda/
  *
  * This is an 'WindowMaker Look & Feel' Dock applet that can be
  * used to control the cdrom and the mixer.
  *
  * Should also work swallowed in any fvwm compatible button bar.
- *
  */
 
-#define WMR_VERSION "1.2"
+#define WMR_VERSION "1.3"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -37,6 +37,8 @@
 #include "mixer.h"
 #include "library.h"
 
+#define MAXRCLINE 1024
+
 /* Functions *****************************************************************/
 void usage ();
 void parseCmdLine (int argc, char *argv[]);
@@ -1468,8 +1470,9 @@ getTime ()
 int
 loadMixerRC ()
 {
-    char line[1024], dev[50], src[10], *d;
-    int i, l, r, n, j, err = 0;
+    char line[MAXRCLINE], dev[MAXRCLINE], src[MAXRCLINE], *d;
+    int i, j, err = 0;
+    int nfields, left, right;
 
     mixer_max = 0;
     mixer_lib = lib_open ("mixer", LIB_READ);
@@ -1480,47 +1483,58 @@ loadMixerRC ()
 	goto endload;
     }
 
-    while ((lib_gets (mixer_lib, line, 1024)) != NULL)
+    while ((lib_gets (mixer_lib, line, MAXRCLINE)) != NULL)
     {
-	for (i = 0; i < mixer_devices; i++)
-	    if (strncmp (line, mixer_names[i], strlen (mixer_names[i])) == 0)
-		break;
-	if (i < mixer_devices)
+	line[MAXRCLINE-1] = '\0';
+	dev[0] = src[0] = '\0';
+
+	nfields = sscanf (line, "%s %d:%d %s", &dev, &left, &right, &src);
+
+	if (nfields >= 3)	/* got at least the left & right info */
 	{
-	    n = sscanf (line, "%s %d:%d %s", &dev, &l, &r, &src);
-	    if (n > 1)
+	    for (i = 0; i < mixer_devices; i++)
 	    {
-		mixer_setvols (mixer, i, l, r);
-		if (strcmp (src, "src") == 0)
-		    mixer_setrecsrc (mixer, i, 1, 0);
+		if (strcmp (mixer_names[i], dev) == 0)
+		{
+		    mixer_setvols (mixer, i, left, right);
+		    if (strcmp (src, "src") == 0)
+		        mixer_setrecsrc (mixer, i, 1, 0);
+		    break;
+		}
 	    }
-	    *dev = *src = 0;
+#ifdef DEBUG
+	    if (i == mixer_devices)
+		fprintf (stderr, "wmrack: unsupported device '%s'\n", dev);
+#endif
 	}
-	else if (strncmp (line, "ORDER ", 6) == 0)
+	else   /* the sscanf failed, check for an ORDER line */
 	{
-	    for (d = strchr (line, 32); d != NULL; d = strchr (d, 32))
+	    d = strtok (line, " \t\n\r");
+	    if (strcmp (d, "ORDER") == 0)
 	    {
-		while (*d == 32)
-		    *d++;
-		if (*d == 0 || *d == '\n' || *d == '\r')
-		    break;
-		for (i = 0; i < mixer_devices; i++)
-		    if (strncmp (d, mixer_names[i], strlen (mixer_names[i]))
-			== 0)
-			break;
-		if (i < mixer_devices && mixer_isdevice (mixer, i))
+		while ((d = strtok (NULL, " \t\n\r")) != NULL)
 		{
-		    mixer_order[mixer_max++] = i;
+		    for (i = 0; i < mixer_devices; i++)
+			if (strcmp (d, mixer_names[i]) == 0)
+			    break;
+		    if (i < mixer_devices && mixer_isdevice (mixer, i))
+		    {
+			mixer_order[mixer_max++] = i;
 #ifdef DEBUG
-		    fprintf (stderr, "wmrack: mixer_order %d=%s\n", mixer_max,
-			     mixer_names[i]);
+			fprintf (stderr, "wmrack: mixer_order %d=%s\n",
+				 mixer_max, mixer_names[i]);
 #endif
-		}
+		    }
 #ifdef DEBUG
-		else
-		    fprintf (stderr, "wmrack: unsupported device '%s'\n", d);
+		    else
+		      fprintf (stderr, "wmrack: unsupported device '%s'\n", d);
 #endif
+		}
 	    }
+#if DEBUG
+	    else
+		fprintf (stderr, "wmrack: invalid setting '%s'\n", line);
+#endif
 	}
     }
 
@@ -1580,10 +1594,10 @@ saveMixerRC ()
     }
     if (mixer_max > 0)
     {
-	lib_printf (mixer_lib, "ORDER ");
+	lib_printf (mixer_lib, "ORDER");
 	for (i = 0; i < mixer_max; i++)
 	{
-	    lib_printf (mixer_lib, "%s ", mixer_names[mixer_order[i]]);
+	    lib_printf (mixer_lib, " %s", mixer_names[mixer_order[i]]);
 	}
 	lib_printf (mixer_lib, "\n");
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmrack.git



More information about the Pkg-wmaker-commits mailing list