summaryrefslogtreecommitdiff
path: root/support/dktools/dkct-tr.h
blob: ab2311ccb95ebbfae59103427dd2e970142d9214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

/**	@file	dkct-tr.h	Header file for the dkct-tr module.
*/

#ifndef DKCT_TR_H_INCLUDED
#define	DKCT_TR_H_INCLUDED 1


#if DK3_USE_WX
#include "DkWxCommunicator.h"
#endif


/**	State machine entry (input, output state).
*/
typedef struct {
  char const	*name;		/**< Name. */
  char const	*comment;	/**< Comment text. */
  unsigned long	 lineno;	/**< Line number of definition. */
  int		 value;		/**< Numeric value. */
  char		 flag;		/**< Flag: Numeric value set. */
} DKCT_STM_ENTRY;



/**	Transition rule.
*/
typedef struct {
  DKCT_STM_ENTRY	*state;		/**< Current (old) state. */
  DKCT_STM_ENTRY	*input;		/**< Input. */
  DKCT_STM_ENTRY	*newstate;	/**< New state. */
  DKCT_STM_ENTRY	*output;	/**< Output. */
  unsigned long		 lineno;	/**< Line number of definition. */
} DKCT_STM_RULE;



/**	State machine description.
*/
typedef struct {
  dk3_sto_t	*s_states;	/**< Storage for states. */
  dk3_sto_it_t	*i_states;	/**< Iterator for states. */
  dk3_sto_t	*s_inputs;	/**< Storage for inputs. */
  dk3_sto_it_t	*i_inputs;	/**< Iterator for inputs. */
  dk3_sto_t	*s_outputs;	/**< Storage for outputs. */
  dk3_sto_it_t	*i_outputs;	/**< Iterator for outputs. */
  dk3_sto_t	*s_exact;	/**< Storage for exact rules. */
  dk3_sto_it_t	*i_exact;	/**< Iterator for exact rules. */
  dk3_sto_t	*s_wildcard;	/**< Storage for one-wildcard rules. */
  dk3_sto_it_t	*i_wildcard;	/**< Iterator for one-wildcard rules. */
  char const	*name;		/**< State machine name. */
  DKCT_STM_ENTRY	*rs;	/**< Reset state. */
  DKCT_STM_ENTRY	*ds;	/**< Default state. */
  DKCT_STM_ENTRY	*dout;	/**< Default output. */
  unsigned long	 stmno;		/**< State machine number. */
  unsigned long	 lineno;	/**< Line number of start. */
  unsigned long	 lngr;		/**< Line number of general rule. */
  int		 wrh;		/**< Flag: Write definitions to header. */
  int		 section;	/**< Current section. */
} DKCT_STM;



/**	One input source line.
*/
typedef struct {
  char const	*t;	/**< Text. */
  unsigned long	 l;	/**< Line number. */
} DKCT_LINE;



