aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xmlGenerator/analyse/sortAsound.conf.sh
blob: b607161a8f1f2850ee2a3975ad02e5321240da2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh

# INTEL CONFIDENTIAL
# Copyright  2013 Intel
# Corporation All Rights Reserved.
#
# The source code contained or described herein and all documents related to
# the source code ("Material") are owned by Intel Corporation or its suppliers
# or licensors. Title to the Material remains with Intel Corporation or its
# suppliers and licensors. The Material contains trade secrets and proprietary
# and confidential information of Intel or its suppliers and licensors. The
# Material is protected by worldwide copyright and trade secret laws and
# treaty provisions. No part of the Material may be used, copied, reproduced,
# modified, published, uploaded, posted, transmitted, distributed, or
# disclosed in any way without Intels prior express written permission.
#
# No license under any patent, copyright, trade secret or other intellectual
# property right is granted to or conferred upon you by disclosure or delivery
# of the Materials, either expressly, by implication, inducement, estoppel or
# otherwise. Any license under such intellectual property rights must be
# express and approved by Intel in writing.


# This script reads an asound.conf file and produce for each alsa mixeur
# it's differend values and pcm
#
# ouput example :
#
# my_alsa_mixeur
#     true
#        a_pcm
#         an_other_pcm
#    false
#         in_this_pcm_my_alsa_mixer_takes_the_value_false
# ...

set -eu

if test $# = 0
then
    file="-"
else
    file="$1"
fi

space="    "
previous_command=""

sed -nr -e 's#^pcm.(.*)\{.*$#\1#; t save;
        b next;
        :save;h;b' \
    \
    -e ':next; s/.*name "(.*)" value ([^}]*).*/\1 = \2 # /; t pcm;
        b;
        :pcm; G;s/\n//p;' -- "$file" |
    sort | \
    while read line
    do
        current_command="$( echo "$line" | sed 's/ =.*#.*//' )"
        #values are case insensitive
        current_value="$( echo "$line" | sed 's/.*= \(.*\) #.*/\1/' | tr [:upper:] [:lower:] )"
        current_mode="$( echo "$line" | sed 's/.*# //' )"

        if test "$previous_command" != "$current_command"
        then
            echo "$current_command"
            previous_command="$current_command"
            previous_value=""
        fi


        if test  "$previous_value" != "$current_value"
        then
            echo "$space$current_value"
            previous_value="$current_value"
        fi

        echo "$space$space$current_mode"
    done