author | sultana |
Sat, 14 Apr 2012 15:08:59 +0100 | |
changeset 47473 | 111cd6351613 |
parent 47412 | aac1aa93f1ea |
child 47517 | 6bc4c66d8c1b |
permissions | -rwxr-xr-x |
47412 | 1 |
#!/usr/bin/env bash |
2 |
# |
|
3 |
# Author: Nik Sultana, Cambridge University Computer Lab |
|
4 |
# |
|
5 |
# DESCRIPTION: TPTP visualisation utility |
|
6 |
||
7 |
||
8 |
PRG="$(basename "$0")" |
|
9 |
||
10 |
#FIXME inline or move to settings |
|
11 |
DOT2TEX=dot2tex |
|
12 |
DOT=dot |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
13 |
PERL=perl |
47412 | 14 |
PDFLATEX=pdflatex |
15 |
[ -n "$ISABELLE_PDFLATEX" ] && PDFLATEX=$ISABELLE_PDFLATEX |
|
16 |
DOT2TEX_VERSION="$($DOT2TEX -V 2> /dev/null)" |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
17 |
DOT_VERSION="$($DOT -V 2>&1 | grep Graphviz)" |
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
18 |
PERL_VERSION="$($PERL -v | grep -e "v[0-9]\+." 2> /dev/null)" |
47412 | 19 |
PDFLATEX_VERSION="$($PDFLATEX -version | head -1 2> /dev/null)" |
20 |
||
21 |
function check_deps() |
|
22 |
{ |
|
23 |
#FIXME how well does this work across different platforms and/or versions of |
|
24 |
# the tools? |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
25 |
for DEP in DOT2TEX DOT PERL PDFLATEX |
47412 | 26 |
do |
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
27 |
eval DEP_VAL=\$${DEP} |
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
28 |
eval DEP_VERSION=\$${DEP}_VERSION |
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
29 |
if [ -z "$DEP_VERSION" ]; then |
47412 | 30 |
echo "$DEP not installed" |
31 |
else |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
32 |
echo "$DEP ($DEP_VAL) : $DEP_VERSION" |
47412 | 33 |
fi |
34 |
done |
|
35 |
} |
|
36 |
||
37 |
function usage() { |
|
38 |
echo |
|
39 |
echo "Usage: isabelle $PRG [OPTIONS] IN_FILE OUT_FILE" |
|
40 |
echo |
|
41 |
echo " Options are:" |
|
42 |
echo " -d probe for dependencies" |
|
43 |
echo " -k don't delete temp files, and print their location" |
|
44 |
echo " -n print name of the generated file" |
|
45 |
echo |
|
46 |
echo " Produces a DOT/TeX/PDF from a TPTP problem/proof, depending on whether" |
|
47 |
echo " the extension of OUT_FILE is dot/tex/pdf." |
|
48 |
echo |
|
49 |
exit 1 |
|
50 |
} |
|
51 |
||
52 |
OUTPUT_FORMAT=2 |
|
53 |
SHOW_TARGET="" |
|
54 |
KEEP_TEMP="" |
|
55 |
NON_EXEC="" |
|
56 |
||
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
57 |
while getopts "dnkX" OPT |
47412 | 58 |
do |
59 |
#FIXME could add "quiet" mode to send stderr (and some stdout) to /dev/null |
|
60 |
case "$OPT" in |
|
61 |
n) |
|
62 |
SHOW_TARGET=true |
|
63 |
;; |
|
64 |
k) |
|
65 |
KEEP_TEMP=true |
|
66 |
;; |
|
67 |
X) |
|
68 |
NON_EXEC=true |
|
69 |
;; |
|
70 |
d) |
|
71 |
check_deps |
|
72 |
exit 0 |
|
73 |
;; |
|
74 |
esac |
|
75 |
done |
|
76 |
||
77 |
shift $(($OPTIND - 1)) |
|
78 |
[ "$#" -ne 2 -o "$1" = "-?" ] && usage |
|
79 |
||
80 |
case "${2##*.}" in |
|
81 |
dot) |
|
82 |
OUTPUT_FORMAT=0 |
|
83 |
;; |
|
84 |
tex) |
|
85 |
OUTPUT_FORMAT=1 |
|
86 |
;; |
|
87 |
pdf) |
|
88 |
OUTPUT_FORMAT=2 |
|
89 |
;; |
|
90 |
*) |
|
91 |
echo "Unrecognised output file extension." |
|
92 |
exit 1 |
|
93 |
;; |
|
94 |
esac |
|
95 |
||
96 |
function generate_dot() |
|
97 |
{ |
|
98 |
#FIXME using a thy might be more robust |
|
99 |
LOADER="use \"$TPTP_HOME/TPTP_Parser/ml_yacc_lib.ML\"; \ |
|
100 |
use \"$TPTP_HOME/TPTP_Parser/tptp_syntax.ML\"; \ |
|
101 |
use \"$TPTP_HOME/TPTP_Parser/tptp_lexyacc.ML\"; \ |
|
102 |
use \"$TPTP_HOME/TPTP_Parser/tptp_parser.ML\"; \ |
|
103 |
(*\"$TPTP_HOME/TPTP_Parser/tptp_problem_name.ML\";*) \ |
|
104 |
use \"$TPTP_HOME/TPTP_Parser/tptp_proof.ML\"; \ |
|
105 |
use \"$TPTP_HOME/TPTP_Parser/tptp_to_dot.ML\"; \ |
|
106 |
TPTP_To_Dot.write_proof_dot \"$1\" \"$2\"; exit 0;" |
|
107 |
"$ISABELLE_PROCESS" -e "$LOADER" Pure |
|
108 |
} |
|
109 |
||
110 |
if [ "$OUTPUT_FORMAT" -eq 0 ]; then |
|
111 |
[ -z "$NON_EXEC" ] && generate_dot "$1" "$2" |
|
112 |
exit 0 |
|
113 |
fi |
|
114 |
||
115 |
## set some essential variables |
|
116 |
||
117 |
WORKDIR="" |
|
118 |
while : |
|
119 |
do |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
120 |
#FIXME not perfectly reliable method, but probably good enough |
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
121 |
WORKDIR="${ISABELLE_TMP_PREFIX}-tptpgraph$RANDOM" |
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
122 |
[ ! -d "$WORKDIR" ] && break |
47412 | 123 |
done |
124 |
OUTPUT_FILENAME="$(basename "$2")" |
|
125 |
FILEDIR="$(cd "$(dirname "$2")"; cd "$(pwd -P)"; pwd)" |
|
126 |
FILENAME="${OUTPUT_FILENAME%.*}" |
|
127 |
WD="$(pwd)" |
|
128 |
||
129 |
## generate and process files in temporary workdir, then move to destination dir |
|
130 |
||
131 |
mkdir -p $WORKDIR |
|
132 |
[ -z "$NON_EXEC" ] && generate_dot $1 "$WORKDIR/${FILENAME}.dot" |
|
133 |
cd $WORKDIR |
|
134 |
if [ -z "$NON_EXEC" ]; then |
|
135 |
$DOT -Txdot "${FILENAME}.dot" \ |
|
136 |
| $DOT2TEX -f pgf -t raw --crop > "${FILENAME}.tex" |
|
47473
111cd6351613
aligned tptp_graph dependencies to Isabelle conventions;
sultana
parents:
47412
diff
changeset
|
137 |
$PERL -w -p -e 's/_/\\_/g' "${FILENAME}.tex" |
47412 | 138 |
fi |
139 |
||
140 |
if [ "$OUTPUT_FORMAT" -eq 1 ]; then |
|
141 |
TARGET=$FILENAME.tex |
|
142 |
else |
|
143 |
TARGET=$FILENAME.pdf |
|
144 |
[ -z "$NON_EXEC" ] && $PDFLATEX "${FILENAME}.tex" |
|
145 |
fi |
|
146 |
[ -z "$NON_EXEC" ] && mv $TARGET $WD |
|
147 |
cd $WD |
|
148 |
if [ -n "$KEEP_TEMP" ]; then |
|
149 |
echo $WORKDIR |
|
150 |
else |
|
151 |
rm -rf $WORKDIR |
|
152 |
fi |
|
153 |
||
154 |
[ -n "$SHOW_TARGET" ] && echo "$FILEDIR/$TARGET" |