/**	One source file read in.
*/
typedef struct {
  DKCT_OPTION_SET	dkcto;	/**< Conversion options. */
  dk3_app_t		*app;	/**< Application structure. */
  dkChar const * const	*msg;	/**< Localized message texts. */
  dkChar const		*ffn;	/**< Full source file name. */
  dk3_sto_t		*hss;	/**< Header start storage. */
  dk3_sto_it_t		*hsi;	/**< Header start iterator. */
  dk3_sto_t		*hes;	/**< Header end storage. */
  dk3_sto_it_t		*hei;	/**< Header end iterator. */
  dk3_sto_t		*clss;	/**< Class start storage. */
  dk3_sto_it_t		*clsi;	/**< Class start iterator. */
  dk3_sto_t		*cles;	/**< Class end storage. */
  dk3_sto_it_t		*clei;	/**< Class end iterator. */
  dk3_sto_t		*mss;	/**< Module start storage. */
  dk3_sto_it_t		*msi;	/**< Module start iterator. */
  dk3_sto_t		*mes;	/**< Module end iterator. */
  dk3_sto_it_t		*mei;	/**< Module end iterator. */
  dk3_sto_t		*coss;	/**< Constructor start storage. */
  dk3_sto_it_t		*cosi;	/**< Constructor start iterator. */
  dk3_sto_t		*coes;	/**< Constructor end iterator. */
  dk3_sto_it_t		*coei;	/**< Constructor end iterator. */
  dk3_sto_t		*s_stm;	/**< Storage for state machines. */
  dk3_sto_it_t		*i_stm;	/**< Iterator for state machines. */
  dk3_sto_it_t		*cursr;	/**< Current source. */
  DKCT_STM		*cstm;	/**< Current state machine. */
  void			*gui;	/**< GUI description. */
  FILE			*fipo;	/**< Output file. */
  FILE			*cbfip;	/**< Comment box file. */
  char const		*sfn;	/**< Short file name. */
  char const		*crn;	/**< Copyright name. */
  char const		*cry;	/**< Copyright year. */
  char			*cmdb;	/**< Command buffer. */
  char			*cbfn;	/**< Comment box file name. */
  unsigned long		lineno;	/**< Current line number. */
  size_t		 szcmd;	/**< Size of command buffer. */
  size_t		 ucmd;	/**< Used characters in command buffer. */
  size_t		 cbcp;	/**< Comment box current position. */
  size_t		 cbmx;	/**< Comment box max line length. */
  int			 lict;	/**< License type. */
  int			 type;	/**< Source type. */
  int			 ec;	/**< Error code. */
  int			 st;	/**< Current state. */
  int			 sufi;	/**< Source suffix index. */
  int			 doxyh;	/**< Doxygen comment found in header. */
  int			 doxym;	/**< Doxygen comment found in module. */
  int			 shln;	/**< Flag: Show line number. */
  int			 curdi;	/**< Flag: Processing the current directory. */
  int			 hdr;	/**< Flag: Currently processing header. */
  char			 cchr;	/**< Current character to process. */
#if DK3_USE_WX
  DkWxCommunicator	*pComm;	/**< Communicator for threads. */
#endif
} DKCT_SRC;


/**	@defgroup	dkctsections	Source file sections.
*/
/**@{*/

/**	Start of module.
*/
#define	DKCT_SECTION_MODULE_START	0

/**	End of module
*/
#define DKCT_SECTION_MODULE_END		1

/**	Start of constructor.
*/
#define	DKCT_SECTION_CONSTRUCTOR_START	2

/**	End of constructor.
*/
#define DKCT_SECTION_CONSTRUCTOR_END	3

/**	Start of header.
*/
#define	DKCT_SECTION_HEADER_START	4

/**	End of header.
*/
#define	DKCT_SECTION_HEADER_END		5

/**	Start of class.
*/
#define	DKCT_SECTION_CLASS_START	6

/**	End of class.
*/
#define	DKCT_SECTION_CLASS_END		7

/**	Options.
*/
#define	DKCT_SECTION_OPTIONS		8

/**	wxWidgets GUI.
*/
#define	DKCT_SECTION_GUI		9

/**	State machine description.
*/
#define	DKCT_SECTION_STATE_MACHINE	10

/**@}*/



