1 [= AutoGen5 Template -*- Mode: text -*-
7 (setenv "SHELL" "/bin/sh")
9 (shellf "[ -f %1$s-fsm.h ] && mv -f %1$s-fsm.h .fsm.head
10 [ -f %1$s-fsm.c ] && mv -f %1$s-fsm.c .fsm.code" (base-name))
12 # AutoGen copyright 1992-2002 Bruce Korb
20 INCLUDE "fsm-trans.tpl" =][=
21 INCLUDE "fsm-macro.tpl" =][=
27 * This file enumerates the states and transition events for a FSM.
29 * te_[=(. pfx)=]_state
30 * The available states. FSS_INIT is always defined to be zero
31 * and FSS_INVALID and FSS_DONE are always made the last entries.
33 * te_[=(. pfx)=]_event
34 * The transition events. These enumerate the event values used
35 * to select the next state from the current state.
36 * [=(. PFX)=]_EV_INVALID is always defined at the end.
38 [=(make-header-guard "autofsm")=]
41 * Finite State machine States
43 * Count of non-terminal states. The generated states INVALID and DONE
44 * are terminal, but INIT is not :-).
46 #define [=(. PFX)=]_STATE_CT [=(+ 1 (count "state"))=]
49 (shellf "${COLUMNS_EXE-columns} --spread=1 -I4 -S, -f'%s_ST_%%s' <<_EOF_
54 _EOF_" PFX (string-upcase! (join "\n" (stack "state"))) )=]
55 } te_[=(. pfx)=]_state;
58 * Finite State machine transition Events.
60 * Count of the valid transition events
62 #define [=(. PFX)=]_EVENT_CT [=(count "event")=]
64 [= compute-transitions =][=
65 (shellf "${COLUMNS_EXE-columns} --spread=1 -I4 -S, -f'%s_EV_%%s' <<_EOF_
68 _EOF_" PFX (string-upcase! (join "\n" (stack "event"))) )=]
69 } te_[=(. pfx)=]_event;
76 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
78 # We are implementing the machine. Declare the external =][=
82 ~* step|reent =][= make-step-proc mode = "extern " =];[=
84 =* loop =][= make-loop-proc mode = "extern " =];[=
87 (error (string-append "invalid FSM type: ``" (get "type")
88 "'' must be ``looping'', ``stepping'' or ``reentrant''" ))
92 # End external procedure declarations
94 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
96 # We are *NOT* implementing the machine. Define the table =][=
99 enumerate-transitions use_ifdef = yes =][=
101 enumerate-transitions use_ifdef = yes =][=
104 "invalid FSM method: ``%s'' must be ``callout'', ``case'' or ``none''"
105 (get "method"))) =][=
108 #endif /* [=(. header-guard)=] */[=
110 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
112 # C OUTPUT BEGINS HERE
118 (if (~ (get "method") "(no.*){0,1}")
119 (begin (shell "rm -f .fsm.*") (out-delete)) ) =][=
125 #include "[=(. header-file)=]"
129 * Do not make changes to this file, except between the START/END
130 * comments, or it will be removed the next time it is generated.
132 [=(extract fsm-source "/* %s === USER HEADERS === %s */")=]
139 # define tSCC static const char
144 enumerate-transitions =][=
146 callback-transitions =][=
148 [=IF (=* (get "type") "step")=]
150 * The FSM machine state
152 static te_[=(. pfx)=]_state [=(. pfx)=]_state = [=(. PFX)=]_ST_INIT;
154 [= emit-invalid-msg =][=
156 IF (=* (get "method") "call") =][=
158 `set -- \`sed 's/,//' .fsm.xlist\`` =][=
162 invoke build-callback
163 cb_prefix = (string-append pfx "_do")
164 cb_name = (shell "echo $1 ; shift") =][=
166 ENDWHILE echo $# =][=
176 stepping-machine =][=