ksh to bash
[anna.git] / source / diameter / stack / setups / flags.sh
1 #!/bin/bash
2
3 _exit() {
4    echo
5    echo $1
6    echo
7    exit
8 }
9
10 _print() {
11    result=
12    must=-
13    may=-
14    shouldnot=-
15    mustnot=-
16    enc=-
17    [[ "$V" = "must" ]] && must="$must,V"
18    [[ "$M" = "must" ]] && must="$must,M"
19    [[ "$P" = "must" ]] && must="$must,P"
20    [[ "$V" = "may" ]] && may="$may,V"
21    [[ "$M" = "may" ]] && may="$may,M"
22    [[ "$P" = "may" ]] && may="$may,P"
23    [[ "$V" = "shouldnot" ]] && shouldnot="$shouldnot,V"
24    [[ "$M" = "shouldnot" ]] && shouldnot="$shouldnot,M"
25    [[ "$P" = "shouldnot" ]] && shouldnot="$shouldnot,P"
26    [[ "$V" = "mustnot" ]] && mustnot="$mustnot,V"
27    [[ "$M" = "mustnot" ]] && mustnot="$mustnot,M"
28    [[ "$P" = "mustnot" ]] && mustnot="$mustnot,P"
29    [[ "$ENC" = "yes" ]] && enc="$enc,Y"
30    [[ "$ENC" = "no" ]] && enc="$enc,N"
31
32    _must=$(echo $must | cut -d',' -f2-)
33    _may=$(echo $may | cut -d',' -f2-)
34    _shouldnot=$(echo $shouldnot | cut -d',' -f2-)
35    _mustnot=$(echo $mustnot | cut -d',' -f2-)
36    _enc=$(echo $enc | cut -d',' -f2-)
37
38    printf "%50s %2s %10s %2s %10s %2s %10s %2s %10s %2s %10s\n" $AVP "|" $_must "|" $_may "|" $_shouldnot "|" $_mustnot "|" $_enc
39 }
40
41
42 [[ "$1" = "" ]] && _exit "Use: $0 <avps dictionary>, i.e.: $0 avps_ietf.xml"
43 FILE=$1
44 BN_FILE=`basename $FILE`
45 TMP_FILE=.${BN_FILE}.tmp
46
47 grep "<avp name=" $FILE > $TMP_FILE
48
49 printf "%50s %2s %10s %2s %10s %2s %10s %2s %10s %2s %10s\n" AVP "|" Must "|" May "|" "Should Not" "|" "Must Not" "|" "May Encrypt"
50 echo "-------------------------------------------------------------------------------------------------------------------------"
51
52 while read -r line
53 do
54    AVP=$(echo $line | awk -F'avp name=' '{ print $2 }' | cut -d'"' -f2)
55    V=$(echo $line | awk -F'v-bit=' '{ print $2 }' | cut -d'"' -f2)
56    M=$(echo $line | awk -F'm-bit=' '{ print $2 }' | cut -d'"' -f2)
57    P=$(echo $line | awk -F'p-bit=' '{ print $2 }' | cut -d'"' -f2)
58    ENC=$(echo $line | awk -F'may-encrypt=' '{ print $2 }' | cut -d'"' -f2)
59
60    _print
61
62 done < $TMP_FILE
63
64
65
66 rm $TMP_FILE