Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 108 lines (94 sloc) 3.041 kB
007e8db @frsyuki preprocess in ./preprocess instead of make
frsyuki authored
1 #!/usr/bin/env bash
2
3 RUBY="ruby"
4 ERB="erb"
5 RAGEL="ragel"
6
7 function r() {
8 echo "$@"
9 "$@"
10 }
11
12 function check_error() {
13 if [ "$1" != 0 ]; then
14 echo ""
15 echo "** preprocess failed **"
16 echo ""
17 exit 1
18 fi
19 }
20
21 function pre_h() {
22 file="$1"
23 out="$(dirname "$file")/$(basename "$file" .pre.h).h"
24 r "$RUBY" -e '
25 def args(n, &block) ;
26 Array.new(n) {|i| yield i+1} .join(", ") ;
27 end ;
28 src = File.read(ARGV[0]) ;
29 src.gsub!(/^MP_ARGS_BEGIN$(.*?)^MP_ARGS_END$/m) {|code| ;
30 result = [] ;
31 1.upto(15) {|n| ;
32 line = code.split("\n")[1..-2].join("\n") ;
33 line.gsub!(/MP_ARGS_TEMPLATE/, args(n) {|i| "typename A#{i}" }) ;
34 line.gsub!(/MP_ARGS_PARAMS_PTR/, args(n) {|i| "A#{i}* a#{i}" }) ;
35 line.gsub!(/MP_ARGS_PARAMS_REF/, args(n) {|i| "A#{i}& a#{i}" }) ;
36 line.gsub!(/MP_ARGS_PARAMS/, args(n) {|i| "A#{i} a#{i}" }) ;
37 line.gsub!(/MP_ARGS_FUNC/, args(n) {|i| "a#{i}" }) ;
38 line.gsub!(/MP_ARGS_TYPES_PTR/, args(n) {|i| "A#{i}*" }) ;
39 line.gsub!(/MP_ARGS_TYPES_REF/, args(n) {|i| "A#{i}&" }) ;
40 line.gsub!(/MP_ARGS_TYPES/, args(n) {|i| "A#{i}" }) ;
41 line.gsub!(/MP_ARGS_ITERATOR_BEGIN$(.*?)^MP_ARGS_ITERATOR_END$/m) {|sub| ;
42 subresult = [] ;
43 subline = sub.split("\n")[1..-2].join("\n") ;
44 1.upto(n) {|it| ;
45 sublineit = subline.dup ;
46 sublineit.gsub!(/MP_ARGS_ITERATOR_PARAM/, "a#{it}") ;
47 sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE_PTR/, "A#{it}*") ;
48 sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE_REF/, "A#{it}&") ;
49 sublineit.gsub!(/MP_ARGS_ITERATOR_TYPE/, "A#{it}") ;
50 sublineit.gsub!(/\[MP_ARGS_ITERATOR\]/, "#{it}" ) ;
51 if it == 1 ;
52 sublineit.gsub!(/MP_ARGS_ITERATOR_FIRST_COLON/, " " ) ;
53 else ;
54 sublineit.gsub!(/MP_ARGS_ITERATOR_FIRST_COLON/, "," ) ;
55 end ;
56 if it == n ;
57 sublineit.gsub!(/MP_ARGS_ITERATOR_LAST_COLON/, " " ) ;
58 else ;
59 sublineit.gsub!(/MP_ARGS_ITERATOR_LAST_COLON/, "," ) ;
60 end ;
61 subresult << sublineit ;
62 } ;
63 subresult.join("\n") ;
64 } ;
65 result << line ;
66 } ;
67 result.join("\n") ;
68 } ;
69 File.open(ARGV[1],"w") {|f| f.puts src }' "$file" "$out"
70 check_error $?
71 }
72
73 function pre_erb() {
74 file="$1"
75 out="$(dirname "$file")/$(basename "$file" .erb)"
76 echo "$ERB" "<" "$file" ">" "$out"
77 "$ERB" < "$file" > "$out"
78 check_error $?
79 }
80
81 pre_h src/mp/object_callback.pre.h
82 pre_h src/mp/wavy/core.pre.h
83 pre_h src/mp/wavy/singleton.pre.h
84
85 pre_erb src/log/mlogger.h.erb
86 pre_erb src/log/logpack.hpp.erb
87
88 r "$RAGEL" -C src/gate/memproto/memtext.rl -o src/gate/memproto/memtext.c
89 check_error $?
90
91 cwd="$(pwd)"
92
93 echo "cd $cwd/src/logic/gateway"
94 cd src/logic/gateway && r "$RUBY" "$cwd/src/logic/protogen" ../gateway.proto.h
95 check_error $?
96 cd "$cwd"
97
98 echo "cd $cwd/src/logic/manager"
99 cd src/logic/manager && r "$RUBY" "$cwd/src/logic/protogen" ../manager.proto.h
100 check_error $?
101 cd "$cwd"
102
103 echo "cd $cwd/src/logic/server"
104 cd src/logic/server && r "$RUBY" "$cwd/src/logic/protogen" ../server.proto.h
105 check_error $?
106 cd "$cwd"
107
Something went wrong with that request. Please try again.