HowTos/NewPacket: Some updates
[senf.git] / doclib / dot
index fca62c8..a0efac5 100755 (executable)
@@ -2,4 +2,37 @@
 
 topdir="`dirname "$0"`"; topdir="`cd "$topdir/.."; pwd`"
 "$topdir/doclib/dot-munge.pl" "$1"
-exec dot "$@"
+
+case "$2" in
+    -Tpng:gd)
+       first="$1"; shift; shift
+       set -- "$first" "-Tpng" "$@"
+       ;;
+    *)
+esac
+
+set -e
+
+dot "$@"
+if [ -r "$4" ]; then
+    size="`pngtopnm "$4" | sed -n -e '2p'`"
+    width_a="${size% *}"
+    height_a="${size#* }"
+    if [ $width_a -gt 800 ]; then
+       for file in "${1%.dot}".*; do
+           cp "$file" "$file.a"
+       done
+       sed -e 's/rankdir=LR/rankdir=TB/' -e t -e 's/rankdir=TB/rankdir=LR/' "$1.a" > "$1"
+       dot "$@"
+       size="`pngtopnm "$4" | sed -n -e '2p'`"
+       width_b="${size% *}"
+       height_b="${size#* }"
+       if [ $width_a -lt $width_b ]; then
+           for file in "${1%.dot}".*.a; do
+               mv "$file" "${file%.a}"
+           done
+       else
+           rm "${1%.dot}".*.a
+       fi
+    fi
+fi