Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/audiocfg Revert about index number changes. It brea...



details:   https://anonhg.NetBSD.org/src/rev/4b7c344be754
branches:  trunk
changeset: 453729:4b7c344be754
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Aug 24 07:39:42 2019 +0000

description:
Revert about index number changes.  It breaks its usage and output format.
Pointed out by mrg@.

diffstat:

 usr.bin/audiocfg/audiodev.c |  25 ++++++-----
 usr.bin/audiocfg/audiodev.h |   4 +-
 usr.bin/audiocfg/main.c     |  95 +++++++++++++++++++++++++++-----------------
 3 files changed, 74 insertions(+), 50 deletions(-)

diffs (226 lines):

diff -r 17deff5f3bbd -r 4b7c344be754 usr.bin/audiocfg/audiodev.c
--- a/usr.bin/audiocfg/audiodev.c       Sat Aug 24 06:32:25 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.c       Sat Aug 24 07:39:42 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.14 2019/08/24 06:32:25 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.15 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -49,7 +49,6 @@
 
 static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
     TAILQ_HEAD_INITIALIZER(audiodevlist);
-static unsigned int maxunit;
 
 static int
 audiodev_getinfo(struct audiodev *adev)
@@ -138,9 +137,6 @@
 
        TAILQ_INSERT_TAIL(&audiodevlist, adev, next);
 
-       if (unit > maxunit)
-               maxunit = unit;
-
        return 0;
 }
 
@@ -182,22 +178,29 @@
 }
 
 unsigned int
-audiodev_maxunit(void)
+audiodev_count(void)
 {
-       return maxunit;
+       struct audiodev *adev;
+       unsigned int n;
+
+       n = 0;
+       TAILQ_FOREACH(adev, &audiodevlist, next)
+               ++n;
+
+       return n;
 }
 
-/*
- * Get audiodev corresponding to audio<i> device.
- */
 struct audiodev *
 audiodev_get(unsigned int i)
 {
        struct audiodev *adev;
+       unsigned int n;
 
+       n = 0;
        TAILQ_FOREACH(adev, &audiodevlist, next) {
-               if (i == adev->unit)
+               if (n == i)
                        return adev;
+               ++n;
        }
 
        return NULL;
diff -r 17deff5f3bbd -r 4b7c344be754 usr.bin/audiocfg/audiodev.h
--- a/usr.bin/audiocfg/audiodev.h       Sat Aug 24 06:32:25 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.h       Sat Aug 24 07:39:42 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.8 2019/08/24 05:45:25 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.9 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -60,7 +60,7 @@
 };
 
 int                    audiodev_refresh(void);
