-
Notifications
You must be signed in to change notification settings - Fork 16
/
preprocess
executable file
·107 lines (94 loc) · 2.97 KB
/
preprocess
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
#!/usr/bin/env bash
RUBY="ruby"
ERB="erb"
RAGEL="ragel"
function r() {
echo "$@"
"$@"
}
function check_error() {
if [ "$1" != 0 ]; then
echo ""
echo "** preprocess failed **"
echo ""
exit 1
fi
}
function pre_h() {
file="$1"
out="$(dirname "$file")/$(basename "$file" .pre.h).h"
r "$RUBY" -e '
def args(n, &block) ;
Array.new(n) {|i| yield i+1} .join(", ") ;
end ;
src = File.read(ARGV[0]) ;
src.gsub!(/^MP_ARGS_BEGIN$(.*?)^MP_ARGS_END$/m) {|code| ;
result = [] ;
1.upto(15) {|n| ;
line = code.split("\n")[1..-2].join("\n") ;
line.gsub!(/MP_ARGS_TEMPLATE/, args(n) {|i| "typename A#{i}" }) ;
line.gsub!(/MP_ARGS_PARAMS_PTR/, args(n) {|i| "A#{i}* a#{i}" }) ;
line.gsub!(/MP_ARGS_PARAMS_REF/, args(n) {|i| "A#{i}& a#{i}" }) ;
line.gsub!(/MP_ARGS_PARAMS/, args(n) {|i| "A#{i} a#{i}" }) ;
line.gsub!(/MP_ARGS_FUNC/, args(n) {|i| "a#{i}" }) ;
line.gsub!(/MP_ARGS_TYPES_PTR/, args(n) {|i| "A#{i}*" }) ;
line.gsub!(/MP_ARGS_TYPES_REF/, args(n) {|i| "A#{i}&" }) ;
line.gsub!(/MP_ARGS_TYPES/, args(n) {|i| "A#{i}" }) ;
line.gsub!(/MP_ARGS_ITERATOR_BEGIN$(.*?)^MP_ARGS_ITERATOR_END$/m) {|sub| ;
subresult = [] ;
subline = sub.split("\n")[1..-2].join("\n") ;
1.upto(n) {|it| ;
sublineit = subline.dup ;
sublineit.gsub!(/MP_ARGS_ITERATOR_PARAM/, "a#{it}") ;
sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE_PTR/, "A#{it}*") ;
sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE_REF/, "A#{it}&") ;
sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE/, "A#{it}") ;
sublineit.gsub!(/\[MP_ARGS_ITERATOR\]/, "#{it}" ) ;
if it == 1 ;
sublineit.gsub!(/MP_ARGS_ITERATOR_FIRST_COLON/, " " ) ;
else ;
sublineit.gsub!(/MP_ARGS_ITERATOR_FIRST_COLON/, "," ) ;
end ;
if it == n ;
sublineit.gsub!(/MP_ARGS_ITERATOR_LAST_COLON/, " " ) ;
else ;
sublineit.gsub!(/MP_ARGS_ITERATOR_LAST_COLON/, "," ) ;
end ;
subresult << sublineit ;
} ;
subresult.join("\n") ;
} ;
result << line ;
} ;
result.join("\n") ;
} ;
File.open(ARGV[1],"w") {|f| f.puts src }' "$file" "$out"
check_error $?
}
function pre_erb() {
file="$1"
out="$(dirname "$file")/$(basename "$file" .erb)"
echo "$ERB" "<" "$file" ">" "$out"
"$ERB" < "$file" > "$out"
check_error $?
}
pre_h src/mp/object_callback.pre.h
pre_h src/mp/wavy/core.pre.h
pre_h src/mp/wavy/singleton.pre.h
pre_erb src/log/mlogger.h.erb
pre_erb src/log/logpack.hpp.erb
r "$RAGEL" -C src/gate/memproto/memtext.rl -o src/gate/memproto/memtext.c
check_error $?
cwd="$(pwd)"
echo "cd $cwd/src/logic/gateway"
cd src/logic/gateway && r "$RUBY" "$cwd/src/logic/protogen" ../gateway.proto.h
check_error $?
cd "$cwd"
echo "cd $cwd/src/logic/manager"
cd src/logic/manager && r "$RUBY" "$cwd/src/logic/protogen" ../manager.proto.h
check_error $?
cd "$cwd"
echo "cd $cwd/src/logic/server"
cd src/logic/server && r "$RUBY" "$cwd/src/logic/protogen" ../server.proto.h
check_error $?
cd "$cwd"