summaryrefslogtreecommitdiffhomepage
path: root/digital
diff options
context:
space:
mode:
authorJerome Jutteau2013-04-03 17:34:26 +0200
committerJerome Jutteau2013-04-06 13:29:43 +0200
commitf2dea26e5ef391abd8bf663b7cd2f46b46b66b39 (patch)
tree8a0ede834bc2a4f58d486cd9dbcbefd571314de8 /digital
parent3d9a5e6ff6d98f9dc09b123918755f0f7711a6c7 (diff)
digital/ai/src/fsm: better dot generation for branches
Diffstat (limited to 'digital')
-rw-r--r--digital/ai/src/fsm/angfsm.host.c49
1 files changed, 39 insertions, 10 deletions
diff --git a/digital/ai/src/fsm/angfsm.host.c b/digital/ai/src/fsm/angfsm.host.c
index 9de8cbea..8a2bd195 100644
--- a/digital/ai/src/fsm/angfsm.host.c
+++ b/digital/ai/src/fsm/angfsm.host.c
@@ -404,6 +404,7 @@ angfsm_build_gen_dot (angfsm_build_t *fsm, char* output)
angfsm_build_trans_chain_t *tc;
angfsm_build_branch_chain_t *bc;
char *fn = NULL;
+ uint dummy_node_cnt = 0;
if (!output || strlen (output) == 0)
{
uint fns = strlen (fsm->name) + strlen ("angfsm_.dot") + 1;
@@ -426,15 +427,43 @@ angfsm_build_gen_dot (angfsm_build_t *fsm, char* output)
while (tc != NULL)
{
bc = tc->trans.output_branches;
- while (bc != NULL)
+ /* This transition has several branches. */
+ if (bc != NULL && bc->next != NULL)
{
- fprintf (f, "\t%s -> %s [label=\"%s",
+ /* Create a dummy node. */
+ dummy_node_cnt++;
+ fprintf (f, "\tdummy_node_%u [shape=\"point\", width=0, height=0]\n",
+ dummy_node_cnt);
+ /* Connect dummy node to state. */
+ fprintf (f, "\t%s -> dummy_node_%u [label=\"%s\", arrowhead=\"none\""
+ ", arrowtail=\"none\", penwidth=2",
tc->trans.state->var_name,
- bc->state->var_name,
+ dummy_node_cnt,
tc->trans.event->var_name);
- if (bc->name != NULL)
- fprintf (f, " (%s)", bc->name);
- fprintf (f, "\"");
+ /* Colorise if previous state. */
+ for (j = 0; j < fsm->max_active_states; j++)
+ if (fsm->run.events_before_active_state[j]
+ && fsm->run.events_before_active_state[j]->code
+ == tc->trans.event->code)
+ fprintf (f, ", color=\"red\"");
+ fprintf (f, "];\n");
+ }
+ while (bc != NULL)
+ {
+ if (bc->name == NULL)
+ {
+ fprintf (f, "\t%s -> %s [label=\"%s\"",
+ tc->trans.state->var_name,
+ bc->state->var_name,
+ tc->trans.event->var_name);
+ }
+ else
+ {
+ fprintf (f, "\tdummy_node_%u -> %s [label=\"(%s)\"",
+ dummy_node_cnt,
+ bc->state->var_name,
+ bc->name);
+ }
/* If the next state is an active state we look if this this event
* was handled before. */
for (j = 0; j < fsm->max_active_states; j++)
@@ -443,7 +472,7 @@ angfsm_build_gen_dot (angfsm_build_t *fsm, char* output)
if (fsm->run.events_before_active_state[j]
&& fsm->run.events_before_active_state[j]->code
== tc->trans.event->code)
- fprintf (f, ", color=red");
+ fprintf (f, ", color=\"red\"");
fprintf (f, "];\n");
bc = bc->next;
@@ -453,7 +482,7 @@ angfsm_build_gen_dot (angfsm_build_t *fsm, char* output)
/* Colorise active states. */
for (j = 0; j < fsm->max_active_states; j++)
if (fsm->run.active_states[j])
- fprintf (f, "\t%s [color=blue, fontcolor=white, style=filled];\n",
+ fprintf (f, "\t%s [color=\"blue\", fontcolor=\"white\", style=\"filled\"];\n",
fsm->run.active_states[j]->var_name);
fprintf (f, "}\n\n");
@@ -942,8 +971,8 @@ angfsm_build_start_with (angfsm_build_t *fsm, const char *starters)
malloc (sizeof (angfsm_build_state_chain_t));
angfsm_build_state_t *s = angfsm_build_get_state (fsm, args[i]);
if (!s)
- fprintf (stderr, "Error: starting state \"%s\" in fsm \"%s\" has "
- "not been declared.\n", args[i], fsm->name);
+ fprintf (stderr, "Error: starting state \"%s\" in fsm \"%s\" has "
+ "not been declared.\n", args[i], fsm->name);
assert (s);
sc->state = *s;
sc->next = fsm->starters;