The cs variable is now always initialized, unless the "nocs" option is given to
[external/ragel.git] / test / errintrans.rl
1 /*
2  * @LANG: c
3  */
4
5 /*
6  * Test of a transition going to the error state.
7  */
8
9 #include <stdio.h>
10 #define BUFSIZE 2048
11
12 struct errintrans
13 {
14         int cs;
15 };
16
17 %%{
18         machine errintrans;
19         variable curstate fsm->cs;
20
21         char = any - (digit | '\n');
22         line = char* "\n";
23         main := line+;
24 }%%
25
26 %% write data;
27
28 void errintrans_init( struct errintrans *fsm )
29 {
30         %% write init;
31 }
32
33 void errintrans_execute( struct errintrans *fsm, const char *_data, int _len )
34 {
35         const char *p = _data;
36         const char *pe = _data+_len;
37
38         %% write exec;
39 }
40
41 int errintrans_finish( struct errintrans *fsm )
42 {
43         %% write eof;
44
45         if ( fsm->cs == errintrans_error )
46                 return -1;
47         if ( fsm->cs >= errintrans_first_final )
48                 return 1;
49         return 0;
50 }
51
52
53 struct errintrans fsm;
54 #include <string.h>
55
56 void test( char *buf )
57 {
58         int len = strlen( buf );
59         errintrans_init( &fsm );
60         errintrans_execute( &fsm, buf, len );
61         if ( errintrans_finish( &fsm ) > 0 )
62                 printf("ACCEPT\n");
63         else
64                 printf("FAIL\n");
65 }
66
67
68 int main()
69 {
70         test(
71                 "good, does not have numbers\n"
72         );
73
74         test(
75                 "bad, has numbers 666\n"
76         );
77
78         return 0;
79 }
80
81 #ifdef _____OUTPUT_____
82 ACCEPT
83 FAIL
84 #endif