1 /*   -*- buffer-read-only: t -*- vi: set ro:
2  *
3  *  DO NOT EDIT THIS FILE   (pseudo-fsm.h)
4  *
5  *  It has been AutoGen-ed
6  *  From the definitions    pseudo.def
7  *  and the template file   fsm
8  *
9  *  Automated Finite State Machine
10  *
11  *  Copyright (C) 1992-2018 Bruce Korb - all rights reserved
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name ``Bruce Korb'' nor the name of any other
22  *    contributor may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * AutoFSM IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
26  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 /*
38  *  This file enumerates the states and transition events for a FSM.
39  *
40  *  te_pm_state
41  *      The available states.  FSS_INIT is always defined to be zero
42  *      and FSS_INVALID and FSS_DONE are always made the last entries.
43  *
44  *  te_pm_event
45  *      The transition events.  These enumerate the event values used
46  *      to select the next state from the current state.
47  *      PM_EV_INVALID is always defined at the end.
48  */
49 #ifndef AUTOFSM_PSEUDO_FSM_H_GUARD
50 #define AUTOFSM_PSEUDO_FSM_H_GUARD 1
51 /**
52  *  Finite State machine States
53  *
54  *  Count of non-terminal states.  The generated states INVALID and DONE
55  *  are terminal, but INIT is not  :-).
56  */
57 #define PM_STATE_CT  5
58 typedef enum {
59     PM_ST_INIT,     PM_ST_ST_MARK,  PM_ST_AGEN,     PM_ST_TEMPL,
60     PM_ST_END_MARK, PM_ST_INVALID,  PM_ST_DONE
61 } te_pm_state;
62 
63 /**
64  *  Finite State machine transition Events.
65  *
66  *  Count of the valid transition events
67  */
68 #define PM_EVENT_CT 7
69 typedef enum {
70     PM_EV_ED_MODE,    PM_EV_MARKER,     PM_EV_END_PSEUDO, PM_EV_AUTOGEN,
71     PM_EV_TEMPLATE,   PM_EV_SUFFIX,     PM_EV_SCHEME,     PM_EV_INVALID
72 } te_pm_event;
73 
74 /**
75  *  Enumeration of the valid transition types
76  *  Some transition types may be common to several transitions.
77  */
78 typedef enum {
79     PM_TR_INIT_MARKER,
80     PM_TR_INVALID,
81     PM_TR_NOOP,
82     PM_TR_SKIP_ED_MODE,
83     PM_TR_TEMPL_MARKER,
84     PM_TR_TEMPL_SCHEME,
85     PM_TR_TEMPL_SUFFIX
86 } te_pm_trans;
87 #define PM_TRANSITION_CT  7
88 
89 /**
90  *  State transition handling map.  Map the state enumeration and the event
91  *  enumeration to the new state and the transition enumeration code (in that
92  *  order).  It is indexed by first the current state and then the event code.
93  */
94 typedef struct pm_transition t_pm_transition;
95 struct pm_transition {
96     te_pm_state  next_state;
97     te_pm_trans  transition;
98 };
99 
100 #ifndef DEFINE_FSM
101 extern const t_pm_transition pm_trans_table[ PM_STATE_CT ][ PM_EVENT_CT ];
102 
103 extern int
104 pm_invalid_transition( te_pm_state st, te_pm_event evt );
105 #else
106 const t_pm_transition
107 pm_trans_table[ PM_STATE_CT ][ PM_EVENT_CT ] = {
108 
109   /* STATE 0:  PM_ST_INIT */
110   { { PM_ST_INIT, PM_TR_SKIP_ED_MODE },             /* EVT:  -*- */
111     { PM_ST_ST_MARK, PM_TR_INIT_MARKER },           /* EVT:  MARKER */
112     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  END_PSEUDO */
113     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  AUTOGEN */
114     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  TEMPLATE */
115     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  SUFFIX */
116     { PM_ST_INVALID, PM_TR_INVALID }                /* EVT:  SCHEME */
117   },
118 
119 
120   /* STATE 1:  PM_ST_ST_MARK */
121   { { PM_ST_ST_MARK, PM_TR_SKIP_ED_MODE },          /* EVT:  -*- */
122     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  MARKER */
123     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  END_PSEUDO */
124     { PM_ST_AGEN, PM_TR_NOOP },                     /* EVT:  AUTOGEN */
125     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  TEMPLATE */
126     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  SUFFIX */
127     { PM_ST_INVALID, PM_TR_INVALID }                /* EVT:  SCHEME */
128   },
129 
130 
131   /* STATE 2:  PM_ST_AGEN */
132   { { PM_ST_AGEN, PM_TR_SKIP_ED_MODE },             /* EVT:  -*- */
133     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  MARKER */
134     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  END_PSEUDO */
135     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  AUTOGEN */
136     { PM_ST_TEMPL, PM_TR_NOOP },                    /* EVT:  TEMPLATE */
137     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  SUFFIX */
138     { PM_ST_INVALID, PM_TR_INVALID }                /* EVT:  SCHEME */
139   },
140 
141 
142   /* STATE 3:  PM_ST_TEMPL */
143   { { PM_ST_TEMPL, PM_TR_SKIP_ED_MODE },            /* EVT:  -*- */
144     { PM_ST_END_MARK, PM_TR_TEMPL_MARKER },         /* EVT:  MARKER */
145     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  END_PSEUDO */
146     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  AUTOGEN */
147     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  TEMPLATE */
148     { PM_ST_TEMPL, PM_TR_TEMPL_SUFFIX },            /* EVT:  SUFFIX */
149     { PM_ST_TEMPL, PM_TR_TEMPL_SCHEME }             /* EVT:  SCHEME */
150   },
151 
152 
153   /* STATE 4:  PM_ST_END_MARK */
154   { { PM_ST_END_MARK, PM_TR_INVALID },              /* EVT:  -*- */
155     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  MARKER */
156     { PM_ST_DONE, PM_TR_NOOP },                     /* EVT:  END_PSEUDO */
157     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  AUTOGEN */
158     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  TEMPLATE */
159     { PM_ST_INVALID, PM_TR_INVALID },               /* EVT:  SUFFIX */
160     { PM_ST_INVALID, PM_TR_INVALID }                /* EVT:  SCHEME */
161   }
162 };
163 #define PmFsmErr_off     19
164 #define PmEvInvalid_off  75
165 #define PmStInit_off     83
166 
167 
168 static char const zPmStrings[169] =
169 /*     0 */ "** OUT-OF-RANGE **\0"
170 /*    19 */ "FSM Error:  in state %d (%s), event %d (%s) is invalid\n\0"
171 /*    75 */ "invalid\0"
172 /*    83 */ "init\0"
173 /*    88 */ "st_mark\0"
174 /*    96 */ "agen\0"
175 /*   101 */ "templ\0"
176 /*   107 */ "end_mark\0"
177 /*   116 */ "-*-\0"
178 /*   120 */ "marker\0"
179 /*   127 */ "end_pseudo\0"
180 /*   138 */ "autogen\0"
181 /*   146 */ "template\0"
182 /*   155 */ "suffix\0"
183 /*   162 */ "scheme";
184 
185 static const size_t aszPmStates[5] = {
186     83,  88,  96,  101, 107 };
187 
188 static const size_t aszPmEvents[8] = {
189     116, 120, 127, 138, 146, 155, 162, 75 };
190 
191 
192 #define PM_EVT_NAME(t)   ( (((unsigned)(t)) >= 8) \
193     ? zPmStrings : zPmStrings + aszPmEvents[t])
194 
195 #define PM_STATE_NAME(s) ( (((unsigned)(s)) >= 5) \
196     ? zPmStrings : zPmStrings + aszPmStates[s])
197 
198 #ifndef EXIT_FAILURE
199 # define EXIT_FAILURE 1
200 #endif
201 
202 static int pm_invalid_transition( te_pm_state st, te_pm_event evt );
203 
204 /* * * * * * * * * THE CODE STARTS HERE * * * * * * * */
205 /**
206  *  Print out an invalid transition message and return EXIT_FAILURE
207  */
208 static int
pm_invalid_transition(te_pm_state st,te_pm_event evt)209 pm_invalid_transition( te_pm_state st, te_pm_event evt )
210 {
211     /* START == INVALID TRANS MSG == DO NOT CHANGE THIS COMMENT */
212     char const * fmt = zPmStrings + PmFsmErr_off;
213     fprintf( stderr, fmt, st, PM_STATE_NAME(st), evt, PM_EVT_NAME(evt));
214     /* END   == INVALID TRANS MSG == DO NOT CHANGE THIS COMMENT */
215 
216     return EXIT_FAILURE;
217 }
218 
219 #endif /* DEFINE_FSM */
220 
221 #endif /* AUTOFSM_PSEUDO_FSM_H_GUARD */
222 /*
223  * Local Variables:
224  * mode: C
225  * c-file-style: "stroustrup"
226  * indent-tabs-mode: nil
227  * End:
228  * end of pseudo-fsm.h */
229