#!/bin/ksh if [[ $# -ne 1 ]]; then echo "Usage : $0 /path/to/my/savedgame.sav.xz" exit 1 fi name=$(basename $1 .sav.xz) tmp_in=$name.diplo out=$name.dot #AL1_diplo_ww1.sh ~/.freeciv/saves/fc322_WW1_T0.sav.xz xzgrep -e "^nation=" -e "^\"Team" -e "^\"Alliance" -e "^\"Peace" -e "^\"Armistice" -e "^\"Cease-fire" -e "^\"War" -e "^\"Never met" $1 |cut -d "," -f1 |sed -e s/\"//g >$tmp_in # nation=Italian # Never met # Alliance # Cease-fire # read the file once to get nations'names nat=$(fgrep '=' $tmp_in |cut -d= -f2) nation=( ${nat} ) N=${#nation[@]} color=(black green gray yellow orange red) long=(0.75 1. 1.25 1.5 1.75 2.) #long=(3. 3. 3. 1.5 1. 0.5) echo "graph { overlap=false; splines=true" > $out i=-1 j=0 cat $tmp_in | while read line do c=$(echo $line | fgrep -c '=') if [[ $c -eq 1 ]]; then i=$(( $i + 1 )) j=0 #nation="italian" echo "${nation[i]}" continue fi if [[ $i -ge $j ]]; then # skip i==j myself # skip j nothing to do j=$(( $j + 1 )) continue fi # only print Team+Alliance vs War (in case of numerous nations like WW1 scen) if [[ $link -eq 0 || $link -eq 1 || $link -eq 5 ]]; then # echo $i,$j # corner case for last element if [[ $i -lt $N && $j -lt $N ]]; then echo "${nation[i]} -- ${nation[j]} [color=\"${color[$link]}\", len=\"${long[$link]}\", style="bold"];">>$out fi fi j=$(( $j + 1 )) done echo "}" >>$out # graphviz tools # maybe adding options can help : -Lg -Ln100 -LT1000 */ circo -Lg -Ln100 -LT1000 -Tpng -o $name.circo.png $out # my prefered one neato -Lg -Ln100 -LT1000 -Tpng -o $name.neato.png $out fdp -Lg -Ln100 -LT1000 -Tpng -o $name.fdp.png $out