-unsigned int           audiodev_maxunit(void);
+unsigned int           audiodev_count(void);
 struct audiodev *      audiodev_get(unsigned int);
 int                    audiodev_set_default(struct audiodev *);
 int                    audiodev_set_param(struct audiodev *, int,
diff -r 17deff5f3bbd -r 4b7c344be754 usr.bin/audiocfg/main.c
--- a/usr.bin/audiocfg/main.c   Sat Aug 24 06:32:25 2019 +0000
+++ b/usr.bin/audiocfg/main.c   Sat Aug 24 07:39:42 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.15 2019/08/24 06:11:10 isaki Exp $ */
+/* $NetBSD: main.c,v 1.16 2019/08/24 07:39:42 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -75,15 +75,15 @@
 u_int encoding_max = __arraycount(encoding_names);
 
 static void
-print_audiodev(struct audiodev *adev)
+print_audiodev(struct audiodev *adev, int i)
 {
        struct audiofmt *f;
        int j;
 
        assert(adev != NULL);
 
-       printf("[%c] %s @ %s: ",
-           adev->defaultdev ? '*' : ' ',
+       printf("%u: [%c] %s @ %s: ",
+           i, adev->defaultdev ? '*' : ' ',
            adev->xname, adev->pxname);
        printf("%s", adev->audio_device.name);
        if (strlen(adev->audio_device.version) > 0)
@@ -142,28 +142,6 @@
        }
 }
 
-/* Always return non-null adev, or exit */
-static struct audiodev *
-getadev_fromstr(const char *str)
-{
-       struct audiodev *adev;
-       unsigned int i;
-
-       if (*str < '0' || *str > '9')
-               usage();
-               /* NOTREACHED */
-       errno = 0;
-       i = strtoul(str, NULL, 10);
-       if (errno)
-               usage();
-               /* NOTREACHED */
-       adev = audiodev_get(i);
-       if (adev == NULL) {
-               errx(EXIT_FAILURE, "no such device");
-       }
-       return adev;
-}
-
 int
 main(int argc, char *argv[])
 {
@@ -184,16 +162,36 @@
                /* NOTREACHED */
 
        if (strcmp(argv[1], "list") == 0 && argc == 2) {
-               n = audiodev_maxunit();
-               for (i = 0; i <= n; i++) {
-                       adev = audiodev_get(i);
-                       if (adev)
-                               print_audiodev(adev);
+               n = audiodev_count();
+               for (i = 0; i < n; i++)
+                       print_audiodev(audiodev_get(i), i);
+       } else if (strcmp(argv[1], "list") == 0 && argc == 3) {
+               if (*argv[2] < '0' || *argv[2] > '9')
+                       usage();
+                       /* NOTREACHED */
+               errno = 0;
+               i = strtoul(argv[2], NULL, 10);
+               if (errno)
+                       usage();
+                       /* NOTREACHED */
+               adev = audiodev_get(i);
+               if (adev == NULL) {
+                       errx(EXIT_FAILURE, "no such device");
                }
-       } else if (strcmp(argv[1], "list") == 0 && argc == 3) {
-               print_audiodev(getadev_fromstr(argv[2]));
+               print_audiodev(adev, i);
        } else if (strcmp(argv[1], "default") == 0 && argc == 3) {
-               adev = getadev_fromstr(argv[2]);
+               if (*argv[2] < '0' || *argv[2] > '9')
+                       usage();
+                       /* NOTREACHED */
+               errno = 0;
+               i = strtoul(argv[2], NULL, 10);
+               if (errno)
+                       usage();
+                       /* NOTREACHED */
+               adev = audiodev_get(i);
+               if (adev == NULL) {
+                       errx(EXIT_FAILURE, "no such device");
+               }
                printf("setting default audio device to %s\n", adev->xname);
                if (audiodev_set_default(adev) == -1) {
                        errx(EXIT_FAILURE, "couldn't set default device");
@@ -201,7 +199,19 @@
        } else if (strcmp(argv[1], "set") == 0 && argc == 8) {
                /* XXX bad commandline... */
                /* audiocfg set <index> [p|r] <enc> <prec> <ch> <freq> */
-               adev = getadev_fromstr(argv[2]);
+               if (*argv[2] < '0' || *argv[2] > '9')
+                       usage();
+                       /* NOTREACHED */
+               errno = 0;
+               i = strtoul(argv[2], NULL, 10);
+               if (errno)
+                       usage();
+                       /* NOTREACHED */
+               adev = audiodev_get(i);
+               if (adev == NULL) {
+                       errx(EXIT_FAILURE, "no such device");
+               }
+
                mode = 0;
                for (j = 0; j < strlen(argv[3]); j++) {
                        if (argv[3][j] == 'p')
@@ -233,8 +243,19 @@
                        errx(EXIT_FAILURE, "couldn't set parameter");
                }
        } else if (strcmp(argv[1], "test") == 0 && argc == 3) {
-               adev = getadev_fromstr(argv[2]);
-               print_audiodev(adev);
+               if (*argv[2] < '0' || *argv[2] > '9')
+                       usage();
+                       /* NOTREACHED */
+               errno = 0;
+               i = strtoul(argv[2], NULL, 10);
+               if (errno)
+                       usage();
+                       /* NOTREACHED */
+               adev = audiodev_get(i);
+               if (adev == NULL) {
+                       errx(EXIT_FAILURE, "no such device");
+               }
+               print_audiodev(adev, i);
                if (audiodev_test(adev) == -1)
                        return EXIT_FAILURE;
        } else



Home | Main Index | Thread Index | Old Index