Install msysDTK-1.0.1
[msysgit.git] / share / autogen / fsm.tpl
blob87907908a420006cbecb2bfdbc78f960484a912e
1 [= AutoGen5 Template  -*- Mode: text -*-
3 h=%s-fsm.h
5 c=%s-fsm.c
7 (setenv "SHELL" "/bin/sh")
8 (define fmt "")
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
14 =][=
16 CASE (suffix) =][=
18 == h =][=
20   INCLUDE "fsm-trans.tpl" =][=
21   INCLUDE "fsm-macro.tpl" =][=
23   preamble     
27  *  This file enumerates the states and transition events for a FSM.
28  *
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.
32  *
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.
37  */
38 [=(make-header-guard "autofsm")=]
41  *  Finite State machine States
42  *
43  *  Count of non-terminal states.  The generated states INVALID and DONE
44  *  are terminal, but INIT is not  :-).
45  */
46 #define [=(. PFX)=]_STATE_CT  [=(+ 1 (count "state"))=]
47 typedef enum {
49   (shellf "${COLUMNS_EXE-columns} --spread=1 -I4 -S, -f'%s_ST_%%s' <<_EOF_
50 INIT
52 INVALID
53 DONE
54 _EOF_" PFX (string-upcase! (join "\n" (stack "state"))) )=]
55 } te_[=(. pfx)=]_state;
58  *  Finite State machine transition Events.
59  *
60  *  Count of the valid transition events
61  */
62 #define [=(. PFX)=]_EVENT_CT [=(count "event")=]
63 typedef enum {
64 [= compute-transitions =][=
65   (shellf "${COLUMNS_EXE-columns} --spread=1 -I4 -S, -f'%s_EV_%%s' <<_EOF_
67 INVALID
68 _EOF_" PFX (string-upcase! (join "\n" (stack "event"))) )=]
69 } te_[=(. pfx)=]_event;
72   CASE method  =][=
74   ~*  call|case=][=
76     # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
77     #
78     #   We are implementing the machine.  Declare the external  =][=
80     CASE type     =][=
82     ~* step|reent =][= make-step-proc mode = "extern " =];[=
84     =* loop       =][= make-loop-proc mode = "extern " =];[=
86     *             =][=
87     (error (string-append "invalid FSM type:  ``" (get "type")
88            "'' must be ``looping'', ``stepping'' or ``reentrant''" ))
89     =][=
90     ESAC          =][=
92     #  End external procedure declarations
93     #
94   # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
95   #
96   #   We are *NOT* implementing the machine.  Define the table  =][=
98   ==  ""       =][=
99     enumerate-transitions  use_ifdef = yes  =][=
100   =*  no       =][=
101     enumerate-transitions  use_ifdef = yes  =][=
102   *            =][=
103     (error (sprintf
104         "invalid FSM method:  ``%s'' must be ``callout'', ``case'' or ``none''"
105         (get "method"))) =][=
106   ESAC         =]
108 #endif /* [=(. header-guard)=] */[=
110 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
112 #   C OUTPUT BEGINS HERE
114 =][=
116 == c =][=
118   (if (~ (get "method") "(no.*){0,1}")
119       (begin (shell "rm -f .fsm.*") (out-delete))  ) =][=
121   preamble     
124 #define DEFINE_FSM
125 #include "[=(. header-file)=]"
126 #include <stdio.h>
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.
131  */
132 [=(extract fsm-source "/* %s === USER HEADERS === %s */")=]
134 #ifndef NULL
135 #  define NULL 0
136 #endif
138 #ifndef tSCC
139 #  define tSCC static const char
140 #endif
141 [= CASE method  =][=
143   =* "case"       =][=
144    enumerate-transitions =][=
145   =* "call"       =][=
146    callback-transitions  =][=
147   ESAC            =]
148 [=IF (=* (get "type") "step")=]
150  *  The FSM machine state
151  */
152 static te_[=(. pfx)=]_state [=(. pfx)=]_state = [=(. PFX)=]_ST_INIT;
153 [=ENDIF=]
154 [= emit-invalid-msg =][=
156   IF  (=* (get "method") "call")        =][=
158     `set -- \`sed 's/,//' .fsm.xlist\`` =][=
160     WHILE `echo $#`     =][=
162       invoke build-callback
163         cb_prefix = (string-append pfx "_do")
164         cb_name   = (shell "echo $1 ; shift") =][=
166     ENDWHILE  echo $#   =][=
168   ENDIF                 =][=
171   CASE type             =][=
173   =*  loop              =][=
174     looping-machine     =][=
175   ~*  step|reent        =][=
176     stepping-machine    =][=
177   ESAC                  =][=
179   `rm -f .fsm.*`        =][=
181 ESAC (suffix) =][=
183 trailer =]