-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate_cs.sh
58 lines (46 loc) · 1.02 KB
/
generate_cs.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
#!/bin/bash
#set -x
OUTPUT=cbusdefs.cs
echo "Generating $OUTPUT"
# first output the header stuff
cat << EOF > $OUTPUT
/* DO NOT EDIT THIS FILE.
* This file is automatically generated by $0 from cbusdefs.csv
*/
namespace merg.cbus
{
EOF
# output the comments
grep '^comment' cbusdefs.csv | cut -f2- -d , | sed 's!^! // !' |sed 's!,!!' | sed 's!,!!' >> $OUTPUT
cat << EOF >> $OUTPUT
public static class CbusDefs
{
EOF
# Each type is a static nested class.
for class in $(cat cbusdefs.csv|cut -f1 -d ,|grep -v comment|sort|uniq)
do
echo " CbusDefs.$class"
cat << EOF >> $OUTPUT
public static class $class
{
EOF
# now output the actual contents
while IFS="," read type name value comment
do
if [ $type = $class ]; then
if [ "X$name" = "X" ]; then
echo -e "\t\t\t// $value$comment"
else
echo -e "\t\t\tpublic const int $name\t= $value;\t// $comment"
fi
fi
done < cbusdefs.csv >> $OUTPUT
cat << EOF >> $OUTPUT
}
EOF
done
# finally output the trailer stuff
cat << EOF >> $OUTPUT
}
}
EOF