Initialize Tizen 2.3
[external/ragel.git] / test / erract6.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 cs 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         if ( fsm->cs == errintrans_error )
44                 return -1;
45         if ( fsm->cs >= errintrans_first_final )
46                 return 1;
47         return 0;
48 }
49
50
51 struct errintrans fsm;
52 #include <string.h>
53
54 void test( char *buf )
55 {
56         int len = strlen( buf );
57         errintrans_init( &fsm );
58         errintrans_execute( &fsm, buf, len );
59         if ( errintrans_finish( &fsm ) > 0 )
60                 printf("ACCEPT\n");
61         else
62                 printf("FAIL\n");
63 }
64
65
66 int main()
67 {
68         test(
69                 "good, does not have numbers\n"
70         );
71
72         test(
73                 "bad, has numbers 666\n"
74         );
75
76         return 0;
77 }
78
79 #ifdef _____OUTPUT_____
80 ACCEPT
81 FAIL
82 #endif