-
Notifications
You must be signed in to change notification settings - Fork 8
/
ostrich-client
executable file
·147 lines (114 loc) · 3.43 KB
/
ostrich-client
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
#!/bin/sh
dotfilebase="/tmp/.ostrich"
JAVA=java
JAVA_OPTS="-Xss20000k -Xmx1500m"
me=`whoami`
portfile="$dotfilebase"_"$me"
errfile="$dotfilebase"_debug_"$me"
if [ $(uname) = "Linux" ]; then
pathCmd="readlink -f"
elif [ $(uname) = "Darwin" ]; then
pathCmd="stat -f %N"
else
pathCmd="realpath"
fi
################################################################################
startDaemon() {
lockfile="$dotfilebase"_lock_"$me"
while [ -f "$lockfile" ] && \
[ $(( `date +%s` - `date -r "$lockfile" +%s` )) -le 10 ]; do
# apparently a concurrent script is starting up the daemon
# already
echo "waiting ..."
sleep 1
done
if [ ! -f "$portfile" ]; then
touch "$lockfile"
BASEDIR=`dirname $($pathCmd $0)`
TARGET=`echo $BASEDIR/target/scala-*/ostrich-assembly*.jar`
tempportfile=`mktemp`
touch "$tempportfile"
chmod go-rwx "$tempportfile"
$JAVA $JAVA_OPTS -cp $TARGET ap.ServerMain >"$tempportfile" &
ostrichId=$!
sleep 1
while [ `wc -l "$tempportfile" | awk '{ printf $1 }'` -lt 2 ]; do
if ps -p $ostrichId >/dev/null; then
sleep 1
else
echo "Could not start server"
exit 1
fi
done
mv "$tempportfile" "$portfile"
rm "$lockfile"
# Make sure that the daemon knows about the string portfolios; for
# this, we have to start solving some initial string problem
$BASEDIR/ostrich-client -timeout=0 $BASEDIR/tests/1234.corecstrs.readable.smt2 >/dev/null
fi
}
################################################################################
stdintoexitstatus() {
read exitstatus
return $exitstatus
}
if [ ! -f "$portfile" ]; then
startDaemon
fi
mainProcess=$$
outputlogfile=`mktemp`
success=1
until [ $success -eq 0 ]; do
port=`head -n1 "$portfile"`
(
# send the ticket
tail -n1 "$portfile"
# command line arguments
ostrichSolver=ostrich.OstrichStringTheory
ostrichParams=""
for var; do
case "$var" in
[+-]eager | [+-]forward | -length=* | [+-]minimizeAutomata | [+-]parikh | -regexTranslator=* | [+-]forwardPropagation | [+-]backwardPropagation | [+-]nielsenSplitter)
if [ x"$ostrichParams" = x"" ]; then
ostrichParams=$var
else
ostrichParams=$ostrichParams,$var
fi
;;
-cea)
ostrichSolver=ostrich.OstrichStringTheory
;;
+cea)
ostrichSolver=ostrich.cesolver.stringtheory.CEStringTheory
;;
-*|+*)
echo "$var"
;;
*)
echo `$pathCmd "$var"`
;;
esac
done
echo "-stringSolver=$ostrichSolver:$ostrichParams"
echo "PROVE_AND_EXIT"
# ping the daemon every second, to show that we are still
# alive
{
sleep 1
while ps -p $mainProcess >/dev/null; do
echo "PING"
sleep 1
done
} &
) | (((( nc localhost $port; echo $? >&3 ) | \
tee $outputlogfile >&4) 3>&1) | stdintoexitstatus) 4>&1
success=$?
if [ $success -ne 0 ]; then
rm "$portfile"
startDaemon
else if grep -q '^ERROR:' $outputlogfile; then
rm $outputlogfile
exit 1
fi; fi
done
rm $outputlogfile