#ifdef __cplusplus
extern "C" {
#endif

/**	Destroy line structure.
	@param	p	Structure to destroy.
*/
void
dkct_tr_line_delete(DKCT_LINE *p);

/**	Create new source line.
	@param	t	Text.
	@param	l	Line number.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	Pointer to new line structure on success, NULL on error.
*/
DKCT_LINE *
dkct_tr_line_new(char const *t, unsigned long l, dk3_app_t *app);

/**	Destroy dkct-tr source structure.
	@param	p	Structure to destroy.
*/
void
dkct_tr_delete(DKCT_SRC *p);

/**	Create new dkct-tr source structure.
	@param	o	Option set.
	@param	fn	Short file name.
	@param	ai	File suffix array index.
	@param	app	Application structure for diagnostics, may be NULL.
	@param	ffn	Full source file name.
	@return	Pointer to new structure on success, NULL on error.
*/
DKCT_SRC *
dkct_tr_new(
  DKCT_OPTION_SET	*o,
  char const		*fn,
  int			 ai,
  dk3_app_t		*app,
  dkChar const		*ffn
);

/**	Read source file.
	@param	psrc	Source file structure to store data.
	@param	fn	Source file name.
	@param	sufi	File name suffix index.
	@return	1 on success, 0 on error.
*/
int
dkct_tr_read(DKCT_SRC *psrc, dkChar const *fn, int sufi);

/**	Check setup (especially GUI).
	@param	psrc	Source file structure to store data.
	@param	fn	Source file name.
	@param	sufi	File name suffix index.
	@return	1 on success, 0 on error.
*/
int
dkct_tr_check(DKCT_SRC *psrc, dkChar const *fn, int sufi);

/**	Write output.
	@param	psrc	Source file structure to store data.
	@param	fn	Source file name.
	@param	sufi	File name suffix index.
	@return	1 on success, 0 on error.
*/
int
dkct_tr_write(DKCT_SRC *psrc, dkChar const *fn, int sufi);

/**	Create new state machine description.
	@param	lineno	Source line number.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	Pointer to new structure on success, NULL on error.
*/
DKCT_STM *
dkct_au_stm_new(unsigned long lineno, dk3_app_t *app);

/**	Destroy state machine description.
	@param	p	Structure to destroy.
*/
void
dkct_au_stm_delete(DKCT_STM *p);

/**	Add one text line to state machine description.
	@param	stm	State machine description.
	@param	psrc	Source structure.
	@param	line	Text to add.
	@param	lineno	Line number.
	@return	1 on success, 0 on error.
*/
int
dkct_au_add_line(
  DKCT_STM *stm, DKCT_SRC *psrc, char *line, unsigned long lineno
);

/**	Check state machine consistency.
	@param	psrc	Source structure.
	@param	stm	State machine to check.
	@return	1 on success, 0 on error.
*/
int
dkct_au_stm_check(DKCT_SRC *psrc, DKCT_STM *stm);

/**	Write "#line ..." information to output.
	@param	psrc	Source structure.
	@param	newlines	Number of newlines to use in counting.
*/
void
dkct_tr_show_source_line(DKCT_SRC *psrc, size_t newlines);

/**	Write state, input and output constants.
	@param	psrc	Source structure.
	@param	stm	State machine.
*/
void
dkct_au_write_entries(DKCT_SRC *psrc, DKCT_STM *stm);

/**	Write function prototypes for state machine.
	@param	psrc	Source structure.
	@param	stm	State machine.
*/
void
dkct_au_write_prototypes(DKCT_SRC *psrc, DKCT_STM *stm);

/**	Write state machine functions.
	@param	psrc	Source structure.
	@param	stm	State machine.
	@param	f_static	Flag: Use static keyword.
*/
void
dkct_au_write_functions(DKCT_SRC *psrc, DKCT_STM *stm, int f_static);

/**	Get one of the dkct-tr keywords.
	@param	sz	Keyword index.
	@return	Pointer to keyword or NULL.
*/
char const *
dkct_tr_get_kw8(size_t sz);

/**	Write string containing file name and line number to output.
	@param	psrc	Source structure.
*/
void
dkct_tr_show_filename_and_lineno(DKCT_SRC *psrc);

/**	Log one message.
	@param	psrc	Source structure.
	@param	scope	Scope (0=GUI only, 1=app+GUI).
	@param	ll	Log level.
	@param	i1	Index of message text in \a psrc->msg.
*/
void
dkct_to_log_1(DKCT_SRC *psrc, int scope, int ll, size_t i1);

/**	Log one message.
	@param	psrc	Source structure.
	@param	scope	Scope (0=GUI only, 1=app+GUI).
	@param	ll	Log level.
	@param	i1	Index of message text in \a psrc->msg.
	@param	i2	Index of second fixed text in \a psrc->msg.
	@param	text	Variable text part.
*/
void
dkct_to_log_3(
  DKCT_SRC *psrc, int scope, int ll, size_t i1, size_t i2, char const *text
);

/**	Log one message.
	@param	psrc	Source structure.
	@param	scope	Scope (0=GUI only, 1=app+GUI).
	@param	ll	Log level.
	@param	i1	Index of message text in \a psrc->msg.
	@param	i2	Index of second fixed text in \a psrc->msg.
	@param	text	Variable text part.
*/
void
dkct_to_log_dk_3(
  DKCT_SRC *psrc, int scope, int ll, size_t i1, size_t i2, dkChar const *text
);


#ifdef __cplusplus
}
#endif

#endif