1#!/bin/sh 2 3# Copyright (c) 2011-2014, Intel Corporation 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without modification, 7# are permitted provided that the following conditions are met: 8# 9# 1. Redistributions of source code must retain the above copyright notice, this 10# list of conditions and the following disclaimer. 11# 12# 2. Redistributions in binary form must reproduce the above copyright notice, 13# this list of conditions and the following disclaimer in the documentation and/or 14# other materials provided with the distribution. 15# 16# 3. Neither the name of the copyright holder nor the names of its contributors 17# may be used to endorse or promote products derived from this software without 18# specific prior written permission. 19# 20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 32 33# This script reads an asound.conf file and produce for each alsa mixeur 34# it's differend values and pcm 35# 36# ouput example : 37# 38# my_alsa_mixeur 39# true 40# a_pcm 41# an_other_pcm 42# false 43# in_this_pcm_my_alsa_mixer_takes_the_value_false 44# ... 45 46set -eu 47 48if test $# = 0 49then 50 file="-" 51else 52 file="$1" 53fi 54 55space=" " 56previous_command="" 57 58sed -nr -e 's#^pcm.(.*)\{.*$#\1#; t save; 59 b next; 60 :save;h;b' \ 61 \ 62 -e ':next; s/.*name\s+"(.*)"\s+value\s+([^}]*).*/\1 = \2 # /; t pcm; 63 b; 64 :pcm; G;s/\n//p;' -- "$file" | 65 sort | \ 66 while read line 67 do 68 current_command="$( echo "$line" | sed 's/ =.*#.*//' )" 69 #values are case insensitive 70 current_value="$( echo "$line" | sed 's/.*= \(.*\) #.*/\1/' | tr [:upper:] [:lower:] )" 71 current_mode="$( echo "$line" | sed 's/.*# //' )" 72 73 if test "$previous_command" != "$current_command" 74 then 75 echo "$current_command" 76 previous_command="$current_command" 77 previous_value="" 78 fi 79 80 81 if test "$previous_value" != "$current_value" 82 then 83 echo "$space$current_value" 84 previous_value="$current_value" 85 fi 86 87 echo "$space$space$current_mode" 88 done 89