-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.sh
executable file
·171 lines (130 loc) · 3.57 KB
/
autogen.sh
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh -e
# Copyright 2013-2015 go-diameter authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Generate Diameter constants from our dictionaries.
#
# Run `sh autogen.sh` to re-generate these files after changing
# dictionary XML files.
os="$(uname -s)"
if [ -z "$SED" ]; then
if [ "$os" = "Darwin" ]; then
command -v gsed || {
echo "gsed is required. install it by running 'brew install gnu-sed'"
exit 1
}
SED="gsed"
else
SED="sed"
fi
fi
if [ -z "$SORT_FLAG_IGNORE_CASE" ]; then
if [ "$os" = "Darwin" ]; then
SORT_FLAG_IGNORE_CASE="-f"
fi
fi
dict=*.xml
## Generate commands.go
src=commands.go
cat << EOF > $src
// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is auto-generated from our dictionaries.
package diam
// Diameter command codes.
const (
EOF
cat $dict | "$SED" \
-e 's/-//g' \
-ne 's/.*command code="\(.*\)" .* name="\(.*\)".*/\2 = \1/p' \
| sort -u >> $src
echo ')\n// Short Command Names\nconst (\n' >> $src
cat $dict | "$SED" \
-e 's/-//g' \
-ne 's/.*command code="[0-9]*".*\s.*short="\([^"]*\).*/\1R = "\1R"\n\1A = "\1A"/p' \
| sort -u >> $src
echo ')' >> $src
go fmt $src
## Generate applications.go
src=applications.go
cat << EOF > $src
// Copyright 2013-2018 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is auto-generated from our dictionaries.
package diam
// Diameter application IDs.
const (
EOF
cat $dict | "$SED" \
-e :1 -e 's/\("[^"]*\)[[:space:]]\([^"]*"\)/\1_\2/g;t1' \
-ne 's/\s*<application\s*id="\([0-9]*\)".*name="\(.*\)".*/\U\2_APP_ID = \1/p' \
| sort -u | sort -nk 3 >> $src
echo ')\n' >> $src
go fmt $src
## Generate avp/codes.go
src=avp/codes.go
cat << EOF > $src
// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is auto-generated from our dictionaries.
package avp
// Diameter AVP types.
const (
EOF
cat $dict | "$SED" \
-e 's/-Id\([-"s]\)/-ID\1/g' \
-e 's/-//g' \
-ne 's/.*avp name="\(.*\)" code="\([0-9]*\)".*/\1 = \2/p' \
| LC_COLLATE=C sort -u $SORT_FLAG_IGNORE_CASE >> $src
echo ')\n' >> $src
go fmt $src
## Generate dict/default.go
src=dict/default.go
cat << EOF > $src
// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is auto-generated from our dictionaries.
package dict
import (
"bytes"
"fmt"
)
// Default is a Parser object with pre-loaded
// Base Protocol and Credit Control dictionaries.
var Default *Parser
func init() {
var dictionaries = []struct{ name, xml string }{
{"Base", baseXML},
{"Credit Control", creditcontrolXML},
{"Gx Charging Control", gxcreditcontrolXML},
{"Network Access Server", networkaccessserverXML},
{"TGPP", tgpprorfXML},
{"TGPP_S6a", tgpps6aXML},
{"TGPP_Swx", tgppswxXML},
}
var err error
Default, err = NewParser()
if err != nil {
panic(err)
}
for _, dict := range dictionaries {
err = Default.Load(bytes.NewReader([]byte(dict.xml)))
if err != nil {
panic(fmt.Sprintf("Cannot load %s dictionary: %s", dict.name, err))
}
}
}
EOF
for f in $dict
do
var=`basename $f | "$SED" -e 's/\.xml/XML/g' -e 's/_//g'`
cat << EOF >> $src
var $var=\``cat $f`\`
EOF
done
go fmt $src