3 # Author: Pekka Riikonen <priikone@silcnet.org>
5 # Copyright (C) 2005 Pekka Riikonen
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # Usage: ./fsmgraph file | dot -Tps -o outfile.ps
18 # Graphviz dot is required to create the graphs.
20 ##############################################################################
23 starts=`awk '/^SILC_FSM_STATE\(/,/^}/ { next } { print }' $@ | grep "silc_fsm_start" | cut -d, -f2 | cut -d\) -f1`
26 states=`grep "^SILC_FSM_STATE(" $@ | grep -v ");" | cut -d\( -f2 | cut -d\) -f1`
34 echo "\"start $i\" [shape=plaintext];"
35 echo "\"start $i\" -> $i;"
38 # Draw states and transitions
43 # This weird line gets us all state transitions and their optioanl
44 # comment lines which be put as labels
45 tr=`cat $@ | grep -v "^SILC_FSM_STATE($i);" | awk '/^SILC_FSM_STATE\('$i'\)/,/^}/ { if (/\/\*\* /) print; if (/silc_fsm_next/) print; }' | sed 's/^[ ]*//; s/\\/\\*\\* /L:/; s/\\*\\///; s/silc_fsm_next/T:silc_fsm_next/' | sed '/L:/s/ /\\\\/g; /T:/s/ /\\\\/g; s/T:/T: /; s/L:/L: /'`
48 threads=`cat $@ | grep -v "^SILC_FSM_STATE($i);" | awk '/^SILC_FSM_STATE\('$i'\)/,/^}/ { if (/\/\*\*\* /) print; if (/silc_fsm_start/) print; }' | sed 's/^[ ]*//; s/\\/\\*\\*\\* /L:/; s/\\*\\///; s/silc_fsm_start/T:silc_fsm_start/' | sed '/L:/s/ /\\\\/g; /T:/s/ /\\\\/g; s/T:/T: /; s/L:/L: /'`
51 asyncs=`cat $@ | grep -v "^SILC_FSM_STATE($i);" | awk '/^SILC_FSM_STATE\('$i'\)/,/^}/ { if (/SILC_FSM_CALL\(/) print; }' | sed 's/SILC_FSM_CALL(//' | cut -d= -f2 | cut -d\( -f1`
59 if test "$t" = "L:"; then
63 if test "$t" = "T:"; then
67 if test "$label" = "L:"; then
71 if test "$trname" = "T:"; then
76 if test "$label"; then
77 label=`echo $label | sed 's/\\\\/ /g'`
79 trname=`echo $trname | sed 's/\\\\/ /g'`
80 trname=`echo $trname | cut -d, -f2 | cut -d\) -f1`
82 echo "$i -> $trname [label=\" $label \"];"
88 # Draw thread transitions
91 if test "$t" = "L:"; then
95 if test "$t" = "T:"; then
99 if test "$label" = "L:"; then
103 if test "$trname" = "T:"; then
108 if test "$label"; then
109 label=`echo $label | sed 's/\\\\/ /g'`
111 trname=`echo $trname | sed 's/\\\\/ /g'`
112 trname=`echo $trname | cut -d, -f2 | cut -d\) -f1`
114 echo "$i -> $trname [label=\" $label \"] [style=dotted];"
123 echo "\"$a\" [shape=plaintext];"
124 echo "$i -> \"$a\" [style=dotted];"